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 From 96f0143b2cbbb93f1c325e1df7c66a2fc3d55b7e Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Tue, 16 Aug 2016 14:16:40 +0500 Subject: GT06 Added alarm decoder for status packets --- src/org/traccar/protocol/Gt06ProtocolDecoder.java | 27 ++++++++++++++++++++-- .../traccar/protocol/Gt06ProtocolDecoderTest.java | 3 +++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/org/traccar/protocol/Gt06ProtocolDecoder.java index d69f425ab..c0b475b1e 100644 --- a/src/org/traccar/protocol/Gt06ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gt06ProtocolDecoder.java @@ -154,14 +154,37 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { private void decodeStatus(Position position, ChannelBuffer buf) { - position.set(Position.KEY_ALARM, Position.ALARM_GENERAL); - int flags = buf.readUnsignedByte(); position.set(Position.KEY_IGNITION, BitUtil.check(flags, 1)); position.set(Position.KEY_STATUS, flags); position.set(Position.KEY_BATTERY, buf.readUnsignedByte()); position.set(Position.KEY_GSM, buf.readUnsignedByte()); + position.set(Position.KEY_ALARM, decodeAlarm(buf.readUnsignedByte())); + } + + private String decodeAlarm(short value) { + switch (value) { + case 0x01: + return Position.ALARM_SOS; + case 0x03: + case 0x09: + return Position.ALARM_VIBRATION; + case 0x04: + return Position.ALARM_GEOFENCE_ENTER; + case 0x05: + return Position.ALARM_GEOFENCE_EXIT; + case 0x06: + return Position.ALARM_OVERSPEED; + case 0x0E: + case 0x0F: + return Position.ALARM_LOW_BATTERY; + case 0x11: + return Position.ALARM_LOW_BATTERY; + default: + break; + } + return null; } @Override diff --git a/test/org/traccar/protocol/Gt06ProtocolDecoderTest.java b/test/org/traccar/protocol/Gt06ProtocolDecoderTest.java index 3343f72e2..8b6b65b8c 100644 --- a/test/org/traccar/protocol/Gt06ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Gt06ProtocolDecoderTest.java @@ -43,6 +43,9 @@ public class Gt06ProtocolDecoderTest extends ProtocolTest { verifyAttributes(decoder, binary( "78780a13440604000201baaf540d0a")); + verifyAttributes(decoder, binary( + "787825160F0C1D0A2B21C8027AC8040C46581000146F0901CC00287D001F714804040301001C84CF0D0A")); + verifyPosition(decoder, binary( "78781f120f0a140e150bc505e51e780293a9e800540000f601006e0055da00035f240d0a"), position("2015-10-20 14:21:11.000", true, 54.94535, 24.01762)); -- cgit v1.2.3