This program attempts to stress the radio by generating traffic between 3 sender components on one node and 3 receiver components on another node.
/**
* Radio stress test
*
* Each mote has three components; one one mote each component send to the
* corresponding component on the other mote. Correspondence is achieved via colour value.
*/
//Used to specify the different led types
type ledType is enum (red, green, blue, other)
type stressI is interface( in integer button ; in RadioPacket ether ; out any bcast)
component stress presents stressI {
buttonPressed = false
led = other
state = true
constructor(ledType l) {
led := l
}
behaviour {
if !buttonPressed then {
//printString("packet or button\n")
select {
//wait for the button press to start
receive press from button when !buttonPressed: {
//printString("Button Press\n")
buttonPressed := true
}
//we got packet ==> receiver
receive packet from ether when !buttonPressed: {
//printString("packet from ether\n")
project packet.payload as data onto
ledType : {
if (data == red and led == red) then{
setRedLedPower(state)
// printString("RED\n")
state := !state
}
if (data == green and led == green) then{
setGreenLedPower(state)
//printString("GREEN\n")
state := !state
}
if (data == blue and led == blue) then{
setBlueLedPower(state)
// printString("BLUE\n")
state := !state
}
}
default : {}
}
}
}
else {
//printString("No button press SEND\n")
send any(led) on bcast
}
}
}
/*******************************************************************/
r = new stress(red)
connect r.ether to radio.received
connect r.bcast to radio.broadcastSend
connect r.button to buttonSensor.output
b = new stress(blue)
connect b.ether to radio.received
connect b.bcast to radio.broadcastSend
connect b.button to buttonSensor.output
g = new stress(green)
connect g.ether to radio.received
connect g.bcast to radio.broadcastSend
connect g.button to buttonSensor.output
The corresponding nesC program for TinyOS is shown below.
configuration RadioStressAppC {
}
implementation {
components MainC, RadioStressC, LedsC;
components BlockingActiveMessageC;
MainC.Boot BlockingActiveMessageC;
RadioStressC.Leds -> LedsC;
components new ThreadC(300) as RadioStressThread0;
components new BlockingAMSenderC(220) as BlockingAMSender0;
components new BlockingAMReceiverC(220) as BlockingAMReceiver0;
RadioStressC.RadioStressThread0 -> RadioStressThread0;
RadioStressC.BlockingAMSend0 -> BlockingAMSender0;
RadioStressC.BlockingReceive0 -> BlockingAMReceiver0;
components new ThreadC(300) as RadioStressThread1;
components new BlockingAMSenderC(221) as BlockingAMSender1;
components new BlockingAMReceiverC(221) as BlockingAMReceiver1;
RadioStressC.RadioStressThread1 -> RadioStressThread1;
RadioStressC.BlockingAMSend1 -> BlockingAMSender1;
RadioStressC.BlockingReceive1 -> BlockingAMReceiver1;
components new ThreadC(300) as RadioStressThread2;
components new BlockingAMSenderC(222) as BlockingAMSender2;
components new BlockingAMReceiverC(222) as BlockingAMReceiver2;
RadioStressC.RadioStressThread2 -> RadioStressThread2;
RadioStressC.BlockingAMSend2 -> BlockingAMSender2;
RadioStressC.BlockingReceive2 -> BlockingAMReceiver2;
}
/********************************************/
#include "AM.h"
module RadioStressC {
uses {
interface Boot;
interface BlockingStdControl as BlockingAMControl;
interface Thread as RadioStressThread0;
interface BlockingAMSend as BlockingAMSend0;
interface BlockingReceive as BlockingReceive0;
interface Thread as RadioStressThread1;
interface BlockingAMSend as BlockingAMSend1;
interface BlockingReceive as BlockingReceive1;
interface Thread as RadioStressThread2;
interface BlockingAMSend as BlockingAMSend2;
interface BlockingReceive as BlockingReceive2;
interface Leds;
}
}
implementation {
message_t m0;
message_t m1;
message_t m2;
event void Boot.booted() {
call RadioStressThread0.start(NULL);
call RadioStressThread1.start(NULL);
call RadioStressThread2.start(NULL);
}
event void RadioStressThread0.run(void* arg) {
call BlockingAMControl.start();
for(;;) {
if(TOS_NODE_ID == 0) {
call BlockingReceive0.receive(&m0, 5000);
call Leds.led0Toggle();
}
else {
call BlockingAMSend0.send(!TOS_NODE_ID, &m0, 0);
call Leds.led0Toggle();
//call RadioStressThread0.sleep(500);
}
}
}
event void RadioStressThread1.run(void* arg) {
call BlockingAMControl.start();
for(;;) {
if(TOS_NODE_ID == 0) {
call BlockingReceive1.receive(&m1, 5000);
call Leds.led1Toggle();
}
else {
call BlockingAMSend1.send(!TOS_NODE_ID, &m1, 0);
call Leds.led1Toggle();
//call RadioStressThread1.sleep(500);
}
}
}
event void RadioStressThread2.run(void* arg) {
call BlockingAMControl.start();
for(;;) {
if(TOS_NODE_ID == 0) {
call BlockingReceive2.receive(&m2, 5000);
call Leds.led2Toggle();
}
else {
call BlockingAMSend2.send(!TOS_NODE_ID, &m2, 0);
call Leds.led2Toggle();
//call RadioStressThread2.sleep(500);
}
}
}
}