On 6/12/07, Iwona Jozwiak <[EMAIL PROTECTED]> wrote:
I am working with TinyOS 2.0 and using MIG for generating Java files. I have a problem with structure size (there are different sizes in a header file and in Java class). When I define a structure in header file:typedef nx_struct attribute { nx_uint8_t messageType:3; nx_uint8_t queryId; nx_uint8_t attribute:5; } attribute_t; it takes total 16 bits (3+8+5 = 16) what is 2 bytes.
No it isn't. Read up on C struct layout rules, on which the rules for nx_structs are based: - fields are allocated in the order they are declared - non bit-fields start on some byte boundary In the case of nx_ types, things are maximally packed given these rules (for non nx_ types, there may be some additional alignment constraints).
However in Java classgenerated by MIG with makefile line:
AttributeMsg.java: mig java -target=null -java-classname=$(APP_PACKET).AttributeMsg Comm.h attribute -o $@ the structure size is different: public static final int DEFAULT_MESSAGE_SIZE = 3; When I use only full types of variables in header file, size in Java class is correct. When using bits, there is always one byte more in Java class (and this in independent of the amount of bit-variables). I would like to send more these structures in one message and every byte is for me very valueable.
Reorder the fields. David Gay _______________________________________________ Tinyos-help mailing list [email protected] https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
