That's correct. Without knowing the actual contents of the header it 
will not be possible to calculate the length. You can either do the 
calculations yourself at a higher layer, or you could implement your own 
interface and handle the header in your module. I suggest the latter if 
this is a more complex project.

If you handle the header in a separate module, you could have a special 
method getPayload(message_t* msg, <headertype>), where <headertype) 
would be your variable to describe the header type you want (e.g., this 
could be implemented using an enum). You would not allow direct access 
to the header fields, but would use special functions to set and get the 
contents of the header fields. In these functions you could also ensure 
that you do not overwrite the wrong fields for the given header type. 
E.g. something like:

error_t MyMessage.setMyField(message_t* msg, <value>) {
   myHeader_t* header = (myHeader_t*)Packet.getPayload(msg);
   if(header->msgType != <special message type>) return ERROR;
   header->myValue = <value>;
   return SUCCESS;
}

Cheers,
Urs

On 12/09/2010 05:54 AM, Xiaohui Liu wrote:
> But there is a nx_union field in "your_header_t", which makes
> sizeof(your_header_t) to be the header length when it contains the
> longest member in the union. And when header comes without the longest
> member, your approach is likely to be problematic, right?
>
> On Wed, Dec 8, 2010 at 2:07 PM, wasif masood <[email protected]
> <mailto:[email protected]>> wrote:
>
>     your header should be the part of the actual payload, then it could
>     look like this:
>
>     command void* Packet.getPayload(message_t* msg, uint8_t len) {
>     void* payload = call SubPacket.getPayload(msg, len +
>     sizeof(your_header_t)*no_of_entries);
>
>     if (payload != NULL) {
>     payload += sizeof(your_header_t)*no_of_entries
>     }
>     return payload;
>     }
>
>
>     On Wed, Dec 8, 2010 at 7:19 PM, Xiaohui Liu <[email protected]
>     <mailto:[email protected]>> wrote:
>
>         Hi everyone,
>
>         My packet has the following format:
>         lower-layer header | my header | payload
>
>         There exists a nx_union filed in the header, thus the header
>         length is not fixed and the typical implementation of
>         Packet.getPayload() may not work:
>
>         command void* Packet.getPayload(message_t* msg, uint8_t len) {
>         uint8_t* payload = call SubPacket.getPayload(msg, len +
>         sizeof(data_header_t));
>         if (payload != NULL) {
>         payload += sizeof(data_header_t);
>         }
>         return payload;
>         }
>
>         Can anyone give me some suggestion on how Packet.getPayload()
>         can be implemented on variable length header? Thanks.
>
>         --
>         -Xiaohui Liu
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to