aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/helper
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-11-06 11:56:19 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2015-11-06 11:56:19 +1300
commit23f83e9f1c6c0f183256a3952a8b3a819dc0ea1c (patch)
tree6bc1a27981a68e9ac8936f30f6f2a0cd77e09bed /src/org/traccar/helper
parent04a40e1cfb9484f3ab25a3390249355bc3e711ae (diff)
downloadtrackermap-server-23f83e9f1c6c0f183256a3952a8b3a819dc0ea1c.tar.gz
trackermap-server-23f83e9f1c6c0f183256a3952a8b3a819dc0ea1c.tar.bz2
trackermap-server-23f83e9f1c6c0f183256a3952a8b3a819dc0ea1c.zip
Finish OBD decoder implementation
Diffstat (limited to 'src/org/traccar/helper')
-rw-r--r--src/org/traccar/helper/ObdDecoder.java50
1 files changed, 49 insertions, 1 deletions
diff --git a/src/org/traccar/helper/ObdDecoder.java b/src/org/traccar/helper/ObdDecoder.java
index 63fd30b09..684702bba 100644
--- a/src/org/traccar/helper/ObdDecoder.java
+++ b/src/org/traccar/helper/ObdDecoder.java
@@ -15,13 +15,61 @@
*/
package org.traccar.helper;
+import org.traccar.model.Event;
+
+import java.util.AbstractMap;
+import java.util.Map;
+
public class ObdDecoder {
private static final int MODE_CURRENT = 0x01;
private static final int MODE_FREEZE_FRAME = 0x02;
- private static final int MODE_DTC = 0x03; // diagnostic trouble codes
+ 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;
+ }
+ }
}