aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-09-03 09:47:26 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2015-09-03 09:47:26 +1200
commit8effc28a59e132982eced64ee470132bfe5a38b9 (patch)
tree78e93e0e32a850bf2999ad520b61281e1828a8be
parentb092dac5607ab8219a4f1d4b8cf8ee89948cc1d3 (diff)
downloadtraccar-server-8effc28a59e132982eced64ee470132bfe5a38b9.tar.gz
traccar-server-8effc28a59e132982eced64ee470132bfe5a38b9.tar.bz2
traccar-server-8effc28a59e132982eced64ee470132bfe5a38b9.zip
Fix Tytan float decoding
-rw-r--r--src/org/traccar/protocol/TytanProtocolDecoder.java13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/org/traccar/protocol/TytanProtocolDecoder.java b/src/org/traccar/protocol/TytanProtocolDecoder.java
index 558664e2d..f7c9b8e4d 100644
--- a/src/org/traccar/protocol/TytanProtocolDecoder.java
+++ b/src/org/traccar/protocol/TytanProtocolDecoder.java
@@ -16,6 +16,7 @@
package org.traccar.protocol;
import java.net.SocketAddress;
+import java.nio.ByteOrder;
import java.nio.charset.Charset;
import java.util.Date;
import java.util.LinkedHashSet;
@@ -37,6 +38,12 @@ public class TytanProtocolDecoder extends BaseProtocolDecoder {
super(protocol);
}
+ private static float readSwappedFloat(ChannelBuffer buf) {
+ byte[] bytes = new byte[4];
+ buf.readBytes(bytes);
+ return ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, bytes).readFloat();
+ }
+
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg)
@@ -114,9 +121,9 @@ public class TytanProtocolDecoder extends BaseProtocolDecoder {
{
int n = buf.readUnsignedByte() >> 4;
if (n < 2) {
- position.set(Event.PREFIX_ADC + n, buf.readFloat());
+ position.set(Event.PREFIX_ADC + n, readSwappedFloat(buf));
} else {
- position.set("di" + (n - 2), buf.readFloat());
+ position.set("di" + (n - 2), readSwappedFloat(buf));
}
}
break;
@@ -186,7 +193,7 @@ public class TytanProtocolDecoder extends BaseProtocolDecoder {
buf.readUnsignedInt(); // diagnostic
break;
case 90:
- position.set(Event.KEY_POWER, buf.readFloat());
+ position.set(Event.KEY_POWER, readSwappedFloat(buf));
break;
case 99:
buf.readUnsignedInt(); // tachograph