diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2021-01-04 20:28:17 -0800 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2021-01-04 20:28:17 -0800 |
commit | cf313ffd7b3774e4c2c328a759153e07a3c31410 (patch) | |
tree | 455288ceefa7d883d33218767cc7c792f0ba9fd5 /src/main/java/org | |
parent | cc69a9907ac9878db3750aa14ffedb28626455da (diff) | |
download | traccar-server-cf313ffd7b3774e4c2c328a759153e07a3c31410.tar.gz traccar-server-cf313ffd7b3774e4c2c328a759153e07a3c31410.tar.bz2 traccar-server-cf313ffd7b3774e4c2c328a759153e07a3c31410.zip |
Unify alarm decoding
Diffstat (limited to 'src/main/java/org')
-rw-r--r-- | src/main/java/org/traccar/protocol/TaipProtocolDecoder.java | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/src/main/java/org/traccar/protocol/TaipProtocolDecoder.java b/src/main/java/org/traccar/protocol/TaipProtocolDecoder.java index 7d31b332d..6f71b6c08 100644 --- a/src/main/java/org/traccar/protocol/TaipProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/TaipProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 - 2020 Anton Tananaev (anton@traccar.org) + * Copyright 2013 - 2021 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -131,6 +131,22 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder { } } + private String decodeAlarm2(int value) { + switch (value) { + case 22: + return Position.ALARM_ACCELERATION; + case 23: + return Position.ALARM_BRAKING; + case 24: + return Position.ALARM_ACCIDENT; + case 26: + case 28: + return Position.ALARM_CORNERING; + default: + return null; + } + } + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { @@ -193,7 +209,7 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_RPM, parser.nextInt()); position.set(Position.PREFIX_TEMP + 1, parser.nextDouble()); position.set(Position.PREFIX_TEMP + 2, parser.nextDouble()); - position.set(Position.KEY_ALARM, decodeAlarm(parser.nextHexInt())); + event = parser.nextHexInt(); } if (parser.hasNext(2)) { @@ -220,22 +236,10 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder { if (event != null) { position.set(Position.KEY_EVENT, event); - switch (event) { - case 22: - position.set(Position.KEY_ALARM, Position.ALARM_ACCELERATION); - break; - case 23: - position.set(Position.KEY_ALARM, Position.ALARM_BRAKING); - break; - case 24: - position.set(Position.KEY_ALARM, Position.ALARM_ACCIDENT); - break; - case 26: - case 28: - position.set(Position.KEY_ALARM, Position.ALARM_CORNERING); - break; - default: - break; + if (sentence.charAt(5) == ',') { + position.set(Position.KEY_ALARM, decodeAlarm2(event)); + } else { + position.set(Position.KEY_ALARM, decodeAlarm(event)); } } |