How can i implement Active, Idle and Sleep Modes to a Node using Timer or without Timer?
Show older comments
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?
Accepted Answer
More Answers (1)
Sagher
on 11 Apr 2018
0 votes
3 Comments
Walter Roberson
on 11 Apr 2018
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
on 25 Apr 2018
Walter Roberson
on 25 Apr 2018
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);
Categories
Find more on WSNs in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!