Re: I cannot find my C mig struct
Guillermo De Cesco <decescog <at> gmail.com>
2010-01-02 00:03:45 GMT
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
<echedey <at> gmail.com> 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
<decescog <at> gmail.com>
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
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
Tinyos-help <at> millennium.berkeley.edu
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.
<div>
<p>Hi,<br><br>suppose you have the following structure defined in mote's side:<br><br> typedef nx_struct SequencedIdPacket{<br> nx_uint8_t moteId;<br> nx_uint16_t sqnumber;<br> nx_uint8_t data[ ];<br>
}SequencedIdPacket_t;<br><br>, 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#):<br><br>
int len, i;<br> uint8_t msg_type;<br>
uint8_t msg_len;<br>
uint8_t moteId; <br> //HERE I GET A PACKET FROM SERIALFORWARDER MAY BE DIFERENT IF YOU CONNECT DIRECTLY TO SERIAL<br> //PORT.<br> uint8_t *packet = read_sf_packet(fd, &len);<br> <br>
if (!packet)<br> exit(0);<br><br> if (len >= 1 + SPACKET_SIZE && packet[0] == SERIAL_TOS_SERIAL_ACTIVE_MESSAGE_ID){<br> <br> tmsg_t *msg = new_tmsg(packet + 1, len - 1);<br><br> if (!msg)<br>
exit(0);<br><br> //THIS IS THE SAME AS EXPLAINED BELOW BUT FOR THE FIELDS OF TINYOS MSG PACKET<br> msg_type = spacket_header_type_get(msg);<br> msg_len = spacket_header_length_get(msg);<br> <br>
free(msg);<br> //HERE IS WHERE YOU ACTUALLY HAVE A POINTER TO THE BEGINNING OF YOUR DATA<br> //AS SEEN BELOW YOU HAVE TO USE THE FUNCTION PROVIDED TO GET THE FIELDS OF THE PACKET<br> //iN THIS CASE I AM READING THE MOTES ID <br>
msg = new_tmsg(packet + 1 + SPACKET_SIZE,len - 1 - SPACKET_SIZE);<br> moteId = seqidpacket_moteId_get(msg);<br> .......<br>----------------------------------------<br>Notes:<br>SPACKET_SIZE and SERIAL_TOS_SERIAL_ACTIVE_MESSAGE_ID are defined "serialpacket.h" and correspond to the serial<br>
protocol comunication of tinyos. <br><br>prettylisten.c prints Tinyos msg header info and payload in hex format as seen below:<br><br> spacket_header_dest_get(msg),<br> spacket_header_src_get(msg),<br> spacket_header_length_get(msg),<br>
spacket_header_group_get(msg),<br> spacket_header_type_get(msg));<br> hexprint((uint8_t *)tmsg_data(msg) + spacket_data_offset(0), tmsg_length(msg) - spacket_data_offset(0));<br><br> free(msg);<br>
---------------------------------------------<br><br>, 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.<br><br>hope this bring some ligth to the problem.<br><br>-Bill<br><br></p>
<div class="gmail_quote">On Fri, Jan 1, 2010 at 6:22 PM, Echedey Lorenzo <span dir="ltr"><<a href="mailto:echedey <at> gmail.com">echedey <at> gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote">Thanks Guillermo for your answer.<br><br>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.<br><br>Kind Regards<br><br><div class="gmail_quote">2010/1/1 Guillermo De Cesco <span dir="ltr"><<a href="mailto:decescog <at> gmail.com" target="_blank">decescog <at> gmail.com</a>></span><div>
<div></div>
<div class="h5">
<br><blockquote class="gmail_quote">
Hi, <br><br>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.<br><br>hope this help.<br><br>-Bill<br><br><div class="gmail_quote">
<div>
<div></div>
<div>On Fri, Jan 1, 2010 at 12:47 PM, Echedey Lorenzo <span dir="ltr"><<a href="mailto:echedey <at> gmail.com" target="_blank">echedey <at> gmail.com</a>></span> wrote:<br>
</div>
</div>
<blockquote class="gmail_quote">
<div>
<div></div>
<div>
Hi friends,<br><br>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:<br><br clear="all">mig c -c-prefix=TELOSBAPP_H -target=telosb Telosbapp.h mystruct_t -o OUTmystruct_t.h<br><br><br>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?<br><br>Thanks a lot and Happy New Year.<br><br>-- <br>--------------------------------------------<br>| Echedey Lorenzo Arencibia |<br>--------------------------------------------<br><br>
</div>
</div>_______________________________________________<br>
Tinyos-help mailing list<br><a href="mailto:Tinyos-help <at> millennium.berkeley.edu" target="_blank">Tinyos-help <at> millennium.berkeley.edu</a><br><a href="https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help" target="_blank">https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help</a><br>
</blockquote>
</div>
<br><br clear="all"><br>
-- <br>Ing. Guillermo De Cesco<br>Invenio Ingenieria srl.<br>tel: (54)2944 442119<br>cel:(54)2944 15534750<br>web: <a href="http://www.invenioing.com" target="_blank">www.invenioing.com</a><br>Av. Pioneros 4163 Dpto 6. CP(R8402AMH)<br>
San Carlos de Bariloche.<br>
Rio Negro, Argentina.<br>
</blockquote>
</div>
</div>
</div>
<br><br clear="all"><br>-- <br>--------------------------------------------<br>| Echedey Lorenzo Arencibia |<br>--------------------------------------------<br>
</blockquote>
</div>
<br><br clear="all"><br>-- <br>Ing. Guillermo De Cesco<br>Invenio Ingenieria srl.<br>tel: (54)2944 442119<br>cel:(54)2944 15534750<br>web: <a href="http://www.invenioing.com">www.invenioing.com</a><br>
Av. Pioneros 4163 Dpto 6. CP(R8402AMH)<br>San Carlos de Bariloche.<br>Rio Negro, Argentina.<br>
</div>