From 0ef38f25be2c6931be8a4cc2e8fc6d3d351e122c Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Thu, 18 Oct 2018 15:14:21 +1300 Subject: Implement AutoTrack response --- .../traccar/protocol/AutoTrackProtocolDecoder.java | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/org/traccar/protocol/AutoTrackProtocolDecoder.java b/src/org/traccar/protocol/AutoTrackProtocolDecoder.java index 43b273be5..fabf2ffda 100644 --- a/src/org/traccar/protocol/AutoTrackProtocolDecoder.java +++ b/src/org/traccar/protocol/AutoTrackProtocolDecoder.java @@ -42,8 +42,10 @@ public class AutoTrackProtocolDecoder extends BaseProtocolDecoder { public static final int MSG_TELEMETRY_2 = 66; public static final int MSG_TELEMETRY_3 = 67; public static final int MSG_KEEP_ALIVE = 114; + public static final int MSG_TELEMETRY_CONFIRM = 123; - private Position decodeTelemetry(DeviceSession deviceSession, ByteBuf buf) { + private Position decodeTelemetry( + Channel channel, SocketAddress remoteAddress, DeviceSession deviceSession, ByteBuf buf) { Position position = new Position(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); @@ -56,6 +58,7 @@ public class AutoTrackProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_FUEL_USED, buf.readUnsignedIntLE()); position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShortLE())); + buf.readUnsignedShortLE(); // max speed position.set(Position.KEY_INPUT, buf.readUnsignedShortLE()); buf.readUnsignedIntLE(); // di 3 count @@ -70,10 +73,21 @@ public class AutoTrackProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_STATUS, buf.readUnsignedShortLE()); position.set(Position.KEY_EVENT, buf.readUnsignedShortLE()); position.set(Position.KEY_DRIVER_UNIQUE_ID, buf.readLongLE()); - position.set(Position.KEY_INDEX, buf.readUnsignedShortLE()); + + int index = buf.readUnsignedShortLE(); buf.readUnsignedShortLE(); // checksum + if (channel != null) { + ByteBuf response = Unpooled.buffer(); + response.writeInt(0xF1F1F1F1); // sync + response.writeByte(MSG_TELEMETRY_CONFIRM); + response.writeShortLE(2); // length + response.writeShortLE(index); + response.writeShort(Checksum.crc16(Checksum.CRC16_XMODEM, response.nioBuffer())); + channel.writeAndFlush(new NetworkMessage(response, remoteAddress)); + } + return position; } @@ -115,7 +129,7 @@ public class AutoTrackProtocolDecoder extends BaseProtocolDecoder { if (deviceSession == null) { return null; } - return decodeTelemetry(deviceSession, buf); + return decodeTelemetry(channel, remoteAddress, deviceSession, buf); default: return null; } -- cgit v1.2.3