Hi Brandon! Yes. My fault was at another place. So this C++ code works. You can use it only on the PC side. A C code you can find in $TOSROOT/support/sdk/c/sf/message.c
//-------------------------------------------------------------------------- /* u2f and f2u convert raw 32-bit values to/from float. This code assumes that the floating point rep in the uint32_t values: bit 31: sign, bits 30-23: exponent, bits 22-0: mantissa matches that of a floating point value when such a value is stored in memory. */ /* Note that C99 wants us to use the union approach rather than the cast-a-pointer approach... */ union f_and_u { uint32_t u; float f; }; static float u2f(uint32_t x) { union f_and_u y = { .u = x}; return y.f; } static uint32_t f2u(float x) { union f_and_u y = { .f = x}; return y.u; } //------------------------------------------------------------ The David's implementation should make the conversion superfluous, but with the one-line patch it doesn't work for me. I assume, one should really use the cvs version of nesC. Best wishes, Andrey Brandon Fu wrote: > Hi, > I have read thru ur emails, and I found out that u mention about int to > float conversion for the motes packet data. Can I use your methods to > apply to my application, as I need to convert my int-> float data. > > I m using mica2 and mib510, tinyos-2.0. Thank you in advance > > yours sincerely, > brandon > >> Date: Tue, 20 Jan 2009 00:04:53 +0100 >> From: andrey.gur...@online.ua >> To: tinyos-help@millennium.berkeley.edu >> Subject: [Tinyos-help] Using cast float/int or nx_float >> >> Hi all, hi David! >> >> I'm trying out two ways of transmitting of float numbers between PC and >> motes now. The first one is with cast int<->float, the second one is >> with nx_float (thanks David for this implementation!). >> >> The simple C++ example doesn't work for me now: >> float pi = 1.1; >> int ipi; >> assert(sizeof(int) == sizeof(float)); >> ipi = reinterpret_cast<int&>(pi); >> >> Motes receive crazy values. >> >> Regarding the second approach. David suggests either to download the >> latest nesc from cvs or to add only one line of code to >> /usr/bin/nescc-mig. So I've added this one line. But during compiling I >> receive the message, there are errors nx_float. Without nx_float all is >> well. I hope you could pointing me, where I'm wrong. >> >> And yet another small question. nx_float should work for atmega128 on >> MicaZ, so it would also work for atmega1281 on IRIS? Or additional >> changes should be made on platform files for IRIS in order to get it >> working? >> >> Thanks in advance! >> Andrey >> >> >> >> > [People regularly ask for nx_float support...] >> > >> > I've just added nx_float support to T2 for atmega128 and msp430 based >> > platforms, along with an apps/tests/NxFloat test app to test that it's >> > working (works for me on micaz and telosb...). >> > >> > The mechanics: each processor arch should define it's functions to >> > convert floats to and from the wire format for floating point. This >> > format is defined to be that used by floatToRawIntBits method >> > > (http://java.sun.com/javase/6/docs/api/java/lang/Float.html#floatToRawIntBits(float)), >> > with the resulting 32-bit number in big-endian format. >> > >> > Conveniently, on the msp430 and atmega128 we can just use memcpy to do >> > this conversion ;-) >> > >> > It would be good if some people out there would fill out the missing >> > processors... >> > >> > To use this with mig, you will need the latest nesC from CVS, or just >> > apply the following patch to /usr/bin/nescc-mig: >> > barnowl:~/motes/nesc/1.3/tools owl$ cvs diff -u -r1.6 nescc-mig.in >> > Index: nescc-mig.in >> > =================================================================== >> > RCS file: /cvsroot/nescc/nesc/tools/nescc-mig.in,v >> > retrieving revision 1.6 >> > retrieving revision 1.7 >> > diff -u -r1.6 -r1.7 >> > --- nescc-mig.in 2 May 2006 21:56:49 -0000 1.6 >> > +++ nescc-mig.in 19 Sep 2008 23:54:34 -0000 1.7 >> > @@ -185,6 +185,7 @@ >> > >> > return "PUSH" if $basetype =~ /^AN?[SU]$/; >> > return "POP" if $basetype eq "AX"; >> > + return "F" if $basetype =~ /^Nnx_float/; >> > return "U" if $basetype =~ /^Nnxle_u/; >> > return "I" if $basetype =~ /^Nnxle_/; >> > return "BU" if $basetype =~ /^Nnx_u/; >> > >> > >> > David >> > _______________________________________________ >> > Tinyos-devel mailing list >> > tinyos-de...@millennium.berkeley.edu >> > > https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-devel >> > >> >> _______________________________________________ >> Tinyos-help mailing list >> Tinyos-help@millennium.berkeley.edu >> https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help > > ------------------------------------------------------------------------ > Share your beautiful moments with Photo Gallery. Windows Live Photo > Gallery <http://get.live.com/photogallery/overview> _______________________________________________ Tinyos-help mailing list Tinyos-help@millennium.berkeley.edu https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help