[Tinyos-help] FW: Errors to pass from hex to dec

Symon Vezina symon_vezina at hotmail.com
Thu Jan 15 10:14:28 PST 2009




 I'm not sure either about what your're trying to do. Seems like your're trying to unmarshalizing or unserializing radio data. And from the bytes received, you seem to be trying to reconstruct a uint32_t. Apart from my speculation and to answer your question, here is what I would do:  #include <string.h>#include <stdint.h>#include <stdio.h> typedef struct {  uint8_t temp1;  uint8_t temp2;  uint8_t temp3;  uint8_t temp4;}temp_t; int main() {   uint32_t temp5 = 0;   temp_t temp = {0xAA,0xBB,0xCC,0xDD};   uint32_t *ptr = (uint32_t*)&temp;   printf("*ptr: %X\n",*ptr); //*ptr points to 0xDDBBCCAA   temp5 = htonl(*ptr); //temp5 is now 0xAABBCCDD   printf("temp5: %X\n",temp5); //prints 0xAABBCCDD   return 0; }  Hence, when you receive your uint32_t in separate bytes, cast those bytes into a uint32_t pointer and then dereference your pointer to those bytes and the pointer will yeild a uint32_t (sometimes in reverse form because of endianness issues). You can make use of the nx and nxle structs in tinyos to get rid of this endianness issues. Beware of pointing to a structure that does not fit perfectly in a multiple of 16bits (msp430 cpu) since there will be padding in your structure and when dereferencing your pointer, yo will most probably corrupt your value with those padded bytes .  Symon > Date: Thu, 15 Jan 2009 10:16:12 +0100> From: uhu at gmx.ch> To: aguilorena at gmail.com> CC: tinyos-help at millennium.berkeley.edu> Subject: Re: [Tinyos-help] Errors to pass from hex to dec> > Hi Lorena,> > I am not sure I understand your question. Why do you use asm?> > How about:> > temp5 = (temp1 << 24l) + (temp2 << 16l) + (temp3 << 8l) + temp4;> > or> > temp5 = 0xAABBCCDDl;> > The 'l' (lower case 'L') tells the compiler to treat the literal as long > (32 bit integer).> > Cheers,> Urs> > > Lorena Aguirre wrote:> > Hello,> > > > I have a sintax error when I try to do asm{temp5 =swap(temp5)}> > > > I have this:> > > > uint8_t temp1 = 0xAA;> > uint8_t temp2 = 0xBB;> > uint8_t temp3 = 0xCC;> > uint8_t temp4 = 0xDD;> > > > and I want to pass them to:> > > > uint32_t temp5;> > > > and than temp5 will be temp5=0xAABBCCDD;> > > > Could anyone help me please?> > > > Thank you!!!> > Lorena> _______________________________________________> Tinyos-help mailing list> Tinyos-help at millennium.berkeley.edu> https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help


_________________________________________________________________
Show them the way! Add maps and directions to your party invites.
http://www.microsoft.com/windows/windowslive/events.aspx
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://www.millennium.berkeley.edu/pipermail/tinyos-help/attachments/20090115/04434af5/attachment.htm 


More information about the Tinyos-help mailing list