aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2019-04-27 09:41:52 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2019-04-27 09:41:52 -0700
commit4abbb070fa13c480f2bc23aff0cfd026d186af80 (patch)
treeab4f5ae8e6c63e60b4efbb8422a181fd7a2b5b26 /src
parent9209299d3e55f07c1585866224a8264aca2bf5a1 (diff)
downloadtrackermap-server-4abbb070fa13c480f2bc23aff0cfd026d186af80.tar.gz
trackermap-server-4abbb070fa13c480f2bc23aff0cfd026d186af80.tar.bz2
trackermap-server-4abbb070fa13c480f2bc23aff0cfd026d186af80.zip
Fix status decoding
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/traccar/protocol/Tlt2hProtocolDecoder.java4
-rw-r--r--src/test/java/org/traccar/ProtocolTest.java9
-rw-r--r--src/test/java/org/traccar/protocol/Tlt2hProtocolDecoderTest.java6
3 files changed, 16 insertions, 3 deletions
diff --git a/src/main/java/org/traccar/protocol/Tlt2hProtocolDecoder.java b/src/main/java/org/traccar/protocol/Tlt2hProtocolDecoder.java
index f67ff88db..2a06d35e5 100644
--- a/src/main/java/org/traccar/protocol/Tlt2hProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/Tlt2hProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 - 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2013 - 2019 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -38,7 +38,7 @@ public class Tlt2hProtocolDecoder extends BaseProtocolDecoder {
private static final Pattern PATTERN_HEADER = new PatternBuilder()
.number("#(d+)#") // imei
.any()
- .expression("([^#]+)#") // status
+ .expression("#([^#]+)#") // status
.number("d+") // number of records
.compile();
diff --git a/src/test/java/org/traccar/ProtocolTest.java b/src/test/java/org/traccar/ProtocolTest.java
index 4d48bb763..bfff4eef3 100644
--- a/src/test/java/org/traccar/ProtocolTest.java
+++ b/src/test/java/org/traccar/ProtocolTest.java
@@ -17,6 +17,7 @@ import java.nio.charset.StandardCharsets;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
+import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;
@@ -101,7 +102,13 @@ public class ProtocolTest extends BaseTest {
}
protected void verifyAttribute(BaseProtocolDecoder decoder, Object object, String key, Object expected) throws Exception {
- Position position = (Position) decoder.decode(null, null, object);
+ Object decodedObject = decoder.decode(null, null, object);
+ Position position;
+ if (decodedObject instanceof Collection) {
+ position = (Position) ((Collection) decodedObject).iterator().next();
+ } else {
+ position = (Position) decodedObject;
+ }
switch (key) {
case "speed":
assertEquals(expected, position.getSpeed());
diff --git a/src/test/java/org/traccar/protocol/Tlt2hProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/Tlt2hProtocolDecoderTest.java
index 83caae208..185c3c368 100644
--- a/src/test/java/org/traccar/protocol/Tlt2hProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/Tlt2hProtocolDecoderTest.java
@@ -2,6 +2,7 @@ package org.traccar.protocol;
import org.junit.Test;
import org.traccar.ProtocolTest;
+import org.traccar.model.Position;
public class Tlt2hProtocolDecoderTest extends ProtocolTest {
@@ -10,6 +11,11 @@ public class Tlt2hProtocolDecoderTest extends ProtocolTest {
Tlt2hProtocolDecoder decoder = new Tlt2hProtocolDecoder(null);
+ verifyAttribute(decoder, text(
+ "#869260042149724#MP90_4G#0000#AUTOLOW#1\r\n" +
+ "#02201be0000$GPRMC,001645.00,A,5333.2920,N,11334.3857,W,0.03,,250419,,,A*5E\r\n"),
+ Position.KEY_IGNITION, false);
+
verifyPositions(decoder, text(
"#867962040161955#MT600#0000#0#0#137#41#0#AUTO#1\r\n" +
"#00019023402$GPRMC,084702.00,A,3228.6772,S,11545.9684,E,,159.80,251018,,,A*56\r\n"));