aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/helper
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar/helper')
-rw-r--r--src/org/traccar/helper/DateBuilder.java18
-rw-r--r--src/org/traccar/helper/Log.java4
-rw-r--r--src/org/traccar/helper/ObdDecoder.java78
-rw-r--r--src/org/traccar/helper/Parser.java13
-rw-r--r--src/org/traccar/helper/PatternBuilder.java2
5 files changed, 111 insertions, 4 deletions
diff --git a/src/org/traccar/helper/DateBuilder.java b/src/org/traccar/helper/DateBuilder.java
index 77c6821aa..c52210326 100644
--- a/src/org/traccar/helper/DateBuilder.java
+++ b/src/org/traccar/helper/DateBuilder.java
@@ -25,13 +25,20 @@ public class DateBuilder {
public DateBuilder() {
this(TimeZone.getTimeZone("UTC"));
+ }
+ public DateBuilder(Date time) {
+ this(time, TimeZone.getTimeZone("UTC"));
}
public DateBuilder(TimeZone timeZone) {
+ this(new Date(0), timeZone);
+ }
+
+ public DateBuilder(Date time, TimeZone timeZone) {
calendar = Calendar.getInstance(timeZone);
calendar.clear();
- calendar.setTimeInMillis(0);
+ calendar.setTimeInMillis(time.getTime());
}
public DateBuilder setYear(int year) {
@@ -90,10 +97,19 @@ public class DateBuilder {
return this;
}
+ public DateBuilder addMillis(long millis) {
+ calendar.setTimeInMillis(calendar.getTimeInMillis() + millis);
+ return this;
+ }
+
public DateBuilder setTime(int hour, int minute, int second) {
return setHour(hour).setMinute(minute).setSecond(second);
}
+ public DateBuilder setTimeReverse(int second, int minute, int hour) {
+ return setHour(hour).setMinute(minute).setSecond(second);
+ }
+
public DateBuilder setTime(int hour, int minute, int second, int millis) {
return setHour(hour).setMinute(minute).setSecond(second).setMillis(millis);
}
diff --git a/src/org/traccar/helper/Log.java b/src/org/traccar/helper/Log.java
index 0e55a5445..2b747734e 100644
--- a/src/org/traccar/helper/Log.java
+++ b/src/org/traccar/helper/Log.java
@@ -40,6 +40,8 @@ public final class Log {
private Log() {
}
+ public static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
+
private static final String LOGGER_NAME = "traccar";
private static final String STACK_PACKAGE = "org.traccar";
@@ -49,7 +51,7 @@ public final class Log {
public static void setupLogger(Config config) throws IOException {
- Layout layout = new PatternLayout("%d{yyyy-MM-dd HH:mm:ss} %5p: %m%n");
+ Layout layout = new PatternLayout("%d{" + DATE_FORMAT + "} %5p: %m%n");
Appender appender = new DailyRollingFileAppender(
layout, config.getString("logger.file"), "'.'yyyyMMdd");
diff --git a/src/org/traccar/helper/ObdDecoder.java b/src/org/traccar/helper/ObdDecoder.java
new file mode 100644
index 000000000..35fa4dc07
--- /dev/null
+++ b/src/org/traccar/helper/ObdDecoder.java
@@ -0,0 +1,78 @@
+/*
+ * 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;
+
+import org.traccar.model.Event;
+
+import java.util.AbstractMap;
+import java.util.Map;
+
+public final class ObdDecoder {
+
+ private ObdDecoder() {
+ }
+
+ private static final int MODE_CURRENT = 0x01;
+ private static final int MODE_FREEZE_FRAME = 0x02;
+
+ private static final int PID_ENGINE_LOAD = 0x04;
+ private static final int PID_COOLANT_TEMPERATURE = 0x05;
+ private static final int PID_ENGINE_RPM = 0x0C;
+ private static final int PID_VEHICLE_SPEED = 0x0D;
+ private static final int PID_THROTTLE_POSITION = 0x11;
+ private static final int PID_MIL_DISTANCE = 0x21;
+ private static final int PID_FUEL_LEVEL = 0x2F;
+ private static final int PID_DISTANCE_CLEARED = 0x31;
+
+ public static Map.Entry<String, Object> decode(int mode, int pid, String value) {
+ switch (mode) {
+ case MODE_CURRENT:
+ case MODE_FREEZE_FRAME:
+ return decodeData(pid, value);
+ default:
+ return null;
+ }
+ }
+
+ private static Map.Entry<String, Object> createEntry(String key, Object value) {
+ return new AbstractMap.SimpleEntry<>(key, value);
+ }
+
+ private static Map.Entry<String, Object> decodeData(int pid, String value) {
+ int intValue = Integer.parseInt(value, 16);
+ switch (pid) {
+ case PID_ENGINE_LOAD:
+ return createEntry("engine-load", intValue * 100 / 255);
+ case PID_COOLANT_TEMPERATURE:
+ return createEntry("coolant-temperature", intValue - 40);
+ case PID_ENGINE_RPM:
+ return createEntry(Event.KEY_RPM, intValue / 4);
+ case PID_VEHICLE_SPEED:
+ return createEntry(Event.KEY_OBD_SPEED, intValue);
+ case PID_THROTTLE_POSITION:
+ return createEntry("throttle", intValue * 100 / 255);
+ case PID_MIL_DISTANCE:
+ return createEntry("mil-distance", intValue);
+ case PID_FUEL_LEVEL:
+ return createEntry(Event.KEY_FUEL, intValue * 100 / 255);
+ case PID_DISTANCE_CLEARED:
+ return createEntry(Event.KEY_FUEL, intValue);
+ default:
+ return null;
+ }
+ }
+
+}
diff --git a/src/org/traccar/helper/Parser.java b/src/org/traccar/helper/Parser.java
index bda7d6366..c5f5d2e37 100644
--- a/src/org/traccar/helper/Parser.java
+++ b/src/org/traccar/helper/Parser.java
@@ -87,9 +87,11 @@ public class Parser {
}
public enum CoordinateFormat {
+ DEG_DEG,
DEG_HEM,
DEG_MIN_HEM,
DEG_MIN_MIN_HEM,
+ HEM_DEG_MIN_MIN,
HEM_DEG,
HEM_DEG_MIN,
HEM_DEG_MIN_HEM
@@ -97,9 +99,12 @@ public class Parser {
public double nextCoordinate(CoordinateFormat format) {
double coordinate;
- String hemisphere;
+ String hemisphere = null;
switch (format) {
+ case DEG_DEG:
+ coordinate = Double.parseDouble(next() + '.' + next());
+ break;
case DEG_HEM:
coordinate = nextDouble();
hemisphere = next();
@@ -126,6 +131,12 @@ public class Parser {
hemisphere = next();
}
break;
+ case HEM_DEG_MIN_MIN:
+ hemisphere = next();
+ coordinate = nextInt();
+ coordinate += Double.parseDouble(next() + '.' + next()) / 60;
+ break;
+ case DEG_MIN_HEM:
default:
coordinate = nextInt();
coordinate += nextDouble() / 60;
diff --git a/src/org/traccar/helper/PatternBuilder.java b/src/org/traccar/helper/PatternBuilder.java
index 6742e7130..3a8bdd868 100644
--- a/src/org/traccar/helper/PatternBuilder.java
+++ b/src/org/traccar/helper/PatternBuilder.java
@@ -48,7 +48,7 @@ public class PatternBuilder {
s = s.replace("dddd", "d{4}").replace("ddd", "d{3}").replace("dd", "d{2}");
s = s.replace("xxxx", "x{4}").replace("xxx", "x{3}").replace("xx", "x{2}");
- s = s.replace("d", "\\d").replace("x", "\\p{XDigit}").replaceAll("([\\.])", "\\\\$1");
+ s = s.replace("d", "\\d").replace("x", "[0-9a-fA-F]").replaceAll("([\\.])", "\\\\$1");
s = s.replaceAll("\\|$", "\\\\|").replaceAll("^\\|", "\\\\|"); // special case for delimiter
fragments.add(s);