aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/org/traccar/protocol/FreematicsProtocolDecoder.java164
-rw-r--r--src/test/java/org/traccar/protocol/FreematicsProtocolDecoderTest.java3
2 files changed, 88 insertions, 79 deletions
diff --git a/src/main/java/org/traccar/protocol/FreematicsProtocolDecoder.java b/src/main/java/org/traccar/protocol/FreematicsProtocolDecoder.java
index 71e2fccd6..34125bffa 100644
--- a/src/main/java/org/traccar/protocol/FreematicsProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/FreematicsProtocolDecoder.java
@@ -88,85 +88,91 @@ public class FreematicsProtocolDecoder extends BaseProtocolDecoder {
for (String pair : sentence.split(",")) {
String[] data = pair.split("[=:]");
- int key = Integer.parseInt(data[0], 16);
+ int key;
+ try {
+ key = Integer.parseInt(data[0], 16);
+ } catch (NumberFormatException e) {
+ continue;
+ }
String value = data[1];
- switch (key) {
- case 0x0:
- if (position != null) {
- position.setTime(dateBuilder.getDate());
- positions.add(position);
- }
- position = new Position(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
- position.setValid(true);
- dateBuilder = new DateBuilder(new Date());
- break;
- case 0x11:
- value = ("000000" + value).substring(value.length());
- dateBuilder.setDateReverse(
- Integer.parseInt(value.substring(0, 2)),
- Integer.parseInt(value.substring(2, 4)),
- Integer.parseInt(value.substring(4)));
- break;
- case 0x10:
- value = ("00000000" + value).substring(value.length());
- dateBuilder.setTime(
- Integer.parseInt(value.substring(0, 2)),
- Integer.parseInt(value.substring(2, 4)),
- Integer.parseInt(value.substring(4, 6)),
- Integer.parseInt(value.substring(6)) * 10);
- break;
- case 0xA:
- position.setLatitude(Double.parseDouble(value));
- break;
- case 0xB:
- position.setLongitude(Double.parseDouble(value));
- break;
- case 0xC:
- position.setAltitude(Double.parseDouble(value));
- break;
- case 0xD:
- position.setSpeed(UnitsConverter.knotsFromKph(Double.parseDouble(value)));
- break;
- case 0xE:
- position.setCourse(Integer.parseInt(value));
- break;
- case 0xF:
- position.set(Position.KEY_SATELLITES, Integer.parseInt(value));
- break;
- case 0x12:
- position.set(Position.KEY_HDOP, Integer.parseInt(value));
- break;
- case 0x20:
- position.set(Position.KEY_ACCELERATION, value);
- break;
- case 0x24:
- position.set(Position.KEY_BATTERY, Integer.parseInt(value) * 0.01);
- break;
- case 0x81:
- position.set(Position.KEY_RSSI, Integer.parseInt(value));
- break;
- case 0x82:
- position.set(Position.KEY_DEVICE_TEMP, Integer.parseInt(value) * 0.1);
- break;
- case 0x104:
- position.set(Position.KEY_ENGINE_LOAD, Integer.parseInt(value));
- break;
- case 0x105:
- position.set(Position.KEY_COOLANT_TEMP, Integer.parseInt(value));
- break;
- case 0x10c:
- position.set(Position.KEY_RPM, Integer.parseInt(value));
- break;
- case 0x10d:
- position.set(Position.KEY_OBD_SPEED, UnitsConverter.knotsFromKph(Integer.parseInt(value)));
- break;
- case 0x111:
- position.set(Position.KEY_THROTTLE, Integer.parseInt(value));
- break;
- default:
- position.set(Position.PREFIX_IO + key, value);
- break;
+ if (key == 0x0) {
+ if (position != null) {
+ position.setTime(dateBuilder.getDate());
+ positions.add(position);
+ }
+ position = new Position(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+ position.setValid(true);
+ dateBuilder = new DateBuilder(new Date());
+ } else if (position != null) {
+ switch (key) {
+ case 0x11:
+ value = ("000000" + value).substring(value.length());
+ dateBuilder.setDateReverse(
+ Integer.parseInt(value.substring(0, 2)),
+ Integer.parseInt(value.substring(2, 4)),
+ Integer.parseInt(value.substring(4)));
+ break;
+ case 0x10:
+ value = ("00000000" + value).substring(value.length());
+ dateBuilder.setTime(
+ Integer.parseInt(value.substring(0, 2)),
+ Integer.parseInt(value.substring(2, 4)),
+ Integer.parseInt(value.substring(4, 6)),
+ Integer.parseInt(value.substring(6)) * 10);
+ break;
+ case 0xA:
+ position.setLatitude(Double.parseDouble(value));
+ break;
+ case 0xB:
+ position.setLongitude(Double.parseDouble(value));
+ break;
+ case 0xC:
+ position.setAltitude(Double.parseDouble(value));
+ break;
+ case 0xD:
+ position.setSpeed(UnitsConverter.knotsFromKph(Double.parseDouble(value)));
+ break;
+ case 0xE:
+ position.setCourse(Integer.parseInt(value));
+ break;
+ case 0xF:
+ position.set(Position.KEY_SATELLITES, Integer.parseInt(value));
+ break;
+ case 0x12:
+ position.set(Position.KEY_HDOP, Integer.parseInt(value));
+ break;
+ case 0x20:
+ position.set(Position.KEY_ACCELERATION, value);
+ break;
+ case 0x24:
+ position.set(Position.KEY_BATTERY, Integer.parseInt(value) * 0.01);
+ break;
+ case 0x81:
+ position.set(Position.KEY_RSSI, Integer.parseInt(value));
+ break;
+ case 0x82:
+ position.set(Position.KEY_DEVICE_TEMP, Integer.parseInt(value) * 0.1);
+ break;
+ case 0x104:
+ position.set(Position.KEY_ENGINE_LOAD, Integer.parseInt(value));
+ break;
+ case 0x105:
+ position.set(Position.KEY_COOLANT_TEMP, Integer.parseInt(value));
+ break;
+ case 0x10c:
+ position.set(Position.KEY_RPM, Integer.parseInt(value));
+ break;
+ case 0x10d:
+ position.set(Position.KEY_OBD_SPEED, UnitsConverter.knotsFromKph(Integer.parseInt(value)));
+ break;
+ case 0x111:
+ position.set(Position.KEY_THROTTLE, Integer.parseInt(value));
+ break;
+ default:
+ position.set(Position.PREFIX_IO + key, value);
+ break;
+ }
}
}
@@ -175,7 +181,7 @@ public class FreematicsProtocolDecoder extends BaseProtocolDecoder {
positions.add(position);
}
- return positions;
+ return positions.isEmpty() ? null : positions;
}
@Override
diff --git a/src/test/java/org/traccar/protocol/FreematicsProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/FreematicsProtocolDecoderTest.java
index 2729f7af7..566d66fd7 100644
--- a/src/test/java/org/traccar/protocol/FreematicsProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/FreematicsProtocolDecoderTest.java
@@ -34,6 +34,9 @@ public class FreematicsProtocolDecoderTest extends ProtocolTest {
verifyPositions(decoder, text(
"1#0=68338,10D=79,30=1010,105=199,10C=4375,104=56,111=62,20=0;-1;95,10=6454200,A=-32.727482,B=150.150301,C=159,D=0,F=5,24=1250*7A"));
+ verifyNull(decoder, text(
+ "M0ZR4X0#DF=4208,SSI=-71,EV=1,TS=20866,ID=M0ZR4X0*9E"));
+
}
}