From 8f7ed4ed8ab881c480c22f605d1ff14918a3e43f Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 4 Oct 2016 05:35:12 +1300 Subject: Decode GPS103 DTCs (fix #2401) --- src/org/traccar/helper/ObdDecoder.java | 4 ++-- src/org/traccar/model/Position.java | 1 + src/org/traccar/protocol/Gps103ProtocolDecoder.java | 6 ++---- test/org/traccar/protocol/Gps103ProtocolDecoderTest.java | 3 +++ 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 @@ -10,6 +10,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,,,,;")); -- cgit v1.2.3