aboutsummaryrefslogtreecommitdiff
path: root/src/org
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2018-08-02 15:55:39 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2018-08-02 15:55:39 +1200
commite8357f9fbde73e5d10f512ded4a5ded935a6efc0 (patch)
tree425be2c7ed5a46ca3eb273b111fd537272da4de6 /src/org
parent2183e5f08d18879ea76ed0fad92877de69bfd496 (diff)
downloadtraccar-server-e8357f9fbde73e5d10f512ded4a5ded935a6efc0.tar.gz
traccar-server-e8357f9fbde73e5d10f512ded4a5ded935a6efc0.tar.bz2
traccar-server-e8357f9fbde73e5d10f512ded4a5ded935a6efc0.zip
Support optional Pretrace data
Diffstat (limited to 'src/org')
-rw-r--r--src/org/traccar/protocol/PretraceProtocolDecoder.java40
1 files changed, 38 insertions, 2 deletions
diff --git a/src/org/traccar/protocol/PretraceProtocolDecoder.java b/src/org/traccar/protocol/PretraceProtocolDecoder.java
index e4306a429..fc0245c0e 100644
--- a/src/org/traccar/protocol/PretraceProtocolDecoder.java
+++ b/src/org/traccar/protocol/PretraceProtocolDecoder.java
@@ -51,8 +51,8 @@ public class PretraceProtocolDecoder extends BaseProtocolDecoder {
.number("(x)") // satellites
.number("(dd)") // hdop
.number("(dd)") // gsm
- .expression("(.{8})") // state
- .any()
+ .expression("(.{8}),&") // state
+ .expression("(.+)?") // optional data
.text("^")
.number("xx") // checksum
.compile();
@@ -89,6 +89,42 @@ public class PretraceProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.KEY_HDOP, parser.nextInt(0));
position.set(Position.KEY_RSSI, parser.nextInt(0));
+ parser.next(); // state
+
+ if (parser.hasNext()) {
+ for (String value : parser.next().split(",")) {
+ switch (value.charAt(0)) {
+ case 'P':
+ if (value.charAt(1) == '1') {
+ if (value.charAt(4) == '%') {
+ position.set(Position.KEY_BATTERY_LEVEL, Integer.parseInt(value.substring(2, 4)));
+ } else {
+ position.set(Position.KEY_BATTERY, Integer.parseInt(value.substring(2), 16) * 0.01);
+ }
+ } else {
+ position.set(Position.KEY_POWER, Integer.parseInt(value.substring(2), 16) * 0.01);
+ }
+ break;
+ case 'T':
+ double temperature = Integer.parseInt(value.substring(2), 16) * 0.25;
+ if (value.charAt(1) == '1') {
+ position.set(Position.KEY_DEVICE_TEMP, temperature);
+ } else {
+ position.set(Position.PREFIX_TEMP + (value.charAt(1) - '0'), temperature);
+ }
+ break;
+ case 'F':
+ position.set("fuel" + (value.charAt(1) - '0'), Integer.parseInt(value.substring(2), 16) * 0.01);
+ break;
+ case 'R':
+ position.set(Position.KEY_DRIVER_UNIQUE_ID, value.substring(3));
+ break;
+ default:
+ break;
+ }
+ }
+ }
+
return position;
}