Академический Документы
Профессиональный Документы
Культура Документы
message$t
Ping
Pong
Radio#essage.h
nodeid% unsigned integer "alue represents the nodeid of the destination. broad&tat% unsigned integer "alue that has two different "alues according to the type of communication. 'n unicast, broadstat will ha"e the se(uence number of how many time Ping has Pong-ed. 'n broadcast or when Ping send a unicast, broadstat will always be ).
*+ecution Se,uence%
he Ping-Pong project e*ecutes as the following% +- Ping application boots first, waits for a timer to fire and then send a broadcast message. he reason of making Ping application waits, is gi"ing Pong application some time to load and be ready to reply for the broadcast message ,broadstat=0-.
event void Timer0.fired() {............``````` call AMSend.send(AM_BROADCAST_ADDR, &pkt, sizeof(RadioMsg))
S!CC"SS
Ping application will continue to broadcast a message .e"ery / seconds0 as long as it doesn1t recei"e any reply from Pong. he broadcast will stop upon recei"ing%
call Timer0.stop();
2- 3hen Pong application recei"es the broadcast message, it e*tracts the sender address and replies with a unicast to that address, the message used in this unicast has% nodeid %4 he address of the node who send a broadcast. broad&tat %4 'n a first unicast, this field will start counting the number of unicast operation done by Pong, the counter starts at +.
newMsg -> nodeid = TO !"O#$!%#; newMsg-> &road tat = &road tat; &road tat = &road tat ' (; if (call )nicast end.send(ping"ode%#* +p,t* si-eof(.adioMsg)) {call 1eds.led0Toggle();2
==
/00$
5- 3hen Ping application recei"es the unicast message, it e*tracts the sender address, builds a UAR message ,type: message$t- and send it to the P! monitor and then replies to the sender with a unicast
message.
newMsg -> nodeid = TO !"O#$!%#; pong"ode%# = &trp,t3 -> nodeid; newMsg -> &road tat = 0; if (call 4M end.send(pong"ode%#* +p,t* si-eof(.adioMsg)) call 1eds.led(Toggle();2
==
/00$
){
6- he unicast process will continue to happen the same way until the "alue of broad&tat will be 2), then the unicast communication between Ping and Pong applications will stop. if(&road tat 5= 30) 678ong 4pplication67
!ompiling Pong% Plug a mote to a U&7 port and run the following commands after changing directory to Pong application directory%
ma,e telos& s)do 7&in7c9mod ::: 7dev7tt;/ <0 ma,e telos& reinstall*=0 &sl*7dev7tt;/ <0