[Tinyos-help] BlinkToRadio nodes not receiving
lacelove
lacelove at 126.com
Tue Mar 11 23:07:08 PDT 2008
1.modify BlinkToRadio.nc
$ cd /opt/tinyOS-2.x/tutorials/BlinkToRadio
$ emacs BlinkToRadio.nc
#include <Timer.h>
#include "BlinkToRadio.h"
module BlinkToRadioC {
uses interface Boot;
uses interface Leds;
uses interface Timer<TMilli> as Timer0;
uses interface Packet;
uses interface AMPacket;
uses interface AMSend;
uses interface Receive;
uses interface SplitControl as AMControl;
}
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, NULL));
btrpkt->nodeid = TOS_NODE_ID;
btrpkt->counter = counter;
if (call AMSend.send(AM_BROADCAST_ADDR,
&pkt, sizeof(BlinkToRadioMsg)) == SUCCESS) {
dbg("BlinkToRadioC","Sending...\n");
busy = TRUE;
}
}
}
event void AMSend.sendDone(message_t* msg, error_t err) {
dbg("BlinkToRadioC","sendDone\n");
if (&pkt == msg) {
busy = FALSE;
}
}
event message_t* Receive.receive(message_t* msg, void* payload, uint8_t len){
dbg("BlinkToRadioC","Received\n");
if (len == sizeof(BlinkToRadioMsg)) {
BlinkToRadioMsg* btrpkt = (BlinkToRadioMsg*)payload;
setLeds(btrpkt->counter);
}
return msg;
}
}
2.creat test.py
#! /usr/bin/python
from TOSSIM import *
import sys
t = Tossim([])
r = t.radio()
r.add(1,2,-54.0)
r.add(2,1,-55.0)
t.addChannel("BlinkToRadioC",sys.stdout)
for i in range(0,1000):
t.getNode(1).addNoiseTraceReading(-98)
t.getNode(2).addNoiseTraceReading(-98)
t.getNode(1).createNoiseModel()
t.getNode(2).createNoiseModel()
t.getNode(1).bootAtTime(1000001)
t.getNode(2).bootAtTime(8000008)
for i in range(0,100):
t.runNextEvent()
3.test
$ make micaz sim
$ python test.py
DEBUG (1): Sending...
DEBUG (2): Sending...
DEBUG (1): Received
DEBUG (2): sendDone
DEBUG (2): Received
DEBUG (1): sendDone
DEBUG (1): Sending...
DEBUG (2): Sending...
DEBUG (1): Received
DEBUG (2): sendDone
DEBUG (2): Received
DEBUG (1): sendDone
DEBUG (1): Sending...
DEBUG (2): Sending...
DEBUG (2): Received
DEBUG (1): sendDone
DEBUG (1): Received
DEBUG (2): sendDone
DEBUG (1): Sending...
DEBUG (2): Sending...
4.env
windows XP + XubunTOS 2
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://www.millennium.berkeley.edu/pipermail/tinyos-help/attachments/20080312/fc787c3e/attachment.htm
More information about the Tinyos-help
mailing list