TinyOS,重启微尘后无法接收数据包

时间:2013-01-09 15:54:04

标签: tinyos nesc

伪代码;

  1. 1-boot(红色led)

  2. 发送完成后,
  3. 广播数据包(绿灯)

  4. 接收数据包,解码数据包并相应地设置为(设置为蓝色)
  5. 编码后广播数据包,发送完成(设置led绿色)
  6. 接收数据包,解码并相应设置为(设置7(红色+绿色+蓝色))

  7. 在此阶段之后,mote 1将下注LED.set(7)并且mote 2将是LED.set(2)[mote 1已经开始传输],直到它工作得非常好。但是当我重新启动mote 1时,它会工作到2个伪代码,而mote 2无法接收到数据包)

     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;
     }
    

1 个答案:

答案 0 :(得分:1)

你有两个接收器。它们是否连接到两个不同的接收模块?如果没有,收到的数据包将触发它们的接收事件,这可能会导致一些问题。