Hi there
I am trying to write some software that, in the TOSSIM environment, sends out a
packet to all nodes (unknown number), and each node responds upon receiving the
packet. This software would allow the creation of a table of all nodes within
range of the current node.
I am using AMSend.send to send my packet. The address is AM_BROADCAST_ADDR,
which I understand means it will send the packet to every node in range (i.e.
Broadcast)?
So, if I send it once any node, 0, 1, or more, would receive the packet and
send it back to the originating node.
I am unable to get this to work as expected, making me think I am not
completely understanding how this works.
I have stripped my code down to its simplest form, and found that on sending
out to AM_BROADCAST_ADDR I only get a response from one node (the originating
node)? Why is this? What am I missing?
Below is my code, TOSSIM code:
#include
#include "BlinkHop1.h"
module BlinkHop1C
{
uses interface Boot;
uses interface Leds;
uses interface Packet;
uses interface AMPacket;
uses interface AMSend;
uses interface SplitControl as AMControl;
uses interface Receive;
}
implementation
{
bool busy = FALSE;
message_t pkt;
bool first = TRUE;
task void sendMsg()
{
if (!busy)
{
BlinkHopMsg* hpkt = (BlinkHopMsg*)call
AMSend.getPayload(&pkt);
if (first)
{
if (call AMSend.send(AM_BROADCAST_ADDR, &pkt,
sizeof(BlinkHopMsg)) == SUCCESS)
{
dbg("Hop","\nFirst send so it goes to everyone, Sending packet with source =
%i\n TTL = %i \n destination = %i \n ", (int)hpkt->source, (int)hpkt->ttl,
(int)hpkt->destination);
busy = TRUE;
first = FALSE;
}
else
{
dbg("Hop","Send failed!!!");
}
}
else
{
dbg("Hop","Not the first time so not sending anything further, every node
should receive hat I sent out\n");
}
}
else
{
dbg("Hop","I am unable to send me packet....\n");
}
}
task void Discover()
{
BlinkHopMsg* hpkt = (BlinkHopMsg*)call
AMSend.getPayload(&pkt);
if (first)
{
dbg("Hop","Creating packet\n");
hpkt->source = (int)TOS_NODE_ID;
hpkt->destination = -1;
hpkt->ack = FALSE;
post sendMsg();
}
else
{
post sendMsg();
}
}
event void Boot.booted()
{
call AMControl.start();
}
event void AMControl.startDone(error_t err)
{
if (err == SUCCESS)
{
post Discover();
}
else
{
call AMControl.start();
}
}
event void AMControl.stopDone(error_t err)
{
}
event void AMSend.sendDone(message_t* msg, error_t error)
{
if (&pkt == msg)
{
busy = FALSE;
post Discover();
}
}
event message_t* Receive.receive(message_t* msg, void* payload, uint8_t
len)
{
BlinkHopMsg* rpkt2 = (BlinkHopMsg*)call AMSend.getPayload(&pkt);
dbg("Hop","rpkt2 \n%i I have received a packet from %i destination %i \n",
(int)TOS_NODE_ID, (int)rpkt2->source, (int)rpkt2->destination);
return &pkt;
}
}
from sys import *
from TOSSIM import *
t = Tossim([]);
t.addChannel("Hop",stdout);
r = t.radio();
f = open("topo.txt","r");
lines = f.readlines()
for line in lines:
s = line.split()
if (len(s)> 0):
print " ", s[0], " ", s[1], " ", s[2];
r.add(int(s[0]), int(s[1]), float(s[2]));
noise = open("hist.txt","r");
lines = noise.readlines()
for line in lines:
str = line.strip()
if (str != ""):
val = int(str)
for i in range(1,3):
t.getNode(i).addNoiseTraceReading(val);
for i in range(1,3):
print "Creating noise for ", i;
t.getNode(i).createNoiseModel();
#t.getNode(31).bootAtTime(45654);
#t.getNode(32).bootAtTime(46665);
for i in range(1,3):
# t.getNode(i).bootAtTime(45654 * (i*100));
t.getNode(i).turnOn();
for i in range(0,999):
t.runNextEvent();
_________________________________________________________________
All new Live Search at Live.com
http://clk.atdmt.com/UKM/go/msnnkmgl0010000006ukm/direct/01/
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help