Although i used interface PacketAcknowledgements,i still found i can't guarantee the communication between within one hop... In my experiment,i only use two motes,every 1 second each node send one packet to the other,then i discovered the command AMsend.send can always been called successfully but event Receive.receive is not always successfully been signaled...do they conflict to each other? if the command send can preempt the event receive,what can i do to deal with it?Thank you very much...
the file RadioCountToLedsC.nc is as followed:
module RadioCountToLedsC @safe() {
uses {
interface Leds;
interface Boot;
interface Receive;
interface AMSend;
interface Timer<TMilli> as MilliTimer;
interface SplitControl as AMControl;
interface Packet;
interface PacketAcknowledgements;
interface AMPacket;
}
}
implementation {
message_t packet;
bool locked = FALSE;
uint16_t counter = 0;
event void Boot.booted() {
dbg("Boot","Application booted.\n");
call AMControl.start();
}
task void senddatatask()
{
counter++;
if (locked==TRUE) {
return;
}
else {
radio_count_msg_t* rcm = (radio_count_msg_t*)call Packet.getPayload(&packet, sizeof(radio_count_msg_t));
if (rcm == NULL) {
return;
}
rcm->counter = counter;
call PacketAcknowledgements.requestAck(&packet);
if (call AMSend.send(AM_BROADCAST_ADDR, &packet, sizeof(radio_count_msg_t)) == SUCCESS) {
locked = TRUE;
}
}
}
event void AMControl.startDone(error_t err) {
if (err == SUCCESS) {
call MilliTimer.startPeriodic(1000);
}
else {
call AMControl.start();
}
}
event void AMControl.stopDone(error_t err) {
// do nothing
}
event void MilliTimer.fired() {
post senddatatask();
}
event message_t* Receive.receive(message_t* bufPtr,
void* payload, uint8_t len) {
if (len != sizeof(radio_count_msg_t)) {return bufPtr;}
else {
radio_count_msg_t* rcm = (radio_count_msg_t*)payload;
dbg("RadioCountToLedsC", "Received packet of counter %u.\n", rcm->counter);
return bufPtr;
}
}
event void AMSend.sendDone(message_t* bufPtr, error_t error) {
if(&packet == bufPtr && call PacketAcknowledgements.wasAcked(bufPtr)==SUCCESS){
dbg("RadioCountToLedsC", "packet %u sent.\n", counter);
locked = FALSE;
}
else
{
dbg("RadioCountToLedsC", "NOT ACKED!\n");
}
//locked = FALSE;
}
}