aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/helper
diff options
context:
space:
mode:
authorduke2906 <philipp.prangenberg@gmail.com>2016-09-26 15:09:20 +0200
committerGitHub <noreply@github.com>2016-09-26 15:09:20 +0200
commit960bf899414d89221e92138fdb98777c3f4f73ec (patch)
tree87f5fd96185aa5f2fff0f84e2e2fa8be379ee837 /src/org/traccar/helper
parent0d3c05a24992eeeba02032e474d3a9bbb3239f10 (diff)
parentaaec58aec04256845dc37afd713b488071b1406b (diff)
downloadtrackermap-server-960bf899414d89221e92138fdb98777c3f4f73ec.tar.gz
trackermap-server-960bf899414d89221e92138fdb98777c3f4f73ec.tar.bz2
trackermap-server-960bf899414d89221e92138fdb98777c3f4f73ec.zip
Merge pull request #1 from tananaev/master
Update Changes, including version 3.7
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);