aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2020-07-12 19:10:19 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2020-07-12 19:10:19 -0700
commit2507a8183ff78cc75dea82327523d9e151d95920 (patch)
tree9b7bc3992b2502327812641f9302a8ebd2ef91b4
parentb2260e5220e7bfbd5098502dbaca0aa68222b79b (diff)
downloadtrackermap-server-2507a8183ff78cc75dea82327523d9e151d95920.tar.gz
trackermap-server-2507a8183ff78cc75dea82327523d9e151d95920.tar.bz2
trackermap-server-2507a8183ff78cc75dea82327523d9e151d95920.zip
Support alternative location report
-rw-r--r--src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java22
-rw-r--r--src/main/java/org/traccar/protocol/Jt600ProtocolDecoder.java55
-rw-r--r--src/test/java/org/traccar/protocol/HuabaoProtocolDecoderTest.java3
3 files changed, 54 insertions, 26 deletions
diff --git a/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java b/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java
index 5ebc721dd..a502755fd 100644
--- a/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java
@@ -47,6 +47,7 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder {
public static final int MSG_TERMINAL_CONTROL = 0x8105;
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_BATCH = 0x0704;
public static final int MSG_OIL_CONTROL = 0XA006;
@@ -117,7 +118,12 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder {
int type = buf.readUnsignedShort();
buf.readUnsignedShort(); // body length
ByteBuf id = buf.readSlice(6); // phone number
- int index = buf.readUnsignedShort();
+ int index;
+ if (type == MSG_LOCATION_REPORT_2) {
+ index = buf.readUnsignedByte();
+ } else {
+ index = buf.readUnsignedShort();
+ }
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, ByteBufUtil.hexDump(id));
if (deviceSession == null) {
@@ -147,6 +153,10 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder {
return decodeLocation(deviceSession, buf);
+ } else if (type == MSG_LOCATION_REPORT_2) {
+
+ return decodeLocation2(deviceSession, buf);
+
} else if (type == MSG_LOCATION_BATCH) {
return decodeLocationBatch(deviceSession, buf);
@@ -279,6 +289,16 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder {
return position;
}
+ private Position decodeLocation2(DeviceSession deviceSession, ByteBuf buf) {
+
+ Position position = new Position(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ Jt600ProtocolDecoder.decodeBinaryLocation(buf, position);
+
+ return position;
+ }
+
private List<Position> decodeLocationBatch(DeviceSession deviceSession, ByteBuf buf) {
List<Position> positions = new LinkedList<>();
diff --git a/src/main/java/org/traccar/protocol/Jt600ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Jt600ProtocolDecoder.java
index f456cd1ef..d745153a4 100644
--- a/src/main/java/org/traccar/protocol/Jt600ProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/Jt600ProtocolDecoder.java
@@ -90,6 +90,35 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder {
return buf.getUnsignedByte(flagIndex) >> 4 == 0x7;
}
+ static void decodeBinaryLocation(ByteBuf buf, Position position) {
+
+ DateBuilder dateBuilder = new DateBuilder()
+ .setDay(BcdUtil.readInteger(buf, 2))
+ .setMonth(BcdUtil.readInteger(buf, 2))
+ .setYear(BcdUtil.readInteger(buf, 2))
+ .setHour(BcdUtil.readInteger(buf, 2))
+ .setMinute(BcdUtil.readInteger(buf, 2))
+ .setSecond(BcdUtil.readInteger(buf, 2));
+ position.setTime(dateBuilder.getDate());
+
+ double latitude = convertCoordinate(BcdUtil.readInteger(buf, 8));
+ double longitude = convertCoordinate(BcdUtil.readInteger(buf, 9));
+
+ byte flags = buf.readByte();
+ position.setValid((flags & 0x1) == 0x1);
+ if ((flags & 0x2) == 0) {
+ latitude = -latitude;
+ }
+ position.setLatitude(latitude);
+ if ((flags & 0x4) == 0) {
+ longitude = -longitude;
+ }
+ position.setLongitude(longitude);
+
+ position.setSpeed(BcdUtil.readInteger(buf, 2));
+ position.setCourse(buf.readUnsignedByte() * 2.0);
+ }
+
private List<Position> decodeBinary(ByteBuf buf, Channel channel, SocketAddress remoteAddress) {
List<Position> positions = new LinkedList<>();
@@ -117,31 +146,7 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
- DateBuilder dateBuilder = new DateBuilder()
- .setDay(BcdUtil.readInteger(buf, 2))
- .setMonth(BcdUtil.readInteger(buf, 2))
- .setYear(BcdUtil.readInteger(buf, 2))
- .setHour(BcdUtil.readInteger(buf, 2))
- .setMinute(BcdUtil.readInteger(buf, 2))
- .setSecond(BcdUtil.readInteger(buf, 2));
- position.setTime(dateBuilder.getDate());
-
- double latitude = convertCoordinate(BcdUtil.readInteger(buf, 8));
- double longitude = convertCoordinate(BcdUtil.readInteger(buf, 9));
-
- byte flags = buf.readByte();
- position.setValid((flags & 0x1) == 0x1);
- if ((flags & 0x2) == 0) {
- latitude = -latitude;
- }
- position.setLatitude(latitude);
- if ((flags & 0x4) == 0) {
- longitude = -longitude;
- }
- position.setLongitude(longitude);
-
- position.setSpeed(BcdUtil.readInteger(buf, 2));
- position.setCourse(buf.readUnsignedByte() * 2.0);
+ decodeBinaryLocation(buf, position);
if (longFormat) {
diff --git a/src/test/java/org/traccar/protocol/HuabaoProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/HuabaoProtocolDecoderTest.java
index 233603179..97a77eb28 100644
--- a/src/test/java/org/traccar/protocol/HuabaoProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/HuabaoProtocolDecoderTest.java
@@ -14,6 +14,9 @@ public class HuabaoProtocolDecoderTest extends ProtocolTest {
verifyNull(decoder, binary(
"7E01000021013345678906000F002C012F373031313142534A2D4D3742203030303030303001D4C1423838383838B47E"));
+ verifyPosition(decoder, binary(
+ "7E550100287001608180000127061008045322332880113555602E050031010000000608000010931435010002000300030100051B7E"));
+
verifyAttribute(decoder, binary(
"7E0200005C03204187290418C70000000000040003015AFC8D06D134D600000000000020040110063457080000000000000000010400000002530901000000000000000030010F310106EB1D000800233030312E3437000A000300000000000000000005000101A500357E"),
"fuel2", 1.47);