You can use the following scheme:
typedef nx_struct my_message
{
nx_uint8_t data[TOSH_DATA_SIZE];
}my_message;
Then after filling the desired amount of data, as Michael said, you can send
only a desired length, e.g.
memcpy(message_ptr, source_buffer, len);
call AMSend.send(address, message_ptr, len);
Note that the MaxPayload function depends on the TOSH_DATA_SIZE, which you
have to define by your self; the default value is 28.
So, if you will define a big enough TOSH_DATA_SIZE, you will be OK. Of
course there is a disadvantage that Michael mentioned - the static buffers
are allocated up to TOSH_DATA_SIZE and can steal your valuable memory.
Arik
On Fri, Mar 5, 2010 at 23:18, Michael Schippling <[email protected]> wrote:
> Only the number of bytes specified in the length field are
> transmitted. So you can send any number up to the MaxPayload
> size defined in the system by specifying the actual length
> in the send() call.
>
> Internal message buffers are allocated to the MAX length,
> usually statically, which is a good reason to keep the MAX
> as small as possible.
>
>
> MS
>
> [email protected] wrote:
> > All:
> >
> > I'm trying to figure out how to have dynamic payload sizes for the
> > packets I am sending. I know usually we use a nx_struct to define our
> > packets but I'm not sure how to make this dynamic in size really. The
> > way my design works, I won't know exactly how much data should be sent
> > in a packet until I've collected that amount of data and I hate to
> > waste Tx power on a full packet if it isn't needed. This data needs
> > to be some sort of data type that I can perform bit operations on.
> >
> > The other issue, I have asked about before, is dealing with maximum
> > packet size. I know that I should use getMaxPayload(), but how should
> > I define the struct based on this data without traditional dynamic
> > memory allocation?
> >
> > I hope these questions make sense.
> >
> > Newlyn
> >
> > _______________________________________________
> > 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
>
--
Best Regards,
Arik Sapojnik
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help