Hi,

suppose you have the following structure defined in mote's side:

 typedef nx_struct SequencedIdPacket{
        nx_uint8_t  moteId;
        nx_uint16_t sqnumber;
        nx_uint8_t  data[ ];
}SequencedIdPacket_t;

, suppose this packet is in tinyos AM message payload, in order to decode
the received packet in PC side you have to do as follow (in C code, this
differs if you are usisng Java or C#):

      int len, i;
      uint8_t msg_type;
      uint8_t msg_len;
      uint8_t moteId;
      //HERE I GET A PACKET FROM SERIALFORWARDER MAY BE DIFERENT IF YOU
CONNECT DIRECTLY TO SERIAL
      //PORT.
      uint8_t *packet = read_sf_packet(fd, &len);

      if (!packet)
            exit(0);

      if (len >= 1 + SPACKET_SIZE && packet[0] ==
SERIAL_TOS_SERIAL_ACTIVE_MESSAGE_ID){

      tmsg_t *msg = new_tmsg(packet + 1, len - 1);

      if (!msg)
           exit(0);

      //THIS IS THE SAME AS EXPLAINED BELOW BUT FOR THE FIELDS OF TINYOS MSG
PACKET
      msg_type = spacket_header_type_get(msg);
      msg_len  = spacket_header_length_get(msg);

      free(msg);
      //HERE IS WHERE YOU ACTUALLY HAVE A POINTER TO THE BEGINNING OF YOUR
DATA
      //AS SEEN BELOW YOU HAVE TO USE THE FUNCTION PROVIDED TO GET THE
FIELDS OF THE PACKET
      //iN THIS CASE I AM READING THE MOTES ID
      msg = new_tmsg(packet + 1 + SPACKET_SIZE,len - 1 - SPACKET_SIZE);
      moteId   = seqidpacket_moteId_get(msg);
 .......
----------------------------------------
Notes:
SPACKET_SIZE and SERIAL_TOS_SERIAL_ACTIVE_MESSAGE_ID are defined
"serialpacket.h" and correspond to the serial
protocol comunication of tinyos.

prettylisten.c prints Tinyos msg header info and payload in hex format as
seen below:

         spacket_header_dest_get(msg),
         spacket_header_src_get(msg),
         spacket_header_length_get(msg),
         spacket_header_group_get(msg),
         spacket_header_type_get(msg));
         hexprint((uint8_t *)tmsg_data(msg) + spacket_data_offset(0),
tmsg_length(msg) - spacket_data_offset(0));

         free(msg);
---------------------------------------------

, is not intuitive in fact is more clear when using object oriented
languages like java or C#, where the offset and size of fields are known
inside the class that reresent the network structure.

hope this bring some ligth to the problem.

-Bill

On Fri, Jan 1, 2010 at 6:22 PM, Echedey Lorenzo <[email protected]> wrote:

> Thanks Guillermo for your answer.
>
> The question is.. where and how do I link the generic type tmsg_t to my
> structure (which I suppose is the *enum *I see in the mig .h generated
> file) When I use prettylisten the data I decode is not the one I am
> expecting. Instead of that, I receive random values. That is why i think I
> am not linking my new mig struct to tmsg_t.
>
> Kind Regards
>
> 2010/1/1 Guillermo De Cesco <[email protected]>
>
> Hi,
>>
>> because of the difference in architecture between PC and motes, even
>> between motes, you cant cast the message payload to your struct because in
>> the mote the struct will have a size and padding different than it will or
>> could have in PC platform. So here is why MIG is usefull, you make your
>> message based on tmsg_t and fill the fields of your struct using the
>> functiones provided in the .c file. The same way you read the fields of your
>> struct inside the tmsg_t with the functions provided to read or get.
>>
>> hope this help.
>>
>> -Bill
>>
>> On Fri, Jan 1, 2010 at 12:47 PM, Echedey Lorenzo <[email protected]>wrote:
>>
>>> Hi friends,
>>>
>>> I want to use the same *nx_struct* that I use in my telosb sensorial
>>> application in my C based listener where I record all the received data:
>>>
>>> *mig c -c-prefix=TELOSBAPP_H -target=telosb Telosbapp.h mystruct_t -o
>>> OUTmystruct_t.h
>>> *
>>>
>>> So I get two files, one .c and one .h with an enum and some functions to
>>> get and set data in the structure. But I can't find any C structure to use
>>> in those files nor I don't know how to do it. I can see for instance in the
>>> *prettylisten *C example of the SDK (
>>> /opt/tinyos-2.x/support/sdk/c/sf/prettylisten.c )  that it uses the *
>>> tmsg_t* by default. I think I am not matching received values with my C
>>> mig structure because I have not linked it in any way. What am I doing
>>> wrong? How can I use my mig generated struct (and where is it) with
>>> prettylisten?
>>>
>>> Thanks a lot and Happy New Year.
>>>
>>> --
>>> --------------------------------------------
>>> | Echedey Lorenzo Arencibia  |
>>> --------------------------------------------
>>>
>>> _______________________________________________
>>> Tinyos-help mailing list
>>> [email protected]
>>> https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
>>>
>>
>>
>>
>> --
>> Ing. Guillermo De Cesco
>> Invenio Ingenieria srl.
>> tel: (54)2944 442119
>> cel:(54)2944 15534750
>> web: www.invenioing.com
>> Av. Pioneros 4163 Dpto 6. CP(R8402AMH)
>> San Carlos de Bariloche.
>> Rio Negro, Argentina.
>>
>
>
>
> --
> --------------------------------------------
> | Echedey Lorenzo Arencibia  |
> --------------------------------------------
>



-- 
Ing. Guillermo De Cesco
Invenio Ingenieria srl.
tel: (54)2944 442119
cel:(54)2944 15534750
web: www.invenioing.com
Av. Pioneros 4163 Dpto 6. CP(R8402AMH)
San Carlos de Bariloche.
Rio Negro, Argentina.
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to