From e8357f9fbde73e5d10f512ded4a5ded935a6efc0 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Thu, 2 Aug 2018 15:55:39 +1200 Subject: Support optional Pretrace data --- .../traccar/protocol/PretraceProtocolDecoder.java | 40 ++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) (limited to 'src/org/traccar/protocol') 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; } -- cgit v1.2.3