aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/org/traccar/protocol/NiotProtocolDecoder.java12
-rw-r--r--src/test/java/org/traccar/protocol/NiotProtocolDecoderTest.java4
2 files changed, 14 insertions, 2 deletions
diff --git a/src/main/java/org/traccar/protocol/NiotProtocolDecoder.java b/src/main/java/org/traccar/protocol/NiotProtocolDecoder.java
index 81b6efc91..58de0d38f 100644
--- a/src/main/java/org/traccar/protocol/NiotProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/NiotProtocolDecoder.java
@@ -24,6 +24,7 @@ import org.traccar.DeviceSession;
import org.traccar.NetworkMessage;
import org.traccar.Protocol;
import org.traccar.helper.BcdUtil;
+import org.traccar.helper.BitUtil;
import org.traccar.helper.Checksum;
import org.traccar.helper.DateBuilder;
import org.traccar.helper.UnitsConverter;
@@ -55,6 +56,12 @@ public class NiotProtocolDecoder extends BaseProtocolDecoder {
}
}
+ private double readCoordinate(ByteBuf buf) {
+ long value = buf.readUnsignedInt();
+ double result = BitUtil.to(value, 31) / 1800000.0;
+ return BitUtil.check(value, 31) ? -result : result;
+ }
+
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
@@ -88,8 +95,9 @@ public class NiotProtocolDecoder extends BaseProtocolDecoder {
.setSecond(BcdUtil.readInteger(buf, 2));
position.setTime(dateBuilder.getDate());
- position.setLatitude(BcdUtil.readCoordinate(buf));
- position.setLongitude(BcdUtil.readCoordinate(buf));
+ position.setValid(true);
+ position.setLatitude(readCoordinate(buf));
+ position.setLongitude(readCoordinate(buf));
position.setSpeed(UnitsConverter.knotsFromKph(BcdUtil.readInteger(buf, 4)));
position.setCourse(BcdUtil.readInteger(buf, 4));
diff --git a/src/test/java/org/traccar/protocol/NiotProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/NiotProtocolDecoderTest.java
index 8787e8c51..e436fb4ed 100644
--- a/src/test/java/org/traccar/protocol/NiotProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/NiotProtocolDecoderTest.java
@@ -11,6 +11,10 @@ public class NiotProtocolDecoderTest extends ProtocolTest {
NiotProtocolDecoder decoder = new NiotProtocolDecoder(null);
verifyPosition(decoder, binary(
+ "585880004c08675430347318522007161451458024b28003f566ee00000328f8000748217ffc500729007a280000000000160001383932353430323130363431363738373136323100050002004e00570d"),
+ position("2020-07-16 14:51:45.000", true, -1.33611, 36.89684));
+
+ verifyPosition(decoder, binary(
"585880004c08675430355777182005201100468024121b03f390ba00000105f8000b8d207ffc5f0f290084500000000000160001383932353430323130363431363839323430303700050002004e55940d"));
verifyPosition(decoder, binary(