Hi!

On Thu, 2 Apr 2009, João Paulo Amaro da Costa Luz Carneiro wrote:

Hi all,

Made a very simple program to test LPL but am not sending/receiving
any messages or sometimes only 1 (depending on the LPL_INTERVAL
value). Can someone tell me what am I doing wrong?

Sending a packet on broadcast will take LPL_INTERVAL ms. So the TIMER_PERIOD_MILLI should be longer than LPL_INTERVAL. :-)

--
Razvan ME

Thanks in advance
Here's the code:

Test.h
#ifndef TEST_H
#define TEST_H

enum {
  AM_TEST = 6,
  TIMER_PERIOD_MILLI = 250,
  LPL_INTERVAL = 2000
};

typedef nx_struct TestMsg {
  nx_uint16_t nodeid;
} TestMsg;

#endif


TestAppC.nc
#include <Timer.h>
#include "Test.h"

configuration TestAppC {
}
implementation {
  components MainC;
  components TestC as App;
  components new TimerMilliC() as Timer0;
  components ActiveMessageC;
  components new AMSenderC(AM_TEST);
  components new AMReceiverC(AM_TEST);
  components CC2420ActiveMessageC as LPLProvider;

  App.Boot -> MainC;
  App.Timer0 -> Timer0;
  App.Packet -> AMSenderC;
  App.AMPacket -> AMSenderC;
  App.AMControl -> ActiveMessageC;
  App.AMSend -> AMSenderC;
  App.Receive -> AMReceiverC;
  App.LPL -> LPLProvider;
}


TestC.nc
#include <Timer.h>
#include "Test.h"

module TestC {
  uses interface Boot;
  uses interface Timer<TMilli> as Timer0;
  uses interface Packet;
  uses interface AMPacket;
  uses interface AMSend;
  uses interface Receive;
  uses interface SplitControl as AMControl;
  uses interface LowPowerListening as LPL;
}
implementation {
  void sendMessage();
  task void sendMessageTask();
  message_t pkt;
  bool busy = FALSE;

  event void Boot.booted() {
    call LPL.setLocalSleepInterval(LPL_INTERVAL);
    call AMControl.start();
  }

  event void AMControl.startDone(error_t err) {
    if (err == SUCCESS) {
      call Timer0.startPeriodic(TIMER_PERIOD_MILLI);
    }
    else {
      call AMControl.start();
    }
  }

  event void AMControl.stopDone(error_t err) {
  }

  event void Timer0.fired() {
    //    if (!busy) {
      TestMsg* tpkt =
        (TestMsg*)(call Packet.getPayload(&pkt, sizeof(TestMsg)));
      if (tpkt == NULL) {
        return;
      }
      tpkt->nodeid = TOS_NODE_ID;

      sendMessage();
      //}
  }

  void sendMessage() {
    call LPL.setRxSleepInterval(&pkt, LPL_INTERVAL);
    if (call AMSend.send(AM_BROADCAST_ADDR,
                         &pkt, sizeof(TestMsg)) == SUCCESS) {
      busy = TRUE;
    }
    else post sendMessageTask();
  }

  task void sendMessageTask() { sendMessage(); }

  event void AMSend.sendDone(message_t* msg, error_t err) {
    if (&pkt == msg) {
      if (err != SUCCESS)
        post sendMessageTask();
      else
        busy = FALSE;
    }
  }

  event message_t* Receive.receive(message_t* msg, void* payload, uint8_t len){
    if (len == sizeof(TestMsg)) {
      TestMsg* tpkt = (TestMsg*)payload;
    }
    return msg;
  }
}


Makefile
COMPONENT=TestAppC

CFLAGS+=-DLOW_POWER_LISTENING

include $(MAKERULES)
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to