Hand Hygiene

August 24, 2009

New Testing Software

Filed under: Uncategorized — gthomas @ 2:05 pm

Gray and Eric wanted a software program that could run the mote tests faster, so they modified the blinkToRadio demo program that came with tinyOS to broadcast when a message was received and the strength of the signal.  This approach allows the motes to exchange 4 messages each second (compared to one every 8 seconds with the old approach). Also it removes a great deal of software complexity so we can concentrate on the radios. The code is after the bump.

BlinkToRadio.h


// $Id: BlinkToRadio.h,v 1.4 2006/12/12 18:22:52 vlahan Exp $

#ifndef BLINKTORADIO_H
#define BLINKTORADIO_H

enum {
AM_BLINKTORADIO = 6,
TIMER_PERIOD_MILLI = 250,
XMIT_POWER = 20
};

typedef nx_struct BlinkToRadioMsg {
nx_uint16_t nodeid;
nx_uint16_t counter;
} BlinkToRadioMsg;

typedef nx_struct Reportingstuffthingy {
nx_uint16_t nodeid;
nx_uint8_t rssi;
nx_uint16_t more_useless_stuff;
} Reportingstuffthingy;

#endif

BlinkToRadioAppC.nc


// $Id: BlinkToRadioAppC.nc,v 1.4 2006/12/12 18:22:52 vlahan Exp $

/*
* "Copyright (c) 2000-2006 The Regents of the University of California.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
* CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
*
*/

/**
* Application file for the BlinkToRadio application. A counter is
* incremented and a radio message is sent whenever a timer fires.
* Whenever a radio message is received, the three least significant
* bits of the counter in the message payload are displayed on the
* LEDs. Program two motes with this application. As long as they
* are both within range of each other, the LEDs on both will keep
* changing. If the LEDs on one (or both) of the nodes stops changing
* and hold steady, then that node is no longer receiving any messages
* from the other node.
*
* @author Prabal Dutta
* @date Feb 1, 2006
*/
#include
#include "BlinkToRadio.h"

configuration BlinkToRadioAppC {
}
implementation {
components MainC;
components LedsC;
components BlinkToRadioC as App;
components new TimerMilliC() as Timer0;
components ActiveMessageC;
components new AMSenderC(AM_BLINKTORADIO);
components new AMReceiverC(AM_BLINKTORADIO);
components CC2420ActiveMessageC;

App.Boot -> MainC;
App.Leds -> LedsC;
App.Timer0 -> Timer0;
App.Packet -> AMSenderC;
App.AMPacket -> AMSenderC;
App.AMControl -> ActiveMessageC;
App.AMSend -> AMSenderC;
App.Receive -> AMReceiverC;
App.CC2420Packet -> CC2420ActiveMessageC;
}

BlinkToRadioC.nc


// $Id: BlinkToRadioC.nc,v 1.5 2007/09/13 23:10:23 scipio Exp $

/*
* "Copyright (c) 2000-2006 The Regents of the University of California.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
* CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
*
*/

/**
* Implementation of the BlinkToRadio application. A counter is
* incremented and a radio message is sent whenever a timer fires.
* Whenever a radio message is received, the three least significant
* bits of the counter in the message payload are displayed on the
* LEDs. Program two motes with this application. As long as they
* are both within range of each other, the LEDs on both will keep
* changing. If the LEDs on one (or both) of the nodes stops changing
* and hold steady, then that node is no longer receiving any messages
* from the other node.
*
* @author Prabal Dutta
* @date Feb 1, 2006
*/
#include
#include "BlinkToRadio.h"

module BlinkToRadioC {
uses interface Boot;
uses interface Leds;
uses interface Timer as Timer0;
uses interface Packet;
uses interface AMPacket;
uses interface AMSend;
uses interface Receive;
uses interface SplitControl as AMControl;
uses interface CC2420Packet;
}
implementation {

uint16_t counter;
message_t pkt;
bool busy = FALSE;

void setLeds(uint16_t val) {
if (val & 0x01)
call Leds.led0On();
else
call Leds.led0Off();
if (val & 0x02)
call Leds.led1On();
else
call Leds.led1Off();
if (val & 0x04)
call Leds.led2On();
else
call Leds.led2Off();
}

event void Boot.booted() {
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() {
counter++;
if (!busy) {
BlinkToRadioMsg* btrpkt =
(BlinkToRadioMsg*)(call Packet.getPayload(&pkt, sizeof(BlinkToRadioMsg)));
if (btrpkt == NULL) {
return;
}
btrpkt->nodeid = TOS_NODE_ID;
btrpkt->counter = counter;
call CC2420Packet.setPower(&pkt, XMIT_POWER);
if (call AMSend.send(AM_BROADCAST_ADDR,
&pkt, sizeof(BlinkToRadioMsg)) == SUCCESS) {
busy = TRUE;
}
}
}

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

event message_t* Receive.receive(message_t* msg, void* payload, uint8_t len){
if (len == sizeof(BlinkToRadioMsg)) {
int8_t rssi;
BlinkToRadioMsg* btrpkt = (BlinkToRadioMsg*)payload;
rssi = call CC2420Packet.getRssi(msg);
setLeds(btrpkt->counter);

if (!busy) {
Reportingstuffthingy* rprtpckt =
(Reportingstuffthingy*)(call Packet.getPayload(&pkt, sizeof(Reportingstuffthingy)));
if (rprtpckt == NULL) {
return msg;
}
rprtpckt->nodeid = TOS_NODE_ID;
rprtpckt->rssi = rssi+60;
rprtpckt->more_useless_stuff = 0x1337;
call CC2420Packet.setPower(&pkt, 31);
if (call AMSend.send(AM_BROADCAST_ADDR,
&pkt, sizeof(Reportingstuffthingy)) == SUCCESS) {
busy = TRUE;
}
}
return msg;
}
}
}

Makefile


COMPONENT=BlinkToRadioAppC

CFLAGS +=-DCC2420_DEF_CHANNEL=11

include $(MAKERULES)

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

You must be logged in to post a comment.

Powered by WordPress