aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2020-07-16 20:25:20 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2020-07-16 20:25:20 -0700
commita92c5786ce74994ad20aee12affd75737a565ba2 (patch)
tree66f5e092b7712fb521e0bf7dcef0c2173b59251d /src/main/java
parent90ddc7b95e3879c20d6d8f7e8b96df87e0ec1f66 (diff)
downloadtrackermap-server-a92c5786ce74994ad20aee12affd75737a565ba2.tar.gz
trackermap-server-a92c5786ce74994ad20aee12affd75737a565ba2.tar.bz2
trackermap-server-a92c5786ce74994ad20aee12affd75737a565ba2.zip
Decode more data
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/traccar/protocol/HuabaoFrameDecoder.java43
-rw-r--r--src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java59
2 files changed, 82 insertions, 20 deletions
diff --git a/src/main/java/org/traccar/protocol/HuabaoFrameDecoder.java b/src/main/java/org/traccar/protocol/HuabaoFrameDecoder.java
index b520f6be9..c99d42a59 100644
--- a/src/main/java/org/traccar/protocol/HuabaoFrameDecoder.java
+++ b/src/main/java/org/traccar/protocol/HuabaoFrameDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2020 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.
@@ -31,25 +31,36 @@ public class HuabaoFrameDecoder extends BaseFrameDecoder {
return null;
}
- int index = buf.indexOf(buf.readerIndex() + 1, buf.writerIndex(), (byte) 0x7e);
- if (index != -1) {
- ByteBuf result = Unpooled.buffer(index + 1 - buf.readerIndex());
-
- while (buf.readerIndex() <= index) {
- int b = buf.readUnsignedByte();
- if (b == 0x7d) {
- int ext = buf.readUnsignedByte();
- if (ext == 0x01) {
- result.writeByte(0x7d);
- } else if (ext == 0x02) {
- result.writeByte(0x7e);
+ if (buf.getByte(buf.readerIndex()) == '(') {
+
+ int index = buf.indexOf(buf.readerIndex() + 1, buf.writerIndex(), (byte) ')');
+ if (index >= 0) {
+ return buf.readRetainedSlice(index + 1);
+ }
+
+ } else {
+
+ int index = buf.indexOf(buf.readerIndex() + 1, buf.writerIndex(), (byte) 0x7e);
+ if (index >= 0) {
+ ByteBuf result = Unpooled.buffer(index + 1 - buf.readerIndex());
+
+ while (buf.readerIndex() <= index) {
+ int b = buf.readUnsignedByte();
+ if (b == 0x7d) {
+ int ext = buf.readUnsignedByte();
+ if (ext == 0x01) {
+ result.writeByte(0x7d);
+ } else if (ext == 0x02) {
+ result.writeByte(0x7e);
+ }
+ } else {
+ result.writeByte(b);
}
- } else {
- result.writeByte(b);
}
+
+ return result;
}
- return result;
}
return null;
diff --git a/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java b/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java
index a502755fd..d89bcdbe8 100644
--- a/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java
@@ -28,6 +28,8 @@ import org.traccar.helper.BitUtil;
import org.traccar.helper.Checksum;
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;
@@ -48,6 +50,7 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder {
public static final int MSG_TERMINAL_AUTH = 0x0102;
public static final int MSG_LOCATION_REPORT = 0x0200;
public static final int MSG_LOCATION_REPORT_2 = 0x5501;
+ public static final int MSG_LOCATION_REPORT_BLIND = 0x5502;
public static final int MSG_LOCATION_BATCH = 0x0704;
public static final int MSG_OIL_CONTROL = 0XA006;
@@ -114,12 +117,16 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder {
ByteBuf buf = (ByteBuf) msg;
+ if (buf.getByte(buf.readerIndex()) == '(') {
+ return decodeResult(channel, remoteAddress, buf.toString(StandardCharsets.US_ASCII));
+ }
+
buf.readUnsignedByte(); // start marker
int type = buf.readUnsignedShort();
buf.readUnsignedShort(); // body length
ByteBuf id = buf.readSlice(6); // phone number
int index;
- if (type == MSG_LOCATION_REPORT_2) {
+ if (type == MSG_LOCATION_REPORT_2 || type == MSG_LOCATION_REPORT_BLIND) {
index = buf.readUnsignedByte();
} else {
index = buf.readUnsignedShort();
@@ -153,9 +160,9 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder {
return decodeLocation(deviceSession, buf);
- } else if (type == MSG_LOCATION_REPORT_2) {
+ } else if (type == MSG_LOCATION_REPORT_2 || type == MSG_LOCATION_REPORT_BLIND) {
- return decodeLocation2(deviceSession, buf);
+ return decodeLocation2(deviceSession, buf, type);
} else if (type == MSG_LOCATION_BATCH) {
@@ -166,6 +173,18 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder {
return null;
}
+ private Position decodeResult(Channel channel, SocketAddress remoteAddress, String sentence) {
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
+ if (deviceSession != null) {
+ Position position = new Position(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+ getLastLocation(position, null);
+ position.set(Position.KEY_RESULT, sentence);
+ return position;
+ }
+ return null;
+ }
+
private Position decodeLocation(DeviceSession deviceSession, ByteBuf buf) {
Position position = new Position(getProtocolName());
@@ -289,12 +308,44 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder {
return position;
}
- private Position decodeLocation2(DeviceSession deviceSession, ByteBuf buf) {
+ private Position decodeLocation2(DeviceSession deviceSession, ByteBuf buf, int type) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
Jt600ProtocolDecoder.decodeBinaryLocation(buf, position);
+ position.setValid(type != MSG_LOCATION_REPORT_BLIND);
+
+ position.set(Position.KEY_RSSI, buf.readUnsignedByte());
+ position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
+ position.set(Position.KEY_ODOMETER, buf.readUnsignedInt() * 1000L);
+ position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte());
+ position.set(Position.KEY_CHARGE, buf.readUnsignedByte() == 0xAA);
+
+ position.setNetwork(new Network(CellTower.fromCidLac(buf.readUnsignedInt(), buf.readUnsignedShort())));
+
+ int product = buf.readUnsignedByte();
+ int status = buf.readUnsignedShort();
+ int alarm = buf.readUnsignedShort();
+
+ if (product == 1 || product == 2) {
+ if (BitUtil.check(alarm, 0)) {
+ position.set(Position.KEY_ALARM, Position.ALARM_LOW_POWER);
+ }
+ } if (product == 3) {
+ position.set(Position.KEY_BLOCKED, BitUtil.check(status, 5));
+ if (BitUtil.check(alarm, 1)) {
+ position.set(Position.KEY_ALARM, Position.ALARM_LOW_POWER);
+ }
+ if (BitUtil.check(alarm, 2)) {
+ position.set(Position.KEY_ALARM, Position.ALARM_VIBRATION);
+ }
+ if (BitUtil.check(alarm, 3)) {
+ position.set(Position.KEY_ALARM, Position.ALARM_LOW_BATTERY);
+ }
+ }
+
+ position.set(Position.KEY_STATUS, status);
return position;
}