aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-11-25 09:49:54 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2015-11-25 09:49:54 +1300
commit2c399889e9b61c8e3580c046a70b556e1ab628e3 (patch)
tree01ccaadeb85be2c71f971986e5d290caaab54917
parent9e5de36d24d477bddc7addc29f4b504314b644cf (diff)
downloadtrackermap-server-2c399889e9b61c8e3580c046a70b556e1ab628e3.tar.gz
trackermap-server-2c399889e9b61c8e3580c046a70b556e1ab628e3.tar.bz2
trackermap-server-2c399889e9b61c8e3580c046a70b556e1ab628e3.zip
Improve H02 protocol decoder regex
-rw-r--r--src/org/traccar/protocol/H02ProtocolDecoder.java31
-rw-r--r--test/org/traccar/protocol/H02ProtocolDecoderTest.java6
2 files changed, 33 insertions, 4 deletions
diff --git a/src/org/traccar/protocol/H02ProtocolDecoder.java b/src/org/traccar/protocol/H02ProtocolDecoder.java
index d245fbdc8..ff3ee169e 100644
--- a/src/org/traccar/protocol/H02ProtocolDecoder.java
+++ b/src/org/traccar/protocol/H02ProtocolDecoder.java
@@ -27,6 +27,7 @@ import org.traccar.helper.ChannelBufferTools;
import org.traccar.helper.DateBuilder;
import org.traccar.helper.Parser;
import org.traccar.helper.PatternBuilder;
+import org.traccar.helper.PatternUtil;
import org.traccar.model.Event;
import org.traccar.model.Position;
@@ -122,9 +123,17 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
.any()
.number("(dd)(dd)(dd),") // time
.expression("([AV])?,") // validity
- .number("-?(d+)-?(dd.d+),") // latitude
+ .groupBegin()
+ .number("(d+)(dd.d+),") // latitude
+ .or()
+ .number("-(d+)-(d+.d+),") // latitude
+ .groupEnd()
.expression("([NS]),")
- .number("-?(d+)-?(dd.d+),") // longitude
+ .groupBegin()
+ .number("(d+)(dd.d+),") // longitude
+ .or()
+ .number("-(d+)-(d+.d+),") // longitude
+ .groupEnd()
.expression("([EW]),")
.number("(d+.?d*),") // speed
.number("(d+.?d*)?,") // course
@@ -135,6 +144,8 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
private Position decodeText(String sentence, Channel channel) {
+ String x = PatternUtil.checkPattern(PATTERN.pattern(), sentence);
+
Parser parser = new Parser(PATTERN, sentence);
if (!parser.matches()) {
return null;
@@ -155,8 +166,20 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
position.setValid(parser.next().equals("A"));
}
- position.setLatitude(parser.nextCoordinate());
- position.setLongitude(parser.nextCoordinate());
+ if (parser.hasNext(2)) {
+ position.setLatitude(parser.nextCoordinate());
+ }
+ if (parser.hasNext(2)) {
+ position.setLatitude(parser.nextCoordinate());
+ }
+
+ if (parser.hasNext(2)) {
+ position.setLongitude(parser.nextCoordinate());
+ }
+ if (parser.hasNext(2)) {
+ position.setLongitude(parser.nextCoordinate());
+ }
+
position.setSpeed(parser.nextDouble());
position.setCourse(parser.nextDouble());
diff --git a/test/org/traccar/protocol/H02ProtocolDecoderTest.java b/test/org/traccar/protocol/H02ProtocolDecoderTest.java
index b7d2b07b0..be503cc65 100644
--- a/test/org/traccar/protocol/H02ProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/H02ProtocolDecoderTest.java
@@ -10,6 +10,12 @@ public class H02ProtocolDecoderTest extends ProtocolDecoderTest {
public void testDecode() throws Exception {
H02ProtocolDecoder decoder = new H02ProtocolDecoder(new H02Protocol());
+
+ verifyPosition(decoder, buffer(
+ "*HQ,1451316485,V1,121557,A,-23-3.3408,S,-48-2.8926,W,0.1,158,241115,FFFFFFFF#"));
+
+ verifyPosition(decoder, buffer(
+ "*HQ,1451316485,V1,121557,A,-23-35.3408,S,-48-2.8926,W,0.1,158,241115,FFFFFFFF#"));
verifyPosition(decoder, buffer(
"*HQ,355488020119695,V1,050418,,2827.61232,N,07703.84822,E,0.00,0,031015,FFFEFBFF#"),