aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-09-18 10:59:56 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2015-09-18 10:59:56 +1200
commitd4e4948bfce5b088f505ff9c89dd8baad34ed16c (patch)
treeff8de9711b3e887cfede151a2a3fd48e57fab797
parent8baf73493d24c85bc5d13069044fc1150ed62c2e (diff)
downloadtrackermap-server-d4e4948bfce5b088f505ff9c89dd8baad34ed16c.tar.gz
trackermap-server-d4e4948bfce5b088f505ff9c89dd8baad34ed16c.tar.bz2
trackermap-server-d4e4948bfce5b088f505ff9c89dd8baad34ed16c.zip
Improve TK103 decoder pattern
-rw-r--r--src/org/traccar/protocol/Tk103ProtocolDecoder.java9
-rw-r--r--test/org/traccar/protocol/Tk103ProtocolDecoderTest.java6
2 files changed, 11 insertions, 4 deletions
diff --git a/src/org/traccar/protocol/Tk103ProtocolDecoder.java b/src/org/traccar/protocol/Tk103ProtocolDecoder.java
index 3885ee2ef..21aa81bda 100644
--- a/src/org/traccar/protocol/Tk103ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Tk103ProtocolDecoder.java
@@ -44,10 +44,10 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder {
"([NS]),?" +
"(\\d{3})(\\d{2}\\.\\d+)" + // Longitude (DDDMM.MMMM)
"([EW]),?" +
- "(\\d+\\.\\d)(?:\\d*,)?" + // Speed
+ "(\\d+\\.\\d{1,2}),?" + // Speed
"(\\d{2})(\\d{2})(\\d{2}),?" + // Time (HHMMSS)
- "(\\d+\\.?\\d+),?" + // Course
- "([0-9a-fA-F]{8})?,?" + // State
+ "(\\d+\\.?\\d{1,2}),?" + // Course
+ "(?:([01]{8})|([0-9a-fA-F]{8}))?,?" + // State
"(?:L([0-9a-fA-F]+))?.*\\)?"); // Odometer
@Override
@@ -137,7 +137,7 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder {
position.setCourse(Double.valueOf(parser.group(index++)));
// State
- String status = parser.group(index++);
+ String status = parser.group(index++); // binary status
if (status != null) {
position.set(Event.KEY_STATUS, status);
@@ -145,6 +145,7 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder {
position.set(Event.KEY_CHARGE, !BitUtil.check(value, 0));
position.set(Event.KEY_IGNITION, BitUtil.check(value, 1));
}
+ position.set(Event.KEY_STATUS, parser.group(index++)); // hex status
// Odometer
String odometer = parser.group(index++);
diff --git a/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java b/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java
index 0cfd790d8..452745189 100644
--- a/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java
@@ -10,6 +10,12 @@ public class Tk103ProtocolDecoderTest extends ProtocolDecoderTest {
public void testDecode() throws Exception {
Tk103ProtocolDecoder decoder = new Tk103ProtocolDecoder(new Tk103Protocol());
+
+ verify(decoder.decode(null, null,
+ "(088048003342BP05354188048003342150917A1352.9801N10030.9050E000.0103115265.5600010000L000003F9)"));
+
+ verify(decoder.decode(null, null,
+ "(088048003342BR00150917A1352.9801N10030.9050E000.0103224000.0000010000L000003F9)"));
verify(decoder.decode(null, null,
"(088048003342BR00150807A1352.9871N10030.9084E000.0110718000.0001010000L00000000)"));