aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/org/traccar/protocol/CastelProtocolDecoder.java32
-rw-r--r--test/org/traccar/protocol/CastelProtocolDecoderTest.java3
2 files changed, 34 insertions, 1 deletions
diff --git a/src/org/traccar/protocol/CastelProtocolDecoder.java b/src/org/traccar/protocol/CastelProtocolDecoder.java
index 7f8009389..09d314dae 100644
--- a/src/org/traccar/protocol/CastelProtocolDecoder.java
+++ b/src/org/traccar/protocol/CastelProtocolDecoder.java
@@ -49,6 +49,8 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder {
private static final short MSG_CC_LOGIN = 0x4001;
private static final short MSG_CC_LOGIN_RESPONSE = (short) 0x8001;
+ private static final short MSG_CC_HEARTBEAT = 0x4206;
+ private static final short MSG_CC_HEARTBEAT_RESPONSE = (short) 0x8206;
private Position readPosition(ChannelBuffer buf) {
@@ -177,7 +179,35 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder {
} else {
- if (type == MSG_CC_LOGIN) {
+ if (type == MSG_CC_HEARTBEAT) {
+
+ sendResponse(channel, remoteAddress, version, id, MSG_CC_HEARTBEAT_RESPONSE, null);
+
+ if (buf.readUnsignedByte() == 0x01) {
+ int count = buf.readUnsignedByte();
+ List<Position> positions = new LinkedList<>();
+
+ for (int i = 0; i < count; i++) {
+ Position position = readPosition(buf);
+
+ position.set(Event.KEY_STATUS, buf.readUnsignedInt());
+ position.set(Event.KEY_BATTERY, buf.readUnsignedByte());
+ position.set(Event.KEY_ODOMETER, buf.readUnsignedInt());
+
+ buf.readUnsignedByte(); // geo-fencing id
+ buf.readUnsignedByte(); // geo-fencing flags
+ buf.readUnsignedByte(); // additional flags
+
+ position.set(Event.KEY_LAC, buf.readUnsignedShort());
+ position.set(Event.KEY_CELL, buf.readUnsignedShort());
+
+ positions.add(position);
+ }
+
+ return positions;
+ }
+
+ } else if (type == MSG_CC_LOGIN) {
sendResponse(channel, remoteAddress, version, id, MSG_CC_LOGIN_RESPONSE, null);
diff --git a/test/org/traccar/protocol/CastelProtocolDecoderTest.java b/test/org/traccar/protocol/CastelProtocolDecoderTest.java
index fe1514738..576c2c772 100644
--- a/test/org/traccar/protocol/CastelProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/CastelProtocolDecoderTest.java
@@ -13,6 +13,9 @@ public class CastelProtocolDecoderTest extends ProtocolDecoderTest {
CastelProtocolDecoder decoder = new CastelProtocolDecoder(new CastelProtocol());
+ verifyNothing(decoder, binary(ByteOrder.LITTLE_ENDIAN,
+ "404044000c3631313135303030303935360000000000000000420600011e0a0f0b1312864fcd08c07a13030100640acf000004000a000000000000007ba083a66ad80d0a"));
+
verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN,
"40405c000c363131313530303030393536000000000000000040011c0a0f0e362dca53cd0860831303000000000300000000ff000000000000007ba083a650542d3639305f56312e312e320050542d3639302056312e32008a020d0a"));