aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-10-05 22:43:55 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2015-10-05 22:43:55 +1300
commitca8264c895b67cb040b63604500254465abc7677 (patch)
tree2fc54af943d37bfff737f81ac99d2c7b1a9cd464
parent037ff8b24880304190187a632612169c471a82a3 (diff)
downloadtrackermap-server-ca8264c895b67cb040b63604500254465abc7677.tar.gz
trackermap-server-ca8264c895b67cb040b63604500254465abc7677.tar.bz2
trackermap-server-ca8264c895b67cb040b63604500254465abc7677.zip
Handle H02 empty validity flag
-rw-r--r--src/org/traccar/protocol/H02ProtocolDecoder.java7
-rw-r--r--test/org/traccar/protocol/H02ProtocolDecoderTest.java5
2 files changed, 9 insertions, 3 deletions
diff --git a/src/org/traccar/protocol/H02ProtocolDecoder.java b/src/org/traccar/protocol/H02ProtocolDecoder.java
index c93d0c6dd..30193a648 100644
--- a/src/org/traccar/protocol/H02ProtocolDecoder.java
+++ b/src/org/traccar/protocol/H02ProtocolDecoder.java
@@ -112,7 +112,7 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
"V\\d," + // Version?
".*" +
"(\\d{2})(\\d{2})(\\d{2})," + // Time (HHMMSS)
- "([AV])," + // Validity
+ "([AV])?," + // Validity
"-?(\\d+)-?(\\d{2}.\\d+)," + // Latitude (DDMM.MMMM)
"([NS])," +
"-?(\\d+)-?(\\d{2}.\\d+)," + // Longitude (DDMM.MMMM)
@@ -151,7 +151,10 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
time.set(Calendar.SECOND, Integer.valueOf(parser.group(index++)));
// Validity
- position.setValid(parser.group(index++).compareTo("A") == 0);
+ String valid = parser.group(index++);
+ if (valid != null) {
+ position.setValid(valid.compareTo("A") == 0);
+ }
// Latitude
Double latitude = Double.valueOf(parser.group(index++));
diff --git a/test/org/traccar/protocol/H02ProtocolDecoderTest.java b/test/org/traccar/protocol/H02ProtocolDecoderTest.java
index 744a9982d..076bdf65f 100644
--- a/test/org/traccar/protocol/H02ProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/H02ProtocolDecoderTest.java
@@ -2,10 +2,10 @@ package org.traccar.protocol;
import java.nio.charset.Charset;
import org.jboss.netty.buffer.ChannelBuffers;
-import static org.traccar.helper.DecoderVerifier.verify;
import static org.junit.Assert.assertNull;
import org.junit.Test;
import org.traccar.helper.ChannelBufferTools;
+import static org.traccar.helper.DecoderVerifier.verify;
public class H02ProtocolDecoderTest extends ProtocolDecoderTest {
@@ -13,6 +13,9 @@ public class H02ProtocolDecoderTest extends ProtocolDecoderTest {
public void testDecode() throws Exception {
H02ProtocolDecoder decoder = new H02ProtocolDecoder(new H02Protocol());
+
+ verify(decoder.decode(null, null, ChannelBuffers.copiedBuffer(
+ "*HQ,355488020119695,V1,050418,,2827.61232,N,07703.84822,E,0.00,0,031015,FFFEFBFF#", Charset.defaultCharset())));
verify(decoder.decode(null, null, ChannelBuffers.copiedBuffer(
"*HQ,1451316409,V1,030149,A,-23-29.0095,S,-46-51.5852,W,2.4,065,070315,FFFFFFFF#", Charset.defaultCharset())));