Hello,
i'm programming my own Outgauge Tool in Java.
I take the Outgauge UDP Packet and want to get the 4 Speed Bytes (12 - 15). After that i use a bitshifter to convert this 4 bytes into float.
But the float is totally wrong with the values.
Can anybody see my fault?
Here is the code:
thx
i'm programming my own Outgauge Tool in Java.
I take the Outgauge UDP Packet and want to get the 4 Speed Bytes (12 - 15). After that i use a bitshifter to convert this 4 bytes into float.
But the float is totally wrong with the values.
Can anybody see my fault?
Here is the code:
<?php
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
/* Data Packet in detail
* Time [0 - 3]
* AutoName [4 - 7]
* Flags [8 - 9]
* Gang [10]
* SpareB [11]
* Speed [12 - 15]
* RPM [16 - 19]
* Turbo [20 - 23]
* EngTemp [24-27]
* Fuel [28 - 31]
* Öldruck [32 - 35]
* ÖlTemp [36 - 39]
* Dashlight [40 - 43]
* ShowLights [44 - 47]
* Throttle [48 - 51]
* Brake [52 - 55]
* Clutch [56 - 59]
* Display1 [60 - 75]
* Display2 [76 - 91]
* ID [92 - 95]
*/
public class client {
private static final int MASK = 0xff;
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) {
DatagramSocket socket = null;
DatagramPacket packet = new DatagramPacket(new byte[92], 92);
try {
socket = new DatagramSocket(9090);
for(;;) {
socket.receive(packet);
byte data[] = packet.getData();
String AutoName = new String();
AutoName += (char)data[4];
AutoName += (char)data[5];
AutoName += (char)data[6];
AutoName += (char)data[7];
int bits = 0;
int i = 12;
for (int shifter = 3; shifter >= 0; shifter--) {
bits |= ((int)data[i] & MASK) << (shifter * 8);
i++;
}
Float Speed = Float.intBitsToFloat(bits);
System.out.print("Car: " + AutoName + " | Gear: " + (int)data[10]);
System.out.print(" | Speed: " + Speed + "| Len: " + data.length + "\n");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
socket.close();
}
}
}
?>