diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2016-08-05 08:50:20 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-05 08:50:20 +0300 |
commit | e15f80a0eb5c57a90a98773e8d21ae20e98a8910 (patch) | |
tree | 3d81f8c60ef3fe8adcd0064c01ab0695122baa8f | |
parent | 132fbb9bd658490ea77aae50e20257b680c3cceb (diff) | |
parent | 791a010e5a449a27e8243b9bc98c918ffa054eac (diff) | |
download | trackermap-server-e15f80a0eb5c57a90a98773e8d21ae20e98a8910.tar.gz trackermap-server-e15f80a0eb5c57a90a98773e8d21ae20e98a8910.tar.bz2 trackermap-server-e15f80a0eb5c57a90a98773e8d21ae20e98a8910.zip |
Merge pull request #2166 from Abyss777/alarms
Organized alarms in the first part of protocols
20 files changed, 163 insertions, 34 deletions
diff --git a/src/org/traccar/model/Position.java b/src/org/traccar/model/Position.java index e667f097d..d2409a75d 100644 --- a/src/org/traccar/model/Position.java +++ b/src/org/traccar/model/Position.java @@ -54,6 +54,7 @@ public class Position extends Message { public static final String KEY_APPROXIMATE = "approximate"; public static final String KEY_THROTTLE = "throttle"; public static final String KEY_MOTION = "motion"; + public static final String KEY_ARMED = "armed"; public static final String KEY_OBD_SPEED = "obd-speed"; public static final String KEY_OBD_ODOMETER = "obd-odometer"; @@ -65,15 +66,25 @@ public class Position extends Message { public static final String PREFIX_ADC = "adc"; public static final String PREFIX_IO = "io"; public static final String PREFIX_COUNT = "count"; + public static final String PREFIX_BUTTON = "button"; + public static final String ALARM_GENERAL = "general"; public static final String ALARM_SOS = "sos"; public static final String ALARM_VIBRATION = "vibration"; public static final String ALARM_MOVEMENT = "movement"; + public static final String ALARM_LOW_SPEED = "lowspeed"; public static final String ALARM_OVERSPEED = "overspeed"; public static final String ALARM_FALL_DOWN = "fallDown"; public static final String ALARM_LOW_BATTERY = "lowBattery"; public static final String ALARM_MOTION = "motion"; public static final String ALARM_FAULT = "fault"; + public static final String ALARM_POWER_OFF = "powerOff"; + public static final String ALARM_GEOFENCE = "geofence"; + public static final String ALARM_GEOFENCE_ENTER = "geofenceEnter"; + public static final String ALARM_GEOFENCE_EXIT = "geofenceExit"; + public static final String ALARM_GPS_ANTENNA_CUT = "gpsAntennaCut"; + public static final String ALARM_ACCIDENT = "accident"; + private String protocol; diff --git a/src/org/traccar/protocol/AutoFonProtocolDecoder.java b/src/org/traccar/protocol/AutoFonProtocolDecoder.java index dd0f54af0..90e8ca103 100644 --- a/src/org/traccar/protocol/AutoFonProtocolDecoder.java +++ b/src/org/traccar/protocol/AutoFonProtocolDecoder.java @@ -169,7 +169,9 @@ public class AutoFonProtocolDecoder extends BaseProtocolDecoder { position.setDeviceId(deviceSession.getDeviceId()); short status = buf.readUnsignedByte(); - position.set(Position.KEY_ALARM, BitUtil.check(status, 7)); + if (BitUtil.check(status, 7)) { + position.set(Position.KEY_ALARM, Position.ALARM_GENERAL); + } position.set(Position.KEY_BATTERY, BitUtil.to(status, 7)); buf.skipBytes(2); // remaining time diff --git a/src/org/traccar/protocol/Avl301ProtocolDecoder.java b/src/org/traccar/protocol/Avl301ProtocolDecoder.java index 4d2dfe126..818dd94df 100644 --- a/src/org/traccar/protocol/Avl301ProtocolDecoder.java +++ b/src/org/traccar/protocol/Avl301ProtocolDecoder.java @@ -123,7 +123,7 @@ public class Avl301ProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_LAC, buf.readUnsignedShort()); position.set(Position.KEY_CID, buf.readUnsignedMedium()); - position.set(Position.KEY_ALARM, true); + position.set(Position.KEY_ALARM, Position.ALARM_GENERAL); int flags = buf.readUnsignedByte(); position.set("acc", (flags & 0x2) != 0); diff --git a/src/org/traccar/protocol/BlackKiteProtocolDecoder.java b/src/org/traccar/protocol/BlackKiteProtocolDecoder.java index 92179072a..c2c051884 100644 --- a/src/org/traccar/protocol/BlackKiteProtocolDecoder.java +++ b/src/org/traccar/protocol/BlackKiteProtocolDecoder.java @@ -122,7 +122,9 @@ public class BlackKiteProtocolDecoder extends BaseProtocolDecoder { case TAG_STATUS: int status = buf.readUnsignedShort(); position.set(Position.KEY_IGNITION, BitUtil.check(status, 9)); - position.set(Position.KEY_ALARM, BitUtil.check(status, 15)); + if (BitUtil.check(status, 15)) { + position.set(Position.KEY_ALARM, Position.ALARM_GENERAL); + } position.set(Position.KEY_POWER, BitUtil.check(status, 2)); break; diff --git a/src/org/traccar/protocol/CarTrackProtocolDecoder.java b/src/org/traccar/protocol/CarTrackProtocolDecoder.java index e0fd60b15..0d21e77e6 100644 --- a/src/org/traccar/protocol/CarTrackProtocolDecoder.java +++ b/src/org/traccar/protocol/CarTrackProtocolDecoder.java @@ -99,7 +99,7 @@ public class CarTrackProtocolDecoder extends BaseProtocolDecoder { odometer = odometer.replace("?", "F"); position.set(Position.KEY_ODOMETER, Integer.parseInt(odometer, 16)); - position.set(Position.KEY_ALARM, parser.next()); + parser.next(); // there is no meaningful alarms position.set(Position.PREFIX_ADC + 1, parser.next()); return position; diff --git a/src/org/traccar/protocol/CarcellProtocolDecoder.java b/src/org/traccar/protocol/CarcellProtocolDecoder.java index 7aacfa4d0..e9b6cdf28 100644 --- a/src/org/traccar/protocol/CarcellProtocolDecoder.java +++ b/src/org/traccar/protocol/CarcellProtocolDecoder.java @@ -143,7 +143,9 @@ public class CarcellProtocolDecoder extends BaseProtocolDecoder { parser.next(); // panic button status String painelStatus = parser.next(); - position.set(Position.KEY_ALARM, painelStatus.equals("1")); + if (painelStatus.equals("1")) { + position.set(Position.KEY_ALARM, Position.ALARM_GENERAL); + } position.set("painel", painelStatus.equals("2")); Double mainVoltage = parser.nextDouble() / 100d; diff --git a/src/org/traccar/protocol/Gps103ProtocolDecoder.java b/src/org/traccar/protocol/Gps103ProtocolDecoder.java index 821cf2d21..b153984cb 100644 --- a/src/org/traccar/protocol/Gps103ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gps103ProtocolDecoder.java @@ -102,6 +102,25 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder { .any() .compile(); + private String decodeAlarm(String value) { + switch (value) { + case "tracker": + return null; + case "help me": + return Position.ALARM_SOS; + case "low battery": + return Position.ALARM_LOW_BATTERY; + case "stockade": + return Position.ALARM_GEOFENCE; + case "move": + return Position.ALARM_MOVEMENT; + case "speed": + return Position.ALARM_OVERSPEED; + default: + return null; + } + } + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { @@ -195,7 +214,7 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder { position.setDeviceId(deviceSession.getDeviceId()); String alarm = parser.next(); - position.set(Position.KEY_ALARM, alarm); + position.set(Position.KEY_ALARM, decodeAlarm(alarm)); if (channel != null && alarm.equals("help me")) { channel.write("**,imei:" + imei + ",E;", remoteAddress); } diff --git a/src/org/traccar/protocol/GranitProtocolDecoder.java b/src/org/traccar/protocol/GranitProtocolDecoder.java index 0c7ea4d1d..3a2d24fa2 100644 --- a/src/org/traccar/protocol/GranitProtocolDecoder.java +++ b/src/org/traccar/protocol/GranitProtocolDecoder.java @@ -71,7 +71,9 @@ public class GranitProtocolDecoder extends BaseProtocolDecoder { private static void decodeStructure(ChannelBuffer buf, Position position) { short flags = buf.readUnsignedByte(); position.setValid(BitUtil.check(flags, 7)); - position.set(Position.KEY_ALARM, BitUtil.check(flags, 1)); + if (BitUtil.check(flags, 1)) { + position.set(Position.KEY_ALARM, Position.ALARM_GENERAL); + } short satDel = buf.readUnsignedByte(); position.set(Position.KEY_SATELLITES, BitUtil.from(satDel, 4)); diff --git a/src/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/org/traccar/protocol/Gt06ProtocolDecoder.java index 3e875086e..d69f425ab 100644 --- a/src/org/traccar/protocol/Gt06ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gt06ProtocolDecoder.java @@ -154,7 +154,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { private void decodeStatus(Position position, ChannelBuffer buf) { - position.set(Position.KEY_ALARM, true); + position.set(Position.KEY_ALARM, Position.ALARM_GENERAL); int flags = buf.readUnsignedByte(); diff --git a/src/org/traccar/protocol/H02ProtocolDecoder.java b/src/org/traccar/protocol/H02ProtocolDecoder.java index bb18a68e2..fc6c9f17c 100644 --- a/src/org/traccar/protocol/H02ProtocolDecoder.java +++ b/src/org/traccar/protocol/H02ProtocolDecoder.java @@ -65,20 +65,15 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { private void processStatus(Position position, long status) { if (!BitUtil.check(status, 0) || !BitUtil.check(status, 1) - || !BitUtil.check(status, 3) || !BitUtil.check(status, 4) || !BitUtil.check(status, 7)) { + || !BitUtil.check(status, 2)) { if (!BitUtil.check(status, 0)) { position.set(Position.KEY_ALARM, Position.ALARM_VIBRATION); } else if (!BitUtil.check(status, 1)) { - position.set(Position.KEY_ALARM, "robbery"); - } else if (!BitUtil.check(status, 3)) { - position.set(Position.KEY_ALARM, "illegal ignition"); - } else if (!BitUtil.check(status, 4)) { - position.set(Position.KEY_ALARM, "entering"); - } else if (!BitUtil.check(status, 7)) { - position.set(Position.KEY_ALARM, "out"); + position.set(Position.KEY_ALARM, Position.ALARM_SOS); + } else if (!BitUtil.check(status, 2)) { + position.set(Position.KEY_ALARM, Position.ALARM_OVERSPEED); } - } position.set(Position.KEY_IGNITION, BitUtil.check(status, 10)); position.set(Position.KEY_STATUS, status); diff --git a/src/org/traccar/protocol/Jt600ProtocolDecoder.java b/src/org/traccar/protocol/Jt600ProtocolDecoder.java index 7e0b54456..372b4cac1 100644 --- a/src/org/traccar/protocol/Jt600ProtocolDecoder.java +++ b/src/org/traccar/protocol/Jt600ProtocolDecoder.java @@ -151,7 +151,7 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder { Position position = new Position(); position.setProtocol(getProtocolName()); - position.set(Position.KEY_ALARM, true); + position.set(Position.KEY_ALARM, Position.ALARM_GENERAL); DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next()); if (deviceSession == null) { diff --git a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java index 9c7e9ea23..41e248791 100644 --- a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java +++ b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java @@ -151,6 +151,27 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { return server; } + 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 0x12: + return Position.ALARM_MOVEMENT; + case 0x13: + return Position.ALARM_GEOFENCE_ENTER; + case 0x50: + return Position.ALARM_POWER_OFF; + case 0x53: + return Position.ALARM_GPS_ANTENNA_CUT; + default: + return null; + } + } + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { @@ -196,7 +217,7 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { // Custom data if (command == MSG_ALARM) { - position.set(Position.KEY_ALARM, buf.readUnsignedByte()); + position.set(Position.KEY_ALARM, decodeAlarm(buf.readUnsignedByte())); } else if (command == MSG_POSITION_LOGGED) { buf.skipBytes(6); } diff --git a/src/org/traccar/protocol/MxtProtocolDecoder.java b/src/org/traccar/protocol/MxtProtocolDecoder.java index 56024057e..1dbfc3696 100644 --- a/src/org/traccar/protocol/MxtProtocolDecoder.java +++ b/src/org/traccar/protocol/MxtProtocolDecoder.java @@ -82,7 +82,9 @@ public class MxtProtocolDecoder extends BaseProtocolDecoder { long flags = buf.readUnsignedInt(); position.set(Position.KEY_IGNITION, BitUtil.check(flags, 0)); - position.set(Position.KEY_ALARM, BitUtil.check(flags, 1)); + if (BitUtil.check(flags, 1)) { + position.set(Position.KEY_ALARM, Position.ALARM_GENERAL); + } position.set(Position.KEY_INPUT, BitUtil.between(flags, 2, 7)); position.set(Position.KEY_OUTPUT, BitUtil.between(flags, 7, 10)); position.setCourse(BitUtil.between(flags, 10, 13) * 45); diff --git a/src/org/traccar/protocol/NavisProtocolDecoder.java b/src/org/traccar/protocol/NavisProtocolDecoder.java index fad24301c..72c5f53c3 100644 --- a/src/org/traccar/protocol/NavisProtocolDecoder.java +++ b/src/org/traccar/protocol/NavisProtocolDecoder.java @@ -95,7 +95,11 @@ public class NavisProtocolDecoder extends BaseProtocolDecoder { buf.skipBytes(6); // event time - position.set(Position.KEY_ALARM, buf.readUnsignedByte()); + short armedStatus = buf.readUnsignedByte(); + position.set(Position.KEY_ARMED, armedStatus & 0x7F); + if (BitUtil.check(armedStatus, 7)) { + position.set(Position.KEY_ALARM, Position.ALARM_GENERAL); + } position.set(Position.KEY_STATUS, buf.readUnsignedByte()); position.set(Position.KEY_GSM, buf.readUnsignedByte()); diff --git a/src/org/traccar/protocol/NoranProtocolDecoder.java b/src/org/traccar/protocol/NoranProtocolDecoder.java index c2161d9c9..aaecfc1db 100644 --- a/src/org/traccar/protocol/NoranProtocolDecoder.java +++ b/src/org/traccar/protocol/NoranProtocolDecoder.java @@ -90,7 +90,23 @@ public class NoranProtocolDecoder extends BaseProtocolDecoder { position.setValid(BitUtil.check(buf.readUnsignedByte(), 0)); - position.set(Position.KEY_ALARM, buf.readUnsignedByte()); + short alarm = buf.readUnsignedByte(); + switch (alarm) { + case 1: + position.set(Position.KEY_ALARM, Position.ALARM_SOS); + break; + case 2: + position.set(Position.KEY_ALARM, Position.ALARM_OVERSPEED); + break; + case 3: + position.set(Position.KEY_ALARM, Position.ALARM_GEOFENCE_EXIT); + break; + case 9: + position.set(Position.KEY_ALARM, Position.ALARM_POWER_OFF); + break; + default: + break; + } if (newFormat) { position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedInt())); diff --git a/src/org/traccar/protocol/ProgressProtocolDecoder.java b/src/org/traccar/protocol/ProgressProtocolDecoder.java index e524626fa..0032a9a1b 100644 --- a/src/org/traccar/protocol/ProgressProtocolDecoder.java +++ b/src/org/traccar/protocol/ProgressProtocolDecoder.java @@ -104,7 +104,7 @@ public class ProgressProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_ARCHIVE, true); int subtype = buf.readUnsignedShort(); if (subtype == MSG_ALARM) { - position.set(Position.KEY_ALARM, true); + position.set(Position.KEY_ALARM, Position.ALARM_GENERAL); } if (buf.readUnsignedShort() > buf.readableBytes()) { lastIndex += 1; diff --git a/src/org/traccar/protocol/SuntechProtocolDecoder.java b/src/org/traccar/protocol/SuntechProtocolDecoder.java index 5169e7c67..503f4d6f8 100644 --- a/src/org/traccar/protocol/SuntechProtocolDecoder.java +++ b/src/org/traccar/protocol/SuntechProtocolDecoder.java @@ -68,7 +68,7 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder { if (parser.hasNext()) { String type = parser.next(); if (type.equals("Alert") || type.equals("Emergency")) { - position.set(Position.KEY_ALARM, true); + position.set(Position.KEY_ALARM, Position.ALARM_GENERAL); } } diff --git a/src/org/traccar/protocol/Tk103ProtocolDecoder.java b/src/org/traccar/protocol/Tk103ProtocolDecoder.java index a76c208b5..55a41f5a2 100644 --- a/src/org/traccar/protocol/Tk103ProtocolDecoder.java +++ b/src/org/traccar/protocol/Tk103ProtocolDecoder.java @@ -75,6 +75,25 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { .any() .compile(); + private String decodeAlarm(int value) { + switch (value) { + case 1: + return Position.ALARM_ACCIDENT; + case 2: + return Position.ALARM_SOS; + case 3: + return Position.ALARM_VIBRATION; + case 4: + return Position.ALARM_LOW_SPEED; + case 5: + return Position.ALARM_OVERSPEED; + case 6: + return Position.ALARM_GEOFENCE_EXIT; + default: + return null; + } + } + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { @@ -160,7 +179,7 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { int alarm = sentence.indexOf("BO01"); if (alarm != -1) { - position.set(Position.KEY_ALARM, Integer.parseInt(sentence.substring(alarm + 4, alarm + 5))); + position.set(Position.KEY_ALARM, decodeAlarm(Integer.parseInt(sentence.substring(alarm + 4, alarm + 5)))); } DateBuilder dateBuilder = new DateBuilder(); diff --git a/src/org/traccar/protocol/TotemProtocolDecoder.java b/src/org/traccar/protocol/TotemProtocolDecoder.java index 7b196f5ad..72c0f6306 100644 --- a/src/org/traccar/protocol/TotemProtocolDecoder.java +++ b/src/org/traccar/protocol/TotemProtocolDecoder.java @@ -159,6 +159,23 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder { .any() .compile(); + 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 { @@ -193,9 +210,9 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder { position.setDeviceId(deviceSession.getDeviceId()); if (pattern == PATTERN1 || pattern == PATTERN2) { - - position.set(Position.KEY_ALARM, parser.next()); - + if (parser.hasNext()) { + position.set(Position.KEY_ALARM, decodeAlarm(Short.parseShort(parser.next(), 16))); + } DateBuilder dateBuilder = new DateBuilder(); int year = 0; if (pattern == PATTERN2) { @@ -238,9 +255,9 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_ODOMETER, parser.next()); } else if (pattern == PATTERN3) { - - position.set(Position.KEY_ALARM, parser.next()); - + if (parser.hasNext()) { + position.set(Position.KEY_ALARM, decodeAlarm(Short.parseShort(parser.next(), 16))); + } DateBuilder dateBuilder = new DateBuilder() .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()) .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); @@ -304,11 +321,9 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder { position.setLongitude(parser.nextCoordinate()); } - if (channel != null) { channel.write("ACK OK\r\n"); } - return position; } diff --git a/src/org/traccar/protocol/UlbotechProtocolDecoder.java b/src/org/traccar/protocol/UlbotechProtocolDecoder.java index c17341b5f..36fb23f9a 100644 --- a/src/org/traccar/protocol/UlbotechProtocolDecoder.java +++ b/src/org/traccar/protocol/UlbotechProtocolDecoder.java @@ -115,6 +115,25 @@ public class UlbotechProtocolDecoder extends BaseProtocolDecoder { } } + private String decodeAlarm(int alarm) { + if (BitUtil.check(alarm, 0)) { + return Position.ALARM_POWER_OFF; + } + if (BitUtil.check(alarm, 1)) { + return Position.ALARM_MOTION; + } + if (BitUtil.check(alarm, 2)) { + return Position.ALARM_OVERSPEED; + } + if (BitUtil.check(alarm, 4)) { + return Position.ALARM_GEOFENCE; + } + if (BitUtil.check(alarm, 10)) { + return Position.ALARM_SOS; + } + return null; + } + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { @@ -181,7 +200,7 @@ public class UlbotechProtocolDecoder extends BaseProtocolDecoder { int status = buf.readUnsignedShort(); position.set(Position.KEY_IGNITION, BitUtil.check(status, 9)); position.set(Position.KEY_STATUS, status); - position.set(Position.KEY_ALARM, buf.readUnsignedShort()); + position.set(Position.KEY_ALARM, decodeAlarm(buf.readUnsignedShort())); break; case DATA_ODOMETER: |