aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2020-07-16 19:52:16 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2020-07-16 19:52:16 -0700
commit90ddc7b95e3879c20d6d8f7e8b96df87e0ec1f66 (patch)
treef7f15260bb0795c92e17942794ff95a02daf8100 /src/main
parentb0339ffbb2756a2ef601270f5b163015b57e8773 (diff)
downloadtrackermap-server-90ddc7b95e3879c20d6d8f7e8b96df87e0ec1f66.tar.gz
trackermap-server-90ddc7b95e3879c20d6d8f7e8b96df87e0ec1f66.tar.bz2
trackermap-server-90ddc7b95e3879c20d6d8f7e8b96df87e0ec1f66.zip
Fix coordinates decoding
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/traccar/protocol/NiotProtocolDecoder.java12
1 files changed, 10 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));