Skip to content

Commit

Permalink
Support optional Pretrace data
Browse files Browse the repository at this point in the history
  • Loading branch information
tananaev committed Aug 2, 2018
1 parent 2183e5f commit e8357f9
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
40 changes: 38 additions & 2 deletions src/org/traccar/protocol/PretraceProtocolDecoder.java
Expand Up @@ -51,8 +51,8 @@ public PretraceProtocolDecoder(PretraceProtocol protocol) {
.number("(x)") // satellites
.number("(dd)") // hdop
.number("(dd)") // gsm
.expression("(.{8})") // state
.any()
.expression("(.{8}),&") // state
.expression("(.+)?") // optional data
.text("^")
.number("xx") // checksum
.compile();
Expand Down Expand Up @@ -89,6 +89,42 @@ protected Object decode(
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;
}

Expand Down
3 changes: 3 additions & 0 deletions test/org/traccar/protocol/PretraceProtocolDecoderTest.java
Expand Up @@ -13,6 +13,9 @@ public void testDecode() throws Exception {
verifyPosition(decoder, text(
"(867967021915915U1110A1701201500102238.1700N11401.9324E000264000000000009001790000000,&P11A4,F1050^47"));

verifyPosition(decoder, text(
"(864244029498838U1110A1509250653072238.1641N11401.9213E000196000000000406002990000000,&P195%,T1050,F14A5,R104C51E47B^30"));

}

}

0 comments on commit e8357f9

Please sign in to comment.