aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAbyss777 <abyss@fox5.ru>2018-05-29 17:03:15 +0500
committerAbyss777 <abyss@fox5.ru>2018-05-29 17:03:15 +0500
commitc71701136245a63ea82a8a595dd51cc011ab2c35 (patch)
tree50f7daaa7addb539121f0309f779a14299b03438 /src
parentb41af1b39cdaa511dbf53769342ebca5b0348931 (diff)
downloadtraccar-server-c71701136245a63ea82a8a595dd51cc011ab2c35.tar.gz
traccar-server-c71701136245a63ea82a8a595dd51cc011ab2c35.tar.bz2
traccar-server-c71701136245a63ea82a8a595dd51cc011ab2c35.zip
Add units converter helper
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/helper/UnitsConverter.java9
-rw-r--r--src/org/traccar/protocol/AplicomProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/AstraProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/ContinentalProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/Gl200TextProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/Gps103ProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/Mta6ProtocolDecoder.java4
-rw-r--r--src/org/traccar/protocol/VtfmsProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/XirgoProtocolDecoder.java2
9 files changed, 21 insertions, 8 deletions
diff --git a/src/org/traccar/helper/UnitsConverter.java b/src/org/traccar/helper/UnitsConverter.java
index 56d15e4e7..7519879c0 100644
--- a/src/org/traccar/helper/UnitsConverter.java
+++ b/src/org/traccar/helper/UnitsConverter.java
@@ -23,6 +23,7 @@ public final class UnitsConverter {
private static final double KNOTS_TO_CPS_RATIO = 0.0194384449;
private static final double METERS_TO_FEET_RATIO = 0.3048;
private static final double METERS_TO_MILE_RATIO = 1609.34;
+ private static final long MILLISECONDS_TO_HOURS_RATIO = 3600000;
private UnitsConverter() {
}
@@ -71,4 +72,12 @@ public final class UnitsConverter {
return value * METERS_TO_MILE_RATIO;
}
+ public static long millisecondsFromHours(int value) {
+ return value * MILLISECONDS_TO_HOURS_RATIO;
+ }
+
+ public static long millisecondsFromHours(double value) {
+ return (long) (value * MILLISECONDS_TO_HOURS_RATIO);
+ }
+
}
diff --git a/src/org/traccar/protocol/AplicomProtocolDecoder.java b/src/org/traccar/protocol/AplicomProtocolDecoder.java
index c713399ea..adfa88f71 100644
--- a/src/org/traccar/protocol/AplicomProtocolDecoder.java
+++ b/src/org/traccar/protocol/AplicomProtocolDecoder.java
@@ -549,7 +549,7 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder {
}
if ((selector & 0x0020) != 0) {
- position.set(Position.KEY_HOURS, buf.readUnsignedInt() * 3600000);
+ position.set(Position.KEY_HOURS, UnitsConverter.millisecondsFromHours(buf.readUnsignedInt()));
position.set("serviceDistance", buf.readInt());
position.set("driverActivity", buf.readUnsignedByte());
position.set(Position.KEY_THROTTLE, buf.readUnsignedByte());
diff --git a/src/org/traccar/protocol/AstraProtocolDecoder.java b/src/org/traccar/protocol/AstraProtocolDecoder.java
index e45c51246..44547e3cd 100644
--- a/src/org/traccar/protocol/AstraProtocolDecoder.java
+++ b/src/org/traccar/protocol/AstraProtocolDecoder.java
@@ -106,7 +106,7 @@ public class AstraProtocolDecoder extends BaseProtocolDecoder {
if (BitUtil.check(status, 8)) {
position.set(Position.KEY_DRIVER_UNIQUE_ID, buf.readBytes(7).toString(StandardCharsets.US_ASCII));
position.set(Position.KEY_ODOMETER, buf.readUnsignedMedium() * 1000);
- position.set(Position.KEY_HOURS, buf.readUnsignedShort() * 3600000);
+ position.set(Position.KEY_HOURS, UnitsConverter.millisecondsFromHours(buf.readUnsignedShort()));
}
if (BitUtil.check(status, 6)) {
diff --git a/src/org/traccar/protocol/ContinentalProtocolDecoder.java b/src/org/traccar/protocol/ContinentalProtocolDecoder.java
index 780a23b72..186b2235e 100644
--- a/src/org/traccar/protocol/ContinentalProtocolDecoder.java
+++ b/src/org/traccar/protocol/ContinentalProtocolDecoder.java
@@ -94,7 +94,7 @@ public class ContinentalProtocolDecoder extends BaseProtocolDecoder {
}
if (buf.readableBytes() > 4) {
- position.set(Position.KEY_HOURS, buf.readUnsignedInt() * 3600000);
+ position.set(Position.KEY_HOURS, UnitsConverter.millisecondsFromHours(buf.readUnsignedInt()));
}
return position;
diff --git a/src/org/traccar/protocol/Gl200TextProtocolDecoder.java b/src/org/traccar/protocol/Gl200TextProtocolDecoder.java
index abced9ac3..7342b1263 100644
--- a/src/org/traccar/protocol/Gl200TextProtocolDecoder.java
+++ b/src/org/traccar/protocol/Gl200TextProtocolDecoder.java
@@ -609,7 +609,8 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.KEY_THROTTLE, Integer.parseInt(values[index - 1]));
}
if (BitUtil.check(reportMask, 11)) {
- position.set(Position.KEY_HOURS, (long) Double.parseDouble(values[index++]) * 3600000);
+ position.set(
+ Position.KEY_HOURS, UnitsConverter.millisecondsFromHours(Double.parseDouble(values[index++])));
}
if (BitUtil.check(reportMask, 12)) {
position.set("drivingHours", Double.parseDouble(values[index++]));
diff --git a/src/org/traccar/protocol/Gps103ProtocolDecoder.java b/src/org/traccar/protocol/Gps103ProtocolDecoder.java
index f7baddfbd..3575d423e 100644
--- a/src/org/traccar/protocol/Gps103ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Gps103ProtocolDecoder.java
@@ -21,6 +21,7 @@ import org.traccar.DeviceSession;
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;
@@ -255,7 +256,7 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.KEY_FUEL_CONSUMPTION, parser.nextDouble(0));
Integer hours = parser.nextInt();
if (hours != null) {
- position.set(Position.KEY_HOURS, hours * 3600000);
+ position.set(Position.KEY_HOURS, UnitsConverter.millisecondsFromHours(hours));
}
position.set(Position.KEY_OBD_SPEED, parser.nextInt(0));
position.set(Position.KEY_ENGINE_LOAD, parser.next());
diff --git a/src/org/traccar/protocol/Mta6ProtocolDecoder.java b/src/org/traccar/protocol/Mta6ProtocolDecoder.java
index 8cbe9eee8..6ec5faea8 100644
--- a/src/org/traccar/protocol/Mta6ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Mta6ProtocolDecoder.java
@@ -29,6 +29,7 @@ import org.traccar.Protocol;
import org.traccar.helper.BitUtil;
import org.traccar.helper.DateBuilder;
import org.traccar.helper.Log;
+import org.traccar.helper.UnitsConverter;
import org.traccar.model.Position;
import java.net.SocketAddress;
@@ -231,7 +232,8 @@ public class Mta6ProtocolDecoder extends BaseProtocolDecoder {
if (BitUtil.check(flags, 1)) {
position.set(Position.KEY_FUEL_CONSUMPTION, new FloatReader().readFloat(buf));
- position.set(Position.KEY_HOURS, (long) (new FloatReader().readFloat(buf) * 3600000));
+ position.set(
+ Position.KEY_HOURS, UnitsConverter.millisecondsFromHours(new FloatReader().readFloat(buf)));
position.set("tank", buf.readUnsignedByte() * 0.4);
}
diff --git a/src/org/traccar/protocol/VtfmsProtocolDecoder.java b/src/org/traccar/protocol/VtfmsProtocolDecoder.java
index dc2171022..76fcf69fa 100644
--- a/src/org/traccar/protocol/VtfmsProtocolDecoder.java
+++ b/src/org/traccar/protocol/VtfmsProtocolDecoder.java
@@ -133,7 +133,7 @@ public class VtfmsProtocolDecoder extends BaseProtocolDecoder {
position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0)));
- position.set(Position.KEY_HOURS, parser.nextInt());
+ position.set(Position.KEY_HOURS, UnitsConverter.millisecondsFromHours(parser.nextInt()));
position.set("idleHours", parser.nextInt());
position.set(Position.KEY_ODOMETER, parser.nextInt() * 100);
position.set(Position.KEY_CHARGE, parser.next().equals("1"));
diff --git a/src/org/traccar/protocol/XirgoProtocolDecoder.java b/src/org/traccar/protocol/XirgoProtocolDecoder.java
index 8a5e9ee12..828893d62 100644
--- a/src/org/traccar/protocol/XirgoProtocolDecoder.java
+++ b/src/org/traccar/protocol/XirgoProtocolDecoder.java
@@ -232,7 +232,7 @@ public class XirgoProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.PREFIX_OUT + 1, parser.nextInt());
position.set(Position.PREFIX_ADC + 1, parser.nextDouble());
position.set(Position.KEY_FUEL_LEVEL, parser.nextDouble());
- position.set(Position.KEY_HOURS, parser.nextInt() * 3600000);
+ position.set(Position.KEY_HOURS, UnitsConverter.millisecondsFromHours(parser.nextInt()));
position.set("oilPressure", parser.nextInt());
position.set("oilLevel", parser.nextInt());
position.set("oilTemp", parser.nextInt());