From d643e9a75f1c6580d098b68cffc2c709db611d8e Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Mon, 17 Apr 2017 16:38:02 +1200 Subject: Normalize fuel level value --- src/org/traccar/protocol/AquilaProtocolDecoder.java | 2 +- src/org/traccar/protocol/Gl200ProtocolDecoder.java | 18 +++++++++--------- src/org/traccar/protocol/TytanProtocolDecoder.java | 6 +++--- src/org/traccar/protocol/WialonProtocolDecoder.java | 6 +++++- test/org/traccar/ProtocolTest.java | 4 ++++ 5 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/org/traccar/protocol/AquilaProtocolDecoder.java b/src/org/traccar/protocol/AquilaProtocolDecoder.java index 9c7b1bb12..30f5667af 100644 --- a/src/org/traccar/protocol/AquilaProtocolDecoder.java +++ b/src/org/traccar/protocol/AquilaProtocolDecoder.java @@ -159,7 +159,7 @@ public class AquilaProtocolDecoder extends BaseProtocolDecoder { if (parser.hasNext(9)) { - position.set(Position.KEY_FUEL_LEVEL, parser.next()); + position.set(Position.KEY_FUEL_LEVEL, parser.nextInt()); position.set(Position.PREFIX_IN + 1, parser.next()); position.set(Position.KEY_CHARGE, parser.next()); position.set(Position.PREFIX_IN + 2, parser.next()); diff --git a/src/org/traccar/protocol/Gl200ProtocolDecoder.java b/src/org/traccar/protocol/Gl200ProtocolDecoder.java index eb1099adc..3d39369bf 100644 --- a/src/org/traccar/protocol/Gl200ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gl200ProtocolDecoder.java @@ -473,16 +473,16 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { return null; } - position.set(Position.KEY_RPM, parser.nextInt(0)); - position.set(Position.KEY_OBD_SPEED, parser.nextInt(0)); - position.set(Position.PREFIX_TEMP + 1, parser.nextInt(0)); + position.set(Position.KEY_RPM, parser.nextInt()); + position.set(Position.KEY_OBD_SPEED, parser.nextInt()); + position.set(Position.PREFIX_TEMP + 1, parser.nextInt()); position.set(Position.KEY_FUEL_CONSUMPTION, parser.next()); - position.set("dtcsClearedDistance", parser.nextInt(0)); + position.set("dtcsClearedDistance", parser.nextInt()); position.set("odbConnect", parser.nextInt(0) == 1); - position.set("dtcsNumber", parser.nextInt(0)); + position.set("dtcsNumber", parser.nextInt()); position.set("dtcsCodes", parser.next()); - position.set(Position.KEY_THROTTLE, parser.nextInt(0)); - position.set(Position.KEY_FUEL_LEVEL, parser.nextInt(0)); + position.set(Position.KEY_THROTTLE, parser.nextInt()); + position.set(Position.KEY_FUEL_LEVEL, parser.nextInt()); position.set(Position.KEY_OBD_ODOMETER, parser.nextInt(0) * 1000); decodeLocation(position, parser); @@ -556,8 +556,8 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { decodeStatus(position, parser); - position.set(Position.KEY_RPM, parser.nextInt(0)); - position.set(Position.KEY_FUEL_LEVEL, parser.nextInt(0)); + position.set(Position.KEY_RPM, parser.nextInt()); + position.set(Position.KEY_FUEL_LEVEL, parser.nextInt()); decodeDeviceTime(position, parser); diff --git a/src/org/traccar/protocol/TytanProtocolDecoder.java b/src/org/traccar/protocol/TytanProtocolDecoder.java index e358e60b1..030fbce78 100644 --- a/src/org/traccar/protocol/TytanProtocolDecoder.java +++ b/src/org/traccar/protocol/TytanProtocolDecoder.java @@ -100,11 +100,11 @@ public class TytanProtocolDecoder extends BaseProtocolDecoder { int fuel = buf.readUnsignedShort(); int fuelFormat = fuel >> 14; if (fuelFormat == 1) { - position.set(Position.KEY_FUEL_LEVEL, (fuel & 0x3fff) * 0.4 + "%"); + position.set("fuelValue", (fuel & 0x3fff) * 0.4 + "%"); } else if (fuelFormat == 2) { - position.set(Position.KEY_FUEL_LEVEL, (fuel & 0x3fff) * 0.5 + " l"); + position.set("fuelValue", (fuel & 0x3fff) * 0.5 + " l"); } else if (fuelFormat == 3) { - position.set(Position.KEY_FUEL_LEVEL, (fuel & 0x3fff) * -0.5 + " l"); + position.set("fuelValue", (fuel & 0x3fff) * -0.5 + " l"); } break; case 108: diff --git a/src/org/traccar/protocol/WialonProtocolDecoder.java b/src/org/traccar/protocol/WialonProtocolDecoder.java index c1a125601..a07dfc7c9 100644 --- a/src/org/traccar/protocol/WialonProtocolDecoder.java +++ b/src/org/traccar/protocol/WialonProtocolDecoder.java @@ -116,7 +116,11 @@ public class WialonProtocolDecoder extends BaseProtocolDecoder { for (String param : values) { Matcher paramParser = Pattern.compile("(.*):[1-3]:(.*)").matcher(param); if (paramParser.matches()) { - position.set(paramParser.group(1).toLowerCase(), paramParser.group(2)); + try { + position.set(paramParser.group(1).toLowerCase(), Double.parseDouble(paramParser.group(2))); + } catch (NumberFormatException e) { + position.set(paramParser.group(1).toLowerCase(), paramParser.group(2)); + } } } } diff --git a/test/org/traccar/ProtocolTest.java b/test/org/traccar/ProtocolTest.java index 59cb96f22..465a3496d 100644 --- a/test/org/traccar/ProtocolTest.java +++ b/test/org/traccar/ProtocolTest.java @@ -188,6 +188,10 @@ public class ProtocolTest extends BaseTest { Assert.assertTrue(attributes.get(Position.KEY_RPM) instanceof Number); } + if (attributes.containsKey(Position.KEY_FUEL_LEVEL)) { + Assert.assertTrue(attributes.get(Position.KEY_FUEL_LEVEL) instanceof Number); + } + if (position.getNetwork() != null && position.getNetwork().getCellTowers() != null) { for (CellTower cellTower : position.getNetwork().getCellTowers()) { checkInteger(cellTower.getMobileCountryCode(), 0, 999); -- cgit v1.2.3