From 5e8dbc78110ab5e28d1d57277a38dd1991dba0e6 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Wed, 24 Aug 2016 09:54:21 +0500 Subject: - Fixed optional odometer for wondex protocol - Do not use zero odometer values to calculateDistance --- src/org/traccar/protocol/WondexProtocolDecoder.java | 4 +++- src/org/traccar/reports/ReportUtils.java | 14 ++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/org/traccar/protocol/WondexProtocolDecoder.java b/src/org/traccar/protocol/WondexProtocolDecoder.java index 97426d78c..0fcb99578 100644 --- a/src/org/traccar/protocol/WondexProtocolDecoder.java +++ b/src/org/traccar/protocol/WondexProtocolDecoder.java @@ -115,7 +115,9 @@ public class WondexProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_EVENT, parser.next()); position.set(Position.KEY_BATTERY, parser.next()); - position.set(Position.KEY_ODOMETER, parser.nextDouble() * 1000); + if (parser.hasNext()) { + position.set(Position.KEY_ODOMETER, parser.nextDouble() * 1000); + } position.set(Position.KEY_INPUT, parser.next()); position.set(Position.PREFIX_ADC + 1, parser.next()); position.set(Position.PREFIX_ADC + 2, parser.next()); diff --git a/src/org/traccar/reports/ReportUtils.java b/src/org/traccar/reports/ReportUtils.java index 67d577904..924dff4c1 100644 --- a/src/org/traccar/reports/ReportUtils.java +++ b/src/org/traccar/reports/ReportUtils.java @@ -45,10 +45,16 @@ public final class ReportUtils { public static double calculateDistance(Position firstPosition, Position lastPosition, boolean useOdometer) { double distance = 0.0; - if (useOdometer && firstPosition.getAttributes().containsKey(Position.KEY_ODOMETER) - && lastPosition.getAttributes().containsKey(Position.KEY_ODOMETER)) { - distance = (((Number) lastPosition.getAttributes().get(Position.KEY_ODOMETER)).doubleValue() - - ((Number) firstPosition.getAttributes().get(Position.KEY_ODOMETER)).doubleValue()); + double firstOdometer = 0.0; + double lastOdometer = 0.0; + if (firstPosition.getAttributes().containsKey(Position.KEY_ODOMETER)) { + firstOdometer = ((Number) firstPosition.getAttributes().get(Position.KEY_ODOMETER)).doubleValue(); + } + if (lastPosition.getAttributes().containsKey(Position.KEY_ODOMETER)) { + lastOdometer = ((Number) lastPosition.getAttributes().get(Position.KEY_ODOMETER)).doubleValue(); + } + if (useOdometer && (firstOdometer != 0.0 || lastOdometer != 0.0)) { + distance = lastOdometer - firstOdometer; } else if (firstPosition.getAttributes().containsKey(Position.KEY_TOTAL_DISTANCE) && lastPosition.getAttributes().containsKey(Position.KEY_TOTAL_DISTANCE)) { distance = ((Number) lastPosition.getAttributes().get(Position.KEY_TOTAL_DISTANCE)).doubleValue() -- cgit v1.2.3