I recently started working with TinyOs and wrote a small application, which 
just sends a packet and signals if it received a packet.
The signalling is done using the Receive interface and the Receive.receive() 
event message. Unfortunately this event is never triggered, although packets 
are send successfully and the nodes are in communication range.
Any idea what could cause the problem?
The code of the application is below:

#include "Timer.h"
#include "Tree.h"
#include "printf.h" 


module TreeC {
  uses {
    interface Leds;
    interface Boot;
    interface Receive;
    interface AMSend;
    interface Timer<TMilli> as MilliTimer;
    interface SplitControl as AMControl;
    interface SplitControl as PrintfControl;
    interface AMPacket;
    interface ActiveMessageAddress;
    interface PrintfFlush;
   }
}
implementation {

  message_t packet;

  bool locked;
  uint16_t counter = 0;
  am_addr_t addr;
  
  event void Boot.booted() {
   
    call AMControl.start();
    call PrintfControl.start();
  }

  event void AMControl.startDone(error_t err) {
    if (err == SUCCESS) {
     if (TOS_NODE_ID == 1) {}
     else
      if (TOS_NODE_ID == 2){
       call MilliTimer.startPeriodic(250);
       call Leds.led0On();
       printf("hello world from Node 2"); call PrintfFlush.flush();
      }
      else {
       call MilliTimer.startPeriodic(250);
      }
    }
    else {
      call AMControl.start();
    }
  }

  event void AMControl.stopDone(error_t err) {
    // do nothing
  }
  
  event void PrintfControl.startDone(error_t err) {
    // do nothing
  }
  event void PrintfControl.stopDone(error_t err) {
    // do nothing
  }
  
  
  
  event void MilliTimer.fired() {
    if (locked) {
      return;
    }
    else {
      msg_t* rcm = (msg_t*)call AMSend.getPayload(&packet);
      if (call AMSend.maxPayloadLength() < sizeof(msg_t)) {
        return;
      }
     rcm->data = 0x5555;
        
     if (call AMSend.send(AM_BROADCAST_ADDR, &packet, sizeof(msg_t)) == 
SUCCESS) {
locked = TRUE;
        }
        
    }
  }

  event message_t* Receive.receive(message_t* bufPtr, void* payload, uint8_t 
len) {
                printf("Received packet"); call PrintfFlush.flush();
                call Leds.led1On();
        return bufPtr;
    
  }

  event void AMSend.sendDone(message_t* bufPtr, error_t error) {
    call Leds.led0Off();
        call Leds.led2On();
    if (&packet == bufPtr) {
      locked = FALSE;
    }
  }
        async event void ActiveMessageAddress.changed() {
  }
  event void PrintfFlush.flushDone(error_t error){}
}



-- 
GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to