aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar
diff options
context:
space:
mode:
authoruser <user@laptop.(none)>2012-10-21 21:42:46 +1300
committeruser <user@laptop.(none)>2012-10-21 21:42:46 +1300
commit0af1cebf1e2f3f719edf5391252fcd4004a75157 (patch)
treed897174c4890a8f4039e24f44020c02411c7c902 /src/org/traccar
parenta3441d3bcd02ec48e408957dfdc61dc6850bc339 (diff)
downloadtrackermap-server-0af1cebf1e2f3f719edf5391252fcd4004a75157.tar.gz
trackermap-server-0af1cebf1e2f3f719edf5391252fcd4004a75157.tar.bz2
trackermap-server-0af1cebf1e2f3f719edf5391252fcd4004a75157.zip
JT600 protocol fix
Diffstat (limited to 'src/org/traccar')
-rw-r--r--src/org/traccar/helper/ChannelBufferTools.java20
-rw-r--r--src/org/traccar/protocol/Jt600ProtocolDecoder.java4
2 files changed, 22 insertions, 2 deletions
diff --git a/src/org/traccar/helper/ChannelBufferTools.java b/src/org/traccar/helper/ChannelBufferTools.java
index 9139ed7ae..4f1ebb7c0 100644
--- a/src/org/traccar/helper/ChannelBufferTools.java
+++ b/src/org/traccar/helper/ChannelBufferTools.java
@@ -15,6 +15,7 @@
*/
package org.traccar.helper;
+import java.util.Formatter;
import org.jboss.netty.buffer.ChannelBuffer;
/**
@@ -77,4 +78,23 @@ public class ChannelBufferTools {
return result;
}
+ /**
+ * Return hex string
+ */
+ public static String readHexString(ChannelBuffer buf, int length) {
+
+ StringBuilder result = new StringBuilder();
+ Formatter formatter = new Formatter(result);
+
+ for (int i = 0; i < length / 2; i++) {
+ formatter.format("%02x", buf.readByte());
+ }
+
+ if (length % 2 == 1) {
+ int b = buf.getUnsignedByte(buf.readerIndex());
+ formatter.format("%01x", b >>> 4);
+ }
+
+ return result.toString();
+ }
}
diff --git a/src/org/traccar/protocol/Jt600ProtocolDecoder.java b/src/org/traccar/protocol/Jt600ProtocolDecoder.java
index 8a2be63fb..11932f8ce 100644
--- a/src/org/traccar/protocol/Jt600ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Jt600ProtocolDecoder.java
@@ -50,8 +50,8 @@ public class Jt600ProtocolDecoder extends GenericProtocolDecoder {
buf.readByte(); // header
// Get device by identifier
- int id = ChannelBufferTools.readHexInteger(buf, 10);
- position.setDeviceId(getDataManager().getDeviceByImei(String.valueOf(id)).getId());
+ String id = Long.valueOf(ChannelBufferTools.readHexString(buf, 10)).toString();
+ position.setDeviceId(getDataManager().getDeviceByImei(id).getId());
buf.readByte(); // protocol version + data type