From 94c04282f1b3792bc2c16758049a57f4c42941c9 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 12 Jun 2020 21:14:31 -0700 Subject: Decode Huasheng alarms --- .../traccar/protocol/HuaShengProtocolDecoder.java | 26 +++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'src/main') diff --git a/src/main/java/org/traccar/protocol/HuaShengProtocolDecoder.java b/src/main/java/org/traccar/protocol/HuaShengProtocolDecoder.java index eac06bbfe..8d39abead 100644 --- a/src/main/java/org/traccar/protocol/HuaShengProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/HuaShengProtocolDecoder.java @@ -64,6 +64,27 @@ public class HuaShengProtocolDecoder extends BaseProtocolDecoder { } } + private String decodeAlarm(int event) { + switch (event) { + case 4: + return Position.ALARM_FATIGUE_DRIVING; + case 6: + return Position.ALARM_SOS; + case 7: + return Position.ALARM_BRAKING; + case 8: + return Position.ALARM_ACCELERATION; + case 9: + return Position.ALARM_CORNERING; + case 10: + return Position.ALARM_ACCIDENT; + case 16: + return Position.ALARM_REMOVING; + default: + return null; + } + } + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { @@ -118,7 +139,10 @@ public class HuaShengProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_STATUS, status); position.set(Position.KEY_IGNITION, BitUtil.check(status, 14)); - position.set(Position.KEY_EVENT, buf.readUnsignedShort()); + + int event = buf.readUnsignedShort(); + position.set(Position.KEY_ALARM, decodeAlarm(event)); + position.set(Position.KEY_EVENT, event); String time = buf.readCharSequence(12, StandardCharsets.US_ASCII).toString(); -- cgit v1.2.3