From 10ee656e44dcbba7f87989ecc0e2ddfcf2c12d4a Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 25 May 2016 13:41:03 -0700 Subject: Fix AutoFon old protocol response --- .../traccar/protocol/AutoFonProtocolDecoder.java | 27 ++++++++-------------- 1 file changed, 9 insertions(+), 18 deletions(-) (limited to 'src/org') diff --git a/src/org/traccar/protocol/AutoFonProtocolDecoder.java b/src/org/traccar/protocol/AutoFonProtocolDecoder.java index a633005b4..011a6542b 100644 --- a/src/org/traccar/protocol/AutoFonProtocolDecoder.java +++ b/src/org/traccar/protocol/AutoFonProtocolDecoder.java @@ -120,10 +120,12 @@ public class AutoFonProtocolDecoder extends BaseProtocolDecoder { int type = buf.readUnsignedByte(); - if (type == MSG_LOGIN) { + if (type == MSG_LOGIN || type == MSG_45_LOGIN) { - buf.readUnsignedByte(); // hardware version - buf.readUnsignedByte(); // software version + if (type == MSG_LOGIN) { + buf.readUnsignedByte(); // hardware version + buf.readUnsignedByte(); // software version + } String imei = ChannelBuffers.hexDump(buf.readBytes(8)).substring(1); if (!identify(imei, channel, remoteAddress)) { @@ -131,7 +133,10 @@ public class AutoFonProtocolDecoder extends BaseProtocolDecoder { } if (channel != null) { - channel.write(ChannelBuffers.wrappedBuffer(new byte[] {buf.readByte()})); + ChannelBuffer response = ChannelBuffers.dynamicBuffer(); + response.writeBytes("resp_crc=".getBytes(StandardCharsets.US_ASCII)); + response.writeByte(buf.getByte(buf.writerIndex() - 1)); + channel.write(response); } } else if (type == MSG_LOCATION) { @@ -150,20 +155,6 @@ public class AutoFonProtocolDecoder extends BaseProtocolDecoder { return positions; - } else if (type == MSG_45_LOGIN) { - - String imei = ChannelBuffers.hexDump(buf.readBytes(8)).substring(1); - if (!identify(imei, channel, remoteAddress)) { - return null; - } - - if (channel != null) { - ChannelBuffer response = ChannelBuffers.dynamicBuffer(); - response.writeBytes("resp_crc=".getBytes(StandardCharsets.US_ASCII)); - response.writeByte(buf.getByte(buf.writerIndex() - 1)); - channel.write(response); - } - } else if (type == MSG_45_LOCATION) { Position position = new Position(); -- cgit v1.2.3