diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2021-08-21 10:29:33 -0700 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2021-08-21 10:29:33 -0700 |
commit | d47b07999d38881ec2a8fee3be6683d3e0a724d5 (patch) | |
tree | 9217c71448f92875b7bb1c37cb6a3988733940d7 /src/main/java/org/traccar | |
parent | b3f779a48a756f83051ca274da2a2f917df9e7c1 (diff) | |
download | trackermap-server-d47b07999d38881ec2a8fee3be6683d3e0a724d5.tar.gz trackermap-server-d47b07999d38881ec2a8fee3be6683d3e0a724d5.tar.bz2 trackermap-server-d47b07999d38881ec2a8fee3be6683d3e0a724d5.zip |
Improve Navtelecom support
Diffstat (limited to 'src/main/java/org/traccar')
-rw-r--r-- | src/main/java/org/traccar/protocol/NavtelecomProtocolDecoder.java | 48 |
1 files changed, 34 insertions, 14 deletions
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 = "*<S"; + String sentence = buf.readCharSequence(length, StandardCharsets.US_ASCII).toString(); + getDeviceSession(channel, remoteAddress, sentence.substring(4)); - ByteBuf response = Unpooled.buffer(); - response.writeCharSequence("@NTC", StandardCharsets.US_ASCII); - response.writeIntLE(sender); - response.writeIntLE(receiver); - response.writeShortLE(data.length()); - response.writeByte(Checksum.xor(data)); - response.writeByte(Checksum.xor(response.nioBuffer())); - response.writeCharSequence(data, StandardCharsets.US_ASCII); + ByteBuf payload = Unpooled.copiedBuffer("*<S", StandardCharsets.US_ASCII); + + sendResponse(channel, remoteAddress, receiver, sender, payload); + + } else if (type.startsWith("*>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); } |