From d47b07999d38881ec2a8fee3be6683d3e0a724d5 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 21 Aug 2021 10:29:33 -0700 Subject: Improve Navtelecom support --- .../protocol/NavtelecomProtocolDecoder.java | 48 +++++++++++++++------- 1 file changed, 34 insertions(+), 14 deletions(-) (limited to 'src/main/java/org') diff --git a/src/main/java/org/traccar/protocol/NavtelecomProtocolDecoder.java b/src/main/java/org/traccar/protocol/NavtelecomProtocolDecoder.java index 2362b1870..b2272a128 100644 --- a/src/main/java/org/traccar/protocol/NavtelecomProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/NavtelecomProtocolDecoder.java @@ -32,6 +32,23 @@ public class NavtelecomProtocolDecoder extends BaseProtocolDecoder { super(protocol); } + private void sendResponse( + Channel channel, SocketAddress remoteAddress, int receiver, int sender, ByteBuf content) { + if (channel != null) { + ByteBuf response = Unpooled.buffer(); + response.writeCharSequence("@NTC", StandardCharsets.US_ASCII); + response.writeIntLE(sender); + response.writeIntLE(receiver); + response.writeShortLE(content.readableBytes()); + response.writeByte(Checksum.xor(content.nioBuffer())); + response.writeByte(Checksum.xor(response.nioBuffer())); + response.writeBytes(content); + content.release(); + + channel.writeAndFlush(new NetworkMessage(response, remoteAddress)); + } + } + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { @@ -45,24 +62,27 @@ public class NavtelecomProtocolDecoder extends BaseProtocolDecoder { buf.readUnsignedByte(); // data checksum buf.readUnsignedByte(); // header checksum - String sentence = buf.readCharSequence(length, StandardCharsets.US_ASCII).toString(); + String type = buf.toString(buf.readerIndex(), 6, StandardCharsets.US_ASCII); - if (sentence.startsWith("*>S")) { + if (type.startsWith("*>S")) { - String data = "*FLEX")) { + + buf.skipBytes(6); + + ByteBuf payload = Unpooled.buffer(); + payload.writeByte(buf.readUnsignedByte()); // protocol + payload.writeByte(buf.readUnsignedByte()); // protocol version + payload.writeByte(buf.readUnsignedByte()); // struct version - if (channel != null) { - channel.writeAndFlush(new NetworkMessage(response, remoteAddress)); - } + sendResponse(channel, remoteAddress, receiver, sender, payload); } -- cgit v1.2.3