http://docs.tinyos.net/index.php/Safe_TinyOS#Understanding_Safe_Code
Quoting Michael Schippling <[email protected]>: > It's all raw bytes all the way down... > but with a good cast you can produce anything. > > Create your structures however you like, > as long as they are equal to or shorter than > the maximum payload size: > typedef nx_struct > { > nx_uint8_t size; > nx_uint16_t data1; > nx_uint8_t data2; > } myData; > > Then create a base level TOS_Msg > (or whatever they call it these days) > and cast the data element to your struct > using a pointer: > TOS_Msg myMessage; > myData *myDatap; > myDatap = (myData*) myMessage.data; > > Fill in myDatap as you would with any structure pointer: > myDatap->data1 = 0xBEEF; > > Then specify the actual length when you do the Send. > Note, if you have a variable length array in your struct > you will need to calculate the actual length that you want > to send, rather than just using sizeof(): > call RStatusMsg.send( TosBaseId, sizeof(myData), myDatap); > > On the Receive end you can look at your size field, > poke directly at the TOS_Msg.length, or be all > modern and data-isolated and use some abstract > interface to get the actual message length. Once > you know the length you can cast the Msgp->data > field back to your struct. > > Or you could just define message types for each of > your structures as the AM gods meant you to do. > > BTW can anyone explain what the "COUNT..." syntax means here? > nx_uint8_t (COUNT(0) data)[0]; > I couldn't find it in the ANSI spec I looked at... > > MS > > > > > > [email protected] wrote: >> That's at least something that lead me to working solution. Ctp >> does not uses embedded structs (neither tymo does, too). Both use >> 'raw' bytes and point arithmetics. That's seems to be the way it >> works. >> >> Quoting wasif masood <[email protected]>: >> >>> you can get some idea form this CTP header structure : >>> >>> typedef nx_struct { >>> nx_ctp_options_t options; >>> nx_uint16_t parent; >>> nx_uint16_t etx; >>> nx_uint8_t (COUNT(0) data)[0]; // Deputy place-holder, field will probably >>> be removed when we Deputize Ctp >>> } ctp_routing_header_t; >>> >>> is uses flexible array. >>> >>> >>> On Sun, Nov 28, 2010 at 2:04 PM, <[email protected]> wrote: >>> >>>> How can i send a varying array of items as part of a message? >>>> >>>> I cast the return of call Packet.getPayload to my struct. The struct >>>> consists of some fix attributes. One of them is the number of >>>> attributes. >>>> The last attribute is a pointer/ array of an other struct. >>>> >>>> Is there anybody who did something similar or might tell how to do this? >>>> >>>> Best regards, >>>> Enrico >>>> >>>> _______________________________________________ >>>> Tinyos-help mailing list >>>> [email protected] >>>> https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help >>>> >>> >>> >>> -- >>> Wasif Masood >>> >> >> >> >> >> _______________________________________________ >> Tinyos-help mailing list >> [email protected] >> https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help _______________________________________________ Tinyos-help mailing list [email protected] https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
