[Tinyos-help] A doubt about little-endian TOS floats and java

virginia estellers virginia.estellers at gmail.com
Fri Apr 27 06:40:13 PDT 2007


Hello,

I'm parsing messages from TOS format using java, but I've got some trouble
with floating points and little-endian.
MIG tool doesn't seem to work with floats and I though it was due to
problems with little-big endian. So far, I've tried to convert myself the
messages
modifying MIG java files, just reversing the bytes once MIG gives you the
buffer.
It doesnt work, has someone some idea what i may be doing wrong?

Here's some code generated by MIG and the last 2 methods i've done myself


/**
* Return the offset (in bytes) of the field 'freq'
*/
public static int offset_freq() {
return (144 / 8);
}

/**
* Return the value (as a float) of the field 'freq'
*/
public float get_freq() {
return (float)getFloatElement(offsetBits_freq(), 32);
}

/**
* it makes the same than the above function generated by MIG
*/
float readFloatBigEndian() {

int accum = 0;
for ( int shiftBy=0; shiftBy<32; shiftBy+=8 ) {
accum |= ( ((byte)getSIntElement(offsetBits_freq()+shiftBy,8)) & 0xff ) <<
shiftBy; }
return Float.intBitsToFloat( accum );
}

/**should work assuming little-endian*/
float readFloatLittleEndian() {
int accum = 0;
for ( int shiftBy=0; shiftBy<32; shiftBy+=8 ) {
accum |= ( ((byte)getSIntElement(offsetBits_freq()+24-shiftBy,8)) & 0xff )
<< shiftBy; }
return Float.intBitsToFloat( accum );
}


Thanks in advance.
Cheers
                     Virginia
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.millennium.berkeley.edu/pipermail/tinyos-help/attachments/20070427/4266e84f/attachment.htm


More information about the Tinyos-help mailing list