From a76e8d71083ef44384b541d33bab92eb096902d2 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 31 Oct 2015 18:49:49 +1300 Subject: Support Castel heartbeat messages --- .../traccar/protocol/CastelProtocolDecoder.java | 32 +++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'src/org/traccar/protocol/CastelProtocolDecoder.java') 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 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); -- cgit v1.2.3