From 806584d5d19f224eb26cade7096926af9cc0e4c2 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 9 Nov 2018 15:48:20 +1300 Subject: Handle GV300 empty CAN fields --- src/org/traccar/protocol/Gl200TextProtocolDecoder.java | 8 ++++---- test/org/traccar/protocol/Gl200TextProtocolDecoderTest.java | 3 +++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/org/traccar/protocol/Gl200TextProtocolDecoder.java b/src/org/traccar/protocol/Gl200TextProtocolDecoder.java index 0b6bcd09d..45b80f0a6 100644 --- a/src/org/traccar/protocol/Gl200TextProtocolDecoder.java +++ b/src/org/traccar/protocol/Gl200TextProtocolDecoder.java @@ -591,8 +591,8 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder { if (BitUtil.check(reportMask, 2)) { position.set(Position.KEY_OBD_ODOMETER, values[index++]); } - if (BitUtil.check(reportMask, 3)) { - position.set(Position.KEY_FUEL_USED, Double.parseDouble(values[index++])); + if (BitUtil.check(reportMask, 3) && !values[index++].isEmpty()) { + position.set(Position.KEY_FUEL_USED, Double.parseDouble(values[index - 1])); } if (BitUtil.check(reportMask, 5) && !values[index++].isEmpty()) { position.set(Position.KEY_RPM, Integer.parseInt(values[index - 1])); @@ -615,8 +615,8 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder { if (BitUtil.check(reportMask, 10) && !values[index++].isEmpty()) { position.set(Position.KEY_THROTTLE, Integer.parseInt(values[index - 1])); } - if (BitUtil.check(reportMask, 11)) { - position.set(Position.KEY_HOURS, UnitsConverter.msFromHours(Double.parseDouble(values[index++]))); + if (BitUtil.check(reportMask, 11) && !values[index++].isEmpty()) { + position.set(Position.KEY_HOURS, UnitsConverter.msFromHours(Double.parseDouble(values[index - 1]))); } if (BitUtil.check(reportMask, 12)) { position.set("drivingHours", Double.parseDouble(values[index++])); diff --git a/test/org/traccar/protocol/Gl200TextProtocolDecoderTest.java b/test/org/traccar/protocol/Gl200TextProtocolDecoderTest.java index a32cec1d4..75edb367c 100644 --- a/test/org/traccar/protocol/Gl200TextProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Gl200TextProtocolDecoderTest.java @@ -10,6 +10,9 @@ public class Gl200TextProtocolDecoderTest extends ProtocolTest { Gl200TextProtocolDecoder decoder = new Gl200TextProtocolDecoder(null); + verifyPosition(decoder, buffer( + "+RESP:GTCAN,4B0201,867995030001575,,10,0,C03FFFFF,,0,H0,,,,,,,,,,0.00,0.03,,,,0,,0,,,0,10.0,310,404.3,14.096743,50.143363,20181102110535,0230,0003,9B14,5066,00,20181102112101,03E0$")); + verifyPositions(decoder, buffer( "+RESP:GTSTR,440502,866427030112088,GL530,0,0,2,,100,3,0.6,0,127.5,2.413963,48.877096,20180704180102,0208,0001,0310,E625,,,0000,20180704180100,004C$")); -- cgit v1.2.3