aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2016-06-20 11:38:21 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2016-06-20 11:38:21 +1200
commitcc26f01471506935d6f438a102fbf9478dcebb1b (patch)
treec5b24d25cfcd55abe2c30a690183b4ded2439db8
parent998e5cf31ae2f7d59948ca9570f93072cffb2acd (diff)
downloadtrackermap-server-cc26f01471506935d6f438a102fbf9478dcebb1b.tar.gz
trackermap-server-cc26f01471506935d6f438a102fbf9478dcebb1b.tar.bz2
trackermap-server-cc26f01471506935d6f438a102fbf9478dcebb1b.zip
Handle H02 messages with no time (fix #2035)
-rw-r--r--src/org/traccar/protocol/H02ProtocolDecoder.java21
-rw-r--r--test/org/traccar/protocol/H02ProtocolDecoderTest.java2
2 files changed, 15 insertions, 8 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/H02ProtocolDecoderTest.java b/test/org/traccar/protocol/H02ProtocolDecoderTest.java
index 4ca387f1a..d147cdec2 100644
--- a/test/org/traccar/protocol/H02ProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/H02ProtocolDecoderTest.java
@@ -10,7 +10,7 @@ public class H02ProtocolDecoderTest extends ProtocolTest {
H02ProtocolDecoder decoder = new H02ProtocolDecoder(new H02Protocol());
- verifyNothing(decoder, buffer(
+ verifyPosition(decoder, buffer(
"*HQ,353505220873067,V1,,V,4605.75732,N,01430.73863,E,0.00,0,,FFFFFFEF,125,194, 64,d3#"));
verifyPosition(decoder, buffer(