From 87a8bf3f5cff9b2e537594d0a13371ed8f06fcea Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Tue, 16 Aug 2016 11:41:53 +0500 Subject: - Added alarm decoding for 5 protocols --- .../traccar/protocol/EelinkProtocolDecoder.java | 32 ++++++++++++++++++- .../traccar/protocol/HuabaoProtocolDecoder.java | 28 +++++++++++++++- src/org/traccar/protocol/IdplProtocolDecoder.java | 4 ++- .../traccar/protocol/MegastekProtocolDecoder.java | 37 ++++++++++++++++++++-- src/org/traccar/protocol/TzoneProtocolDecoder.java | 19 ++++++++++- 5 files changed, 113 insertions(+), 7 deletions(-) diff --git a/src/org/traccar/protocol/EelinkProtocolDecoder.java b/src/org/traccar/protocol/EelinkProtocolDecoder.java index 85f231a17..24cd6b570 100644 --- a/src/org/traccar/protocol/EelinkProtocolDecoder.java +++ b/src/org/traccar/protocol/EelinkProtocolDecoder.java @@ -64,6 +64,36 @@ public class EelinkProtocolDecoder extends BaseProtocolDecoder { } } + private String decodeAlarm(Short value) { + switch (value) { + case 0x01: + return Position.ALARM_POWER_OFF; + case 0x02: + return Position.ALARM_SOS; + case 0x03: + return Position.ALARM_LOW_BATTERY; + case 0x04: + return Position.ALARM_VIBRATION; + case 0x08: + case 0x09: + return Position.ALARM_GPS_ANTENNA_CUT; + case 0x81: + return Position.ALARM_LOW_SPEED; + case 0x82: + return Position.ALARM_OVERSPEED; + case 0x83: + return Position.ALARM_GEOFENCE_ENTER; + case 0x84: + return Position.ALARM_GEOFENCE_EXIT; + case 0x85: + return Position.ALARM_ACCIDENT; + case 0x86: + return Position.ALARM_FALL_DOWN; + default: + return null; + } + } + private Position decodeOld(DeviceSession deviceSession, ChannelBuffer buf, int type, int index) { Position position = new Position(); @@ -90,7 +120,7 @@ public class EelinkProtocolDecoder extends BaseProtocolDecoder { } if (type == MSG_STATE) { - position.set(Position.KEY_STATUS, buf.readUnsignedByte()); + position.set(Position.KEY_STATUS, decodeAlarm(buf.readUnsignedByte())); } return position; diff --git a/src/org/traccar/protocol/HuabaoProtocolDecoder.java b/src/org/traccar/protocol/HuabaoProtocolDecoder.java index e4c9a9860..9223ea9a5 100644 --- a/src/org/traccar/protocol/HuabaoProtocolDecoder.java +++ b/src/org/traccar/protocol/HuabaoProtocolDecoder.java @@ -70,6 +70,32 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder { sendResponse(channel, remoteAddress, MSG_GENERAL_RESPONSE, id, response); } + private String decodeAlarm(long value) { + if (BitUtil.check(value, 0)) { + return Position.ALARM_SOS; + } + if (BitUtil.check(value, 1)) { + return Position.ALARM_OVERSPEED; + } + if (BitUtil.check(value, 5)) { + return Position.ALARM_GPS_ANTENNA_CUT; + } + if (BitUtil.check(value, 4) || BitUtil.check(value, 9) + || BitUtil.check(value, 10) || BitUtil.check(value, 11)) { + return Position.ALARM_FAULT; + } + if (BitUtil.check(value, 8)) { + return Position.ALARM_POWER_OFF; + } + if (BitUtil.check(value, 20)) { + return Position.ALARM_GEOFENCE; + } + if (BitUtil.check(value, 29)) { + return Position.ALARM_ACCIDENT; + } + return null; + } + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { @@ -105,7 +131,7 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder { position.setProtocol(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); - position.set(Position.KEY_ALARM, buf.readUnsignedInt()); + position.set(Position.KEY_ALARM, decodeAlarm(buf.readUnsignedInt())); int flags = buf.readInt(); diff --git a/src/org/traccar/protocol/IdplProtocolDecoder.java b/src/org/traccar/protocol/IdplProtocolDecoder.java index 5b8ec7897..4fdf9d677 100644 --- a/src/org/traccar/protocol/IdplProtocolDecoder.java +++ b/src/org/traccar/protocol/IdplProtocolDecoder.java @@ -97,7 +97,9 @@ public class IdplProtocolDecoder extends BaseProtocolDecoder { parser.next(); // vehicle status position.set(Position.KEY_POWER, parser.nextInt()); position.set(Position.KEY_BATTERY, parser.nextDouble()); - position.set(Position.KEY_ALARM, parser.nextInt()); + if (parser.nextInt() == 1) { + position.set(Position.KEY_ALARM, Position.ALARM_SOS); + } parser.nextInt(); // body tamper parser.nextInt(); // ac status position.set(Position.KEY_IGNITION, parser.nextInt() == 1); diff --git a/src/org/traccar/protocol/MegastekProtocolDecoder.java b/src/org/traccar/protocol/MegastekProtocolDecoder.java index 1ff7add1a..d20532faa 100644 --- a/src/org/traccar/protocol/MegastekProtocolDecoder.java +++ b/src/org/traccar/protocol/MegastekProtocolDecoder.java @@ -156,7 +156,7 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { Parser parser = new Parser(PATTERN_SIMPLE, status); if (parser.matches()) { - position.set(Position.KEY_ALARM, parser.next()); + position.set(Position.KEY_ALARM, decodeAlarm(parser.next())); DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next(), id); if (deviceSession == null) { @@ -217,7 +217,7 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { position.set(Position.PREFIX_ADC + 1, parser.next()); position.set(Position.PREFIX_ADC + 2, parser.next()); position.set(Position.PREFIX_ADC + 3, parser.next()); - position.set(Position.KEY_ALARM, parser.next()); + position.set(Position.KEY_ALARM, decodeAlarm(parser.next())); } } @@ -337,11 +337,42 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_BATTERY, Integer.parseInt(battery)); } - position.set(Position.KEY_ALARM, parser.next()); + position.set(Position.KEY_ALARM, decodeAlarm(parser.next())); return position; } + private String decodeAlarm(String value) { + switch (value) { + case "SOS": + case "Help": + return Position.ALARM_SOS; + case "Over Speed": + case "OverSpeed": + return Position.ALARM_OVERSPEED; + case "LowSpeed": + return Position.ALARM_LOW_SPEED; + case "Low Battery": + case "LowBattery": + return Position.ALARM_LOW_BATTERY; + case "VIB": + return Position.ALARM_VIBRATION; + case "Move in": + case "Geo in": + case "Geo1 in": + case "Geo2 in": + return Position.ALARM_GEOFENCE_ENTER; + case "Move out": + case "Geo out": + case "Geo1 out": + case "Geo2 out": + return Position.ALARM_GEOFENCE_EXIT; + default: + break; + } + return null; + } + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { diff --git a/src/org/traccar/protocol/TzoneProtocolDecoder.java b/src/org/traccar/protocol/TzoneProtocolDecoder.java index 9caf77b0c..4b530efa4 100644 --- a/src/org/traccar/protocol/TzoneProtocolDecoder.java +++ b/src/org/traccar/protocol/TzoneProtocolDecoder.java @@ -32,6 +32,23 @@ public class TzoneProtocolDecoder extends BaseProtocolDecoder { super(protocol); } + private String decodeAlarm(Short value) { + switch (value) { + case 0x01: + return Position.ALARM_SOS; + case 0x10: + return Position.ALARM_LOW_BATTERY; + case 0x11: + return Position.ALARM_OVERSPEED; + case 0x42: + return Position.ALARM_GEOFENCE_EXIT; + case 0x43: + return Position.ALARM_GEOFENCE_ENTER; + default: + return null; + } + } + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { @@ -116,7 +133,7 @@ public class TzoneProtocolDecoder extends BaseProtocolDecoder { if (blockLength > 0) { - position.set(Position.KEY_ALARM, buf.readUnsignedByte()); + position.set(Position.KEY_ALARM, decodeAlarm(buf.readUnsignedByte())); buf.readUnsignedByte(); // terminal info position.set(Position.PREFIX_IO + 1, buf.readUnsignedShort()); position.set(Position.KEY_GSM, buf.readUnsignedByte()); -- cgit v1.2.3