aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/org/traccar/protocol/NavtelecomProtocolDecoder.java48
-rw-r--r--src/test/java/org/traccar/protocol/NavtelecomProtocolDecoderTest.java3
2 files changed, 37 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);
}
diff --git a/src/test/java/org/traccar/protocol/NavtelecomProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/NavtelecomProtocolDecoderTest.java
index 8b22c6e79..be51cb852 100644
--- a/src/test/java/org/traccar/protocol/NavtelecomProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/NavtelecomProtocolDecoderTest.java
@@ -16,6 +16,9 @@ public class NavtelecomProtocolDecoderTest extends ProtocolTest {
verifyNull(decoder, binary(
"404e544301000000000000001300f7fc2a3e464c4558b00a0a45fffe00000000000000"));
+ verifyNull(decoder, binary(
+ "404e544301000000000000001300cbc02a3e464c4558b00a0a45fffe300a0e08000000"));
+
}
}