忻州师范学院电子系课程设计
第 1 页
function x=animation_data
small=5; medium=20; large=50;
% Event_name Animated Color/{on/off/toggle} Size
anim_def={...
{'Init_Application', 0, [0 0 0 ], small}, ...
{'Packet_Sent', 1, [0 1 0 ], small}, ...
{'Packet_Received', 1, [0 1 0 ], small}, ...
{'Collided_Packet_Received', 0, [1 0 0 ], small}, ...
{'Clock_Tick', 0, [0 0 0 ], small}, ...
{'Channel_Request', 0, [0 0 0 ], small}, ...
{'Channel_Idle_Check', 1, [1 0 0 ], small}, ...
{'Packet_Receive_Start' 0, [0 1 0 ], small}, ...
{'Packet_Receive_End', 0, [0 0 0 ], small}, ...
{'Packet_Transmit_Start', 1, [1 0 0 ], medium}, ...
{'Packet_Transmit_End', 0, [0 1 0 ], small}};
for i=1:length(anim_def)
a=anim_def{i};
x(i)=struct('event', a{1}, 'animated', a{2}, 'color', a{3},
'size', a{4});
end
function application(S)
% DO NOT edit simulator code (lines that begin with S;)
S; persistent app_data
S; global ID t
S; [t, event, ID, data]=get_event(S);
S; [topology, mote_IDs]=prowler('GetTopologyInfo'); S;
ix=find(mote_IDs==ID);
S; if ~strcmp(event, 'Init_Application')
S; try memory=app_data{ix}; catch memory=[]; end
S; end
S;
switch event
case 'Init_Application'
signal_strength=1;
if ID==1 % first node starts flood
Set_Clock(1000)
end
PrintMessage('i')