diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2018-12-17 22:37:15 -0800 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2018-12-17 22:37:15 -0800 |
commit | 85cd0f9e023b7c664373ea19418c2ed5675c5025 (patch) | |
tree | e051c3c713cd669728c7408403a0d737b2e0a70a | |
parent | 42e836fc36831ad0dae900e1bd9c6fed4ef59912 (diff) | |
download | trackermap-server-85cd0f9e023b7c664373ea19418c2ed5675c5025.tar.gz trackermap-server-85cd0f9e023b7c664373ea19418c2ed5675c5025.tar.bz2 trackermap-server-85cd0f9e023b7c664373ea19418c2ed5675c5025.zip |
Improve GPS103 decoding
-rw-r--r-- | src/org/traccar/protocol/Gps103ProtocolDecoder.java | 10 | ||||
-rw-r--r-- | test/org/traccar/protocol/Gps103ProtocolDecoderTest.java | 13 |
2 files changed, 17 insertions, 6 deletions
diff --git a/src/org/traccar/protocol/Gps103ProtocolDecoder.java b/src/org/traccar/protocol/Gps103ProtocolDecoder.java index c0f485349..1fbae15ce 100644 --- a/src/org/traccar/protocol/Gps103ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gps103ProtocolDecoder.java @@ -73,9 +73,11 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder { .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(); @@ -193,7 +195,7 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder { } 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")) { diff --git a/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java b/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java index 7dc1d36f4..00e85f5e3 100644 --- a/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java @@ -2,6 +2,7 @@ package org.traccar.protocol; import org.junit.Test; import org.traccar.ProtocolTest; +import org.traccar.model.Position; public class Gps103ProtocolDecoderTest extends ProtocolTest { @@ -11,6 +12,13 @@ public class Gps103ProtocolDecoderTest extends ProtocolTest { 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,---,*")); verifyPosition(decoder, text( @@ -22,8 +30,9 @@ public class Gps103ProtocolDecoderTest extends ProtocolTest { 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%,,;")); |