aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2020-06-03 23:11:46 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2020-06-03 23:12:12 -0700
commit0be1c61132ecff3d5b502926f3c30d7ada5b968a (patch)
tree148f96049671f558adea45271cd5ab25c8609b9b
parent20ac86632a7d42c7ed4cb888219a05cf7ba4c8b0 (diff)
downloadtrackermap-server-0be1c61132ecff3d5b502926f3c30d7ada5b968a.tar.gz
trackermap-server-0be1c61132ecff3d5b502926f3c30d7ada5b968a.tar.bz2
trackermap-server-0be1c61132ecff3d5b502926f3c30d7ada5b968a.zip
Calculate total fuel
-rw-r--r--src/main/java/org/traccar/protocol/SuntechProtocolDecoder.java10
-rw-r--r--src/test/java/org/traccar/protocol/SuntechProtocolDecoderTest.java4
2 files changed, 13 insertions, 1 deletions
diff --git a/src/main/java/org/traccar/protocol/SuntechProtocolDecoder.java b/src/main/java/org/traccar/protocol/SuntechProtocolDecoder.java
index e65ab6167..3d6f5b8a5 100644
--- a/src/main/java/org/traccar/protocol/SuntechProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/SuntechProtocolDecoder.java
@@ -339,16 +339,19 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder {
break;
case "UEX":
int remaining = Integer.parseInt(values[index++]);
+ double totalFuel = 0;
while (remaining > 0) {
String attribute = values[index++];
if (attribute.startsWith("CabAVL")) {
String[] data = attribute.split(",");
double fuel1 = Double.parseDouble(data[2]);
if (fuel1 > 0) {
+ totalFuel += fuel1;
position.set("fuel1", fuel1);
}
double fuel2 = Double.parseDouble(data[3]);
if (fuel2 > 0) {
+ totalFuel += fuel2;
position.set("fuel2", fuel2);
}
} else {
@@ -363,7 +366,9 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder {
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));
+ int fuel = Integer.parseInt(value, 16);
+ totalFuel += fuel;
+ position.set("fuel" + pair[0].charAt(2), fuel);
break;
case 'Q':
position.set("drivingQuality", Integer.parseInt(value, 16));
@@ -375,6 +380,9 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder {
}
remaining -= attribute.length() + 1;
}
+ if (totalFuel > 0) {
+ position.set(Position.KEY_FUEL_LEVEL, totalFuel);
+ }
index += 1; // checksum
break;
default:
diff --git a/src/test/java/org/traccar/protocol/SuntechProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/SuntechProtocolDecoderTest.java
index fb4dd5d37..549402697 100644
--- a/src/test/java/org/traccar/protocol/SuntechProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/SuntechProtocolDecoderTest.java
@@ -95,6 +95,10 @@ public class SuntechProtocolDecoderTest extends ProtocolTest {
"ALT;0520000295;3FFFFF;52;1.0.2;0;20190703;01:03:24;00004697;732;101;0002;59;+4.682583;-74.128142;0.00;0.00;6;1;00000000;00000000;9;1;;4.1;12.92;103188"));
verifyAttribute(decoder, buffer(
+ "ST600UEX;008728327;20;568;20200602;17:10:03;0bf1a893;334;20;2f19;23;+20.514492;-100.743221;000.033;000.00;12;1;41564973;13.17;000000;44;t_0=1C;N_0=0419.0;t_1=22;N_1=0001.0;Q_D=09\n\r;76;113771;4.1;1"),
+ Position.KEY_FUEL_LEVEL, 1050.0);
+
+ verifyAttribute(decoder, buffer(
"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);