I changed my code and it works perfectly thanks a lot. I removed aux2
and just modified aux1 which is pointing at the payload region of my
intercepted message. RadMsgis the name of the structure sent, it has
fields for sensor readings and for the nodes in the packet route.

Here's the new code, each Node0X is a Node in the packet route:

WIRING:
components CollectionC as Collector, new CollectionSenderC(COL_ID);

  App.Send -> CollectionSenderC;
  App.CollectionControl -> Collector;
  App.Forward -> Collector.Intercept[COL_ID];

MODULE:

uses {
    
...
    interface StdControl as CollectionControl;
    interface Send;
    interface Intercept as Forward;
  }
}

implementation
{
        bool busy = FALSE;
        .....
event bool Forward.forward(message_t* msg, void* payload, uint8_t len)
  {
    if (!busy){
      
      RadMsg* aux1 = (RadMsg*)payload;
      
      busy = TRUE;
      
      if (aux1->nodeid == TOS_NODE_ID)
      {
        return FALSE;
//don't forward if it's the same Node
      }else{
        
        call Leds.led0Toggle();
        
        aux1->HopCount++; 
        switch (aux1->HopCount)
        {
          case 1: aux1->Node01 = TOS_NODE_ID;
                  break;
          case 2: aux1->Node02 = TOS_NODE_ID;
                  break;
          case 3: aux1->Node03 = TOS_NODE_ID;
                  break;
          case 4: aux1->Node04 = TOS_NODE_ID;
                  break;
          case 5: aux1->Node05 = TOS_NODE_ID;
                  break;
          default: break;
        }    
        busy = FALSE;
        return TRUE;
      }      
    }else{
      busy = FALSE;
      return FALSE;
    }
    
  }  

}

-----Mensaje original-----
De: [email protected] [mailto:[email protected]] En nombre de Omprakash
Gnawali
Enviado el: jueves, 15 de enero de 2009 3:00
Para: Manuel Fernandez Santo Tomas
CC: [email protected]
Asunto: Re: [Tinyos-help] Understanding CTP intercept

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



Este mensaje se dirige exclusivamente a su destinatario, y puede contener 
información confidencial sometida a secreto profesional, o cuya divulgación 
esté legalmente prohibida. Cualquier opinión en él contenida es exclusiva de su 
autor y no representa necesariamente la opinión de la empresa. Si ha recibido 
este mensaje por error, le rogamos nos lo comunique de forma inmediata por esta 
misma vía y proceda a su eliminación, así como a la de cualquier documento 
adjunto al mismo. El correo electrónico vía Internet no es seguro y no se puede 
garantizar que no haya errores ya que puede ser interceptado, modificado, 
perdido o destruido, o contener virus. Cualquier persona que se ponga en 
contacto con nosotros por correo electrónico se considerará que asume estos 
riesgos.

This e-mail is addressed exclusively to the recipient and may contain 
privileged information under a professional confidential agreement or it may be 
against the law to disclose its contents. Any opinion contained in it belongs 
exclusively to his/her author and does not necessarily reflect the company’s 
view. If you receive this e-mail in error, please let us know immediately (by 
return e-mail) and proceed to its destruction, as well as any document attached 
to it. The sending of e-mails through the Internet is not safe and, therefore, 
error-free communications cannot be guaranteed, as they can be intercepted, 
changed, misled or destroyed or they might contain a virus. Any user contacting 
us through e-mails shall be understood to be assuming these risks.



_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to