On Mon, Jan 12, 2009 at 11:48 PM, Manuel Fernandez Santo Tomas
<[email protected]> wrote:
> Hello,
>
> I'm new to TinyOs, so please excuse me for the long email. I've been
> developing an application using CTP on a group of micaz motes. The idea
> is for them to monitor some sensors, and send them to the collection
> base. The data arrives but I've also been asked to track the route a
> packet follows.
>
> I have read the archives such as:
>
> http://www.mail-archive.com/[email protected]/msg20973
> .html
>
> where the advice is "you will need to put the
> local node id in the packet somewhere each time it is forwarded."
>
> That I understand, and so far I've added some fields to my data
> structure. One of them is hopcount, and several Node0x fields to add
> possible hops. The idea is to increment hopcount each forward and write
> in the appropriate Node0x field the TOS_NODE_ID.
>
> Wiring:
>
> components CollectionC as Collector;
> App.Forward -> Collector.Intercept[COL_ID];
>
> And in the module:
>
> uses interface Intercept as Forward;
>
> event bool Forward.forward(message_t* msg, void* payload, uint8_t len)
> {
> if (!busy){
>
> RadMsg* aux1 = (RadMsg*)payload;
>
> RadMsg *aux2 = (RadMsg*)call Send.getPayload(&pkt_int,
> sizeof(RadMsg));
>
> busy = TRUE;
>
> if (aux1->nodeid == TOS_NODE_ID) //To avoid forwarding when it is
> the //own node
> {
> return FALSE;
> }else{
>
> call Leds.led0Toggle();
> aux2->Voltage = aux1->Voltage;
> aux2->TempValue = aux1->TempValue;
> aux2->PhotoValue = aux1->PhotoValue;
> aux2->nodeid = aux1->nodeid;
> aux2->HopCount = aux1->HopCount;
> aux2->NodoInterm01 = aux1->NodoInterm01;
> aux2->NodoInterm02 = aux1->NodoInterm02;
> aux2->NodoInterm03 = aux1->NodoInterm03;
> aux2->NodoInterm04 = aux1->NodoInterm04;
> aux2->NodoInterm05 = aux1->NodoInterm05;
>
> aux2->HopCount++;
>
> switch (aux2->HopCount)
> {
> case 1: aux2->Node01 = TOS_NODE_ID;
> break;
> case 2: aux2->Node02 = TOS_NODE_ID;
> break;
> case 3: aux2->Node03 = TOS_NODE_ID;
> break;
> case 4: aux2->Node04 = TOS_NODE_ID;
> break;
> case 5: aux2->Node05 = TOS_NODE_ID;
> break;
> default: break;
> }
>
> check(call Send.send(&pkt_int, sizeof(RadMsg)));//Here I resend
> the //new message with the
> new hop added.
>
> return TRUE;
> }
> }else{
> return FALSE;
> }
>
> }
>
> Now this "seems" to work, as I'm receiving the data with the hops I more
> or less expected, but I'm not sure if I'm doing it the correct way. I
> also have a doubt about what happens if more messages arrive to be
> forwarded while I'm sending one, or the nodes own readings. Should I
> make a queue?
>
> Please tell me if I'm using intercept the way it's meant to.
>
To understand how Intercept works, lets look at CtpForwardingEngineP.nc:
event message_t*
SubReceive.receive(message_t* msg, void* payload, uint8_t len) {
...
// I'm on the routing path and Intercept indicates that I
// should not forward the packet.
else if (!signal Intercept.forward[collectid](msg,
call
Packet.getPayload(msg, call Packet.payloadLength(msg)),
call
Packet.payloadLength(msg)))
return msg;
else {
dbg("Route", "Forwarding packet from %hu.\n", getHeader(msg)->origin);
return forward(msg);
}
}
We can see that the forwarding engine is going to call
Intercept.forward implemented by your application. If you look at the
arguments, you will notice that once your application receives this
call, your application has access to the packet and it can modify any
way it wants. Once your application completes its modifications to the
packet, it should return either TRUE or FALSE.
Here is an excerpt from the definition of Intercept.forward:
* @return TRUE indicates the packet should be forwarded, FALSE
* indicates that it should not be forwarded.
*
*/
event bool forward(message_t* msg, void* payload, uint8_t len);
This tells us that if we want the message to get forwarded to the
root, we should return TRUE. Note that we do not need to call
Send(...) to get the packet forwarded which is what you are doing.
To implement the functionality you are looking for, you would
implement Intercept.forward() that allows the forwarding nodes to
modify the packet payload to include information to keep track of the
path and return TRUE.
Does this help?
- om_p
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help