aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2021-12-04 08:28:19 -0800
committerAnton Tananaev <anton.tananaev@gmail.com>2021-12-04 08:28:19 -0800
commitd7aabe103f4a560353d9ed16d541540b834c5e19 (patch)
tree70da79da9fb51773ca5aa9cbfc7e8ece9f06853a
parentbff2f2d61878390827ed452bd8a6c4e48f89083b (diff)
downloadtraccar-server-d7aabe103f4a560353d9ed16d541540b834c5e19.tar.gz
traccar-server-d7aabe103f4a560353d9ed16d541540b834c5e19.tar.bz2
traccar-server-d7aabe103f4a560353d9ed16d541540b834c5e19.zip
Additional alarm field
-rw-r--r--src/main/java/org/traccar/protocol/TopinProtocolDecoder.java29
-rw-r--r--src/test/java/org/traccar/protocol/TopinProtocolDecoderTest.java4
2 files changed, 22 insertions, 11 deletions
diff --git a/src/main/java/org/traccar/protocol/TopinProtocolDecoder.java b/src/main/java/org/traccar/protocol/TopinProtocolDecoder.java
index 267bce562..40a583f2a 100644
--- a/src/main/java/org/traccar/protocol/TopinProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/TopinProtocolDecoder.java
@@ -93,6 +93,19 @@ public class TopinProtocolDecoder extends BaseProtocolDecoder {
return negative ? -result : result;
}
+ private String decodeAlarm(int alarms) {
+ if (BitUtil.check(alarms, 0)) {
+ return Position.ALARM_VIBRATION;
+ }
+ if (BitUtil.check(alarms, 1)) {
+ return Position.ALARM_OVERSPEED;
+ }
+ if (BitUtil.check(alarms, 4)) {
+ return Position.ALARM_LOW_POWER;
+ }
+ return null;
+ }
+
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
@@ -158,17 +171,7 @@ public class TopinProtocolDecoder extends BaseProtocolDecoder {
if (buf.readableBytes() >= 5) {
position.setAltitude(buf.readShort());
-
- int alarms = buf.readUnsignedByte();
- if (BitUtil.check(alarms, 0)) {
- position.set(Position.KEY_ALARM, Position.ALARM_VIBRATION);
- }
- if (BitUtil.check(alarms, 1)) {
- position.set(Position.KEY_ALARM, Position.ALARM_OVERSPEED);
- }
- if (BitUtil.check(alarms, 4)) {
- position.set(Position.KEY_ALARM, Position.ALARM_LOW_POWER);
- }
+ position.set(Position.KEY_ALARM, decodeAlarm(buf.readUnsignedByte()));
}
ByteBuf content = Unpooled.buffer();
@@ -246,6 +249,10 @@ public class TopinProtocolDecoder extends BaseProtocolDecoder {
mcc, mnc, buf.readUnsignedShort(), buf.readUnsignedShort(), buf.readUnsignedByte()));
}
+ if (buf.readableBytes() > 2) {
+ position.set(Position.KEY_ALARM, decodeAlarm(buf.readUnsignedByte()));
+ }
+
position.setNetwork(network);
ByteBuf content = Unpooled.buffer();
diff --git a/src/test/java/org/traccar/protocol/TopinProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/TopinProtocolDecoderTest.java
index 331be974c..e8da93006 100644
--- a/src/test/java/org/traccar/protocol/TopinProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/TopinProtocolDecoderTest.java
@@ -18,6 +18,10 @@ public class TopinProtocolDecoderTest extends ProtocolTest {
"78780d0103593390754169634d0d0a"));
verifyAttribute(decoder, binary(
+ "7878006921120412565802010601071e4a9764071e4a9864010d0a"),
+ Position.KEY_ALARM, Position.ALARM_VIBRATION);
+
+ verifyAttribute(decoder, binary(
"787801940D0A"),
Position.KEY_ALARM, Position.ALARM_VIBRATION);