I modified the apps/EasyCollection to add a counter in the message, and I found 
that the Root received every message for many times(about 30).
Is that normal and how can I avoid this.

part of my code
---------------------------------------------
module NodeC {
  uses interface Boot;
  uses interface SplitControl as RadioControl;
  uses interface StdControl as RoutingControl;
  uses interface Send;
  uses interface Leds;
  uses interface Timer<TMilli>;
  uses interface RootControl;
  uses interface Receive;
}
implementation {
message_t packet;
bool sendBusy = FALSE;
uint16_t counter = 0;
event void Boot.booted() {
call RadioControl.start();
}
  
  event void RadioControl.startDone(error_t err) {
if (err != SUCCESS)
call RadioControl.start();
else {
call RoutingControl.start();
call Timer.startPeriodic(2000);
}
  }
  event void RadioControl.stopDone(error_t err) {}
  void sendMessage() {
SensorMsg* msg =
  (SensorMsg*)call Send.getPayload(&packet, sizeof(SensorMsg));
msg->nodeid = TOS_NODE_ID;
msg->sensorType = SENSOR_TYPE_SOUND;
msg->data = counter++;
if (call Send.send(&packet, sizeof(SensorMsg)) != SUCCESS) 
call Leds.led0On();
else 
sendBusy = TRUE;
  }
event void Timer.fired() {
if (!sendBusy) {
call Leds.led2Toggle();
sendMessage();
}
}
  
  event void Send.sendDone(message_t* m, error_t err) {
if (err != SUCCESS) 
  call Leds.led0On();
sendBusy = FALSE;
  }
}

************************************************
module RootC {
  uses interface Boot;
  uses interface SplitControl as RadioControl;
  uses interface SplitControl as SerialControl;
  uses interface StdControl as RoutingControl;
uses interface AMSend as UartAMSend;
uses interface AMPacket as UartAMPacket;
uses interface Packet as UartPacket;
  uses interface Leds;
  uses interface Timer<TMilli>;
  uses interface RootControl;
  uses interface Receive;
}
implementation {
message_t packet;
SensorMsg *sensorMsg;
bool UartSendBusy = FALSE;
event void Boot.booted() {
call RadioControl.start();
call SerialControl.start();
}
  
event void RadioControl.startDone(error_t err) {
if (err != SUCCESS)
call RadioControl.start();
else {
call RoutingControl.start();
call RootControl.setRoot();
}
}
event void RadioControl.stopDone(error_t err) {}
event void SerialControl.startDone(error_t error) {
if( error == SUCCESS ) {
call Leds.led0Toggle();
} else {
call SerialControl.start();
call Leds.led2Toggle();
}
}
event void SerialControl.stopDone(error_t err) {};
event void UartAMSend.sendDone(message_t *msg, error_t err) {
if(&packet==msg) {
UartSendBusy = FALSE;
}
}
event void Timer.fired() {
}
  
event message_t* 
Receive.receive(message_t* msg, void* payload, uint8_t len) {
SensorMsg *btrpkt = (SensorMsg *)call UartPacket.getPayload(&packet, NULL);
sensorMsg = (SensorMsg*)payload;
    btrpkt->nodeid = sensorMsg->nodeid;
btrpkt->sensorType = sensorMsg->sensorType;
btrpkt->data = sensorMsg->data;
    call Leds.led1Toggle(); 
if( (call UartAMSend.send(AM_BROADCAST_ADDR, &packet, 
sizeof(SensorMsg)))==SUCCESS) {
     UartSendBusy = TRUE;
    } 
return msg;
}


2010-12-09 



cui 
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to