[Tinyos-devel] copying non nx_structs into messages

David Gay dgay42 at gmail.com
Mon Jul 30 08:55:43 PDT 2007


On 7/27/07, Kevin Klues <klueska at gmail.com> wrote:
> Yes there is a more convenient way to do this or yes I have to copy
> element by element.

Oops, thought it was clear "Yes, you can't do a struct->struct copy,
and no, there's no simpler way than the manual copy". And no, a
language change is not likely.

>
> Kevin
>
> On 7/27/07, David Gay <dgay42 at gmail.com> wrote:
> > On 7/27/07, Kevin Klues <klueska at gmail.com> wrote:
> > > Is there a convenient way to copy the contents of a non nx-type struct
> > > into a message payload?
> > >
> > > i.e. I have a struct defined
> > > typedef struct my_struct {
> > >   uint16_t a;
> > >   uint16_t b;
> > >   uint16_t c;
> > > } my_struct_t;
> > >
> > > and I want to copy it into the payload of a message whose data members
> > > must all be nx types.  Normally I would use something like memcopy,
> > > but this doesn't work when copying from a non-nx type structure into
> > > an nx-type one.
> > >
> > > Do I have to create a duplicate of my struct specifically for casting
> > > the payload of a message to and then copy everything element by
> > > element?
> > >
> > > i.e.
> > >   typedef nx_struct nx_my_struct {
> > >   uint16_t a;
> > >   uint16_t b;
> > >   uint16_t c;
> > > } nx_my_struct_t;
> > >
> > > message_t msg;
> > >
> > > event void MyRead.readDone(my_struct_t* data, error_t error) {
> > >   nx_my_struct_t* data_msg = call AMSend.getPayload(&msg);
> > >   data_msg->a = data->a;
> > >   data_msg->b = data->b;
> > >   data_msg->c = data->c;
> > >   //Doesn't work -- memcpy(data_msg, data, sizeof(my_struct_t));
> > > }
> >
> > Yes.
> >
> > David Gay
> >
>
>
> --
> ~Kevin
>


More information about the Tinyos-devel mailing list