[Tinyos-beta-commits] CVS: tinyos-1.x/beta/Drain/TestDrain Makefile, NONE, 1.1 TestDrain.h, NONE, 1.1 TestDrain.nc, NONE, 1.1 TestDrainM.nc, NONE, 1.1

Gilman Tolle gtolle at users.sourceforge.net
Mon Feb 14 15:16:39 PST 2005


Update of /cvsroot/tinyos/tinyos-1.x/beta/Drain/TestDrain
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13285/TestDrain

Added Files:
	Makefile TestDrain.h TestDrain.nc TestDrainM.nc 
Log Message:
First checkin of Drain -- untested

--- NEW FILE: Makefile ---
COMPONENT=TestDrain

PFLAGS += -I$(TOSDIR)/../beta/Drain
PFLAGS += -I$(TOSDIR)/../contrib/nucleus/tos/lib/Nucleus

include $(TOSDIR)/../apps/Makerules

--- NEW FILE: TestDrain.h ---
enum {
  AM_TESTDRAINMSG = 254,
  TESTDRAIN_SEND_PERIOD = 1000,
};

typedef struct TestDrainMsg {
  uint16_t data;
} TestDrainMsg;

--- NEW FILE: TestDrain.nc ---
includes TestDrain;

configuration TestDrain {

}
implementation {
  
  components 
    Main, 
    TestDrainM,
    DrainC,
    TimerC,
    RandomLFSR,
    LedsC as Leds;

  Main.StdControl -> DrainC;
  Main.StdControl -> TestDrainM;

  TestDrainM.Leds -> Leds;

  TestDrainM.Send -> DrainC.Send[AM_TESTDRAINMSG];
  TestDrainM.Timer -> TimerC.Timer[unique("Timer")];
  TestDrainM.Random -> RandomLFSR;
}

--- NEW FILE: TestDrainM.nc ---
module TestDrainM {
  provides interface StdControl;
  
  uses {
    interface Leds;

    interface Send;
    interface Timer;
    interface Random;
  }
}

implementation {
  
  TOS_Msg msgBuf;
  bool msgBufBusy;
  uint16_t counter;
  uint16_t sendPeriod;

  command result_t StdControl.init() { 
    sendPeriod = TESTDRAIN_SEND_PERIOD;
    counter = 0;
    msgBufBusy = FALSE;
    return SUCCESS; 
  }
  
  command result_t StdControl.start() { 
    call Timer.start(TIMER_ONE_SHOT, 
		     (call Random.rand() % sendPeriod) + 1);
    return SUCCESS; 
  }
  
  command result_t StdControl.stop() { 
    call Timer.stop();
    return SUCCESS; 
  }

  event result_t Timer.fired() {
    uint16_t length;
    TestDrainMsg* testMHMsg = 
      (TestDrainMsg*) call Send.getBuffer(&msgBuf, &length);
    
    call Leds.redOn();
    
    call Timer.start(TIMER_ONE_SHOT, sendPeriod);

    if (msgBufBusy) {
      return SUCCESS;
    } else {
      msgBufBusy = TRUE;
    }

    testMHMsg->data = counter;

    if (call Send.send(&msgBuf, sizeof(TestDrainMsg)) == FAIL) {
      call Leds.yellowToggle();
      msgBufBusy = FALSE;
    }

    return SUCCESS;
  }

  event result_t Send.sendDone(TOS_MsgPtr msg, result_t success) {

    dbg(DBG_USR1, "sendDone(msg=0x%x,success=%d)\n",
	msg, success);

    if (msg == &msgBuf) {
      msgBufBusy = FALSE;
      if (success)
	call Leds.redOff();
      else
	call Leds.greenToggle();
    }

    counter++;

    return SUCCESS;
  }
}



More information about the Tinyos-beta-commits mailing list