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!