diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-10-29 15:09:52 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-10-29 15:09:52 +1300 |
commit | 0d65586e0011f44d7597a0e332a0a1b83276607c (patch) | |
tree | 499ff94d48578eacf63451426f5d2380c32fa938 | |
parent | 9a72eea4bfe43dba9512cfef744d539d5f78ad49 (diff) | |
download | trackermap-server-0d65586e0011f44d7597a0e332a0a1b83276607c.tar.gz trackermap-server-0d65586e0011f44d7597a0e332a0a1b83276607c.tar.bz2 trackermap-server-0d65586e0011f44d7597a0e332a0a1b83276607c.zip |
Fix a problem in GoSafe decoder
-rw-r--r-- | src/org/traccar/protocol/GoSafeProtocolDecoder.java | 14 | ||||
-rw-r--r-- | test/org/traccar/ProtocolDecoderTest.java | 2 | ||||
-rw-r--r-- | test/org/traccar/protocol/GoSafeProtocolDecoderTest.java | 3 |
3 files changed, 13 insertions, 6 deletions
diff --git a/src/org/traccar/protocol/GoSafeProtocolDecoder.java b/src/org/traccar/protocol/GoSafeProtocolDecoder.java index e1321633e..7ec395672 100644 --- a/src/org/traccar/protocol/GoSafeProtocolDecoder.java +++ b/src/org/traccar/protocol/GoSafeProtocolDecoder.java @@ -22,10 +22,7 @@ import java.util.List; import java.util.regex.Pattern; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; -import org.traccar.helper.BitUtil; -import org.traccar.helper.DateBuilder; -import org.traccar.helper.Parser; -import org.traccar.helper.PatternBuilder; +import org.traccar.helper.*; import org.traccar.model.Event; import org.traccar.model.Position; @@ -56,7 +53,7 @@ public class GoSafeProtocolDecoder extends BaseProtocolDecoder { .number("(d+);") // satellites .number("([NS])(d+.d+);") // latitude .number("([EW])(d+.d+);") // longitude - .number("(d+);") // speed + .number("(d+)?;") // speed .number("(d+);") // course .number("(d+);") // altitude .number("(d+.d+)") // hdop @@ -89,7 +86,8 @@ public class GoSafeProtocolDecoder extends BaseProtocolDecoder { .text("ETD:").expression("[^,],?") .groupEnd("?") .groupBegin() - .text("OBD:").expression("[^,],?") + .text("OBD:") + .number("(x+),?") .groupEnd("?") .groupBegin() .text("FUL:").expression("[^,],?") @@ -127,6 +125,10 @@ public class GoSafeProtocolDecoder extends BaseProtocolDecoder { position.set(Event.KEY_STATUS, status); } + if (parser.hasNext()) { + position.set("obd", parser.next()); + } + return position; } diff --git a/test/org/traccar/ProtocolDecoderTest.java b/test/org/traccar/ProtocolDecoderTest.java index e6d5270e8..925f457a1 100644 --- a/test/org/traccar/ProtocolDecoderTest.java +++ b/test/org/traccar/ProtocolDecoderTest.java @@ -69,6 +69,7 @@ public class ProtocolDecoderTest { Object decodedObject = decoder.decode(null, null, object); Assert.assertNotNull(decodedObject); Assert.assertTrue(decodedObject instanceof List); + Assert.assertFalse("list if empty", ((List) decodedObject).isEmpty()); for (Object item : (List) decodedObject) { verifyDecodedPosition(item); } @@ -78,6 +79,7 @@ public class ProtocolDecoderTest { Object decodedObject = decoder.decode(null, null, object); Assert.assertNotNull(decodedObject); Assert.assertTrue(decodedObject instanceof List); + Assert.assertFalse("list if empty", ((List) decodedObject).isEmpty()); for (Object item : (List) decodedObject) { verifyDecodedPosition(item, position); } diff --git a/test/org/traccar/protocol/GoSafeProtocolDecoderTest.java b/test/org/traccar/protocol/GoSafeProtocolDecoderTest.java index d5e2213c4..9f1d82b8c 100644 --- a/test/org/traccar/protocol/GoSafeProtocolDecoderTest.java +++ b/test/org/traccar/protocol/GoSafeProtocolDecoderTest.java @@ -10,6 +10,9 @@ public class GoSafeProtocolDecoderTest extends ProtocolDecoderTest { GoSafeProtocolDecoder decoder = new GoSafeProtocolDecoder(new GoSafeProtocol()); + verifyPositions(decoder, text( + "*GS16,351535059439208,083515281015,,GPS:A;9;N31.959502;E35.908316;;108;890;1.05;1.79,GSM:1;4;416;3;AF0;A3A6;-59;416;3;AF0;A3A3;-50;416;3;AF0;A3A4;-56;416;3;AF0;A3A5;-62;416;3;AF0;B195;-76,OBD:04410C194603410D2303411C0103410583037F011203411115")); + verifyNothing(decoder, text( "*GS16,351535058709775")); |