aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2019-06-29 21:29:48 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2019-06-29 21:29:48 -0700
commit0527e6817084a1c907ddb41ff9bb3c6e67a3dabd (patch)
tree8ef3ee4ca54f8199c3c07f537c261f376eb138c5
parent5b7722bd3fd6f7782eadd4b1afc518fdba28e8d3 (diff)
downloadtrackermap-server-0527e6817084a1c907ddb41ff9bb3c6e67a3dabd.tar.gz
trackermap-server-0527e6817084a1c907ddb41ff9bb3c6e67a3dabd.tar.bz2
trackermap-server-0527e6817084a1c907ddb41ff9bb3c6e67a3dabd.zip
Support fuel sensor data
-rw-r--r--src/main/java/org/traccar/protocol/SuntechProtocolDecoder.java46
-rw-r--r--src/test/java/org/traccar/protocol/SuntechProtocolDecoderTest.java4
2 files changed, 33 insertions, 17 deletions
diff --git a/src/main/java/org/traccar/protocol/SuntechProtocolDecoder.java b/src/main/java/org/traccar/protocol/SuntechProtocolDecoder.java
index 1ad984c60..903c37a8f 100644
--- a/src/main/java/org/traccar/protocol/SuntechProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/SuntechProtocolDecoder.java
@@ -327,24 +327,36 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder {
int remaining = Integer.parseInt(values[index++]);
while (remaining > 0) {
String attribute = values[index++];
- String[] pair = attribute.split("=");
- if (pair.length >= 2) {
- String value = pair[1].trim();
- if (value.contains(".")) {
- value = value.substring(0, value.indexOf('.'));
+ if (attribute.startsWith("CabAVL")) {
+ String[] data = attribute.split(",");
+ double fuel1 = Double.parseDouble(data[2]);
+ if (fuel1 > 0) {
+ position.set("fuel1", fuel1);
}
- switch (pair[0].charAt(0)) {
- case 't':
- position.set(Position.PREFIX_TEMP + pair[0].charAt(2), Integer.parseInt(value, 16));
- break;
- case 'N':
- position.set("fuel" + pair[0].charAt(2), Integer.parseInt(value, 16));
- break;
- case 'Q':
- position.set("drivingQuality", Integer.parseInt(value, 16));
- break;
- default:
- break;
+ double fuel2 = Double.parseDouble(data[3]);
+ if (fuel2 > 0) {
+ position.set("fuel2", fuel2);
+ }
+ } else {
+ String[] pair = attribute.split("=");
+ if (pair.length >= 2) {
+ String value = pair[1].trim();
+ if (value.contains(".")) {
+ value = value.substring(0, value.indexOf('.'));
+ }
+ switch (pair[0].charAt(0)) {
+ case 't':
+ position.set(Position.PREFIX_TEMP + pair[0].charAt(2), Integer.parseInt(value, 16));
+ break;
+ case 'N':
+ position.set("fuel" + pair[0].charAt(2), Integer.parseInt(value, 16));
+ break;
+ case 'Q':
+ position.set("drivingQuality", Integer.parseInt(value, 16));
+ break;
+ default:
+ break;
+ }
}
}
remaining -= attribute.length() + 1;
diff --git a/src/test/java/org/traccar/protocol/SuntechProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/SuntechProtocolDecoderTest.java
index cb5df63e6..ac46b6356 100644
--- a/src/test/java/org/traccar/protocol/SuntechProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/SuntechProtocolDecoderTest.java
@@ -58,6 +58,10 @@ public class SuntechProtocolDecoderTest extends ProtocolTest {
SuntechProtocolDecoder decoder = new SuntechProtocolDecoder(null);
+ verifyAttribute(decoder, text(
+ "ST300UEX;109003241;08;1026;20190425;17:36:04;04402;+04.722553;-074.052583;000.020;000.00;10;1;0;12.04;010000;51;CabAVL\"CabMensaje,0,58.5,-1.0,,,FinMensaje\"FinAVL\r\n;B1;0000000000;4.1;1"),
+ "fuel1", 58.5);
+
verifyPosition(decoder, text(
"ST600UEX;008728327;20;520;20190218;10:56:51;0bf1a893;334;20;2f19;18;+20.514195;-100.743597;000.015;000.00;9;1;3720808;12.89;000000;44;t_0=0D;N_0=0551.0;t_1=14;N_1=039F.0;Q_D=0B\r\n;9E;010440;4.1;1"));