aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2021-01-14 22:10:07 -0800
committerAnton Tananaev <anton.tananaev@gmail.com>2021-01-14 22:10:07 -0800
commit3e2124609d98678daf2881428dd857a8573b6b96 (patch)
tree545b9191dbc34385f6405503a1670097a7a15567 /src
parent94d34a85f2ee87418618779a4399c9a908900c63 (diff)
downloadtraccar-server-3e2124609d98678daf2881428dd857a8573b6b96.tar.gz
traccar-server-3e2124609d98678daf2881428dd857a8573b6b96.tar.bz2
traccar-server-3e2124609d98678daf2881428dd857a8573b6b96.zip
Skip empty values
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java56
-rw-r--r--src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java6
2 files changed, 35 insertions, 27 deletions
diff --git a/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java
index 48d9c813a..755cfe33e 100644
--- a/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java
@@ -1065,33 +1065,35 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder {
String data = buf.readCharSequence(buf.readableBytes() - 18, StandardCharsets.US_ASCII).toString();
for (String pair : data.split(",")) {
String[] values = pair.split("=");
- switch (Integer.parseInt(values[0].substring(0, 2), 16)) {
- case 40:
- position.set(Position.KEY_ODOMETER, Integer.parseInt(values[1], 16) * 0.01);
- break;
- case 43:
- position.set(Position.KEY_FUEL_LEVEL, Integer.parseInt(values[1], 16) * 0.01);
- break;
- case 45:
- position.set(Position.KEY_COOLANT_TEMP, Integer.parseInt(values[1], 16) * 0.01);
- break;
- case 53:
- position.set(Position.KEY_OBD_SPEED, Integer.parseInt(values[1], 16) * 0.01);
- break;
- case 54:
- position.set(Position.KEY_RPM, Integer.parseInt(values[1], 16) * 0.01);
- break;
- case 71:
- position.set(Position.KEY_FUEL_USED, Integer.parseInt(values[1], 16) * 0.01);
- break;
- case 73:
- position.set(Position.KEY_HOURS, Integer.parseInt(values[1], 16) * 0.01);
- break;
- case 74:
- position.set(Position.KEY_VIN, values[1]);
- break;
- default:
- break;
+ if (values.length >= 2) {
+ switch (Integer.parseInt(values[0].substring(0, 2), 16)) {
+ case 40:
+ position.set(Position.KEY_ODOMETER, Integer.parseInt(values[1], 16) * 0.01);
+ break;
+ case 43:
+ position.set(Position.KEY_FUEL_LEVEL, Integer.parseInt(values[1], 16) * 0.01);
+ break;
+ case 45:
+ position.set(Position.KEY_COOLANT_TEMP, Integer.parseInt(values[1], 16) * 0.01);
+ break;
+ case 53:
+ position.set(Position.KEY_OBD_SPEED, Integer.parseInt(values[1], 16) * 0.01);
+ break;
+ case 54:
+ position.set(Position.KEY_RPM, Integer.parseInt(values[1], 16) * 0.01);
+ break;
+ case 71:
+ position.set(Position.KEY_FUEL_USED, Integer.parseInt(values[1], 16) * 0.01);
+ break;
+ case 73:
+ position.set(Position.KEY_HOURS, Integer.parseInt(values[1], 16) * 0.01);
+ break;
+ case 74:
+ position.set(Position.KEY_VIN, values[1]);
+ break;
+ default:
+ break;
+ }
}
}
diff --git a/src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java
index 518aeed9d..4bdd5572e 100644
--- a/src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java
@@ -20,6 +20,12 @@ public class Gt06ProtocolDecoderTest extends ProtocolTest {
verifyNull(decoder, binary(
"797900099b0380d600046f91e90d0a"));
+ verifyNull(decoder, binary(
+ "797900a56615010d081f3b012c323131303d30303033643238342c323130353d30303030316332302c323130623d30303030326537632c323130633d30303033643238342c323130663d30303030306331632c323130643d30303030323166632c323161363d30303030303030302c323130343d30303030306531302c323132663d30303030303030302c323134353d30303030303030302ccb03851f5f03c020525514a7003e216a0d0a"));
+
+ verifyNotNull(decoder, binary(
+ "797900cd8c15010d08200d013137333d302c3232333d312c3238333d30303032373464382c3436333d30303030303239352c3437333d30303030363333622c3438333d30303030303036372c3242333d30303030303030302c3244333d30303030316332302c3335333d30303030323133342c3336333d30303033626430382c3339333d30303030303336622c3330333d30303030303539362c3439333d30303030306563382c3441333d2c3341333d30303030303430352c3530333d30303030cb03850c3603c025af5414a6003fc5940d0a"));
+
verifyNotNull(decoder, binary(
"787844F3140C0B0A262A070000DC9FDB1C1D760000C83A3569A37100008825937287000000EC41180C8209000088C39749553700003891D5604D6300003891D5604D68002EC4230D0A"));