From 20c2456a9df46eaef04c787ea5471bf31a71f93c Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Fri, 29 Jul 2016 15:50:59 +0500 Subject: Organized alarms in the first part of protocols --- src/org/traccar/model/Position.java | 31 +++++++++++++++ .../traccar/protocol/GranitProtocolDecoder.java | 4 +- .../traccar/protocol/MeiligaoProtocolDecoder.java | 30 ++++++++++++++- src/org/traccar/protocol/MxtProtocolDecoder.java | 4 +- src/org/traccar/protocol/NavisProtocolDecoder.java | 6 ++- src/org/traccar/protocol/NoranProtocolDecoder.java | 13 ++++++- .../traccar/protocol/ProgressProtocolDecoder.java | 2 +- .../traccar/protocol/SuntechProtocolDecoder.java | 2 +- src/org/traccar/protocol/TotemProtocolDecoder.java | 44 ++++++++++++++++++---- .../traccar/protocol/UlbotechProtocolDecoder.java | 33 +++++++++++++++- 10 files changed, 153 insertions(+), 16 deletions(-) diff --git a/src/org/traccar/model/Position.java b/src/org/traccar/model/Position.java index e667f097d..3b6b9c8b1 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_GUARD = "guard"; public static final String KEY_OBD_SPEED = "obd-speed"; public static final String KEY_OBD_ODOMETER = "obd-odometer"; @@ -65,15 +66,45 @@ 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 ENDING_PRESSED = "Pressed"; + public static final String ENDING_RELEASED = "Released"; + public static final String ENDING_OPEN = "Open"; + public static final String ENDING_CLOSE = "Close"; + public static final String ENDING_ACTIVE = "Active"; + public static final String ENDING_INACTIVE = "Inactive"; + + + 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_OVERSPEED = "overspeed"; + public static final String ALARM_OVERSPEED_END = "overspeedEnd"; 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_JAMMING = "jamming"; + 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_ODB = "odb"; + public static final String ALARM_POWER_LOW = "powerLow"; + public static final String ALARM_PARKING = "parking"; + public static final String ALARM_CHARGE_BEGIN = "chargeBegin"; + public static final String ALARM_CHARGE_END = "chargeEnd"; + public static final String ALARM_RFID_NEW = "rfidNew"; + public static final String ALARM_SLEEP_INTO = "intoSleep"; + public static final String ALARM_SLEEP_FROM = "fromSleep"; + public static final String ALARM_TRACKER_ON = "trackerOn"; + public static final String ALARM_SHUTDOWN = "shutdown"; + public static final String ALARM_GPS_BLIND_ENTER = "gpsBlindEnter"; + public static final String ALARM_GPS_BLIND_EXIT = "gpsBlindExit"; + public static final String ALARM_GPS_ANTENNA_CUT = "gpsAntennaCut"; + private String protocol; 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/MeiligaoProtocolDecoder.java b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java index 9c7e9ea23..196b24d27 100644 --- a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java +++ b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java @@ -150,6 +150,31 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { } return server; } + + private String decodeAlarm(short value) { + switch (value) { + case 0x01: return Position.ALARM_SOS; + case 0x02: return Position.PREFIX_BUTTON + "B" + Position.ENDING_PRESSED; + case 0x03: return Position.PREFIX_BUTTON + "C" + Position.ENDING_PRESSED; + case 0x04: return Position.PREFIX_IO + "4" + Position.ENDING_ACTIVE; + case 0x05: return Position.PREFIX_IO + "5" + Position.ENDING_ACTIVE; + 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 0x14: return Position.ALARM_TRACKER_ON; + case 0x15: return Position.ALARM_GPS_BLIND_ENTER; + case 0x16: return Position.ALARM_GPS_BLIND_EXIT; + case 0x31: return Position.ALARM_SOS + Position.ENDING_RELEASED; + case 0x32: return Position.PREFIX_BUTTON + "B" + Position.ENDING_RELEASED; + case 0x33: return Position.PREFIX_BUTTON + "C" + Position.ENDING_RELEASED; + case 0x34: return Position.PREFIX_IO + "4" + Position.ENDING_INACTIVE; + case 0x35: return Position.PREFIX_IO + "5" + Position.ENDING_INACTIVE; + case 0x50: return Position.ALARM_POWER_OFF; + case 0x53: return Position.ALARM_GPS_ANTENNA_CUT; + default: return null; + } + } @Override protected Object decode( @@ -196,7 +221,10 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { // Custom data if (command == MSG_ALARM) { - position.set(Position.KEY_ALARM, buf.readUnsignedByte()); + String alarm = decodeAlarm(buf.readUnsignedByte()); + if (alarm != null) { + position.set(Position.KEY_ALARM, alarm); + } } 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..046068c5d 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 guardStatus = buf.readUnsignedByte(); + position.set(Position.KEY_GUARD, guardStatus & 0x7F); + if (BitUtil.check(guardStatus, 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..7071b9625 100644 --- a/src/org/traccar/protocol/NoranProtocolDecoder.java +++ b/src/org/traccar/protocol/NoranProtocolDecoder.java @@ -90,7 +90,18 @@ public class NoranProtocolDecoder extends BaseProtocolDecoder { position.setValid(BitUtil.check(buf.readUnsignedByte(), 0)); - position.set(Position.KEY_ALARM, buf.readUnsignedByte()); + short alarm = buf.readUnsignedByte(); + if (alarm != 0x80) { + if (alarm == 1) { + position.set(Position.KEY_ALARM, Position.ALARM_SOS); + } else if (alarm == 2) { + position.set(Position.KEY_ALARM, Position.ALARM_OVERSPEED); + } else if (alarm == 3) { + position.set(Position.KEY_ALARM, Position.ALARM_GEOFENCE_EXIT); + } else if (alarm == 9) { + position.set(Position.KEY_ALARM, Position.ALARM_POWER_OFF); + } + } 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/TotemProtocolDecoder.java b/src/org/traccar/protocol/TotemProtocolDecoder.java index 7b196f5ad..97201521d 100644 --- a/src/org/traccar/protocol/TotemProtocolDecoder.java +++ b/src/org/traccar/protocol/TotemProtocolDecoder.java @@ -159,6 +159,34 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder { .any() .compile(); + private String decodeAlarm(String value) { + switch (value) { + case "01": return Position.ALARM_SOS; + case "49": return Position.PREFIX_BUTTON + "A" + Position.ENDING_PRESSED; + case "09": return Position.ALARM_SHUTDOWN; + case "10": return Position.ALARM_LOW_BATTERY; + case "11": return Position.ALARM_OVERSPEED; + case "13": return Position.ALARM_OVERSPEED_END; + case "30": return Position.ALARM_PARKING; + case "42": return Position.ALARM_GEOFENCE_EXIT; + case "43": return Position.ALARM_GEOFENCE_ENTER; + case "50": return Position.PREFIX_IO + "1" + Position.ENDING_CLOSE; + case "51": return Position.PREFIX_IO + "1" + Position.ENDING_OPEN; + case "52": return Position.PREFIX_IO + "2" + Position.ENDING_CLOSE; + case "53": return Position.PREFIX_IO + "2" + Position.ENDING_OPEN; + case "54": return Position.PREFIX_IO + "3" + Position.ENDING_CLOSE; + case "55": return Position.PREFIX_IO + "3" + Position.ENDING_OPEN; + case "56": return Position.PREFIX_IO + "4" + Position.ENDING_CLOSE; + case "57": return Position.PREFIX_IO + "4" + Position.ENDING_OPEN; + case "60": return Position.ALARM_CHARGE_BEGIN; + case "61": return Position.ALARM_CHARGE_END; + case "66": return Position.ALARM_RFID_NEW; + case "91": return Position.ALARM_SLEEP_INTO; + case "92": return Position.ALARM_SLEEP_FROM; + default: return null; + } + } + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { @@ -193,9 +221,10 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder { position.setDeviceId(deviceSession.getDeviceId()); if (pattern == PATTERN1 || pattern == PATTERN2) { - - position.set(Position.KEY_ALARM, parser.next()); - + String alarm = decodeAlarm(parser.next()); + if (alarm != null) { + position.set(Position.KEY_ALARM, alarm); + } DateBuilder dateBuilder = new DateBuilder(); int year = 0; if (pattern == PATTERN2) { @@ -238,9 +267,10 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_ODOMETER, parser.next()); } else if (pattern == PATTERN3) { - - position.set(Position.KEY_ALARM, parser.next()); - + String alarm = decodeAlarm(parser.next()); + if (alarm != null) { + position.set(Position.KEY_ALARM, alarm); + } DateBuilder dateBuilder = new DateBuilder() .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()) .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); @@ -304,11 +334,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..7abe9fb70 100644 --- a/src/org/traccar/protocol/UlbotechProtocolDecoder.java +++ b/src/org/traccar/protocol/UlbotechProtocolDecoder.java @@ -115,6 +115,34 @@ 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, 3)) { + return Position.ALARM_JAMMING; + } + if (BitUtil.check(alarm, 4)) { + return Position.ALARM_GEOFENCE; + } + if (BitUtil.check(alarm, 10)) { + return Position.ALARM_SOS; + } + if (BitUtil.check(alarm, 11)) { + return Position.ALARM_ODB; + } + if (BitUtil.check(alarm, 15)) { + return Position.ALARM_POWER_LOW; + } + return null; + } + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { @@ -181,7 +209,10 @@ 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()); + String alarm = decodeAlarm(buf.readUnsignedShort()); + if (alarm != null) { + position.set(Position.KEY_ALARM, alarm); + } break; case DATA_ODOMETER: -- cgit v1.2.3 From c41c8edd7e4d275885cbef72212e553a2c86c9b4 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Mon, 1 Aug 2016 12:10:17 +0500 Subject: - Added a few more protocols - Removed useless alarms - Optimizations --- src/org/traccar/model/Position.java | 24 ++----------- .../traccar/protocol/AutoFonProtocolDecoder.java | 4 ++- .../traccar/protocol/Avl301ProtocolDecoder.java | 2 +- .../traccar/protocol/BlackKiteProtocolDecoder.java | 4 ++- .../traccar/protocol/CarTrackProtocolDecoder.java | 2 +- .../traccar/protocol/CarcellProtocolDecoder.java | 4 ++- .../traccar/protocol/Gps103ProtocolDecoder.java | 19 ++++++++++- src/org/traccar/protocol/Gt06ProtocolDecoder.java | 2 +- src/org/traccar/protocol/H02ProtocolDecoder.java | 13 +++----- src/org/traccar/protocol/Jt600ProtocolDecoder.java | 2 +- .../traccar/protocol/MeiligaoProtocolDecoder.java | 14 +------- src/org/traccar/protocol/NoranProtocolDecoder.java | 18 +++++----- src/org/traccar/protocol/Tk103ProtocolDecoder.java | 15 ++++++++- src/org/traccar/protocol/TotemProtocolDecoder.java | 39 ++++++---------------- .../traccar/protocol/UlbotechProtocolDecoder.java | 11 +----- 15 files changed, 72 insertions(+), 101 deletions(-) diff --git a/src/org/traccar/model/Position.java b/src/org/traccar/model/Position.java index 3b6b9c8b1..868719033 100644 --- a/src/org/traccar/model/Position.java +++ b/src/org/traccar/model/Position.java @@ -68,20 +68,12 @@ public class Position extends Message { public static final String PREFIX_COUNT = "count"; public static final String PREFIX_BUTTON = "button"; - public static final String ENDING_PRESSED = "Pressed"; - public static final String ENDING_RELEASED = "Released"; - public static final String ENDING_OPEN = "Open"; - public static final String ENDING_CLOSE = "Close"; - public static final String ENDING_ACTIVE = "Active"; - public static final String ENDING_INACTIVE = "Inactive"; - - 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_OVERSPEED_END = "overspeedEnd"; public static final String ALARM_FALL_DOWN = "fallDown"; public static final String ALARM_LOW_BATTERY = "lowBattery"; public static final String ALARM_MOTION = "motion"; @@ -91,19 +83,9 @@ public class Position extends Message { 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_ODB = "odb"; - public static final String ALARM_POWER_LOW = "powerLow"; - public static final String ALARM_PARKING = "parking"; - public static final String ALARM_CHARGE_BEGIN = "chargeBegin"; - public static final String ALARM_CHARGE_END = "chargeEnd"; - public static final String ALARM_RFID_NEW = "rfidNew"; - public static final String ALARM_SLEEP_INTO = "intoSleep"; - public static final String ALARM_SLEEP_FROM = "fromSleep"; - public static final String ALARM_TRACKER_ON = "trackerOn"; - public static final String ALARM_SHUTDOWN = "shutdown"; - public static final String ALARM_GPS_BLIND_ENTER = "gpsBlindEnter"; - public static final String ALARM_GPS_BLIND_EXIT = "gpsBlindExit"; public static final String ALARM_GPS_ANTENNA_CUT = "gpsAntennaCut"; + public static final String ALARM_OIL_CUT = "oilCut"; + 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..45f1b0812 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..9d3fda345 100644 --- a/src/org/traccar/protocol/Gps103ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gps103ProtocolDecoder.java @@ -102,6 +102,23 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder { .any() .compile(); + private String decodeAlarm(String value) { + if (value == "tracker") { + return null; + } else if (value == "help me") { + return Position.ALARM_SOS; + } else if (value == "low battery") { + return Position.ALARM_LOW_BATTERY; + } else if (value == "stockade") { + return Position.ALARM_GEOFENCE; + } else if (value == "move") { + return Position.ALARM_MOVEMENT; + } else if (value == "speed") { + return Position.ALARM_OVERSPEED; + } + return null; + } + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { @@ -195,7 +212,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/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 196b24d27..f23641ddb 100644 --- a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java +++ b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java @@ -150,26 +150,14 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { } return server; } - + private String decodeAlarm(short value) { switch (value) { case 0x01: return Position.ALARM_SOS; - case 0x02: return Position.PREFIX_BUTTON + "B" + Position.ENDING_PRESSED; - case 0x03: return Position.PREFIX_BUTTON + "C" + Position.ENDING_PRESSED; - case 0x04: return Position.PREFIX_IO + "4" + Position.ENDING_ACTIVE; - case 0x05: return Position.PREFIX_IO + "5" + Position.ENDING_ACTIVE; 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 0x14: return Position.ALARM_TRACKER_ON; - case 0x15: return Position.ALARM_GPS_BLIND_ENTER; - case 0x16: return Position.ALARM_GPS_BLIND_EXIT; - case 0x31: return Position.ALARM_SOS + Position.ENDING_RELEASED; - case 0x32: return Position.PREFIX_BUTTON + "B" + Position.ENDING_RELEASED; - case 0x33: return Position.PREFIX_BUTTON + "C" + Position.ENDING_RELEASED; - case 0x34: return Position.PREFIX_IO + "4" + Position.ENDING_INACTIVE; - case 0x35: return Position.PREFIX_IO + "5" + Position.ENDING_INACTIVE; case 0x50: return Position.ALARM_POWER_OFF; case 0x53: return Position.ALARM_GPS_ANTENNA_CUT; default: return null; diff --git a/src/org/traccar/protocol/NoranProtocolDecoder.java b/src/org/traccar/protocol/NoranProtocolDecoder.java index 7071b9625..5b4533422 100644 --- a/src/org/traccar/protocol/NoranProtocolDecoder.java +++ b/src/org/traccar/protocol/NoranProtocolDecoder.java @@ -91,16 +91,14 @@ public class NoranProtocolDecoder extends BaseProtocolDecoder { position.setValid(BitUtil.check(buf.readUnsignedByte(), 0)); short alarm = buf.readUnsignedByte(); - if (alarm != 0x80) { - if (alarm == 1) { - position.set(Position.KEY_ALARM, Position.ALARM_SOS); - } else if (alarm == 2) { - position.set(Position.KEY_ALARM, Position.ALARM_OVERSPEED); - } else if (alarm == 3) { - position.set(Position.KEY_ALARM, Position.ALARM_GEOFENCE_EXIT); - } else if (alarm == 9) { - position.set(Position.KEY_ALARM, Position.ALARM_POWER_OFF); - } + if (alarm == 1) { + position.set(Position.KEY_ALARM, Position.ALARM_SOS); + } else if (alarm == 2) { + position.set(Position.KEY_ALARM, Position.ALARM_OVERSPEED); + } else if (alarm == 3) { + position.set(Position.KEY_ALARM, Position.ALARM_GEOFENCE_EXIT); + } else if (alarm == 9) { + position.set(Position.KEY_ALARM, Position.ALARM_POWER_OFF); } if (newFormat) { diff --git a/src/org/traccar/protocol/Tk103ProtocolDecoder.java b/src/org/traccar/protocol/Tk103ProtocolDecoder.java index a76c208b5..72ecdc2de 100644 --- a/src/org/traccar/protocol/Tk103ProtocolDecoder.java +++ b/src/org/traccar/protocol/Tk103ProtocolDecoder.java @@ -75,6 +75,19 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { .any() .compile(); + private String decodeAlarm(int value) { + switch (value) { + case 0: return Position.ALARM_OIL_CUT; + 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 +173,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 97201521d..fed1c3bd8 100644 --- a/src/org/traccar/protocol/TotemProtocolDecoder.java +++ b/src/org/traccar/protocol/TotemProtocolDecoder.java @@ -159,30 +159,13 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder { .any() .compile(); - private String decodeAlarm(String value) { + private String decodeAlarm(Short value) { switch (value) { - case "01": return Position.ALARM_SOS; - case "49": return Position.PREFIX_BUTTON + "A" + Position.ENDING_PRESSED; - case "09": return Position.ALARM_SHUTDOWN; - case "10": return Position.ALARM_LOW_BATTERY; - case "11": return Position.ALARM_OVERSPEED; - case "13": return Position.ALARM_OVERSPEED_END; - case "30": return Position.ALARM_PARKING; - case "42": return Position.ALARM_GEOFENCE_EXIT; - case "43": return Position.ALARM_GEOFENCE_ENTER; - case "50": return Position.PREFIX_IO + "1" + Position.ENDING_CLOSE; - case "51": return Position.PREFIX_IO + "1" + Position.ENDING_OPEN; - case "52": return Position.PREFIX_IO + "2" + Position.ENDING_CLOSE; - case "53": return Position.PREFIX_IO + "2" + Position.ENDING_OPEN; - case "54": return Position.PREFIX_IO + "3" + Position.ENDING_CLOSE; - case "55": return Position.PREFIX_IO + "3" + Position.ENDING_OPEN; - case "56": return Position.PREFIX_IO + "4" + Position.ENDING_CLOSE; - case "57": return Position.PREFIX_IO + "4" + Position.ENDING_OPEN; - case "60": return Position.ALARM_CHARGE_BEGIN; - case "61": return Position.ALARM_CHARGE_END; - case "66": return Position.ALARM_RFID_NEW; - case "91": return Position.ALARM_SLEEP_INTO; - case "92": return Position.ALARM_SLEEP_FROM; + 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; } } @@ -221,9 +204,8 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder { position.setDeviceId(deviceSession.getDeviceId()); if (pattern == PATTERN1 || pattern == PATTERN2) { - String alarm = decodeAlarm(parser.next()); - if (alarm != null) { - position.set(Position.KEY_ALARM, alarm); + if (parser.hasNext()) { + position.set(Position.KEY_ALARM, decodeAlarm(Short.parseShort(parser.next(), 16))); } DateBuilder dateBuilder = new DateBuilder(); int year = 0; @@ -267,9 +249,8 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_ODOMETER, parser.next()); } else if (pattern == PATTERN3) { - String alarm = decodeAlarm(parser.next()); - if (alarm != null) { - position.set(Position.KEY_ALARM, alarm); + 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()) diff --git a/src/org/traccar/protocol/UlbotechProtocolDecoder.java b/src/org/traccar/protocol/UlbotechProtocolDecoder.java index 7abe9fb70..0cde5c0d4 100644 --- a/src/org/traccar/protocol/UlbotechProtocolDecoder.java +++ b/src/org/traccar/protocol/UlbotechProtocolDecoder.java @@ -134,12 +134,6 @@ public class UlbotechProtocolDecoder extends BaseProtocolDecoder { if (BitUtil.check(alarm, 10)) { return Position.ALARM_SOS; } - if (BitUtil.check(alarm, 11)) { - return Position.ALARM_ODB; - } - if (BitUtil.check(alarm, 15)) { - return Position.ALARM_POWER_LOW; - } return null; } @@ -209,10 +203,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); - String alarm = decodeAlarm(buf.readUnsignedShort()); - if (alarm != null) { - position.set(Position.KEY_ALARM, alarm); - } + position.set(Position.KEY_ALARM, decodeAlarm(buf.readUnsignedShort())); break; case DATA_ODOMETER: -- cgit v1.2.3 From a2214178139b7fb097e2b6aee2518a0255d44f06 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Mon, 1 Aug 2016 12:21:44 +0500 Subject: Removed jamming --- src/org/traccar/model/Position.java | 1 - src/org/traccar/protocol/UlbotechProtocolDecoder.java | 3 --- 2 files changed, 4 deletions(-) diff --git a/src/org/traccar/model/Position.java b/src/org/traccar/model/Position.java index 868719033..a62839702 100644 --- a/src/org/traccar/model/Position.java +++ b/src/org/traccar/model/Position.java @@ -79,7 +79,6 @@ public class Position extends Message { 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_JAMMING = "jamming"; public static final String ALARM_GEOFENCE = "geofence"; public static final String ALARM_GEOFENCE_ENTER = "geofenceEnter"; public static final String ALARM_GEOFENCE_EXIT = "geofenceExit"; diff --git a/src/org/traccar/protocol/UlbotechProtocolDecoder.java b/src/org/traccar/protocol/UlbotechProtocolDecoder.java index 0cde5c0d4..36fb23f9a 100644 --- a/src/org/traccar/protocol/UlbotechProtocolDecoder.java +++ b/src/org/traccar/protocol/UlbotechProtocolDecoder.java @@ -125,9 +125,6 @@ public class UlbotechProtocolDecoder extends BaseProtocolDecoder { if (BitUtil.check(alarm, 2)) { return Position.ALARM_OVERSPEED; } - if (BitUtil.check(alarm, 3)) { - return Position.ALARM_JAMMING; - } if (BitUtil.check(alarm, 4)) { return Position.ALARM_GEOFENCE; } -- cgit v1.2.3 From 4ebce65e3d6db55d427f504bd62972370fab2eec Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Mon, 1 Aug 2016 17:39:57 +0500 Subject: Small optimization --- src/org/traccar/protocol/MeiligaoProtocolDecoder.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java index f23641ddb..c6c984dda 100644 --- a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java +++ b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java @@ -209,10 +209,7 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { // Custom data if (command == MSG_ALARM) { - String alarm = decodeAlarm(buf.readUnsignedByte()); - if (alarm != null) { - position.set(Position.KEY_ALARM, alarm); - } + position.set(Position.KEY_ALARM, decodeAlarm(buf.readUnsignedByte())); } else if (command == MSG_POSITION_LOGGED) { buf.skipBytes(6); } -- cgit v1.2.3 From 791a010e5a449a27e8243b9bc98c918ffa054eac Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Fri, 5 Aug 2016 10:07:35 +0500 Subject: - Removed OIL_CUT - Renamed guard to armed - Style fixes and optimizations --- src/org/traccar/model/Position.java | 3 +-- .../traccar/protocol/CarTrackProtocolDecoder.java | 2 +- .../traccar/protocol/Gps103ProtocolDecoder.java | 16 ++++++++------- .../traccar/protocol/MeiligaoProtocolDecoder.java | 24 ++++++++++++++-------- src/org/traccar/protocol/NavisProtocolDecoder.java | 6 +++--- src/org/traccar/protocol/NoranProtocolDecoder.java | 15 ++++++++++---- src/org/traccar/protocol/Tk103ProtocolDecoder.java | 22 ++++++++++++-------- src/org/traccar/protocol/TotemProtocolDecoder.java | 18 ++++++++++------ 8 files changed, 67 insertions(+), 39 deletions(-) diff --git a/src/org/traccar/model/Position.java b/src/org/traccar/model/Position.java index a62839702..d2409a75d 100644 --- a/src/org/traccar/model/Position.java +++ b/src/org/traccar/model/Position.java @@ -54,7 +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_GUARD = "guard"; + 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"; @@ -83,7 +83,6 @@ public class Position extends Message { 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_OIL_CUT = "oilCut"; public static final String ALARM_ACCIDENT = "accident"; diff --git a/src/org/traccar/protocol/CarTrackProtocolDecoder.java b/src/org/traccar/protocol/CarTrackProtocolDecoder.java index 45f1b0812..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)); - parser.next(); //there is no meaningful alarms + parser.next(); // there is no meaningful alarms position.set(Position.PREFIX_ADC + 1, parser.next()); return position; diff --git a/src/org/traccar/protocol/Gps103ProtocolDecoder.java b/src/org/traccar/protocol/Gps103ProtocolDecoder.java index 9d3fda345..b153984cb 100644 --- a/src/org/traccar/protocol/Gps103ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gps103ProtocolDecoder.java @@ -103,20 +103,22 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder { .compile(); private String decodeAlarm(String value) { - if (value == "tracker") { + switch (value) { + case "tracker": return null; - } else if (value == "help me") { + case "help me": return Position.ALARM_SOS; - } else if (value == "low battery") { + case "low battery": return Position.ALARM_LOW_BATTERY; - } else if (value == "stockade") { + case "stockade": return Position.ALARM_GEOFENCE; - } else if (value == "move") { + case "move": return Position.ALARM_MOVEMENT; - } else if (value == "speed") { + case "speed": return Position.ALARM_OVERSPEED; + default: + return null; } - return null; } @Override diff --git a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java index c6c984dda..41e248791 100644 --- a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java +++ b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java @@ -153,14 +153,22 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { 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; + 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; } } diff --git a/src/org/traccar/protocol/NavisProtocolDecoder.java b/src/org/traccar/protocol/NavisProtocolDecoder.java index 046068c5d..72c5f53c3 100644 --- a/src/org/traccar/protocol/NavisProtocolDecoder.java +++ b/src/org/traccar/protocol/NavisProtocolDecoder.java @@ -95,9 +95,9 @@ public class NavisProtocolDecoder extends BaseProtocolDecoder { buf.skipBytes(6); // event time - short guardStatus = buf.readUnsignedByte(); - position.set(Position.KEY_GUARD, guardStatus & 0x7F); - if (BitUtil.check(guardStatus, 7)) { + 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()); diff --git a/src/org/traccar/protocol/NoranProtocolDecoder.java b/src/org/traccar/protocol/NoranProtocolDecoder.java index 5b4533422..aaecfc1db 100644 --- a/src/org/traccar/protocol/NoranProtocolDecoder.java +++ b/src/org/traccar/protocol/NoranProtocolDecoder.java @@ -91,14 +91,21 @@ public class NoranProtocolDecoder extends BaseProtocolDecoder { position.setValid(BitUtil.check(buf.readUnsignedByte(), 0)); short alarm = buf.readUnsignedByte(); - if (alarm == 1) { + switch (alarm) { + case 1: position.set(Position.KEY_ALARM, Position.ALARM_SOS); - } else if (alarm == 2) { + break; + case 2: position.set(Position.KEY_ALARM, Position.ALARM_OVERSPEED); - } else if (alarm == 3) { + break; + case 3: position.set(Position.KEY_ALARM, Position.ALARM_GEOFENCE_EXIT); - } else if (alarm == 9) { + break; + case 9: position.set(Position.KEY_ALARM, Position.ALARM_POWER_OFF); + break; + default: + break; } if (newFormat) { diff --git a/src/org/traccar/protocol/Tk103ProtocolDecoder.java b/src/org/traccar/protocol/Tk103ProtocolDecoder.java index 72ecdc2de..55a41f5a2 100644 --- a/src/org/traccar/protocol/Tk103ProtocolDecoder.java +++ b/src/org/traccar/protocol/Tk103ProtocolDecoder.java @@ -77,14 +77,20 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { private String decodeAlarm(int value) { switch (value) { - case 0: return Position.ALARM_OIL_CUT; - 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; + 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; } } diff --git a/src/org/traccar/protocol/TotemProtocolDecoder.java b/src/org/traccar/protocol/TotemProtocolDecoder.java index fed1c3bd8..72c0f6306 100644 --- a/src/org/traccar/protocol/TotemProtocolDecoder.java +++ b/src/org/traccar/protocol/TotemProtocolDecoder.java @@ -161,12 +161,18 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder { 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; + 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; } } -- cgit v1.2.3