aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2021-01-25 22:46:13 -0800
committerAnton Tananaev <anton.tananaev@gmail.com>2021-01-25 22:46:19 -0800
commit050941422cc6fe9581ac87f8cbd7196ed304ede8 (patch)
treefa0d2f8afa6e1b14c00d6e75f8b9873c373501c3 /src
parent136d44701594bd88e19aef026b929eff764d9f2d (diff)
downloadtraccar-server-050941422cc6fe9581ac87f8cbd7196ed304ede8.tar.gz
traccar-server-050941422cc6fe9581ac87f8cbd7196ed304ede8.tar.bz2
traccar-server-050941422cc6fe9581ac87f8cbd7196ed304ede8.zip
Alternative identifier method
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/traccar/protocol/KhdProtocolDecoder.java15
-rw-r--r--src/test/java/org/traccar/protocol/KhdProtocolDecoderTest.java3
2 files changed, 14 insertions, 4 deletions
diff --git a/src/main/java/org/traccar/protocol/KhdProtocolDecoder.java b/src/main/java/org/traccar/protocol/KhdProtocolDecoder.java
index 343b78cb5..16ad616ed 100644
--- a/src/main/java/org/traccar/protocol/KhdProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/KhdProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014 - 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2014 - 2021 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
package org.traccar.protocol;
import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
@@ -38,12 +39,18 @@ public class KhdProtocolDecoder extends BaseProtocolDecoder {
super(protocol);
}
- private String readSerialNumber(ByteBuf buf) {
+ private String[] readIdentifiers(ByteBuf buf) {
+ String[] identifiers = new String[2];
+
+ identifiers[0] = ByteBufUtil.hexDump(buf, buf.readerIndex(), 4);
+
int b1 = buf.readUnsignedByte();
int b2 = buf.readUnsignedByte() - 0x80;
int b3 = buf.readUnsignedByte() - 0x80;
int b4 = buf.readUnsignedByte();
- return String.format("%02d%02d%02d%02d", b1, b2, b3, b4);
+ identifiers[1] = String.format("%02d%02d%02d%02d", b1, b2, b3, b4);
+
+ return identifiers;
}
public static final int MSG_LOGIN = 0xB1;
@@ -93,7 +100,7 @@ public class KhdProtocolDecoder extends BaseProtocolDecoder {
Position position = new Position(getProtocolName());
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, readSerialNumber(buf));
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, readIdentifiers(buf));
if (deviceSession == null) {
return null;
}
diff --git a/src/test/java/org/traccar/protocol/KhdProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/KhdProtocolDecoderTest.java
index aa80c1cd9..b82a277b3 100644
--- a/src/test/java/org/traccar/protocol/KhdProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/KhdProtocolDecoderTest.java
@@ -11,6 +11,9 @@ public class KhdProtocolDecoderTest extends ProtocolTest {
KhdProtocolDecoder decoder = new KhdProtocolDecoder(null);
verifyPosition(decoder, binary(
+ "292980002825863156210105095059035109370460010100000211ffff000002fc0000001e780b12000034e70d"));
+
+ verifyPosition(decoder, binary(
"2929a3003420b2ab46201115115601800115110350825100000133fb00df4bfdff0d000000000000000900000c180887d9ffffffffffff960d"));
verifyNull(decoder, binary(