aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/traccar/protocol/WliProtocolDecoder.java74
-rw-r--r--src/test/java/org/traccar/protocol/WliProtocolDecoderTest.java3
2 files changed, 65 insertions, 12 deletions
diff --git a/src/main/java/org/traccar/protocol/WliProtocolDecoder.java b/src/main/java/org/traccar/protocol/WliProtocolDecoder.java
index 0e2a0a65e..976d4fb27 100644
--- a/src/main/java/org/traccar/protocol/WliProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/WliProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2020 Anton Tananaev (anton@traccar.org)
+ * Copyright 2020 - 2022 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.
@@ -22,6 +22,8 @@ import org.traccar.DeviceSession;
import org.traccar.Protocol;
import org.traccar.helper.DateBuilder;
import org.traccar.helper.UnitsConverter;
+import org.traccar.model.CellTower;
+import org.traccar.model.Network;
import org.traccar.model.Position;
import java.net.SocketAddress;
@@ -41,9 +43,9 @@ public class WliProtocolDecoder extends BaseProtocolDecoder {
ByteBuf buf = (ByteBuf) msg;
buf.readUnsignedByte(); // header
- int type = buf.readUnsignedByte();
+ int clazz = buf.readUnsignedByte();
- if (type == '1') {
+ if (clazz == '1') {
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
if (deviceSession == null) {
@@ -53,11 +55,13 @@ public class WliProtocolDecoder extends BaseProtocolDecoder {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
+ CellTower cellTower = new CellTower();
+
position.set(Position.KEY_INDEX, buf.readUnsignedShort());
buf.readUnsignedShort(); // length
buf.readUnsignedShort(); // checksum
- buf.readUnsignedByte(); // application message type
+ int type = buf.readUnsignedByte();
buf.readUnsignedByte(); // delimiter
while (buf.readableBytes() > 1) {
@@ -95,18 +99,56 @@ public class WliProtocolDecoder extends BaseProtocolDecoder {
String value = buf.readCharSequence(
endIndex - buf.readerIndex(), StandardCharsets.US_ASCII).toString();
- switch (fieldNumber) {
- case 246:
- String[] values = value.split(",");
- position.set(Position.KEY_POWER, Integer.parseInt(values[2]) * 0.01);
- position.set(Position.KEY_BATTERY, Integer.parseInt(values[3]) * 0.01);
+ int networkFieldsOffset;
+ switch (type) {
+ case 0xE4:
+ networkFieldsOffset = 10;
+ break;
+ case 0xCB:
+ networkFieldsOffset = 80;
break;
- case 255:
- position.setDeviceTime(new Date(Long.parseLong(value) * 1000));
+ case 0x1E:
+ networkFieldsOffset = 182;
break;
+ case 0xC9:
default:
+ networkFieldsOffset = 35;
break;
}
+ if (fieldNumber - networkFieldsOffset >= 0 && fieldNumber - networkFieldsOffset < 10) {
+ switch (fieldNumber - networkFieldsOffset) {
+ case 0:
+ cellTower.setMobileCountryCode(Integer.parseInt(value));
+ break;
+ case 1:
+ cellTower.setMobileNetworkCode(Integer.parseInt(value));
+ break;
+ case 2:
+ cellTower.setLocationAreaCode(Integer.parseInt(value));
+ break;
+ case 3:
+ cellTower.setCellId(Long.parseLong(value));
+ break;
+ case 4:
+ cellTower.setSignalStrength(Integer.parseInt(value));
+ break;
+ default:
+ break;
+ }
+ } else {
+ switch (fieldNumber) {
+ case 246:
+ String[] values = value.split(",");
+ position.set(Position.KEY_POWER, Integer.parseInt(values[2]) * 0.01);
+ position.set(Position.KEY_BATTERY, Integer.parseInt(values[3]) * 0.01);
+ break;
+ case 255:
+ position.setDeviceTime(new Date(Long.parseLong(value) * 1000));
+ break;
+ default:
+ break;
+ }
+ }
}
@@ -114,13 +156,21 @@ public class WliProtocolDecoder extends BaseProtocolDecoder {
}
+ if (type == 0xE4) {
+ getLastLocation(position, position.getDeviceTime());
+ }
+
+ if (cellTower.getCellId() != null) {
+ position.setNetwork(new Network(cellTower));
+ }
+
if (!position.getValid()) {
getLastLocation(position, position.getDeviceTime());
}
return position;
- } else if (type == '2') {
+ } else if (clazz == '2') {
String id = buf.toString(buf.readerIndex(), buf.readableBytes() - 1, StandardCharsets.US_ASCII);
getDeviceSession(channel, remoteAddress, id.substring("wli:".length()));
diff --git a/src/test/java/org/traccar/protocol/WliProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/WliProtocolDecoderTest.java
index 6f86a9fd9..77184f86a 100644
--- a/src/test/java/org/traccar/protocol/WliProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/WliProtocolDecoderTest.java
@@ -13,6 +13,9 @@ public class WliProtocolDecoderTest extends ProtocolTest {
verifyNull(decoder, binary(
"0232776c693a30343930333332303332343103"));
+ verifyAttributes(decoder, binary(
+ "0231000101536c27e40001003400dbd20030363a34323a303000dbd30030352f30322f31390004002d3100060030000a00343235000b003031000c003130343232000d003336343733000e003239000f0037001000312c312c312c312c31302e3230322e33342e33312c36353533352c302c39392c39392c3235352c3235352c3235352c323535001100300013003000140033001500343237001600333700170031001800313038001900320031003000320030004500302c323031392f30352f30322c30363a34313a34312c323031392f30352f30322c30363a33353a303800f100342c302c332c302c2d312c2d3100f2003300f3003100f50038363634323530333137303639323400f600312c302c302c3431322c3000f70038343437373200f800302c3330302c302c302c302c302c2c2c2c2c2c302c3000f9003300fa00393100fb0032313100fc0032313000ff00313535363737393332300003"));
+
verifyPosition(decoder, binary(
"0231000101bba758c900010034000500ff001001258fc9013e80ed00001183350101e20006003200090030000a0032000b003331000c0031000d00343438000e003530000f003100100031303800130032001b003134001c0033392c33352c32382c33382c34302c33372c33332c33382c33352c34322c33372c3335001d003130001e0038002300343235002400303100250031303432320026003336343733002700323800280037002900312c312c312c312c31302e3232352e3135312e3230342c36353533352c302c39392c39392c3235352c3235352c3235352c323535002a0030002c0030003000300032003000330031003400ff001c0214130502061b0101258fc9013e80ed000001e2000000000000004d004500302c323031392f30352f30322c30363a33333a30302c323031392f30352f30322c30363a32363a3230005a003000f100352c302c342c302c2d312c2d3100f2003300f3003100f50038363634323530333137303639323400f600312c302c302c3431322c3000f70038343437373200f80032312c31312c302c302c302c302c2c2c2c2c2c302c3000f9003300fa00393100fb0032313100fc0032313000ff00313535363737383533340003"));