From 2f41a4d95b5be4804b32cac6d96c1b152d53d7ec Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 28 Nov 2018 15:28:55 +1300 Subject: Extend KHD / Sabo SPG02B support --- src/org/traccar/protocol/KhdProtocolDecoder.java | 39 ++++++++++++++---------- 1 file changed, 23 insertions(+), 16 deletions(-) (limited to 'src/org/traccar/protocol/KhdProtocolDecoder.java') diff --git a/src/org/traccar/protocol/KhdProtocolDecoder.java b/src/org/traccar/protocol/KhdProtocolDecoder.java index f186fc0d5..0dd5b085a 100644 --- a/src/org/traccar/protocol/KhdProtocolDecoder.java +++ b/src/org/traccar/protocol/KhdProtocolDecoder.java @@ -50,7 +50,10 @@ public class KhdProtocolDecoder extends BaseProtocolDecoder { public static final int MSG_POSITION_UPLOAD = 0x80; public static final int MSG_POSITION_REUPLOAD = 0x8E; public static final int MSG_ALARM = 0x82; + public static final int MSG_ADMIN_NUMBER = 0x83; + public static final int MSG_SEND_TEXT = 0x84; public static final int MSG_REPLY = 0x85; + public static final int MSG_SMS_ALARM_SWITCH = 0x86; public static final int MSG_PERIPHERAL = 0xA3; @Override @@ -63,6 +66,26 @@ public class KhdProtocolDecoder extends BaseProtocolDecoder { int type = buf.readUnsignedByte(); buf.readUnsignedShort(); // size + if (type == MSG_LOGIN || type == MSG_ADMIN_NUMBER || type == MSG_SEND_TEXT + || type == MSG_SMS_ALARM_SWITCH || type == MSG_POSITION_REUPLOAD) { + + ByteBuf response = Unpooled.buffer(); + response.writeByte(0x29); + response.writeByte(0x29); // header + response.writeByte(MSG_CONFIRMATION); + response.writeShort(5); // size + response.writeByte(buf.getByte(buf.writerIndex() - 2)); + response.writeByte(type); + response.writeByte(buf.writerIndex() > 9 ? buf.getByte(9) : 0); // 10th byte + response.writeByte(Checksum.xor(response.nioBuffer())); + response.writeByte(0x0D); // ending + + if (channel != null) { + channel.writeAndFlush(new NetworkMessage(response, remoteAddress)); + } + + } + if (type == MSG_ON_DEMAND || type == MSG_POSITION_UPLOAD || type == MSG_POSITION_REUPLOAD || type == MSG_ALARM || type == MSG_REPLY || type == MSG_PERIPHERAL) { @@ -126,22 +149,6 @@ public class KhdProtocolDecoder extends BaseProtocolDecoder { return position; - } else if (type == MSG_LOGIN && channel != null) { - - buf.skipBytes(4); // serial number - buf.readByte(); // reserved - - ByteBuf response = Unpooled.buffer(); - response.writeByte(0x29); response.writeByte(0x29); // header - response.writeByte(MSG_CONFIRMATION); - response.writeShort(5); // size - response.writeByte(buf.readUnsignedByte()); - response.writeByte(type); - response.writeByte(0); // reserved - response.writeByte(Checksum.xor(response.nioBuffer())); - response.writeByte(0x0D); // ending - channel.writeAndFlush(new NetworkMessage(response, remoteAddress)); - } return null; -- cgit v1.2.3