aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2020-08-16 10:52:10 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2020-08-16 10:52:10 -0700
commit0d73e71a2b5a37192ebeddbf2af1115f4074e35c (patch)
tree5e7456206b36af9f62b020b88f363074de0389fc /src
parentf9a564f5cf8859a92e8b8f18be9c1ad9df60f514 (diff)
downloadtraccar-server-0d73e71a2b5a37192ebeddbf2af1115f4074e35c.tar.gz
traccar-server-0d73e71a2b5a37192ebeddbf2af1115f4074e35c.tar.bz2
traccar-server-0d73e71a2b5a37192ebeddbf2af1115f4074e35c.zip
Decode additional attributes
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/traccar/protocol/NiotProtocolDecoder.java58
1 files changed, 56 insertions, 2 deletions
diff --git a/src/main/java/org/traccar/protocol/NiotProtocolDecoder.java b/src/main/java/org/traccar/protocol/NiotProtocolDecoder.java
index 58de0d38f..47c6e2ffd 100644
--- a/src/main/java/org/traccar/protocol/NiotProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/NiotProtocolDecoder.java
@@ -31,6 +31,7 @@ import org.traccar.helper.UnitsConverter;
import org.traccar.model.Position;
import java.net.SocketAddress;
+import java.nio.charset.StandardCharsets;
public class NiotProtocolDecoder extends BaseProtocolDecoder {
@@ -95,12 +96,65 @@ public class NiotProtocolDecoder extends BaseProtocolDecoder {
.setSecond(BcdUtil.readInteger(buf, 2));
position.setTime(dateBuilder.getDate());
- position.setValid(true);
position.setLatitude(readCoordinate(buf));
position.setLongitude(readCoordinate(buf));
- position.setSpeed(UnitsConverter.knotsFromKph(BcdUtil.readInteger(buf, 4)));
+ BcdUtil.readInteger(buf, 4); // reserved
position.setCourse(BcdUtil.readInteger(buf, 4));
+ int statusX = buf.readUnsignedByte();
+ position.setValid(BitUtil.check(statusX, 7));
+ switch (BitUtil.between(statusX, 3, 5)) {
+ case 0b10:
+ position.set(Position.KEY_ALARM, Position.ALARM_POWER_CUT);
+ break;
+ case 0b01:
+ position.set(Position.KEY_ALARM, Position.ALARM_LOW_POWER);
+ break;
+ default:
+ break;
+ }
+
+ position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
+
+ int statusA = buf.readUnsignedByte();
+ position.set(Position.KEY_IGNITION, !BitUtil.check(statusA, 7));
+ if (!BitUtil.check(statusA, 6)) {
+ position.set(Position.KEY_ALARM, Position.ALARM_OVERSPEED);
+ }
+
+ buf.readUnsignedByte(); // statusB
+ buf.readUnsignedByte(); // statusC
+ position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
+ position.set(Position.KEY_BATTERY, buf.readUnsignedByte() * 0.1);
+ position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.1);
+ buf.readUnsignedByte(); // speed limit
+ position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
+ buf.readUnsignedByte(); // sensor speed
+ buf.readUnsignedByte(); // reserved
+ buf.readUnsignedByte(); // reserved
+
+ while (buf.readableBytes() > 4) {
+ int extendedLength = buf.readUnsignedShort();
+ int extendedType = buf.readUnsignedShort();
+ switch (extendedType) {
+ case 0x0001:
+ position.set(Position.KEY_ICCID,
+ buf.readCharSequence(20, StandardCharsets.US_ASCII).toString());
+ break;
+ case 0x0002:
+ int statusD = buf.readUnsignedByte();
+ position.set(Position.KEY_ALARM, BitUtil.check(statusD, 5) ? Position.ALARM_REMOVING : null);
+ position.set(Position.KEY_ALARM, BitUtil.check(statusD, 4) ? Position.ALARM_TAMPERING : null);
+ buf.readUnsignedByte(); // run mode
+ buf.readUnsignedByte(); // reserved
+ break;
+ default:
+ buf.skipBytes(extendedLength - 2);
+ break;
+ }
+
+ }
+
return position;
}