aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/org/traccar/protocol/H02ProtocolDecoder.java13
-rw-r--r--test/org/traccar/protocol/H02ProtocolDecoderTest.java6
2 files changed, 17 insertions, 2 deletions
diff --git a/src/org/traccar/protocol/H02ProtocolDecoder.java b/src/org/traccar/protocol/H02ProtocolDecoder.java
index 64c45a22f..9603200ab 100644
--- a/src/org/traccar/protocol/H02ProtocolDecoder.java
+++ b/src/org/traccar/protocol/H02ProtocolDecoder.java
@@ -107,10 +107,18 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
Position position = new Position(getProtocolName());
+ boolean longId = buf.readableBytes() == 42;
+
buf.readByte(); // marker
- DeviceSession deviceSession = getDeviceSession(
- channel, remoteAddress, ByteBufUtil.hexDump(buf.readSlice(5)));
+ String id;
+ if (longId) {
+ id = ByteBufUtil.hexDump(buf.readSlice(8)).substring(0, 15);
+ } else {
+ id = ByteBufUtil.hexDump(buf.readSlice(5));
+ }
+
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, id);
if (deviceSession == null) {
return null;
}
@@ -183,6 +191,7 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
.expression("([EW]),")
.number("(d+.?d*),") // speed
.number("(d+.?d*)?,") // course
+ .number("(?:d+,)?") // battery
.number("(?:(dd)(dd)(dd))?") // date (ddmmyy)
.groupBegin()
.expression(",[^,]*,")
diff --git a/test/org/traccar/protocol/H02ProtocolDecoderTest.java b/test/org/traccar/protocol/H02ProtocolDecoderTest.java
index 3a758069c..1a49b4bfb 100644
--- a/test/org/traccar/protocol/H02ProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/H02ProtocolDecoderTest.java
@@ -11,6 +11,12 @@ public class H02ProtocolDecoderTest extends ProtocolTest {
H02ProtocolDecoder decoder = new H02ProtocolDecoder(new H02Protocol());
+ verifyPosition(decoder, binary(
+ "2435248308419329301047591808172627335900074412294E024138FEFFFFFFFF01120064BA73005ECC"));
+
+ verifyPosition(decoder, buffer(
+ "*HQ,4210209006,V1,054048,A,2828.2297,N,07733.4332,E,000.5,047,4,080918,EEE7FBDF,4261193,0#"));
+
verifyPosition(decoder, buffer(
"*HQ,353505221264507,V2,100220,0,5238.26259,N,00507.33983,E,0.25,0,280917,FFFFFFFF,cc,28, db,d75b#"));