diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2018-08-02 15:55:39 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2018-08-02 15:55:39 +1200 |
commit | e8357f9fbde73e5d10f512ded4a5ded935a6efc0 (patch) | |
tree | 425be2c7ed5a46ca3eb273b111fd537272da4de6 /src/org/traccar/protocol | |
parent | 2183e5f08d18879ea76ed0fad92877de69bfd496 (diff) | |
download | trackermap-server-e8357f9fbde73e5d10f512ded4a5ded935a6efc0.tar.gz trackermap-server-e8357f9fbde73e5d10f512ded4a5ded935a6efc0.tar.bz2 trackermap-server-e8357f9fbde73e5d10f512ded4a5ded935a6efc0.zip |
Support optional Pretrace data
Diffstat (limited to 'src/org/traccar/protocol')
-rw-r--r-- | src/org/traccar/protocol/PretraceProtocolDecoder.java | 40 |
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; } |