How can i implement Active, Idle and Sleep Modes to a Node using Timer or without Timer?
显示 更早的评论
I want to implement active, idle and sleep modes in LEACH protocol. How can i do this using timer? is there there any method exists in MAT LAB?
采纳的回答
更多回答(1 个)
Sagher
2018-4-11
0 个投票
3 个评论
Walter Roberson
2018-4-11
This should not be difficult for you to write. Create a struct to represent events. The event queue is a struct array of individual events. Keep the struct array sorted by time the event is intended to start. At each step, act on the first entry in the queue.
If you have multiple entries with the same time stamp, it is important that you simulate the confusion caused by multiple simultaneous reads and writes to the same data.
Sagher
2018-4-25
Walter Roberson
2018-4-25
num_nodes = [length(first_structure), length(second_structure), length(third_structure), ...];
total_number_of_nodes = sum(num_nodes);
running_total = cumsum([0, num_nodes]);
idx = randi(total_number_of_nodes);
struct_number = find(running_total <= idx, 1, 'first');
offset = idx - running_total(struct_number);
switch struct_number
case 1:
random_node = first_structure(offset);
case 2:
random_node = second_structure(offset);
case 3:
random_node = third_structure(offset);
case 4:
random_node = fourth_structure(offset);
otherwise:
error('How did structure_number get to be %d??', struct_number);
end
The code would be somewhat simpler and less error-prone if all of the data was in one structure, like
num_nodes = structfun(@length, master_structure);
...
random_node = master_structure(struct_number).node_structure(offset);
类别
在 帮助中心 和 File Exchange 中查找有关 WSNs 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!