From fecb7efe2bbe868ccbb66bb157fcb64d7e78eaac Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Mon, 27 Mar 2017 03:29:48 +1300 Subject: Fix Teltonika UDP acknowledgement --- .../traccar/protocol/TeltonikaProtocolDecoder.java | 23 ++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'src/org') diff --git a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java index 30a3f4cda..3f5b68f67 100644 --- a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java +++ b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java @@ -246,7 +246,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { } private List parseData( - Channel channel, SocketAddress remoteAddress, ChannelBuffer buf, int packetId, String... imei) { + Channel channel, SocketAddress remoteAddress, ChannelBuffer buf, int locationPacketId, String... imei) { List positions = new LinkedList<>(); if (!(channel instanceof DatagramChannel)) { @@ -279,13 +279,15 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { if (channel != null) { if (channel instanceof DatagramChannel) { - ChannelBuffer response = ChannelBuffers.directBuffer(5); - response.writeShort(3); - response.writeShort(packetId); - response.writeByte(0x02); + ChannelBuffer response = ChannelBuffers.dynamicBuffer(); + response.writeShort(5); + response.writeShort(0); + response.writeByte(0x01); + response.writeByte(locationPacketId); + response.writeByte(count); channel.write(response, remoteAddress); } else { - ChannelBuffer response = ChannelBuffers.directBuffer(4); + ChannelBuffer response = ChannelBuffers.dynamicBuffer(); response.writeInt(count); channel.write(response); } @@ -320,12 +322,13 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { private Object decodeUdp(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) throws Exception { - buf.skipBytes(2); - int packetId = buf.readUnsignedShort(); - buf.skipBytes(2); + buf.readUnsignedShort(); // length + buf.readUnsignedShort(); // packet id + buf.readUnsignedByte(); // packet type + int locationPacketId = buf.readUnsignedByte(); String imei = buf.readBytes(buf.readUnsignedShort()).toString(StandardCharsets.US_ASCII); - return parseData(channel, remoteAddress, buf, packetId, imei); + return parseData(channel, remoteAddress, buf, locationPacketId, imei); } -- cgit v1.2.3