diff options
-rw-r--r-- | src/org/traccar/protocol/H02ProtocolDecoder.java | 21 | ||||
-rw-r--r-- | test/org/traccar/protocol/H02ProtocolDecoderTest.java | 2 |
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( |