Actually, there was a stupid mistake in my code where I access the
data. With the mistake fixed, it works!

I mean this works:
receive(message_t * msg, void * payload, uint8_t length){
  sensing_msg_t * sm = payload;
  do_something_with(sm->value[0]);
  ...
}

I have to say I don't really understand why...
Does the nesc (or C) compiler recognize the uint8_t[] and
automatically put copy instructions ? Or better, does it set the value
of <code>value</code> with payload+2bytes ?

Anyway, thanks for your reply Michael.

Romain

On 5/18/07, Michael Schippling <[EMAIL PROTECTED]> wrote:
unfortunately
        nx_uint8_t value[];
is just another way to say
        nx_uint8_t *value;

The packet definition must contain the actual data because
the lower levels treat the message as a single char array.

When you do the assignment, whatever is at payload[2] and [3]
is treated as a pointer, probably into space...especially on
the receiving end because it will be pointing to something
in the transmitter's memory.

I'm not sure where the copy you are trying to avoid is,
so I can't be of much more help...

MS


Romain Thouvenin wrote:
> Actually, the copy does not work either.
>
> When I access sm->value[1] at different times, it seems to have random
> values, I guess I'm accessing the data of some other component.
>
> I quite clueless now...
>
> Romain
>
> On 5/18/07, Romain Thouvenin <[EMAIL PROTECTED]> wrote:
>> Hi,
>>
>> I have made a TLV packet with the following declaration :
>> typedef nx_struct sensing_msg {
>>   nx_uint8_t flags;
>>   nx_uint8_t length;
>>   nx_uint8_t value[];
>> } sensing_msg_t;
>>
>> I used [] instead of a pointer, because I need to mig the packet in
>> java and a pointer won't work. In my nesC application, when I receive
>> the packet, I would like to avoid a copy of the payload, so I naïvely
>> tried :
>> sensing_msg_t * sm = payload;
>>
>> But of course It does not work, payload[2] is assigned to value, not
>> value[0].
>> So I tried then :
>> sm->value = payload + 2
>>
>> But this does not compile, even if I cast value into a pointer.
>>
>> Am I obliged to copy the payload here, or is there another trick I
>> didn't think of ?
>>
>> Thanks for your help,
>>
>> Romain
>>
> _______________________________________________
> Tinyos-help mailing list
> Tinyos-help@Millennium.Berkeley.EDU
> https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

_______________________________________________
Tinyos-help mailing list
Tinyos-help@Millennium.Berkeley.EDU
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to