aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/org/traccar/protocol/PretraceProtocolDecoder.java40
-rw-r--r--test/org/traccar/protocol/PretraceProtocolDecoderTest.java3
2 files changed, 41 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;
}
diff --git a/test/org/traccar/protocol/PretraceProtocolDecoderTest.java b/test/org/traccar/protocol/PretraceProtocolDecoderTest.java
index ae7e48f14..573b6b888 100644
--- a/test/org/traccar/protocol/PretraceProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/PretraceProtocolDecoderTest.java
@@ -13,6 +13,9 @@ public class PretraceProtocolDecoderTest extends ProtocolTest {
verifyPosition(decoder, text(
"(867967021915915U1110A1701201500102238.1700N11401.9324E000264000000000009001790000000,&P11A4,F1050^47"));
+ verifyPosition(decoder, text(
+ "(864244029498838U1110A1509250653072238.1641N11401.9213E000196000000000406002990000000,&P195%,T1050,F14A5,R104C51E47B^30"));
+
}
}