aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2018-08-05 10:41:07 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2018-08-05 10:41:07 +1200
commit495714f9322db11971d0349bc9c2b4a5ce7348e9 (patch)
tree8f0137cdeda38c2dc101a27cb4947d26c2e7e9b5
parent18e64c7118297d363a293e1c1af5a9d35033fee2 (diff)
downloadtraccar-server-495714f9322db11971d0349bc9c2b4a5ce7348e9.tar.gz
traccar-server-495714f9322db11971d0349bc9c2b4a5ce7348e9.tar.bz2
traccar-server-495714f9322db11971d0349bc9c2b4a5ce7348e9.zip
TK103 regex refactoring
-rw-r--r--src/org/traccar/protocol/Tk103ProtocolDecoder.java34
-rw-r--r--test/org/traccar/protocol/Tk103ProtocolDecoderTest.java6
2 files changed, 19 insertions, 21 deletions
diff --git a/src/org/traccar/protocol/Tk103ProtocolDecoder.java b/src/org/traccar/protocol/Tk103ProtocolDecoder.java
index 2bcd62407..3b1ab9655 100644
--- a/src/org/traccar/protocol/Tk103ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Tk103ProtocolDecoder.java
@@ -54,22 +54,20 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder {
.expression("([EW]),?")
.number("(d+.d)(?:d*,)?") // speed
.number("(dd)(dd)(dd),?") // time (hhmmss)
- .number("(d+.?d{1,4}),?") // course
.groupBegin()
+ .number("(?:([d.]{6})|(dd)),?") // course
.number("([01])") // charge
.number("([01])") // ignition
.number("(x)") // io
.number("(x)") // io
.number("(x)") // io
- .number("(xxx),?") // fuel
- .groupEnd("?")
- .number("(?:L(x+))?") // odometer
+ .number("(xxx)") // fuel
+ .number("L(x+)") // odometer
+ .or()
+ .number("(d+.d+)") // course
+ .groupEnd()
.any()
.number("([+-]ddd.d)?") // temperature
- .groupBegin()
- .number("([+-]?d+.d{1,2}),") // altitude
- .number("(d+)$") // number of visible satellites
- .groupEnd("?")
.text(")").optional()
.compile();
@@ -400,9 +398,14 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder {
dateBuilder.setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
position.setTime(dateBuilder.getDate());
- position.setCourse(parser.nextDouble(0));
+ if (parser.hasNext()) {
+ position.setCourse(parser.nextDouble());
+ }
+ if (parser.hasNext()) {
+ position.setCourse(parser.nextDouble());
+ }
- if (parser.hasNext(6)) {
+ if (parser.hasNext(7)) {
position.set(Position.KEY_CHARGE, parser.nextInt() == 0);
position.set(Position.KEY_IGNITION, parser.nextInt() == 1);
@@ -432,22 +435,15 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder {
}
position.set(Position.KEY_FUEL_LEVEL, parser.nextHexInt());
- }
-
- if (parser.hasNext()) {
position.set(Position.KEY_ODOMETER, parser.nextLong(16, 0));
}
if (parser.hasNext()) {
- position.set(Position.PREFIX_TEMP + 1, parser.nextDouble(0));
- }
-
- if (parser.hasNext()) {
- position.setAltitude(parser.nextDouble(0));
+ position.setCourse(parser.nextDouble());
}
if (parser.hasNext()) {
- position.set(Position.KEY_SATELLITES_VISIBLE, parser.nextInt(0));
+ position.set(Position.PREFIX_TEMP + 1, parser.nextDouble(0));
}
return position;
diff --git a/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java b/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java
index 4b4097600..699c702c9 100644
--- a/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java
@@ -2,6 +2,7 @@ package org.traccar.protocol;
import org.junit.Test;
import org.traccar.ProtocolTest;
+import org.traccar.model.Position;
public class Tk103ProtocolDecoderTest extends ProtocolTest {
@@ -34,8 +35,9 @@ public class Tk103ProtocolDecoderTest extends ProtocolTest {
verifyPosition(decoder, text(
"(325031693849BR00170228A5750.8012N02700.7476E000.2154529000.0000000200L00000000,170228,194530)"));
- verifyPosition(decoder, text(
- "(087073803649BR00170221A6142.0334N02712.2197E000.3203149000.00,00000000L00000000)"));
+ verifyAttribute(decoder, text(
+ "(087073803649BR00170221A6142.0334N02712.2197E000.3203149000.00,00000000L00000000)"),
+ Position.KEY_FUEL_LEVEL, 0);
verifyPosition(decoder, text(
"(864768010869060,DW30,050117,A,5135.82713N,00001.17918E,0.089,154745,000.0,43.40,12)"));