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 +++++++++++++--------- .../traccar/protocol/KhdProtocolDecoderTest.java | 3 ++ 2 files changed, 26 insertions(+), 16 deletions(-) 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; diff --git a/test/org/traccar/protocol/KhdProtocolDecoderTest.java b/test/org/traccar/protocol/KhdProtocolDecoderTest.java index 21494014c..62b6070b6 100644 --- a/test/org/traccar/protocol/KhdProtocolDecoderTest.java +++ b/test/org/traccar/protocol/KhdProtocolDecoderTest.java @@ -13,6 +13,9 @@ public class KhdProtocolDecoderTest extends ProtocolTest { verifyNull(decoder, binary( "2929b1000605162935b80d")); + verifyPosition(decoder, binary( + "29298e006d1f29402d181117083846801193910365274500000000f80000227ffc3f00001e00500000000000060088000000220019ffc100000000000000000000000000000000007080002000000016ff893839323534303231303734313134323334333639000800233030302e30306e0d")); + verifyPosition(decoder, binary( "2929a3002e1780c663170216203353003060811013839500000114f8000000ffff5000000a00000000000000060102003db70d")); -- cgit v1.2.3