aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2016-10-04 05:35:12 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2016-10-04 13:35:56 +1300
commit8f7ed4ed8ab881c480c22f605d1ff14918a3e43f (patch)
tree8c4d6cadfae72c98c3eeea7cfdfde472da291af5
parentda251c52ba6a001e85574f688455a698a6998855 (diff)
downloadtraccar-server-8f7ed4ed8ab881c480c22f605d1ff14918a3e43f.tar.gz
traccar-server-8f7ed4ed8ab881c480c22f605d1ff14918a3e43f.tar.bz2
traccar-server-8f7ed4ed8ab881c480c22f605d1ff14918a3e43f.zip
Decode GPS103 DTCs (fix #2401)
-rw-r--r--src/org/traccar/helper/ObdDecoder.java4
-rw-r--r--src/org/traccar/model/Position.java1
-rw-r--r--src/org/traccar/protocol/Gps103ProtocolDecoder.java6
-rw-r--r--test/org/traccar/protocol/Gps103ProtocolDecoderTest.java3
4 files changed, 8 insertions, 6 deletions
diff --git a/src/org/traccar/helper/ObdDecoder.java b/src/org/traccar/helper/ObdDecoder.java
index 3196c25e4..5a75fa368 100644
--- a/src/org/traccar/helper/ObdDecoder.java
+++ b/src/org/traccar/helper/ObdDecoder.java
@@ -60,7 +60,7 @@ public final class ObdDecoder {
StringBuilder codes = new StringBuilder();
for (int i = 0; i < value.length() / 4; i++) {
int numValue = Integer.parseInt(value.substring(i * 4, (i + 1) * 4), 16);
- codes.append(',');
+ codes.append(' ');
switch (numValue >> 14) {
case 1:
codes.append('C');
@@ -78,7 +78,7 @@ public final class ObdDecoder {
codes.append(String.format("%04X", numValue & 0x3FFF));
}
if (codes.length() > 0) {
- return createEntry("dtcs", codes.toString().replaceFirst(",", ""));
+ return createEntry(Position.KEY_DTCS, codes.toString().trim());
} else {
return null;
}
diff --git a/src/org/traccar/model/Position.java b/src/org/traccar/model/Position.java
index a1423993b..3a7070083 100644
--- a/src/org/traccar/model/Position.java
+++ b/src/org/traccar/model/Position.java
@@ -60,6 +60,7 @@ public class Position extends Message {
public static final String KEY_ARMED = "armed";
public static final String KEY_ACCURACY = "accuracy";
+ public static final String KEY_DTCS = "dtcs";
public static final String KEY_OBD_SPEED = "obdSpeed";
public static final String KEY_OBD_ODOMETER = "obdOdometer";
diff --git a/src/org/traccar/protocol/Gps103ProtocolDecoder.java b/src/org/traccar/protocol/Gps103ProtocolDecoder.java
index 363834f89..ed50c33f0 100644
--- a/src/org/traccar/protocol/Gps103ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Gps103ProtocolDecoder.java
@@ -95,10 +95,7 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder {
.number("(d+.?d*%),") // throttle
.number("(d+),") // rpm
.number("(d+.d+),") // battery
- .number("[^,]*,") // dtc 1
- .number("[^,]*,") // dtc 2
- .number("[^,]*,") // dtc 3
- .number("[^,]*") // dtc 4
+ .number("([^;]*)") // dtcs
.any()
.compile();
@@ -197,6 +194,7 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.KEY_THROTTLE, parser.next());
position.set(Position.KEY_RPM, parser.next());
position.set(Position.KEY_BATTERY, parser.next());
+ position.set(Position.KEY_DTCS, parser.next().replace(',', ' ').trim());
return position;
diff --git a/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java b/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java
index 72b0be1b5..2640051fb 100644
--- a/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java
@@ -11,6 +11,9 @@ public class Gps103ProtocolDecoderTest extends ProtocolTest {
Gps103ProtocolDecoder decoder = new Gps103ProtocolDecoder(new Gps103Protocol());
verifyAttributes(decoder, text(
+ "imei:359710049057798,OBD,161003192752,1785,,,0,54,96.47%,75,20.00%,1892,0.00,P0134,P0571,,;"));
+
+ verifyAttributes(decoder, text(
"imei:359710049090138,OBD,160629022949,51442,0.00,15.88,5632,122,40.39%,95,0.00%,2101,13.80,,,,;"));
verifyPosition(decoder, text(