aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2017-08-30 00:08:52 +1200
committerGitHub <noreply@github.com>2017-08-30 00:08:52 +1200
commite3dfcf55262b60142a10458641f720aff3a0f6ad (patch)
tree22550a31fad86f044633af278c731173d63398eb /src/org/traccar
parent561915e44fdf630ac10fdc8e4a207e384ea59d9a (diff)
parent72d35d6c63ff80353eae1559d5c5d71c94d137bb (diff)
downloadtraccar-server-e3dfcf55262b60142a10458641f720aff3a0f6ad.tar.gz
traccar-server-e3dfcf55262b60142a10458641f720aff3a0f6ad.tar.bz2
traccar-server-e3dfcf55262b60142a10458641f720aff3a0f6ad.zip
Merge pull request #3491 from Abyss777/osmand_speedunits
Make OsmAnd speed units configurable
Diffstat (limited to 'src/org/traccar')
-rw-r--r--src/org/traccar/BaseProtocolDecoder.java15
-rw-r--r--src/org/traccar/protocol/OsmAndProtocolDecoder.java4
-rw-r--r--src/org/traccar/protocol/Tk103ProtocolDecoder.java13
-rw-r--r--src/org/traccar/protocol/XexunProtocolDecoder.java11
4 files changed, 19 insertions, 24 deletions
diff --git a/src/org/traccar/BaseProtocolDecoder.java b/src/org/traccar/BaseProtocolDecoder.java
index cc16000f4..2d6286bf8 100644
--- a/src/org/traccar/BaseProtocolDecoder.java
+++ b/src/org/traccar/BaseProtocolDecoder.java
@@ -19,6 +19,7 @@ import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.socket.DatagramChannel;
import org.jboss.netty.handler.codec.http.HttpRequestDecoder;
import org.traccar.helper.Log;
+import org.traccar.helper.UnitsConverter;
import org.traccar.model.Device;
import org.traccar.model.Position;
@@ -66,6 +67,20 @@ public abstract class BaseProtocolDecoder extends ExtendedObjectDecoder {
return protocol.getName();
}
+ protected double convertSpeed(double value, String defaultUnits) {
+ switch (Context.getConfig().getString(getProtocolName() + ".speed", defaultUnits)) {
+ case "kmh":
+ return UnitsConverter.knotsFromKph(value);
+ case "mps":
+ return UnitsConverter.knotsFromMps(value);
+ case "mph":
+ return UnitsConverter.knotsFromMph(value);
+ case "kn":
+ default:
+ return value;
+ }
+ }
+
private DeviceSession channelDeviceSession; // connection-based protocols
private Map<SocketAddress, DeviceSession> addressDeviceSessions = new HashMap<>(); // connectionless protocols
diff --git a/src/org/traccar/protocol/OsmAndProtocolDecoder.java b/src/org/traccar/protocol/OsmAndProtocolDecoder.java
index 6f8513c41..c06582a15 100644
--- a/src/org/traccar/protocol/OsmAndProtocolDecoder.java
+++ b/src/org/traccar/protocol/OsmAndProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 - 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2013 - 2017 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -110,7 +110,7 @@ public class OsmAndProtocolDecoder extends BaseProtocolDecoder {
position.setLongitude(Double.parseDouble(location[1]));
break;
case "speed":
- position.setSpeed(Double.parseDouble(value));
+ position.setSpeed(convertSpeed(Double.parseDouble(value), "kn"));
break;
case "bearing":
case "heading":
diff --git a/src/org/traccar/protocol/Tk103ProtocolDecoder.java b/src/org/traccar/protocol/Tk103ProtocolDecoder.java
index aa75f5675..be3def453 100644
--- a/src/org/traccar/protocol/Tk103ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Tk103ProtocolDecoder.java
@@ -23,7 +23,6 @@ import org.traccar.helper.BitUtil;
import org.traccar.helper.DateBuilder;
import org.traccar.helper.Parser;
import org.traccar.helper.PatternBuilder;
-import org.traccar.helper.UnitsConverter;
import org.traccar.model.CellTower;
import org.traccar.model.Network;
import org.traccar.model.Position;
@@ -253,17 +252,7 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder {
position.setLatitude(parser.nextCoordinate());
position.setLongitude(parser.nextCoordinate());
- switch (Context.getConfig().getString(getProtocolName() + ".speed", "kmh")) {
- case "kn":
- position.setSpeed(parser.nextDouble(0));
- break;
- case "mph":
- position.setSpeed(UnitsConverter.knotsFromMph(parser.nextDouble(0)));
- break;
- default:
- position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0)));
- break;
- }
+ position.setSpeed(convertSpeed(parser.nextDouble(0), "kmh"));
dateBuilder.setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
position.setTime(dateBuilder.getDate());
diff --git a/src/org/traccar/protocol/XexunProtocolDecoder.java b/src/org/traccar/protocol/XexunProtocolDecoder.java
index 20804bbb4..a5a38c370 100644
--- a/src/org/traccar/protocol/XexunProtocolDecoder.java
+++ b/src/org/traccar/protocol/XexunProtocolDecoder.java
@@ -17,13 +17,11 @@ package org.traccar.protocol;
import org.jboss.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
-import org.traccar.Context;
import org.traccar.DeviceSession;
import org.traccar.helper.DateBuilder;
import org.traccar.helper.Parser;
import org.traccar.helper.PatternBuilder;
import org.traccar.model.Position;
-import org.traccar.helper.UnitsConverter;
import java.net.SocketAddress;
import java.util.regex.Pattern;
@@ -121,14 +119,7 @@ public class XexunProtocolDecoder extends BaseProtocolDecoder {
position.setLatitude(parser.nextCoordinate());
position.setLongitude(parser.nextCoordinate());
- switch (Context.getConfig().getString(getProtocolName() + ".speed", "kn")) {
- case "kmh":
- position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0)));
- break;
- default:
- position.setSpeed(parser.nextDouble(0));
- break;
- }
+ position.setSpeed(convertSpeed(parser.nextDouble(0), "kn"));
position.setCourse(parser.nextDouble(0));