aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2018-02-12 07:50:49 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2018-02-12 07:50:49 +1300
commite6f5d3acf27f6705881f5b956ec505fd78bad7a4 (patch)
treed563e8f4c6cbff35431feb892c2c1ea53f86e7a4
parentcb607f6fce8655ff7915cbf6ec67c14cb515f21e (diff)
downloadtrackermap-server-e6f5d3acf27f6705881f5b956ec505fd78bad7a4.tar.gz
trackermap-server-e6f5d3acf27f6705881f5b956ec505fd78bad7a4.tar.bz2
trackermap-server-e6f5d3acf27f6705881f5b956ec505fd78bad7a4.zip
Fix MPIP-618 protocol decoding
-rw-r--r--src/org/traccar/protocol/CastelProtocolDecoder.java76
-rw-r--r--test/org/traccar/protocol/CastelProtocolDecoderTest.java3
2 files changed, 53 insertions, 26 deletions
diff --git a/src/org/traccar/protocol/CastelProtocolDecoder.java b/src/org/traccar/protocol/CastelProtocolDecoder.java
index 022a5b023..ebd3d202c 100644
--- a/src/org/traccar/protocol/CastelProtocolDecoder.java
+++ b/src/org/traccar/protocol/CastelProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -399,7 +399,6 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder {
return null;
}
-
private Object decodeCc(
Channel channel, SocketAddress remoteAddress, ChannelBuffer buf,
int version, ChannelBuffer id, int type, DeviceSession deviceSession) {
@@ -457,6 +456,47 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder {
return null;
}
+ private Object decodeMpip(
+ Channel channel, SocketAddress remoteAddress, ChannelBuffer buf,
+ int version, ChannelBuffer id, int type, DeviceSession deviceSession) {
+
+ if (type == 0x4001) {
+
+ sendResponse(channel, remoteAddress, version, id, (short) type, null);
+
+ return readPosition(deviceSession, buf);
+
+ } else if (type == 0x2001) {
+
+ sendResponse(channel, remoteAddress, id, (short) 0x1001);
+
+ buf.readUnsignedInt(); // index
+ buf.readUnsignedInt(); // unix time
+ buf.readUnsignedByte();
+
+ return readPosition(deviceSession, buf);
+
+ } else if (type == 0x4201 || type == 0x4202 || type == 0x4206) {
+
+ return readPosition(deviceSession, buf);
+
+ } else if (type == 0x4204) {
+
+ List<Position> positions = new LinkedList<>();
+
+ for (int i = 0; i < 8; i++) {
+ Position position = readPosition(deviceSession, buf);
+ buf.skipBytes(31);
+ positions.add(position);
+ }
+
+ return positions;
+
+ }
+
+ return null;
+ }
+
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
@@ -480,31 +520,15 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- if (version == -1) {
-
- if (type == 0x2001) {
-
- sendResponse(channel, remoteAddress, id, (short) 0x1001);
-
- buf.readUnsignedInt(); // index
- buf.readUnsignedInt(); // unix time
- buf.readUnsignedByte();
-
- return readPosition(deviceSession, buf);
-
- }
-
- } else if (version == 3 || version == 4) {
-
- return decodeSc(channel, remoteAddress, buf, version, id, type, deviceSession);
-
- } else {
-
- return decodeCc(channel, remoteAddress, buf, version, id, type, deviceSession);
-
+ switch (version) {
+ case -1:
+ return decodeMpip(channel, remoteAddress, buf, version, id, type, deviceSession);
+ case 3:
+ case 4:
+ return decodeSc(channel, remoteAddress, buf, version, id, type, deviceSession);
+ default:
+ return decodeCc(channel, remoteAddress, buf, version, id, type, deviceSession);
}
-
- return null;
}
}
diff --git a/test/org/traccar/protocol/CastelProtocolDecoderTest.java b/test/org/traccar/protocol/CastelProtocolDecoderTest.java
index bdf69e1af..a7d83f62b 100644
--- a/test/org/traccar/protocol/CastelProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/CastelProtocolDecoderTest.java
@@ -12,6 +12,9 @@ public class CastelProtocolDecoderTest extends ProtocolTest {
CastelProtocolDecoder decoder = new CastelProtocolDecoder(new CastelProtocol());
+ verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN,
+ "24245000363137313135313243333133360000000000000040011b011207133ac49a390464514a15000000008e480c00000917000000000000ffafffaf00010000ffff7800ffffffffffffff003c0d0a"));
+
verifyPositions(decoder, binary(ByteOrder.LITTLE_ENDIAN,
"40408200033231334c32303137303031313039000000000000100136477b5964477b590400000000000000dc410f000000000204000709207910008304011c07110e110dd41a160714a95a0f00001e058c4944442d3231334c2056312e312e3120323031372d30352d3038004944442d3231334c2056312e312e300000006da10d0a"));