[Tinyos-help] MSP struct field alignment/Strange results when sending uint16_t values.(SOLVED)

Manu Bansal manub686 at gmail.com
Sun Sep 3 04:27:50 PDT 2006


Hi,
This post is in response to the thread
http://mail.millennium.berkeley.edu/pipermail/tinyos-help/2006-March/015499.htmlof
March, 2006. I didn't how to reply in that thread itself, hence a
separate post.

David said:

--------------------------------------------------------

Sumit,

You're right - the padding byte gets placed after the uint8_t.

The sizes can be deceptive though.  The problem I ran into was actually
between the computer and the mote, passing an array of non-word aligned
structs.  I was writing bytes into a buffer that was contained in an element
of an array of structures where the struct's weren't word aligned, and I was
passing that array in a message to a java app on the computer.  So the
computer expected the values in the array to be placed in certain locations,
as they were defined in the .h file, and the msp430 actually placed the
values in different locations because of the padding bytes it automatically
adds.

sizeof(f1) = 1
sizeof(f2) = 4
sizeof(a) = 6

a.f1 = 0xAA;
a.f2 = 0xBBCCDDEE;
=> {0xAA, 0x0, 0xEE, 0xDD, 0xCC, 0xBB}

If you're doing everything mote-side and don't have to worry about
communicating with a pc, then you shouldn't see any problems.
-david

--------------------------------------------------------

Wouldn't there be a problem even if it's everything mote-side? If I try to
send a struct by passing the pointer to it as the pointer to buffer (to
RadioSend.send), it will transmit extra bytes, and what I think to be a
full-length packet could actually be longer. And casting into the struct
back on the receiver will have mismatched fields. I know this is a standard
C programming issue, and the solution usually is to first write all fields
of the struct (by referring by field name) into a string, and then
transmitting the char buffer.

Thanks,

Manu Bansal.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.millennium.berkeley.edu/pipermail/tinyos-help/attachments/20060903/fcb8351d/attachment.htm


More information about the Tinyos-help mailing list