Skip to content

Commit

Permalink
Improve GPS103 decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
tananaev committed Dec 18, 2018
1 parent 42e836f commit 85cd0f9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
10 changes: 6 additions & 4 deletions src/org/traccar/protocol/Gps103ProtocolDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,11 @@ public Gps103ProtocolDecoder(Protocol protocol) {
.number(",(d+.?d*)?").optional() // altitude
.number(",([01])?").optional() // ignition
.number(",([01])?").optional() // door
.number(",(?:(d+.d+)%)?").optional() // fuel 1
.number(",(?:(d+.d+)%)?").optional() // fuel 2
.number("(-?d+)?") // temperature
.groupBegin()
.number(",(?:(d+.d+)%)?") // fuel 1
.number(",(?:(d+.d+)%|d+)?") // fuel 2
.groupEnd("?")
.number(",([-+]?d+)?") // temperature
.groupEnd()
.any()
.compile();
Expand Down Expand Up @@ -193,7 +195,7 @@ private Position decodeRegular(Channel channel, SocketAddress remoteAddress, Str
} else if (alarm.equals("acc off")) {
position.set(Position.KEY_IGNITION, false);
} else if (alarm.startsWith("T:")) {
position.set(Position.PREFIX_TEMP + 1, alarm.substring(2));
position.set(Position.PREFIX_TEMP + 1, Double.parseDouble(alarm.substring(2)));
} else if (alarm.startsWith("oil ")) {
position.set(Position.KEY_FUEL_LEVEL, Double.parseDouble(alarm.substring(4)));
} else if (!position.getAttributes().containsKey(Position.KEY_ALARM) && !alarm.equals("tracker")) {
Expand Down
13 changes: 11 additions & 2 deletions test/org/traccar/protocol/Gps103ProtocolDecoderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.junit.Test;
import org.traccar.ProtocolTest;
import org.traccar.model.Position;

public class Gps103ProtocolDecoderTest extends ProtocolTest {

Expand All @@ -10,6 +11,13 @@ public void testDecode() throws Exception {

Gps103ProtocolDecoder decoder = new Gps103ProtocolDecoder(null);

verifyPosition(decoder, text(
"imei:868683026321020,T:+11,181217080050,,F,080047.000,A,3227.3057,N,11649.4754,W,0.00,0,,0,0,0.00%,,+11;"));

verifyAttribute(decoder, text(
"imei:868683026321020,tracker,181217080106,,F,080102.000,A,3227.3057,N,11649.4754,W,0.00,0,,0,0,0.00%,0,+11;"),
Position.PREFIX_TEMP + 1, 11);

verifyPosition(decoder, text(
"imei:861359038609986,Equipo 1,---,------,----,214734,241018,26,1,-33.42317,-70.61930,067,229,0674,1.00,08,0,1,---,*"));

Expand All @@ -22,8 +30,9 @@ public void testDecode() throws Exception {
verifyAttributes(decoder, text(
"imei:868683027758113,OBD,180905200218,,,,0,0,0.39%,70,9.41%,494,0.00,P0137,P0430,,;"));

verifyPosition(decoder, text(
"imei:353451044508750,001,0809231929,13554900601,F,055403.000,A,2233.1870,N,11354.3067,E,0.00,30.1,65.43,1,0,10.5%,0.0%,28;"));
verifyAttribute(decoder, text(
"imei:353451044508750,001,0809231929,13554900601,F,055403.000,A,2233.1870,N,11354.3067,E,0.00,30.1,65.43,1,0,10.5%,0.0%,28;"),
"fuel1", 10.5);

verifyPosition(decoder, text(
"imei:864180036029895,acc on,180508145653,,F,065645.000,A,4729.1497,N,01904.2342,E,0.00,0,,1,,0.00%,,;"));
Expand Down

0 comments on commit 85cd0f9

Please sign in to comment.