aboutsummaryrefslogtreecommitdiff
path: root/src/org
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-05-13 16:21:04 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2015-05-13 16:21:04 +1200
commitf01ebc2af707bccfd29049afad7d081c58e7f771 (patch)
treef0ccb599554be8e29c141da64df19b65969d4abb /src/org
parent84d99d15e6048eb87ad4547273c5c9e6f69488b5 (diff)
downloadtraccar-server-f01ebc2af707bccfd29049afad7d081c58e7f771.tar.gz
traccar-server-f01ebc2af707bccfd29049afad7d081c58e7f771.tar.bz2
traccar-server-f01ebc2af707bccfd29049afad7d081c58e7f771.zip
Implement units conversion class
Diffstat (limited to 'src/org')
-rw-r--r--src/org/traccar/helper/UnitsConverter.java36
-rw-r--r--src/org/traccar/protocol/ApelProtocolDecoder.java5
-rw-r--r--src/org/traccar/protocol/AplicomProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/Ardi01ProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/AtrackProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/CalAmpProtocolDecoder.java5
-rw-r--r--src/org/traccar/protocol/CellocatorProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/EelinkProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/GatorProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/GlobalSatProtocolDecoder.java5
-rw-r--r--src/org/traccar/protocol/GotopProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/Gt06ProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/KhdProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/MeitrackProtocolDecoder.java5
-rw-r--r--src/org/traccar/protocol/NavigilProtocolDecoder.java9
-rw-r--r--src/org/traccar/protocol/RuptelaProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/SuntechProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/SyrusProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/TeltonikaProtocolDecoder.java5
-rw-r--r--src/org/traccar/protocol/Tk103ProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/Tr20ProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/TramigoProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/TytanProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/UlbotechProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/VisiontekProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/WialonProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/WondexProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/XirgoProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/Xt013ProtocolDecoder.java3
29 files changed, 100 insertions, 36 deletions
diff --git a/src/org/traccar/helper/UnitsConverter.java b/src/org/traccar/helper/UnitsConverter.java
new file mode 100644
index 000000000..e490f366c
--- /dev/null
+++ b/src/org/traccar/helper/UnitsConverter.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.traccar.helper;
+
+public class UnitsConverter {
+
+ public static double knotsFromKph(double value) { // km/h
+ return value * 0.539957;
+ }
+
+ public static double knotsFromMph(double value) {
+ return value * 0.868976;
+ }
+
+ public static double knotsFromMps(double value) { // m/s
+ return value * 1.94384;
+ }
+
+ public static double knotsFromCps(double value) { // cm/s
+ return value * 0.0194384449;
+ }
+
+}
diff --git a/src/org/traccar/protocol/ApelProtocolDecoder.java b/src/org/traccar/protocol/ApelProtocolDecoder.java
index 6b4e43dbd..5729231a5 100644
--- a/src/org/traccar/protocol/ApelProtocolDecoder.java
+++ b/src/org/traccar/protocol/ApelProtocolDecoder.java
@@ -30,6 +30,7 @@ import org.jboss.netty.channel.ChannelHandlerContext;
import org.traccar.BaseProtocolDecoder;
import org.traccar.helper.Crc;
import org.traccar.helper.Log;
+import org.traccar.helper.UnitsConverter;
import org.traccar.model.Event;
import org.traccar.model.Position;
@@ -193,12 +194,12 @@ public class ApelProtocolDecoder extends BaseProtocolDecoder {
if (subtype == MSG_TYPE_STATE_FULL_INFO_T104) {
int speed = buf.readUnsignedByte();
position.setValid(speed != 255);
- position.setSpeed(speed * 0.539957);
+ position.setSpeed(UnitsConverter.knotsFromKph(speed));
position.set(Event.KEY_HDOP, buf.readByte());
} else {
int speed = buf.readShort();
position.setValid(speed != -1);
- position.setSpeed(speed / 100.0 * 0.539957);
+ position.setSpeed(UnitsConverter.knotsFromKph(speed / 100.0));
}
// Course
diff --git a/src/org/traccar/protocol/AplicomProtocolDecoder.java b/src/org/traccar/protocol/AplicomProtocolDecoder.java
index 824c2af26..102c7e90d 100644
--- a/src/org/traccar/protocol/AplicomProtocolDecoder.java
+++ b/src/org/traccar/protocol/AplicomProtocolDecoder.java
@@ -26,6 +26,7 @@ import org.jboss.netty.channel.ChannelHandlerContext;
import org.traccar.BaseProtocolDecoder;
import org.traccar.Context;
import org.traccar.helper.ChannelBufferTools;
+import org.traccar.helper.UnitsConverter;
import org.traccar.model.Event;
import org.traccar.model.Position;
@@ -164,7 +165,7 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder {
// Speed and heading
if ((selector & 0x0010) != 0) {
- position.setSpeed(buf.readUnsignedByte() * 0.539957);
+ position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
buf.readUnsignedByte(); // maximum speed
position.setCourse(buf.readUnsignedByte() * 2.0);
}
diff --git a/src/org/traccar/protocol/Ardi01ProtocolDecoder.java b/src/org/traccar/protocol/Ardi01ProtocolDecoder.java
index fdd160bdd..3a254cf41 100644
--- a/src/org/traccar/protocol/Ardi01ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Ardi01ProtocolDecoder.java
@@ -18,6 +18,7 @@ package org.traccar.protocol;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.traccar.BaseProtocolDecoder;
+import org.traccar.helper.UnitsConverter;
import org.traccar.model.Event;
import org.traccar.model.Position;
@@ -84,7 +85,7 @@ public class Ardi01ProtocolDecoder extends BaseProtocolDecoder {
// Location data
position.setLongitude(Double.valueOf(parser.group(index++)));
position.setLatitude(Double.valueOf(parser.group(index++)));
- position.setSpeed(Double.valueOf(parser.group(index++)) * 0.539957);
+ position.setSpeed(UnitsConverter.knotsFromKph(Double.valueOf(parser.group(index++))));
position.setCourse(Double.valueOf(parser.group(index++)));
position.setAltitude(Double.valueOf(parser.group(index++)));
diff --git a/src/org/traccar/protocol/AtrackProtocolDecoder.java b/src/org/traccar/protocol/AtrackProtocolDecoder.java
index e922f0cb8..b0b7ef1fc 100644
--- a/src/org/traccar/protocol/AtrackProtocolDecoder.java
+++ b/src/org/traccar/protocol/AtrackProtocolDecoder.java
@@ -27,6 +27,7 @@ import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.traccar.BaseProtocolDecoder;
+import org.traccar.helper.UnitsConverter;
import org.traccar.model.Event;
import org.traccar.model.Position;
@@ -128,7 +129,7 @@ public class AtrackProtocolDecoder extends BaseProtocolDecoder {
position.set(Event.KEY_INPUT, buf.readUnsignedByte());
// Speed
- position.setSpeed(buf.readUnsignedShort() * 0.539957);
+ position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort()));
// Output
position.set(Event.KEY_OUTPUT, buf.readUnsignedByte());
diff --git a/src/org/traccar/protocol/CalAmpProtocolDecoder.java b/src/org/traccar/protocol/CalAmpProtocolDecoder.java
index f5362f705..f6b06ebe7 100644
--- a/src/org/traccar/protocol/CalAmpProtocolDecoder.java
+++ b/src/org/traccar/protocol/CalAmpProtocolDecoder.java
@@ -26,6 +26,7 @@ import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.Channels;
import org.jboss.netty.channel.MessageEvent;
import org.traccar.BaseProtocolDecoder;
+import org.traccar.helper.UnitsConverter;
import org.traccar.model.Event;
import org.traccar.model.Position;
@@ -170,11 +171,11 @@ public class CalAmpProtocolDecoder extends BaseProtocolDecoder {
position.setLongitude(buf.readInt() * 0.0000001);
if (type != MSG_MINI_EVENT_REPORT) {
position.setAltitude(buf.readInt() * 0.01);
- position.setSpeed(buf.readUnsignedInt() * 0.0194384449); // cm/s
+ position.setSpeed(UnitsConverter.knotsFromCps(buf.readUnsignedInt()));
}
position.setCourse(buf.readShort());
if (type == MSG_MINI_EVENT_REPORT) {
- position.setSpeed(buf.readUnsignedByte() * 0.539957); // km/h
+ position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
}
// Fix status
diff --git a/src/org/traccar/protocol/CellocatorProtocolDecoder.java b/src/org/traccar/protocol/CellocatorProtocolDecoder.java
index 70d5d7c62..adb01b234 100644
--- a/src/org/traccar/protocol/CellocatorProtocolDecoder.java
+++ b/src/org/traccar/protocol/CellocatorProtocolDecoder.java
@@ -25,6 +25,7 @@ import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.traccar.BaseProtocolDecoder;
+import org.traccar.helper.UnitsConverter;
import org.traccar.model.Event;
import org.traccar.model.Position;
@@ -145,7 +146,7 @@ public class CellocatorProtocolDecoder extends BaseProtocolDecoder {
position.setLongitude(buf.readInt() / Math.PI * 180 / 100000000);
position.setLatitude(buf.readInt() / Math.PI * 180 / 100000000.0);
position.setAltitude(buf.readInt() * 0.01);
- position.setSpeed(buf.readInt() * 0.01 * 1.943844);
+ position.setSpeed(UnitsConverter.knotsFromMps(buf.readInt() * 0.01));
position.setCourse(buf.readUnsignedShort() / Math.PI * 180.0 / 1000.0);
// Time
diff --git a/src/org/traccar/protocol/EelinkProtocolDecoder.java b/src/org/traccar/protocol/EelinkProtocolDecoder.java
index bbcce5cfc..6628b9c37 100644
--- a/src/org/traccar/protocol/EelinkProtocolDecoder.java
+++ b/src/org/traccar/protocol/EelinkProtocolDecoder.java
@@ -24,6 +24,7 @@ import org.jboss.netty.channel.ChannelHandlerContext;
import org.traccar.BaseProtocolDecoder;
import org.traccar.helper.ChannelBufferTools;
+import org.traccar.helper.UnitsConverter;
import org.traccar.model.Event;
import org.traccar.model.Position;
@@ -103,7 +104,7 @@ public class EelinkProtocolDecoder extends BaseProtocolDecoder {
position.setTime(new Date(buf.readUnsignedInt() * 1000));
position.setLatitude(buf.readInt() / 1800000.0);
position.setLongitude(buf.readInt() / 1800000.0);
- position.setSpeed(buf.readUnsignedByte() * 0.539957);
+ position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
position.setCourse(buf.readUnsignedShort());
// Cell
diff --git a/src/org/traccar/protocol/GatorProtocolDecoder.java b/src/org/traccar/protocol/GatorProtocolDecoder.java
index 4078fd64f..bebba144d 100644
--- a/src/org/traccar/protocol/GatorProtocolDecoder.java
+++ b/src/org/traccar/protocol/GatorProtocolDecoder.java
@@ -24,6 +24,7 @@ import org.jboss.netty.channel.ChannelHandlerContext;
import org.traccar.BaseProtocolDecoder;
import org.traccar.helper.ChannelBufferTools;
+import org.traccar.helper.UnitsConverter;
import org.traccar.model.Event;
import org.traccar.model.Position;
@@ -91,7 +92,7 @@ public class GatorProtocolDecoder extends BaseProtocolDecoder {
// Location
position.setLatitude(ChannelBufferTools.readCoordinate(buf));
position.setLongitude(ChannelBufferTools.readCoordinate(buf));
- position.setSpeed(ChannelBufferTools.readHexInteger(buf, 4) * 0.539957);
+ position.setSpeed(UnitsConverter.knotsFromKph(ChannelBufferTools.readHexInteger(buf, 4)));
position.setCourse(ChannelBufferTools.readHexInteger(buf, 4));
// Flags
diff --git a/src/org/traccar/protocol/GlobalSatProtocolDecoder.java b/src/org/traccar/protocol/GlobalSatProtocolDecoder.java
index 512ed9da8..17cfacbb5 100644
--- a/src/org/traccar/protocol/GlobalSatProtocolDecoder.java
+++ b/src/org/traccar/protocol/GlobalSatProtocolDecoder.java
@@ -26,6 +26,7 @@ import org.jboss.netty.channel.ChannelHandlerContext;
import org.traccar.BaseProtocolDecoder;
import org.traccar.Context;
+import org.traccar.helper.UnitsConverter;
import org.traccar.model.Event;
import org.traccar.model.Position;
@@ -159,10 +160,10 @@ public class GlobalSatProtocolDecoder extends BaseProtocolDecoder {
position.setSpeed(Double.valueOf(value));
break;
case 'I':
- position.setSpeed(Double.valueOf(value) * 0.539957);
+ position.setSpeed(UnitsConverter.knotsFromKph(Double.valueOf(value)));
break;
case 'J':
- position.setSpeed(Double.valueOf(value) * 0.868976);
+ position.setSpeed(UnitsConverter.knotsFromMph(Double.valueOf(value)));
break;
case 'K':
position.setCourse(Double.valueOf(value));
diff --git a/src/org/traccar/protocol/GotopProtocolDecoder.java b/src/org/traccar/protocol/GotopProtocolDecoder.java
index baa54b09e..eed0b4703 100644
--- a/src/org/traccar/protocol/GotopProtocolDecoder.java
+++ b/src/org/traccar/protocol/GotopProtocolDecoder.java
@@ -24,6 +24,7 @@ import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.traccar.BaseProtocolDecoder;
+import org.traccar.helper.UnitsConverter;
import org.traccar.model.Event;
import org.traccar.model.Position;
@@ -94,7 +95,7 @@ public class GotopProtocolDecoder extends BaseProtocolDecoder {
position.setLongitude(longitude);
// Speed
- position.setSpeed(Double.valueOf(parser.group(index++)) * 0.539957);
+ position.setSpeed(UnitsConverter.knotsFromKph(Double.valueOf(parser.group(index++))));
// Status
position.set(Event.KEY_STATUS, parser.group(index++));
diff --git a/src/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/org/traccar/protocol/Gt06ProtocolDecoder.java
index c4670cc2c..01ffe5490 100644
--- a/src/org/traccar/protocol/Gt06ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Gt06ProtocolDecoder.java
@@ -22,6 +22,7 @@ import org.jboss.netty.channel.ChannelHandlerContext;
import org.traccar.BaseProtocolDecoder;
import org.traccar.Context;
import org.traccar.helper.Crc;
+import org.traccar.helper.UnitsConverter;
import org.traccar.model.Event;
import org.traccar.model.Position;
@@ -168,7 +169,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder {
double longitude = buf.readUnsignedInt() / (60.0 * 30000.0);
// Speed
- position.setSpeed(buf.readUnsignedByte() * 0.539957);
+ position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
// Course and flags
int union = buf.readUnsignedShort();
diff --git a/src/org/traccar/protocol/KhdProtocolDecoder.java b/src/org/traccar/protocol/KhdProtocolDecoder.java
index bf1f5deea..e9d43798c 100644
--- a/src/org/traccar/protocol/KhdProtocolDecoder.java
+++ b/src/org/traccar/protocol/KhdProtocolDecoder.java
@@ -26,6 +26,7 @@ import org.jboss.netty.channel.ChannelHandlerContext;
import org.traccar.BaseProtocolDecoder;
import org.traccar.helper.ChannelBufferTools;
import org.traccar.helper.Crc;
+import org.traccar.helper.UnitsConverter;
import org.traccar.model.Event;
import org.traccar.model.Position;
@@ -95,7 +96,7 @@ public class KhdProtocolDecoder extends BaseProtocolDecoder {
// Location
position.setLatitude(ChannelBufferTools.readCoordinate(buf));
position.setLongitude(ChannelBufferTools.readCoordinate(buf));
- position.setSpeed(ChannelBufferTools.readHexInteger(buf, 4) * 0.539957);
+ position.setSpeed(UnitsConverter.knotsFromKph(ChannelBufferTools.readHexInteger(buf, 4)));
position.setCourse(ChannelBufferTools.readHexInteger(buf, 4));
// Flags
diff --git a/src/org/traccar/protocol/MeitrackProtocolDecoder.java b/src/org/traccar/protocol/MeitrackProtocolDecoder.java
index 8bfd21145..3d6eb2a78 100644
--- a/src/org/traccar/protocol/MeitrackProtocolDecoder.java
+++ b/src/org/traccar/protocol/MeitrackProtocolDecoder.java
@@ -30,6 +30,7 @@ import org.jboss.netty.channel.ChannelHandlerContext;
import org.traccar.BaseProtocolDecoder;
import org.traccar.helper.ChannelBufferTools;
+import org.traccar.helper.UnitsConverter;
import org.traccar.model.Event;
import org.traccar.model.Position;
@@ -122,7 +123,7 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
position.set(Event.KEY_GSM, parser.group(index++));
// Speed
- position.setSpeed(Double.valueOf(parser.group(index++)) * 0.539957);
+ position.setSpeed(UnitsConverter.knotsFromKph(Double.valueOf(parser.group(index++))));
// Course
position.setCourse(Double.valueOf(parser.group(index++)));
@@ -215,7 +216,7 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
position.set(Event.KEY_GSM, buf.readUnsignedByte());
// Speed
- position.setSpeed(buf.readUnsignedShort() * 0.539957);
+ position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort()));
// Course
position.setCourse(buf.readUnsignedShort());
diff --git a/src/org/traccar/protocol/NavigilProtocolDecoder.java b/src/org/traccar/protocol/NavigilProtocolDecoder.java
index a51acf3fe..0a2e8ce44 100644
--- a/src/org/traccar/protocol/NavigilProtocolDecoder.java
+++ b/src/org/traccar/protocol/NavigilProtocolDecoder.java
@@ -25,6 +25,7 @@ import org.jboss.netty.channel.ChannelHandlerContext;
import org.traccar.BaseProtocolDecoder;
import org.traccar.helper.Crc;
+import org.traccar.helper.UnitsConverter;
import org.traccar.model.Event;
import org.traccar.model.Position;
@@ -161,8 +162,8 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder {
position.setLatitude(buf.readMedium() * 0.00002);
position.setLongitude(buf.readMedium() * 0.00002);
- position.setSpeed(buf.readUnsignedByte() * 0.539957);
- position.setCourse(buf.readUnsignedByte() * 2.0);
+ position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
+ position.setCourse(buf.readUnsignedByte() * 2);
short flags = buf.readUnsignedByte();
position.setValid((flags & 0x80) == 0x80 && (flags & 0x40) == 0x40);
@@ -184,7 +185,7 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder {
buf.readUnsignedByte(); // report trigger
- position.setSpeed(buf.readUnsignedByte() * 0.539957);
+ position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
short flags = buf.readUnsignedByte();
position.setValid((flags & 0x80) == 0x80 && (flags & 0x40) == 0x40);
@@ -251,7 +252,7 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder {
position.setLatitude(buf.readInt() * 0.0000001);
position.setLongitude(buf.readInt() * 0.0000001);
- position.setSpeed(buf.readUnsignedByte() * 0.539957);
+ position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
position.setCourse(buf.readUnsignedByte() * 2.0);
buf.readUnsignedByte(); // satellites in fix
diff --git a/src/org/traccar/protocol/RuptelaProtocolDecoder.java b/src/org/traccar/protocol/RuptelaProtocolDecoder.java
index d14fc6d15..833285ca3 100644
--- a/src/org/traccar/protocol/RuptelaProtocolDecoder.java
+++ b/src/org/traccar/protocol/RuptelaProtocolDecoder.java
@@ -25,6 +25,7 @@ import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.traccar.BaseProtocolDecoder;
+import org.traccar.helper.UnitsConverter;
import org.traccar.model.Event;
import org.traccar.model.Position;
@@ -80,7 +81,7 @@ public class RuptelaProtocolDecoder extends BaseProtocolDecoder {
position.set(Event.KEY_SATELLITES, satellites);
position.setValid(satellites >= 3);
- position.setSpeed(buf.readUnsignedShort() * 0.539957);
+ position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort()));
position.set(Event.KEY_HDOP, buf.readUnsignedByte() / 10.0);
diff --git a/src/org/traccar/protocol/SuntechProtocolDecoder.java b/src/org/traccar/protocol/SuntechProtocolDecoder.java
index dc1f2f274..f21f6e0a0 100644
--- a/src/org/traccar/protocol/SuntechProtocolDecoder.java
+++ b/src/org/traccar/protocol/SuntechProtocolDecoder.java
@@ -24,6 +24,7 @@ import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.traccar.BaseProtocolDecoder;
+import org.traccar.helper.UnitsConverter;
import org.traccar.model.Event;
import org.traccar.model.Position;
@@ -95,7 +96,7 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder {
position.setValid(true); // wrong?
// Speed
- position.setSpeed(Double.valueOf(parser.group(index++)) * 0.539957);
+ position.setSpeed(UnitsConverter.knotsFromKph(Double.valueOf(parser.group(index++))));
// Course
position.setCourse(Double.valueOf(parser.group(index++)));
diff --git a/src/org/traccar/protocol/SyrusProtocolDecoder.java b/src/org/traccar/protocol/SyrusProtocolDecoder.java
index 8a12b5e26..5959715d9 100644
--- a/src/org/traccar/protocol/SyrusProtocolDecoder.java
+++ b/src/org/traccar/protocol/SyrusProtocolDecoder.java
@@ -25,6 +25,7 @@ import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.traccar.BaseProtocolDecoder;
+import org.traccar.helper.UnitsConverter;
import org.traccar.model.Event;
import org.traccar.model.Position;
@@ -154,7 +155,7 @@ public class SyrusProtocolDecoder extends BaseProtocolDecoder {
position.setLongitude(Double.valueOf(longitude));
// Speed and Course
- position.setSpeed(Double.valueOf(parser.group(index++)) * 0.868976);
+ position.setSpeed(UnitsConverter.knotsFromMph(Double.valueOf(parser.group(index++))));
position.setCourse(Double.valueOf(parser.group(index++)));
// Validity
diff --git a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java
index d2f77549c..d3e946f69 100644
--- a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java
+++ b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java
@@ -26,6 +26,7 @@ import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.traccar.BaseProtocolDecoder;
+import org.traccar.helper.UnitsConverter;
import org.traccar.model.Event;
import org.traccar.model.Position;
@@ -106,7 +107,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder {
}
if (checkBit(locationMask, 3)) {
- position.setSpeed(buf.readUnsignedByte() * 0.539957);
+ position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
}
if (checkBit(locationMask, 4)) {
@@ -144,7 +145,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder {
position.setValid(satellites != 0);
- position.setSpeed(buf.readUnsignedShort() * 0.539957);
+ position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort()));
position.set(Event.KEY_EVENT, buf.readUnsignedByte());
diff --git a/src/org/traccar/protocol/Tk103ProtocolDecoder.java b/src/org/traccar/protocol/Tk103ProtocolDecoder.java
index 81481ced8..e51f8dea5 100644
--- a/src/org/traccar/protocol/Tk103ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Tk103ProtocolDecoder.java
@@ -24,6 +24,7 @@ import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.traccar.BaseProtocolDecoder;
+import org.traccar.helper.UnitsConverter;
import org.traccar.model.Event;
import org.traccar.model.Position;
@@ -120,7 +121,7 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder {
position.setLongitude(longitude);
// Speed
- position.setSpeed(Double.valueOf(parser.group(index++)) * 0.539957);
+ position.setSpeed(UnitsConverter.knotsFromKph(Double.valueOf(parser.group(index++))));
// Time
time.set(Calendar.HOUR_OF_DAY, Integer.valueOf(parser.group(index++)));
diff --git a/src/org/traccar/protocol/Tr20ProtocolDecoder.java b/src/org/traccar/protocol/Tr20ProtocolDecoder.java
index cd0bde746..048f510b4 100644
--- a/src/org/traccar/protocol/Tr20ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Tr20ProtocolDecoder.java
@@ -24,6 +24,7 @@ import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.traccar.BaseProtocolDecoder;
+import org.traccar.helper.UnitsConverter;
import org.traccar.model.Event;
import org.traccar.model.Position;
@@ -116,7 +117,7 @@ public class Tr20ProtocolDecoder extends BaseProtocolDecoder {
position.setLongitude(longitude * hemisphere);
// Speed
- position.setSpeed(Double.valueOf(parser.group(index++)) * 0.539957);
+ position.setSpeed(UnitsConverter.knotsFromKph(Double.valueOf(parser.group(index++))));
// Course
position.setCourse(Double.valueOf(parser.group(index++)));
diff --git a/src/org/traccar/protocol/TramigoProtocolDecoder.java b/src/org/traccar/protocol/TramigoProtocolDecoder.java
index b578efb4a..38b343ad9 100644
--- a/src/org/traccar/protocol/TramigoProtocolDecoder.java
+++ b/src/org/traccar/protocol/TramigoProtocolDecoder.java
@@ -20,6 +20,7 @@ import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.traccar.BaseProtocolDecoder;
+import org.traccar.helper.UnitsConverter;
import org.traccar.model.Event;
import org.traccar.model.Position;
@@ -120,7 +121,7 @@ public class TramigoProtocolDecoder extends BaseProtocolDecoder {
pattern = Pattern.compile("([NSWE]{1,2}) with speed (\\d+) km/h");
matcher = pattern.matcher(sentence);
if (matcher.find()) {
- position.setSpeed(Double.valueOf(matcher.group(2)) * 0.539957);
+ position.setSpeed(UnitsConverter.knotsFromKph(Double.valueOf(matcher.group(2))));
position.setCourse(0); // matcher.group(1) for course
}
diff --git a/src/org/traccar/protocol/TytanProtocolDecoder.java b/src/org/traccar/protocol/TytanProtocolDecoder.java
index 5e48c2813..3ef0e11b7 100644
--- a/src/org/traccar/protocol/TytanProtocolDecoder.java
+++ b/src/org/traccar/protocol/TytanProtocolDecoder.java
@@ -25,6 +25,7 @@ import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.traccar.BaseProtocolDecoder;
import org.traccar.helper.ChannelBufferTools;
+import org.traccar.helper.UnitsConverter;
import org.traccar.model.Event;
import org.traccar.model.Position;
@@ -92,7 +93,7 @@ public class TytanProtocolDecoder extends BaseProtocolDecoder {
// Speed
int speed = buf.readUnsignedByte();
if (speed < 250) {
- position.setSpeed(speed * 0.539957);
+ position.setSpeed(UnitsConverter.knotsFromKph(speed));
}
while (buf.readerIndex() < end) {
diff --git a/src/org/traccar/protocol/UlbotechProtocolDecoder.java b/src/org/traccar/protocol/UlbotechProtocolDecoder.java
index af61b0b6e..3ec50b3fc 100644
--- a/src/org/traccar/protocol/UlbotechProtocolDecoder.java
+++ b/src/org/traccar/protocol/UlbotechProtocolDecoder.java
@@ -20,6 +20,7 @@ import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.traccar.BaseProtocolDecoder;
import org.traccar.helper.ChannelBufferTools;
+import org.traccar.helper.UnitsConverter;
import org.traccar.model.Event;
import org.traccar.model.Position;
@@ -84,7 +85,7 @@ public class UlbotechProtocolDecoder extends BaseProtocolDecoder {
position.setValid(true);
position.setLatitude(buf.readInt() / 1000000.0);
position.setLongitude(buf.readInt() / 1000000.0);
- position.setSpeed(buf.readUnsignedShort() * 0.539957);
+ position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort()));
position.setCourse(buf.readUnsignedShort());
position.set(Event.KEY_HDOP, buf.readUnsignedShort());
break;
diff --git a/src/org/traccar/protocol/VisiontekProtocolDecoder.java b/src/org/traccar/protocol/VisiontekProtocolDecoder.java
index aeabed039..2fe58e5be 100644
--- a/src/org/traccar/protocol/VisiontekProtocolDecoder.java
+++ b/src/org/traccar/protocol/VisiontekProtocolDecoder.java
@@ -24,6 +24,7 @@ import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.traccar.BaseProtocolDecoder;
+import org.traccar.helper.UnitsConverter;
import org.traccar.model.Event;
import org.traccar.model.Position;
@@ -107,7 +108,7 @@ public class VisiontekProtocolDecoder extends BaseProtocolDecoder {
position.setLongitude(longitude);
// Speed
- position.setSpeed(Double.valueOf(parser.group(index++)) * 0.539957);
+ position.setSpeed(UnitsConverter.knotsFromKph(Double.valueOf(parser.group(index++))));
// Course
position.setCourse(Double.valueOf(parser.group(index++)));
diff --git a/src/org/traccar/protocol/WialonProtocolDecoder.java b/src/org/traccar/protocol/WialonProtocolDecoder.java
index 5638c2dbe..423f614bc 100644
--- a/src/org/traccar/protocol/WialonProtocolDecoder.java
+++ b/src/org/traccar/protocol/WialonProtocolDecoder.java
@@ -26,6 +26,7 @@ import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.traccar.BaseProtocolDecoder;
+import org.traccar.helper.UnitsConverter;
import org.traccar.model.Event;
import org.traccar.model.Position;
@@ -107,7 +108,7 @@ public class WialonProtocolDecoder extends BaseProtocolDecoder {
// Speed
String speed = parser.group(index++);
if (speed != null) {
- position.setSpeed(Double.valueOf(speed) * 0.539957);
+ position.setSpeed(UnitsConverter.knotsFromKph(Double.valueOf(speed)));
}
// Course
diff --git a/src/org/traccar/protocol/WondexProtocolDecoder.java b/src/org/traccar/protocol/WondexProtocolDecoder.java
index 556e1b2ad..0c627b07c 100644
--- a/src/org/traccar/protocol/WondexProtocolDecoder.java
+++ b/src/org/traccar/protocol/WondexProtocolDecoder.java
@@ -24,6 +24,7 @@ import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.traccar.BaseProtocolDecoder;
+import org.traccar.helper.UnitsConverter;
import org.traccar.model.Event;
import org.traccar.model.Position;
@@ -88,7 +89,7 @@ public class WondexProtocolDecoder extends BaseProtocolDecoder {
// Position data
position.setLongitude(Double.valueOf(parser.group(index++)));
position.setLatitude(Double.valueOf(parser.group(index++)));
- position.setSpeed(Double.valueOf(parser.group(index++)) * 0.539957);
+ position.setSpeed(UnitsConverter.knotsFromKph(Double.valueOf(parser.group(index++))));
position.setCourse(Double.valueOf(parser.group(index++)));
position.setAltitude(Double.valueOf(parser.group(index++)));
diff --git a/src/org/traccar/protocol/XirgoProtocolDecoder.java b/src/org/traccar/protocol/XirgoProtocolDecoder.java
index 74b1bd077..7ff82a5aa 100644
--- a/src/org/traccar/protocol/XirgoProtocolDecoder.java
+++ b/src/org/traccar/protocol/XirgoProtocolDecoder.java
@@ -25,6 +25,7 @@ import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.traccar.BaseProtocolDecoder;
+import org.traccar.helper.UnitsConverter;
import org.traccar.model.Event;
import org.traccar.model.Position;
@@ -95,7 +96,7 @@ public class XirgoProtocolDecoder extends BaseProtocolDecoder {
position.setLatitude(Double.valueOf(parser.group(index++)));
position.setLongitude(Double.valueOf(parser.group(index++)));
position.setAltitude(Double.valueOf(parser.group(index++)));
- position.setSpeed(Double.valueOf(parser.group(index++)) * 0.868976);
+ position.setSpeed(UnitsConverter.knotsFromMph(Double.valueOf(parser.group(index++))));
position.setCourse(Double.valueOf(parser.group(index++)));
// Additional data
diff --git a/src/org/traccar/protocol/Xt013ProtocolDecoder.java b/src/org/traccar/protocol/Xt013ProtocolDecoder.java
index 62deed0ea..37f204bb3 100644
--- a/src/org/traccar/protocol/Xt013ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Xt013ProtocolDecoder.java
@@ -18,6 +18,7 @@ package org.traccar.protocol;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.traccar.BaseProtocolDecoder;
+import org.traccar.helper.UnitsConverter;
import org.traccar.model.Event;
import org.traccar.model.Position;
@@ -94,7 +95,7 @@ public class Xt013ProtocolDecoder extends BaseProtocolDecoder {
// Location
position.setLatitude(Double.valueOf(parser.group(index++)));
position.setLongitude(Double.valueOf(parser.group(index++)));
- position.setSpeed(Double.valueOf(parser.group(index++)) * 0.539957);
+ position.setSpeed(UnitsConverter.knotsFromKph(Double.valueOf(parser.group(index++))));
position.setCourse(Double.valueOf(parser.group(index++)));
position.setAltitude(Double.valueOf(parser.group(index++)));
position.setValid(parser.group(index++).equals("F"));