aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2021-01-04 22:30:19 -0800
committerAnton Tananaev <anton.tananaev@gmail.com>2021-01-04 22:30:19 -0800
commitbca343a9704aa0040467599f9196eff08e674bc7 (patch)
tree4336648efb6e23ea607bd4a27e08354ff0f70afd /src
parenteaca872f70921c63030d4758d52cf4fe2df2bfac (diff)
downloadtrackermap-server-bca343a9704aa0040467599f9196eff08e674bc7.tar.gz
trackermap-server-bca343a9704aa0040467599f9196eff08e674bc7.tar.bz2
trackermap-server-bca343a9704aa0040467599f9196eff08e674bc7.zip
Add events and fix speed
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/traccar/protocol/IotmProtocolDecoder.java23
-rw-r--r--src/test/java/org/traccar/protocol/IotmProtocolDecoderTest.java3
2 files changed, 20 insertions, 6 deletions
diff --git a/src/main/java/org/traccar/protocol/IotmProtocolDecoder.java b/src/main/java/org/traccar/protocol/IotmProtocolDecoder.java
index 88641081e..c5a9050e4 100644
--- a/src/main/java/org/traccar/protocol/IotmProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/IotmProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2020 Anton Tananaev (anton@traccar.org)
+ * Copyright 2020 - 2021 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,6 +28,7 @@ import org.traccar.BaseProtocolDecoder;
import org.traccar.DeviceSession;
import org.traccar.NetworkMessage;
import org.traccar.Protocol;
+import org.traccar.helper.UnitsConverter;
import org.traccar.model.Position;
import java.net.SocketAddress;
@@ -144,10 +145,9 @@ public class IotmProtocolDecoder extends BaseProtocolDecoder {
while (buf.readableBytes() > 1) {
int type = buf.readUnsignedByte();
int length = buf.readUnsignedShortLE();
+ ByteBuf record = buf.readSlice(length);
if (type == 1) {
- ByteBuf record = buf.readSlice(length);
-
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.setTime(new Date(record.readUnsignedIntLE() * 1000));
@@ -160,7 +160,7 @@ public class IotmProtocolDecoder extends BaseProtocolDecoder {
position.setValid(true);
position.setLatitude(record.readFloatLE());
position.setLongitude(record.readFloatLE());
- position.setSpeed(record.readUnsignedShortLE());
+ position.setSpeed(UnitsConverter.knotsFromKph(record.readUnsignedShortLE()));
position.set(Position.KEY_HDOP, record.readUnsignedByte());
position.set(Position.KEY_SATELLITES, record.readUnsignedByte());
@@ -181,8 +181,19 @@ public class IotmProtocolDecoder extends BaseProtocolDecoder {
positions.add(position);
- } else {
- buf.skipBytes(length);
+ } else if (type == 3) {
+
+ Position position = new Position(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ getLastLocation(position, new Date(record.readUnsignedIntLE() * 1000));
+
+ record.readUnsignedByte(); // function identifier
+
+ position.set(Position.KEY_EVENT, record.readUnsignedByte());
+
+ positions.add(position);
+
}
}
diff --git a/src/test/java/org/traccar/protocol/IotmProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/IotmProtocolDecoderTest.java
index f3962efd5..9a8c6534c 100644
--- a/src/test/java/org/traccar/protocol/IotmProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/IotmProtocolDecoderTest.java
@@ -16,6 +16,9 @@ public class IotmProtocolDecoderTest extends ProtocolTest {
"123456789012345").build());
verifyPositions(decoder, false, MqttMessageBuilders.publish().payload(binary(
+ "020208009188752DE7120300030A002000AD59000146543250030A002200AD59643346543250FB")).qos(MqttQoS.EXACTLY_ONCE).messageId(1).build());
+
+ verifyPositions(decoder, false, MqttMessageBuilders.publish().payload(binary(
"020208004f6af053901403000135007715ec5f0d02b000485cea73083041040b30ee050030ae38040020120e00d0d34bc9412e9c5d4212000806ee00feff011300006d006e")).qos(MqttQoS.EXACTLY_ONCE).messageId(1).build());
verifyPositions(decoder, false, MqttMessageBuilders.publish().payload(binary(