aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2021-06-12 11:25:40 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2021-06-12 11:25:47 -0700
commitb9ceb322b85493d2b8065b2614b3fda8c73194a1 (patch)
tree9f6585ef6c2f0fb45738456ce4c97d96eed11e59 /src/main
parent79c10ee538392cbca4a0573919296a98816e98ad (diff)
downloadtrackermap-server-b9ceb322b85493d2b8065b2614b3fda8c73194a1.tar.gz
trackermap-server-b9ceb322b85493d2b8065b2614b3fda8c73194a1.tar.bz2
trackermap-server-b9ceb322b85493d2b8065b2614b3fda8c73194a1.zip
Support Kingwo protocol
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/traccar/protocol/UproProtocolDecoder.java66
1 files changed, 58 insertions, 8 deletions
diff --git a/src/main/java/org/traccar/protocol/UproProtocolDecoder.java b/src/main/java/org/traccar/protocol/UproProtocolDecoder.java
index a17003fc8..05e6fd811 100644
--- a/src/main/java/org/traccar/protocol/UproProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/UproProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2019 Anton Tananaev (anton@traccar.org)
+ * Copyright 2012 - 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.
@@ -127,6 +127,7 @@ public class UproProtocolDecoder extends BaseProtocolDecoder {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
+ Network network = new Network();
String type = parser.next();
String subtype = parser.next();
@@ -135,7 +136,7 @@ public class UproProtocolDecoder extends BaseProtocolDecoder {
channel.writeAndFlush(new NetworkMessage("*" + head + "Y" + type + subtype + "#", remoteAddress));
}
- while (buf.isReadable()) {
+ while (buf.readableBytes() > 1) {
buf.readByte(); // skip delimiter
@@ -143,10 +144,15 @@ public class UproProtocolDecoder extends BaseProtocolDecoder {
int delimiterIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '&');
if (delimiterIndex < 0) {
- delimiterIndex = buf.writerIndex();
+ delimiterIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '#');
+ if (delimiterIndex < 0) {
+ delimiterIndex = buf.writerIndex();
+ }
}
ByteBuf data = buf.readSlice(delimiterIndex - buf.readerIndex());
+ int mcc = 0, mnc = 0, count;
+ String stringValue;
switch (dataType) {
case 'A':
@@ -171,6 +177,22 @@ public class UproProtocolDecoder extends BaseProtocolDecoder {
position.setAltitude(
Integer.parseInt(data.readSlice(6).toString(StandardCharsets.US_ASCII)) * 0.1);
break;
+ case 'I':
+ stringValue = data.toString(StandardCharsets.US_ASCII);
+ count = Integer.parseInt(stringValue.substring(0, 1));
+ if (stringValue.length() == 6 + count * 10) {
+ mcc = Integer.parseInt(stringValue.substring(1, 4));
+ mnc = Integer.parseInt(stringValue.substring(4, 6));
+ for (int i = 0; i < count; i++) {
+ int offset = 6 + i * 10;
+ network.addCellTower(CellTower.from(
+ mcc, mnc,
+ Integer.parseInt(stringValue.substring(offset, offset + 4), 16),
+ Integer.parseInt(stringValue.substring(offset + 4, offset + 8), 16),
+ Integer.parseInt(stringValue.substring(offset + 8, offset + 10))));
+ }
+ }
+ break;
case 'J':
if (data.readableBytes() == 6) {
char index = (char) data.readUnsignedByte();
@@ -215,7 +237,9 @@ public class UproProtocolDecoder extends BaseProtocolDecoder {
}
break;
case 'Q':
- position.set("obdPid", ByteBufUtil.hexDump(data));
+ if (!head.startsWith("HQ")) {
+ position.set("obdPid", ByteBufUtil.hexDump(data));
+ }
break;
case 'R':
if (head.startsWith("HQ")) {
@@ -230,6 +254,12 @@ public class UproProtocolDecoder extends BaseProtocolDecoder {
case 'S':
position.set("obdTraffic", ByteBufUtil.hexDump(data));
break;
+ case 'T':
+ if (data.readableBytes() == 2) {
+ position.set(Position.KEY_BATTERY_LEVEL,
+ Integer.parseInt(data.toString(StandardCharsets.US_ASCII)));
+ }
+ break;
case 'V':
position.set(Position.KEY_POWER,
Integer.parseInt(data.readSlice(4).toString(StandardCharsets.US_ASCII)) * 0.1);
@@ -239,8 +269,6 @@ public class UproProtocolDecoder extends BaseProtocolDecoder {
decodeAlarm(Integer.parseInt(data.readSlice(2).toString(StandardCharsets.US_ASCII))));
break;
case 'X':
- Network network = new Network();
- int mcc = 0, mnc = 0;
String[] cells = data.toString(StandardCharsets.US_ASCII).split(";");
if (!cells[0].startsWith("(")) {
for (int i = 0; i < cells.length; i++) {
@@ -260,8 +288,26 @@ public class UproProtocolDecoder extends BaseProtocolDecoder {
}
break;
case 'Y':
- position.set(Position.KEY_POWER,
- Integer.parseInt(data.readSlice(5).toString(StandardCharsets.US_ASCII)) * 0.001);
+ stringValue = data.toString(StandardCharsets.US_ASCII);
+ count = Integer.parseInt(stringValue.substring(0, 1));
+ if (stringValue.length() == 6 + count * 14) {
+ mcc = Integer.parseInt(stringValue.substring(1, 4));
+ mnc = Integer.parseInt(stringValue.substring(4, 6));
+ for (int i = 0; i < count; i++) {
+ int offset = 6 + i * 14;
+ network.addCellTower(CellTower.from(
+ mcc, mnc,
+ Integer.parseInt(stringValue.substring(offset, offset + 4), 16),
+ Long.parseLong(stringValue.substring(offset + 4, offset + 12), 16),
+ Integer.parseInt(stringValue.substring(offset + 12, offset + 14))));
+ }
+ } else {
+ position.set(Position.KEY_POWER,
+ Integer.parseInt(data.readSlice(5).toString(StandardCharsets.US_ASCII)) * 0.001);
+ }
+ break;
+ case 'b':
+ position.set("serial", data.toString(StandardCharsets.US_ASCII).substring(3));
break;
default:
break;
@@ -269,6 +315,10 @@ public class UproProtocolDecoder extends BaseProtocolDecoder {
}
+ if (network.getCellTowers() != null || network.getWifiAccessPoints() != null) {
+ position.setNetwork(network);
+ }
+
if (position.getLatitude() == 0 || position.getLongitude() == 0) {
if (position.getAttributes().isEmpty()) {
return null;