aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/org/traccar/protocol/H02ProtocolDecoder.java21
-rw-r--r--test/org/traccar/protocol/CarscopProtocolDecoderTest.java9
-rw-r--r--test/org/traccar/protocol/Gt02ProtocolDecoderTest.java9
-rw-r--r--test/org/traccar/protocol/H02ProtocolDecoderTest.java3
4 files changed, 35 insertions, 7 deletions
diff --git a/src/org/traccar/protocol/H02ProtocolDecoder.java b/src/org/traccar/protocol/H02ProtocolDecoder.java
index 9ba30f12b..ec5d3adef 100644
--- a/src/org/traccar/protocol/H02ProtocolDecoder.java
+++ b/src/org/traccar/protocol/H02ProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2014 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,6 +28,7 @@ import org.traccar.model.Position;
import java.net.SocketAddress;
import java.nio.charset.StandardCharsets;
+import java.util.Date;
import java.util.regex.Pattern;
public class H02ProtocolDecoder extends BaseProtocolDecoder {
@@ -120,7 +121,7 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
.number("(d+),") // imei
.number("Vd,") // version?
.any()
- .number("(dd)(dd)(dd),") // time
+ .number("(?:(dd)(dd)(dd))?,") // time
.expression("([AV])?,") // validity
.groupBegin()
.number("-(d+)-(d+.d+),") // latitude
@@ -136,7 +137,7 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
.expression("([EW]),")
.number("(d+.?d*),") // speed
.number("(d+.?d*)?,") // course
- .number("(dd)(dd)(dd),") // date (ddmmyy)
+ .number("(?:(dd)(dd)(dd))?,") // date (ddmmyy)
.number("(x{8})") // status
.any()
.compile();
@@ -156,8 +157,10 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
}
position.setDeviceId(getDeviceId());
- DateBuilder dateBuilder = new DateBuilder()
- .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt());
+ DateBuilder dateBuilder = new DateBuilder();
+ if (parser.hasNext(3)) {
+ dateBuilder.setTime(parser.nextInt(), parser.nextInt(), parser.nextInt());
+ }
if (parser.hasNext()) {
position.setValid(parser.next().equals("A"));
@@ -180,8 +183,12 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
position.setSpeed(parser.nextDouble());
position.setCourse(parser.nextDouble());
- dateBuilder.setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt());
- position.setTime(dateBuilder.getDate());
+ if (parser.hasNext(3)) {
+ dateBuilder.setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt());
+ position.setTime(dateBuilder.getDate());
+ } else {
+ position.setTime(new Date());
+ }
processStatus(position, parser.nextLong(16));
diff --git a/test/org/traccar/protocol/CarscopProtocolDecoderTest.java b/test/org/traccar/protocol/CarscopProtocolDecoderTest.java
index e2ac62e0b..ab64ddd3c 100644
--- a/test/org/traccar/protocol/CarscopProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/CarscopProtocolDecoderTest.java
@@ -10,6 +10,15 @@ public class CarscopProtocolDecoderTest extends ProtocolTest {
CarscopProtocolDecoder decoder = new CarscopProtocolDecoder(new CarscopProtocol());
+ verifyNothing(decoder, text(
+ "*160618233129UB00HSO"));
+
+ verifyNothing(decoder, text(
+ "*160618232614UD00232614A5009.1747N01910.3829E0.000160618298.2811000000L000000"));
+
+ verifyNothing(decoder, text(
+ "*160618232529UB05CW9999C00000538232529A5009.1747N01910.3829E0.000160618298.2811000000L000000"));
+
verifyPosition(decoder, text(
"*040331141830UB05123456789012345061825A2934.0133N10627.2544E000.0040331309.6200000000L000000"),
position("2004-03-31 06:18:25.000", true, 29.56689, 106.45424));
diff --git a/test/org/traccar/protocol/Gt02ProtocolDecoderTest.java b/test/org/traccar/protocol/Gt02ProtocolDecoderTest.java
index c094c75cc..3cfa0ea4a 100644
--- a/test/org/traccar/protocol/Gt02ProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/Gt02ProtocolDecoderTest.java
@@ -11,6 +11,15 @@ public class Gt02ProtocolDecoderTest extends ProtocolTest {
Gt02ProtocolDecoder decoder = new Gt02ProtocolDecoder(new Gt02Protocol());
verifyAttributes(decoder, binary(
+ "68680f0504035889905831401700df1a00000d0a"));
+
+ verifyAttributes(decoder, binary(
+ "6868130504035889905831401700001a040423261e290d0a"));
+
+ verifyAttributes(decoder, binary(
+ "68681905040358899058314017000e1a010a2623211b2722252329000d0a"));
+
+ verifyAttributes(decoder, binary(
"68681a060303588990500037252de91a010a171a191b171915191e10000d0a"));
verifyPosition(decoder, binary(
diff --git a/test/org/traccar/protocol/H02ProtocolDecoderTest.java b/test/org/traccar/protocol/H02ProtocolDecoderTest.java
index 8e0abac58..d147cdec2 100644
--- a/test/org/traccar/protocol/H02ProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/H02ProtocolDecoderTest.java
@@ -11,6 +11,9 @@ public class H02ProtocolDecoderTest extends ProtocolTest {
H02ProtocolDecoder decoder = new H02ProtocolDecoder(new H02Protocol());
verifyPosition(decoder, buffer(
+ "*HQ,353505220873067,V1,,V,4605.75732,N,01430.73863,E,0.00,0,,FFFFFFEF,125,194, 64,d3#"));
+
+ verifyPosition(decoder, buffer(
"*HQ,4210051415,V1,164549,A,0956.3869,N,08406.7068,W,000.00,000,221215,FFFFFBFF,712,01,0,0,6#"),
position("2015-12-22 16:45:49.000", true, 9.93978, -84.11178));