0

In order to learn how to use the interface PacketAcknowledgements,i try to modify the example in apps/RadioCountToLeds,but there are some problem,the transmit of data can't be done and it seems there is no ack back to the sender.

the file RadioCountToLedsC is as follows:

#include "Timer.h"
#include "RadioCountToLeds.h"


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

  event void AMControl.startDone(error_t err) {
    if (err == SUCCESS) {
    if(TOS_NODE_ID==0)
    {
      call MilliTimer.startPeriodic(1000);
    }
    }
    else {
      call AMControl.start();
    }
  }

  event void AMControl.stopDone(error_t err) {
    // do nothing
  }

  event void MilliTimer.fired() {
    counter++;

     dbg("RadioCountToLedsC", "RadioCountToLedsC: timer fired, counter is %hu.\n", 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) {
        dbg("RadioCountToLedsC", "RadioCountToLedsC: packet sent.\n", counter); 
        locked = TRUE;
          }
      }

  }

  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);
      if (rcm->counter & 0x1) {
    call Leds.led0On();
      }
      else {
    call Leds.led0Off();
      }
      if (rcm->counter & 0x2) {
    call Leds.led1On();
      }
      else {
    call Leds.led1Off();
      }
      if (rcm->counter & 0x4) {
    call Leds.led2On();
      }
      else {
    call Leds.led2Off();
      }
      return bufPtr;
    }
  }

  event void AMSend.sendDone(message_t* bufPtr, error_t error) {
    if(call PacketAcknowledgements.wasAcked(bufPtr)){
        dbg("RadioCountToLedsC", "ACKED!\n");
        locked = FALSE;
    }
    else
    {
        dbg("RadioCountToLedsC", "NOT ACKED!\n");
    }
  }

}

i want to know where the error is. by the way,can anyone give me an example about how to use the interface PacketAcknowledgements? thanks very much.

the configuration file are as follows:

configuration RadioCountToLedsAppC {}
implementation {
  components MainC, RadioCountToLedsC as App, LedsC;
  components new AMSenderC(AM_RADIO_COUNT_MSG);
  components new AMReceiverC(AM_RADIO_COUNT_MSG);
  components new TimerMilliC();
  components ActiveMessageC;

  App.Boot -> MainC.Boot;
  App.PacketAcknowledgements ->AMSenderC.Acks;
  App.Receive -> AMReceiverC;
  App.AMSend -> AMSenderC;
  App.AMControl -> ActiveMessageC;
  App.Leds -> LedsC;
  App.MilliTimer -> TimerMilliC;
  App.Packet -> AMSenderC;
  App.AMPacket ->ActiveMessageC;
}
ybk1996
  • 1
  • 1
  • I don't know the answer to your question but there are [some questions on TinyOS mailing list](https://www.google.co.uk/search?q=packetacknowledgements+site%3Ahttp%3A%2F%2Fmail.millennium.berkeley.edu%2Fpipermail%2Ftinyos-help) which discuss PacketAcknowledgements – James Allen Jan 05 '18 at 14:31
  • @ybk1996 What particular error message are you getting? Can you please also post the configuration file (i.e RadioCountToLedsAppC) so we can see how you are wiring the PacketAcknowledgement interface. – KillaKem Jan 07 '18 at 22:53
  • i have posted the configuraton file...and by the way i think my question has been solved,while i call PacketAcknowledgements.wasAcked(bufPtr),if it has been acked the result of it is 0,not 1. – ybk1996 Jan 08 '18 at 07:29

0 Answers0