pseudocode;
1-boot (red led)
broadcast the packet,after send done(green light)
- receive the packet, decode the packet and set led accordingly as (set blue)
- broadcast the packet after coding, send done (set led green)
- receive packet, decode it and set led accordingly as (set 7 (red+green+blue))
after this stage mote 1 will bet LED.set(7) and mote 2 will be LED.set(2) [mote 1 has started the transmission] ,till there it works very fine. but when i restart mote 1 it works till 2 steps of pseudocode and mote 2 could not able to receive the packet)
implementation{
bool busy = FALSE;
message_t pkt;
message_t i_pkt;
event void Boot.booted() {
call Leds.set(1);
call AMControl.start();
printf("Booted %d\n",1);
call CC2420Packet.setPower(&pkt, 20);
call CC2420Packet.setPower(&i_pkt, 2);
}
event void Timer0.fired() {
if (!busy) {
FindRoute_t *btrpkt = (FindRoute_t*)(call Packet.getPayload(&pkt, sizeof (FindRoute_t)));
btrpkt->counter = 4;
if (call firstsender.send(AM_BROADCAST_ADDR, &pkt, sizeof(FindRoute_t)) == SUCCESS) {
busy = TRUE;
}
}
}
event void AMControl.startDone(error_t err) {
if (err == SUCCESS) {
call Timer0.startOneShot(250);
}
else {
call AMControl.start();
}
}
event void AMControl.stopDone(error_t err) {
}
event void firstsender.sendDone(message_t *msg, error_t error) {
if (&pkt == msg) {
call Leds.set(2);
busy = FALSE;
}
}
event message_t* firstreceiver.receive(message_t* msg, void* payload, uint8_t len) {
if (len == sizeof(FindRoute_t)) {
FindRoute_t* btrpkt = (FindRoute_t*)payload;
call Leds.set(btrpkt->counter);
call Timer1.startOneShot(3000);
}
return msg;
}
event void Timer1.fired(){
if (!busy) {
FindRoute_t *btrpkt = (FindRoute_t*)(call Packet.getPayload(&i_pkt, sizeof (FindRoute_t)));
btrpkt->counter = 7;
if (call nextsender.send(AM_BROADCAST_ADDR, &i_pkt, sizeof(FindRoute_t)) == SUCCESS) {
busy = TRUE;
}
}
}
event void nextsender.sendDone(message_t *msg, error_t error) {
if (&i_pkt == msg) {
call Leds.set(2);
busy = FALSE;
}
}
event message_t* nextreceiver.receive(message_t* msg, void* payload, uint8_t len) {
if (len == sizeof(FindRoute_t)) {
FindRoute_t* btrpkt = (FindRoute_t*)payload;
call Leds.set(btrpkt->counter);
}
return msg;
}
You have two receivers. Are they wired to two different receiving modules? If not, a received packet will trigger both of their receive event, which may cause some problem.