diff options
-rw-r--r-- | src/org/traccar/protocol/Gps103ProtocolDecoder.java | 6 | ||||
-rw-r--r-- | test/org/traccar/ProtocolTest.java | 17 | ||||
-rw-r--r-- | test/org/traccar/protocol/Gps103ProtocolDecoderTest.java | 4 |
3 files changed, 21 insertions, 6 deletions
diff --git a/src/org/traccar/protocol/Gps103ProtocolDecoder.java b/src/org/traccar/protocol/Gps103ProtocolDecoder.java index 27b94739b..aa02e8ad4 100644 --- a/src/org/traccar/protocol/Gps103ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gps103ProtocolDecoder.java @@ -81,10 +81,10 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder { .number(",([01])?").optional() // ignition .number(",([01])?").optional() // door .groupBegin() - .number(",(?:(d+.d+)%)?") // fuel 1 - .number(",(?:(d+.d+)%|d+)?") // fuel 2 + .number(",(?:(d+.d+)%)?") // fuel 1 + .number(",(?:(d+.d+)%|d+)?") // fuel 2 .groupEnd("?") - .number(",([-+]?d+)?") // temperature + .number(",([-+]?d+)?").optional() // temperature .groupEnd() .any() .compile(); diff --git a/test/org/traccar/ProtocolTest.java b/test/org/traccar/ProtocolTest.java index 939b3bd2c..1b5c0ea00 100644 --- a/test/org/traccar/ProtocolTest.java +++ b/test/org/traccar/ProtocolTest.java @@ -84,7 +84,7 @@ public class ProtocolTest extends BaseTest { assertNotNull(decoder.decode(null, null, object)); } - protected void verifyNull(Object object) throws Exception { + protected void verifyNull(Object object) { assertNull(object); } @@ -93,7 +93,18 @@ public class ProtocolTest extends BaseTest { } protected void verifyAttribute(BaseProtocolDecoder decoder, Object object, String key, Object expected) throws Exception { - assertEquals(expected, ((Position) decoder.decode(null, null, object)).getAttributes().get(key)); + Position position = (Position) decoder.decode(null, null, object); + switch (key) { + case "speed": + assertEquals(expected, position.getSpeed()); + break; + case "course": + assertEquals(expected, position.getCourse()); + break; + default: + assertEquals(expected, position.getAttributes().get(key)); + break; + } } protected void verifyAttributes(BaseProtocolDecoder decoder, Object object) throws Exception { @@ -291,7 +302,7 @@ public class ProtocolTest extends BaseTest { } protected void verifyCommand( - BaseProtocolEncoder encoder, Command command, ByteBuf expected) throws Exception { + BaseProtocolEncoder encoder, Command command, ByteBuf expected) { verifyFrame(expected, encoder.encodeCommand(command)); } diff --git a/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java b/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java index b44eb26f9..da8d8ff5a 100644 --- a/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java @@ -11,6 +11,10 @@ public class Gps103ProtocolDecoderTest extends ProtocolTest { Gps103ProtocolDecoder decoder = new Gps103ProtocolDecoder(null); + verifyAttribute(decoder, text( + "imei:868683023212255,tracker,190205084503,,F,064459.000,A,4915.1221,N,01634.5655,E,3.91,83.95;"), + "course", 83.95); + verifyPosition(decoder, text( "imei:864180034124375,vt14,190116192753,,F,172750.000,A,3649.2186,N,00235.8411,W,0.00,0,,0,0,51.93%,,+22;")); |