aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-10-04 18:53:33 -0700
committerAnton Tananaev <anton@traccar.org>2022-10-04 18:53:33 -0700
commitbcd0d17008c2c3e3ccede34a618feac53b199d02 (patch)
tree9400b02540f274423c740e1b036406e94df0e4a0
parent471de2a758b063cc8d6dd5321cbc459c70b88fd8 (diff)
downloadtrackermap-server-bcd0d17008c2c3e3ccede34a618feac53b199d02.tar.gz
trackermap-server-bcd0d17008c2c3e3ccede34a618feac53b199d02.tar.bz2
trackermap-server-bcd0d17008c2c3e3ccede34a618feac53b199d02.zip
Concox Vl502 IMEI device id
-rw-r--r--src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java15
-rw-r--r--src/test/java/org/traccar/protocol/HuabaoProtocolDecoderTest.java3
2 files changed, 16 insertions, 2 deletions
diff --git a/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java b/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java
index 0639b9dcf..0eded4b42 100644
--- a/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java
@@ -160,6 +160,17 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder {
return dateBuilder.getDate();
}
+ private String decodeId(ByteBuf id) {
+ String serial = ByteBufUtil.hexDump(id);
+ if (serial.matches("[0-9]+")) {
+ return serial;
+ } else {
+ long imei = id.readUnsignedShort();
+ imei = (imei << 32) + id.readUnsignedInt();
+ return String.valueOf(imei);
+ }
+ }
+
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
@@ -193,7 +204,7 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder {
index = buf.readUnsignedShort();
}
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, ByteBufUtil.hexDump(id));
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, decodeId(id));
if (deviceSession == null) {
return null;
}
@@ -208,7 +219,7 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder {
ByteBuf response = Unpooled.buffer();
response.writeShort(index);
response.writeByte(RESULT_SUCCESS);
- response.writeBytes(ByteBufUtil.hexDump(id).getBytes(StandardCharsets.US_ASCII));
+ response.writeBytes(decodeId(id).getBytes(StandardCharsets.US_ASCII));
channel.writeAndFlush(new NetworkMessage(
formatMessage(MSG_TERMINAL_REGISTER_RESPONSE, id, false, response), remoteAddress));
}
diff --git a/src/test/java/org/traccar/protocol/HuabaoProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/HuabaoProtocolDecoderTest.java
index 3661a0202..f7873ef08 100644
--- a/src/test/java/org/traccar/protocol/HuabaoProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/HuabaoProtocolDecoderTest.java
@@ -11,6 +11,9 @@ public class HuabaoProtocolDecoderTest extends ProtocolTest {
var decoder = inject(new HuabaoProtocolDecoder(null));
+ verifyNull(decoder, binary(
+ "7e010200204f07788ef67601824f4459344f544d314d4459774d4441314d444977626d5633553235536457786cba7e"));
+
verifyAttribute(decoder, binary(
"7e0200005e01229130231209e300000000000c002300d264a305ff322300160000000022091514493503020000a70400000000ac0400000000e5020003e62c01bc5729009ca319bbff0002dd34020754fe1a83393c03bc572900ce371a6133d704dd34020751551d00fefb9a7e"),
Position.PREFIX_TEMP + 4, 29.0);