aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/traccar/protocol/TopinProtocolDecoder.java29
1 files changed, 18 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();