[Tinyos-help] C mig generated files
Michael Schippling
schip at santafe.edu
Mon Dec 4 13:25:53 PST 2006
Here is another shining example of why I should Just-Stay-Out-Of-It(TM),
but I plunge ahead anyway....All of my advice is based on T1, as I have
not T2 loaded (being afraid that it will destroy my already shaky working
back rev)....anyway...
Sorry for the confusion of typedefs. What you tried:
"payload = &msg->data ;"
might work in some compilers, but is redundant.
If "msg" is indeed declared as a pointer to TOS_Msg,
and set to the beginning of a message packet,
and "data" is a byte array element of TOS_Msg, ala:
int8_t data[TOSH_DATA_LENGTH];
as it says in my T1 AM.h.
Then the right way to get a pointer to the payload
contained in "data", is:
myStuff *ms = (myStuff*)msg->data;
Note, there is no "&" ampersand to take the address of data
because C treats an array name (without an index) as a pointer
already. Also you need to cast the pointers to the right types
(...yes, dear compiler, I really meant to do that...) or the
compiler will "help" you by whinging about it.
What confused me about the first message (many things confuse me...)
was this: payload = (tmsg_t *) tmsg_data(msg) ;
where you seem to want to cast the payload to be a TOS_Msg. What I think you
really want is your own payload structure "myStuff" or whatever you call it.
But I'd have to be able to rummage through all your T2 files to see what the
error "undefined type `struct tmsg'" really means.
I don't know what all the other functons you are using do, but
my guess would be that they return pre-defined lengths for various
structs, so the arithemetic at the end, which you say works, should
do just about the same thing as the more succinct but perhaps less
portable casting I was advocating....
MS
Dimas Abreu Dutra wrote:
> Hi,
>
> Thanks for the help, but I had to use a different solution.
>
> Yes, this is correct. The +1 is to skip the first byte of serial
> packets which indicates packet kind (0 for active-message packets).
>
> This was already done in tmsg_t *msg = new_tmsg(packet + 1, len - 1);
>
> > From the description it sounds like your ReportMsg_field_get()
> function
> > is expecting to get a pointer to the payload, not the full message.
> >
> > Unless things are very different in T2, the message payload should
> > be at a fixed offset from the beginning of the packet and shouldn't
> > vary with payload type (although the actual length might vary). The
> > old standby technique is something like:
> >
> > TOS_Msg *msg = (TOS_Msg*) (packet + 1); // assume +1 skips sync byte?
> > tmsg_t *tmsg = (tmsg_t *) msg->data;
>
> The TOS_Msg type in the T2 C support libraries is the tmsg_t. If I tried
> payload = &msg->data ;
> the compiler complained: deferencing pointer to incomplete type. If I used
> payload = (tmsg_t *) tmsg_data(msg) ;
> the compiler complained: invalid use of undefined type `struct tmsg'.
>
> After some tries and a few segmentation faults, I found out that
> payload = new_tmsg(tmsg_data(msg) + spacket_data_offset(0),
> spacket_header_length_get(msg));
> would make it work, otherwise the bytes inside each field of the
> ReportMsg would come shuffled randomlly (the same random shuffling always).
>
> ~Dimas~
>
> ------------------------------------------------------------------------
> Novidade no Yahoo! Mail: receba alertas de novas mensagens no seu
> celular. Registre seu aparelho agora!
> <http://us.rd.yahoo.com/mail/br/tagline/mobile_alerts/*http://br.mobile.yahoo.com/mailalertas/>
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Tinyos-help mailing list
> Tinyos-help at Millennium.Berkeley.EDU
> https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
More information about the Tinyos-help
mailing list