Re: [Tinyos-help] Fill first 8 bytes with memcpy

2012-08-09 Thread Michael Schippling
There's a number of strange and inexplicable things here,
but probably the problem is that you have not set "pointer"
to point to anything. Try something like:

uint8_t* pointer;
uint8_t buffer[8];
pointer = buffer;
call interface.function(pointer);

or even just:

uint8_t buffer[8];
call interface.function(buffer);


Also, unless you insist on using memcpy(),
you could make your fill loop like this:

for(i=0; i<8; i++)
{
pointer[i] = i+1;
}

MS

Felipe Cruz Martínez wrote:
> Hi all,
> i want to fill the first 8 bytes of a uint8_t* pointer with the values 0x01
> 0x02 0x03 0x04 0x05 0x06 0x07 0x08, and send it by radio (micaz motes):
> This is the code of my app (App.nc):
> <
> /uint8_t* pointer;
> /
> /call interface.function(pointer);/
> ->
> In other module/file, i have got the implementation of that function:
> <
>
> /command void interface.function(uint8_t* pointer) /
> /{/
> /uint8_t x = 1;/
> //
> /memset(pointer, 0, 8*sizeof(uint8_t)); //For security, fill the
> first 8 bytes of the pointer with ‘0x00’
> /
> /for(i=0; i<8; i++) {/
> //
> /memcpy(pointer+i, &x, sizeof(uint8_t));/
> /printf("pointer[%d]: 0x%02X \n", i, pointer[i]);/
> /x++;/
> /}/
> /   }/
> >
>
> /Output:
> /
> /pointer[*1614823456ð*]: *0x00 */
> /pointer[1]: *0x00 */
> /pointer[2]: 0x03 /
> /pointer[3]: 0x04 /
> /pointer[4]: 0x05 /
> /pointer[5]: 0x06 /
> /pointer[6]: 0x07 /
> /pointer[7]: 0x08 /
> //
> As you can see, first two bytes of the pointer are wrong.
> First byte of pointer got a wrong index: ‘1614823456ð’, and his value
> should be pointer[0] = 0x01
> Second byte got a correct index, but a value of ‘0x00’, when it should be
> pointer[1] = 0x02
> What i’m doing wrong? I hope that someone can help me, i took several days
> without solving this problem.
> Thanks for your time,
> Felipe.
>
>
> ___
> Tinyos-help mailing list
> Tinyos-help@millennium.berkeley.edu
> https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
>

___
Tinyos-help mailing list
Tinyos-help@millennium.berkeley.edu
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help


[Tinyos-help] Fill first 8 bytes with memcpy

2012-08-09 Thread Felipe Cruz Martínez
Hi all,

i want to fill the first 8 bytes of a uint8_t* pointer with the values 0x01 
0x02 0x03 0x04 0x05 0x06 0x07 0x08, and send it by radio (micaz motes):

This is the code of my app (App.nc):
<  
uint8_t* pointer;

call interface.function(pointer);
->

In other module/file, i have got the implementation of that function:
<


command void interface.function(uint8_t* pointer) 
{
uint8_t x = 1;

memset(pointer, 0, 8*sizeof(uint8_t)); //For security, fill the first 8 
bytes of the pointer with ‘0x00’

for(i=0; i<8; i++) {
   
memcpy(pointer+i, &x, sizeof(uint8_t));
printf("pointer[%d]: 0x%02X \n", i, pointer[i]);
x++;
}
   }
>


Output:

pointer[1614823456ð]: 0x00 
pointer[1]: 0x00 
pointer[2]: 0x03 
pointer[3]: 0x04 
pointer[4]: 0x05 
pointer[5]: 0x06 
pointer[6]: 0x07 
pointer[7]: 0x08 

As you can see, first two bytes of the pointer are wrong.
First byte of pointer got a wrong index: ‘1614823456ð’, and his value should be 
pointer[0] = 0x01
Second byte got a correct index, but a value of ‘0x00’, when it should be 
pointer[1] = 0x02

What i’m doing wrong? I hope that someone can help me, i took several days 
without solving this problem.

Thanks for your time,
Felipe.___
Tinyos-help mailing list
Tinyos-help@millennium.berkeley.edu
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help