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!