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/ObdDecoder.java37
-rw-r--r--src/org/traccar/helper/PatternUtil.java26
2 files changed, 31 insertions, 32 deletions
diff --git a/src/org/traccar/helper/ObdDecoder.java b/src/org/traccar/helper/ObdDecoder.java
index 4686aa682..3196c25e4 100644
--- a/src/org/traccar/helper/ObdDecoder.java
+++ b/src/org/traccar/helper/ObdDecoder.java
@@ -25,9 +25,9 @@ public final class ObdDecoder {
private ObdDecoder() {
}
- public static final int MODE_CURRENT = 0x01;
- public static final int MODE_FREEZE_FRAME = 0x02;
- public static final int MODE_CODES = 0x03;
+ private static final int MODE_CURRENT = 0x01;
+ private static final int MODE_FREEZE_FRAME = 0x02;
+ private static final int MODE_CODES = 0x03;
private static final int PID_ENGINE_LOAD = 0x04;
private static final int PID_COOLANT_TEMPERATURE = 0x05;
@@ -42,7 +42,9 @@ public final class ObdDecoder {
switch (mode) {
case MODE_CURRENT:
case MODE_FREEZE_FRAME:
- return decodeData(Integer.parseInt(value.substring(0, 2), 16), value.substring(2));
+ return decodeData(
+ Integer.parseInt(value.substring(0, 2), 16),
+ Integer.parseInt(value.substring(2), 16), true);
case MODE_CODES:
return decodeCodes(value);
default:
@@ -54,7 +56,7 @@ public final class ObdDecoder {
return new AbstractMap.SimpleEntry<>(key, value);
}
- private static Map.Entry<String, Object> decodeCodes(String value) {
+ public static Map.Entry<String, Object> decodeCodes(String value) {
StringBuilder codes = new StringBuilder();
for (int i = 0; i < value.length() / 4; i++) {
int numValue = Integer.parseInt(value.substring(i * 4, (i + 1) * 4), 16);
@@ -75,28 +77,31 @@ public final class ObdDecoder {
}
codes.append(String.format("%04X", numValue & 0x3FFF));
}
- return createEntry("dtcs", codes.toString().replaceFirst(",", ""));
+ if (codes.length() > 0) {
+ return createEntry("dtcs", codes.toString().replaceFirst(",", ""));
+ } else {
+ return null;
+ }
}
- private static Map.Entry<String, Object> decodeData(int pid, String value) {
- int intValue = Integer.parseInt(value, 16);
+ public static Map.Entry<String, Object> decodeData(int pid, int value, boolean convert) {
switch (pid) {
case PID_ENGINE_LOAD:
- return createEntry("engineLoad", intValue * 100 / 255);
+ return createEntry("engineLoad", convert ? value * 100 / 255 : value);
case PID_COOLANT_TEMPERATURE:
- return createEntry("coolantTemperature", intValue - 40);
+ return createEntry("coolantTemperature", convert ? value - 40 : value);
case PID_ENGINE_RPM:
- return createEntry(Position.KEY_RPM, intValue / 4);
+ return createEntry(Position.KEY_RPM, convert ? value / 4 : value);
case PID_VEHICLE_SPEED:
- return createEntry(Position.KEY_OBD_SPEED, intValue);
+ return createEntry(Position.KEY_OBD_SPEED, value);
case PID_THROTTLE_POSITION:
- return createEntry("throttle", intValue * 100 / 255);
+ return createEntry("throttle", convert ? value * 100 / 255 : value);
case PID_MIL_DISTANCE:
- return createEntry("milDistance", intValue);
+ return createEntry("milDistance", value);
case PID_FUEL_LEVEL:
- return createEntry(Position.KEY_FUEL, intValue * 100 / 255);
+ return createEntry(Position.KEY_FUEL, convert ? value * 100 / 255 : value);
case PID_DISTANCE_CLEARED:
- return createEntry("clearedDistance", intValue);
+ return createEntry("clearedDistance", value);
default:
return null;
}
diff --git a/src/org/traccar/helper/PatternUtil.java b/src/org/traccar/helper/PatternUtil.java
index 88c3f053b..f665eb30d 100644
--- a/src/org/traccar/helper/PatternUtil.java
+++ b/src/org/traccar/helper/PatternUtil.java
@@ -25,20 +25,13 @@ public final class PatternUtil {
}
public static class MatchResult {
- private String pattern;
- private String matched;
- private String remaining;
+ private String patternMatch;
+ private String patternTail;
+ private String stringMatch;
+ private String stringTail;
- public String getPattern() {
- return this.pattern;
- }
-
- public String getMatched() {
- return this.matched;
- }
-
- public String getRemaining() {
- return this.remaining;
+ public String getPatternMatch() {
+ return patternMatch;
}
}
@@ -50,9 +43,10 @@ public final class PatternUtil {
try {
Matcher matcher = Pattern.compile("(" + pattern.substring(0, i) + ").*").matcher(input);
if (matcher.matches()) {
- result.pattern = pattern.substring(0, i);
- result.matched = matcher.group(1);
- result.remaining = input.substring(matcher.group(1).length());
+ result.patternMatch = pattern.substring(0, i);
+ result.patternTail = pattern.substring(i);
+ result.stringMatch = matcher.group(1);
+ result.stringTail = input.substring(matcher.group(1).length());
}
} catch (PatternSyntaxException error) {
Log.warning(error);