[Tinyos-devel] copying non nx_structs into messages

Kevin Klues klueska at gmail.com
Fri Jul 27 13:04:47 PDT 2007


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));
}

-- 
~Kevin


More information about the Tinyos-devel mailing list