Skip to content

Commit

Permalink
Fix GPS103 course decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
tananaev committed Feb 6, 2019
1 parent 6810c4c commit 9cd715d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/org/traccar/protocol/Gps103ProtocolDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ public Gps103ProtocolDecoder(Protocol protocol) {
.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();
Expand Down
17 changes: 14 additions & 3 deletions test/org/traccar/ProtocolTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected void verifyNotNull(BaseProtocolDecoder decoder, Object object) throws
assertNotNull(decoder.decode(null, null, object));
}

protected void verifyNull(Object object) throws Exception {
protected void verifyNull(Object object) {
assertNull(object);
}

Expand All @@ -93,7 +93,18 @@ protected void verifyNull(BaseProtocolDecoder decoder, Object object) throws Exc
}

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 {
Expand Down Expand Up @@ -291,7 +302,7 @@ private void checkInteger(Object value, int min, int max) {
}

protected void verifyCommand(
BaseProtocolEncoder encoder, Command command, ByteBuf expected) throws Exception {
BaseProtocolEncoder encoder, Command command, ByteBuf expected) {
verifyFrame(expected, encoder.encodeCommand(command));
}

Expand Down
4 changes: 4 additions & 0 deletions test/org/traccar/protocol/Gps103ProtocolDecoderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ public void testDecode() throws Exception {

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;"));

Expand Down

0 comments on commit 9cd715d

Please sign in to comment.