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(-) (limited to 'src/org') 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(-) (limited to 'src/org') 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(-) (limited to 'src/org') 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(-) (limited to 'src/org') 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 c7675dbe4bafede36f540e2ee6fbe69f9b136e1c Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Thu, 4 Aug 2016 22:12:20 +0300 Subject: Exception for Teltonika status (fix #2100) --- src/org/traccar/MainEventHandler.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/org') diff --git a/src/org/traccar/MainEventHandler.java b/src/org/traccar/MainEventHandler.java index c01760283..7d364d5e7 100644 --- a/src/org/traccar/MainEventHandler.java +++ b/src/org/traccar/MainEventHandler.java @@ -25,6 +25,7 @@ import org.jboss.netty.handler.timeout.IdleStateAwareChannelHandler; import org.jboss.netty.handler.timeout.IdleStateEvent; import org.traccar.helper.Log; import org.traccar.model.Position; +import org.traccar.protocol.TeltonikaProtocolDecoder; import java.sql.SQLException; import java.text.SimpleDateFormat; @@ -78,7 +79,8 @@ public class MainEventHandler extends IdleStateAwareChannelHandler { Log.info(formatChannel(e.getChannel()) + " disconnected"); closeChannel(e.getChannel()); - if (ctx.getPipeline().get("httpDecoder") == null) { + if (ctx.getPipeline().get("httpDecoder") == null && + !(ctx.getPipeline().get("objectDecoder") instanceof TeltonikaProtocolDecoder)) { Context.getConnectionManager().removeActiveDevice(e.getChannel()); } } -- cgit v1.2.3 From d4407022ef004e141374c542a511a6405aa17377 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Thu, 4 Aug 2016 22:18:51 +0300 Subject: Fix codestyle issue with if condition --- src/org/traccar/MainEventHandler.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/org') diff --git a/src/org/traccar/MainEventHandler.java b/src/org/traccar/MainEventHandler.java index 7d364d5e7..3f7e68b2a 100644 --- a/src/org/traccar/MainEventHandler.java +++ b/src/org/traccar/MainEventHandler.java @@ -79,8 +79,8 @@ public class MainEventHandler extends IdleStateAwareChannelHandler { Log.info(formatChannel(e.getChannel()) + " disconnected"); closeChannel(e.getChannel()); - if (ctx.getPipeline().get("httpDecoder") == null && - !(ctx.getPipeline().get("objectDecoder") instanceof TeltonikaProtocolDecoder)) { + if (ctx.getPipeline().get("httpDecoder") == null + && !(ctx.getPipeline().get("objectDecoder") instanceof TeltonikaProtocolDecoder)) { Context.getConnectionManager().removeActiveDevice(e.getChannel()); } } -- 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(-) (limited to 'src/org') 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 From 2cc642af2b1aeeb07e2b6676cf433112cc7cd7bc Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 5 Aug 2016 14:23:00 +0300 Subject: Implement OBD dongle protocol --- debug.xml | 1 + src/org/traccar/protocol/ObdDongleProtocol.java | 43 +++++++ .../traccar/protocol/ObdDongleProtocolDecoder.java | 128 +++++++++++++++++++++ .../protocol/ObdDongleProtocolDecoderTest.java | 22 ++++ 4 files changed, 194 insertions(+) create mode 100644 src/org/traccar/protocol/ObdDongleProtocol.java create mode 100644 src/org/traccar/protocol/ObdDongleProtocolDecoder.java create mode 100644 test/org/traccar/protocol/ObdDongleProtocolDecoderTest.java (limited to 'src/org') diff --git a/debug.xml b/debug.xml index 70bd0e80f..3f875aae7 100644 --- a/debug.xml +++ b/debug.xml @@ -448,5 +448,6 @@ 5112 5113 5114 + 5115 diff --git a/src/org/traccar/protocol/ObdDongleProtocol.java b/src/org/traccar/protocol/ObdDongleProtocol.java new file mode 100644 index 000000000..e87f9a99a --- /dev/null +++ b/src/org/traccar/protocol/ObdDongleProtocol.java @@ -0,0 +1,43 @@ +/* + * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; + +import java.util.List; + +public class ObdDongleProtocol extends BaseProtocol { + + public ObdDongleProtocol() { + super("obddongle"); + } + + @Override + public void initTrackerServers(List serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1099, 20, 2, 3, 0)); + pipeline.addLast("objectDecoder", new ObdDongleProtocolDecoder(ObdDongleProtocol.this)); + } + }); + } + +} diff --git a/src/org/traccar/protocol/ObdDongleProtocolDecoder.java b/src/org/traccar/protocol/ObdDongleProtocolDecoder.java new file mode 100644 index 000000000..84ff1450a --- /dev/null +++ b/src/org/traccar/protocol/ObdDongleProtocolDecoder.java @@ -0,0 +1,128 @@ +/* + * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.traccar.protocol; + +import org.jboss.netty.buffer.ChannelBuffer; +import org.jboss.netty.buffer.ChannelBuffers; +import org.jboss.netty.channel.Channel; +import org.traccar.BaseProtocolDecoder; +import org.traccar.DeviceSession; +import org.traccar.helper.BitUtil; +import org.traccar.helper.UnitsConverter; +import org.traccar.model.Position; + +import java.net.SocketAddress; +import java.nio.charset.StandardCharsets; +import java.util.Date; + +public class ObdDongleProtocolDecoder extends BaseProtocolDecoder { + + public ObdDongleProtocolDecoder(ObdDongleProtocol protocol) { + super(protocol); + } + + public static final int MSG_TYPE_CONNECT = 0x01; + public static final int MSG_TYPE_CONNACK = 0x02; + public static final int MSG_TYPE_PUBLISH = 0x03; + public static final int MSG_TYPE_PUBACK = 0x04; + public static final int MSG_TYPE_PINGREQ = 0x0C; + public static final int MSG_TYPE_PINGRESP = 0x0D; + public static final int MSG_TYPE_DISCONNECT = 0x0E; + + private static void sendResponse(Channel channel, int type, int index, String imei, ChannelBuffer content) { + if (channel != null) { + ChannelBuffer response = ChannelBuffers.dynamicBuffer(); + response.writeShort(0x5555); // header + response.writeShort(index); + response.writeBytes(imei.getBytes(StandardCharsets.US_ASCII)); + response.writeByte(type); + response.writeShort(content.readableBytes()); + response.writeBytes(content); + response.writeByte(0); // checksum + response.writeShort(0xAAAA); + channel.write(response); + } + } + + @Override + protected Object decode( + Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { + + ChannelBuffer buf = (ChannelBuffer) msg; + + buf.skipBytes(2); // header + int index = buf.readUnsignedShort(); + + String imei = buf.readBytes(15).toString(StandardCharsets.US_ASCII); + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei); + if (deviceSession == null) { + return null; + } + + int type = buf.readUnsignedByte(); + + buf.readUnsignedShort(); // data length + + if (type == MSG_TYPE_CONNECT) { + + ChannelBuffer response = ChannelBuffers.dynamicBuffer(); + response.writeByte(1); + response.writeShort(0); + response.writeInt(0); + sendResponse(channel, MSG_TYPE_CONNACK, index, imei, response); + + } else if (type == MSG_TYPE_PUBLISH) { + + int typeMajor = buf.readUnsignedByte(); + int typeMinor = buf.readUnsignedByte(); + + buf.readUnsignedByte(); // event id + + Position position = new Position(); + position.setProtocol(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + + position.setTime(new Date(buf.readUnsignedInt() * 1000)); + + int flags = buf.readUnsignedByte(); + + position.setValid(!BitUtil.check(flags, 6)); + + position.set(Position.KEY_SATELLITES, BitUtil.to(flags, 4)); + + double longitude = ((BitUtil.to(buf.readUnsignedShort(), 1) << 24) + buf.readUnsignedMedium()) * 0.00001; + position.setLongitude(BitUtil.check(flags, 5) ? longitude : -longitude); + + double latitude = buf.readUnsignedMedium() * 0.00001; + position.setLatitude(BitUtil.check(flags, 4) ? latitude : -latitude); + + int speedCourse = buf.readUnsignedMedium(); + position.setSpeed(UnitsConverter.knotsFromMph(BitUtil.from(speedCourse, 10) * 0.1)); + position.setCourse(BitUtil.to(speedCourse, 10)); + + ChannelBuffer response = ChannelBuffers.dynamicBuffer(); + response.writeByte(typeMajor); + response.writeByte(typeMinor); + sendResponse(channel, MSG_TYPE_PUBACK, index, imei, response); + + return position; + + } + + return null; + } + +} diff --git a/test/org/traccar/protocol/ObdDongleProtocolDecoderTest.java b/test/org/traccar/protocol/ObdDongleProtocolDecoderTest.java new file mode 100644 index 000000000..19e3a4ff2 --- /dev/null +++ b/test/org/traccar/protocol/ObdDongleProtocolDecoderTest.java @@ -0,0 +1,22 @@ +package org.traccar.protocol; + +import org.junit.Test; +import org.traccar.ProtocolTest; + +public class ObdDongleProtocolDecoderTest extends ProtocolTest { + + @Test + public void testDecode() throws Exception { + + ObdDongleProtocolDecoder decoder = new ObdDongleProtocolDecoder(new ObdDongleProtocol()); + + verifyNothing(decoder, binary( + "55550003383634383637303232353131303135010009010011023402010201ABAAAA")); + + verifyPosition(decoder, binary( + "5555000338363438363730323235313130313503000100010355AABBCC184F1ABC614E21C1FA08712A84ABAAAA"), + position("2015-07-18 20:49:16.000", true, 22.12346, -123.45678)); + + } + +} -- cgit v1.2.3 From 08e058e868566e44a8e955fa8d18bdae5630ecec Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 6 Aug 2016 10:24:53 +0300 Subject: Fix an issue in Castel decoder --- src/org/traccar/protocol/CastelProtocolDecoder.java | 8 +++++++- test/org/traccar/protocol/CastelProtocolDecoderTest.java | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'src/org') diff --git a/src/org/traccar/protocol/CastelProtocolDecoder.java b/src/org/traccar/protocol/CastelProtocolDecoder.java index 212096018..0beca4070 100644 --- a/src/org/traccar/protocol/CastelProtocolDecoder.java +++ b/src/org/traccar/protocol/CastelProtocolDecoder.java @@ -218,7 +218,13 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { return positions; } - } else if (type == MSG_SC_GPS_SLEEP || type == MSG_SC_AGPS_REQUEST) { + } else if (type == MSG_SC_GPS_SLEEP) { + + buf.readUnsignedInt(); // device time + + return readPosition(deviceSession, buf); + + } else if (type == MSG_SC_AGPS_REQUEST) { return readPosition(deviceSession, buf); diff --git a/test/org/traccar/protocol/CastelProtocolDecoderTest.java b/test/org/traccar/protocol/CastelProtocolDecoderTest.java index 6df2fd387..feba9386e 100644 --- a/test/org/traccar/protocol/CastelProtocolDecoderTest.java +++ b/test/org/traccar/protocol/CastelProtocolDecoderTest.java @@ -12,6 +12,9 @@ public class CastelProtocolDecoderTest extends ProtocolTest { CastelProtocolDecoder decoder = new CastelProtocolDecoder(new CastelProtocol()); + verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, + "40403600043231334e583230313630303033343600000000004009ad31a457050810061a35b29bf80ae6da83180300320bbe32580d0a40403600043231334e583230313630303033343600000000004009ad31a457050810061a35b29bf80ae6da83180300320bbe32580d0a")); + verifyNothing(decoder, binary(ByteOrder.LITTLE_ENDIAN, "4040d400043535333133350000000000000000000000000000100196d499574bd899570000000000000000010000000000000000000000002410000000004944445f3231334730325f532056322e332e345f4e004944445f3231334730325f482056322e332e345f4e0032000110021003100410051006100710081009100a100b100c100d100e1011100111021103110411051106110711011202120312041201130213031301160216011701180218011b011c011d011e011f021f031f041f051f061f071f012102210126012701285b410d0a")); -- cgit v1.2.3 From b8b330317dbac78c2d0a007a195efd8d42b3e791 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 6 Aug 2016 10:34:41 +0300 Subject: Support temperature for TK103 protocol --- src/org/traccar/protocol/Tk103ProtocolDecoder.java | 7 ++++++- test/org/traccar/protocol/Tk103ProtocolDecoderTest.java | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) (limited to 'src/org') diff --git a/src/org/traccar/protocol/Tk103ProtocolDecoder.java b/src/org/traccar/protocol/Tk103ProtocolDecoder.java index 55a41f5a2..ac99a1440 100644 --- a/src/org/traccar/protocol/Tk103ProtocolDecoder.java +++ b/src/org/traccar/protocol/Tk103ProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 - 2015 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2012 - 2016 Anton Tananaev (anton.tananaev@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -51,6 +51,7 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { .number("(?:([01]{8})|(x{8}))?,?") // state .number("(?:L(x+))?") // odometer .any() + .number("([+-]ddd.d)?") // temperature .text(")").optional() .compile(); @@ -225,6 +226,10 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_ODOMETER, parser.nextLong(16)); } + if (parser.hasNext()) { + position.set(Position.PREFIX_TEMP + 1, parser.nextDouble()); + } + return position; } diff --git a/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java b/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java index b15d7894e..c1bf148bc 100644 --- a/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java @@ -10,6 +10,12 @@ public class Tk103ProtocolDecoderTest extends ProtocolTest { Tk103ProtocolDecoder decoder = new Tk103ProtocolDecoder(new Tk103Protocol()); + verifyPosition(decoder, text( + "(088046338039BR00160727A3354.7768N03540.7258E000.0140832068.4700000000L00BEB0D4+017.7)")); + + verifyPosition(decoder, text( + "(088046338039BP05000088046338039160727A3354.7768N03540.7258E000.0140309065.1000000000L00BEB0D4+017.3)")); + verifyAttributes(decoder, text( "(013632651491,ZC20,180716,144222,6,392,65535,255")); -- cgit v1.2.3 From 683dce7d6475810910e6cfb2cab61efda43d2f80 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 6 Aug 2016 10:44:45 +0300 Subject: Refactor Castel protocol decoder --- .../traccar/protocol/CastelProtocolDecoder.java | 221 +++++++++++---------- 1 file changed, 120 insertions(+), 101 deletions(-) (limited to 'src/org') diff --git a/src/org/traccar/protocol/CastelProtocolDecoder.java b/src/org/traccar/protocol/CastelProtocolDecoder.java index 0beca4070..994c66ea6 100644 --- a/src/org/traccar/protocol/CastelProtocolDecoder.java +++ b/src/org/traccar/protocol/CastelProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -132,156 +132,175 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { } } - @Override - protected Object decode( - Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { + private Object decodeSc( + Channel channel, SocketAddress remoteAddress, ChannelBuffer buf, + int version, ChannelBuffer id, int type, DeviceSession deviceSession) { - ChannelBuffer buf = (ChannelBuffer) msg; + if (type == MSG_SC_HEARTBEAT) { - int header = buf.readUnsignedShort(); - buf.readUnsignedShort(); // length + sendResponse(channel, remoteAddress, version, id, MSG_SC_HEARTBEAT_RESPONSE, null); - int version = -1; - if (header == 0x4040) { - version = buf.readUnsignedByte(); - } + } else if (type == MSG_SC_LOGIN || type == MSG_SC_LOGOUT || type == MSG_SC_GPS + || type == MSG_SC_ALARM || type == MSG_SC_CURRENT_LOCATION) { - ChannelBuffer id = buf.readBytes(20); - int type = ChannelBuffers.swapShort(buf.readShort()); + if (type == MSG_SC_LOGIN) { + ChannelBuffer response = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 10); + response.writeInt(0xFFFFFFFF); + response.writeShort(0); + response.writeInt((int) (System.currentTimeMillis() / 1000)); + sendResponse(channel, remoteAddress, version, id, MSG_SC_LOGIN_RESPONSE, response); + } - DeviceSession deviceSession = getDeviceSession( - channel, remoteAddress, id.toString(StandardCharsets.US_ASCII).trim()); - if (deviceSession == null) { - return null; - } + if (type == MSG_SC_GPS) { + buf.readUnsignedByte(); // historical + } else if (type == MSG_SC_ALARM) { + buf.readUnsignedInt(); // alarm + } else if (type == MSG_SC_CURRENT_LOCATION) { + buf.readUnsignedShort(); + } - if (version == -1) { + buf.readUnsignedInt(); // ACC ON time + buf.readUnsignedInt(); // UTC time + long odometer = buf.readUnsignedInt(); + buf.readUnsignedInt(); // trip odometer + buf.readUnsignedInt(); // total fuel consumption + buf.readUnsignedShort(); // current fuel consumption + long status = buf.readUnsignedInt(); + buf.skipBytes(8); - if (type == 0x2001) { + int count = buf.readUnsignedByte(); - sendResponse(channel, remoteAddress, id, (short) 0x1001); + List positions = new LinkedList<>(); - buf.readUnsignedInt(); // index - buf.readUnsignedInt(); // unix time - buf.readUnsignedByte(); - - return readPosition(deviceSession, buf); + for (int i = 0; i < count; i++) { + Position position = readPosition(deviceSession, buf); + position.set(Position.KEY_ODOMETER, odometer); + position.set(Position.KEY_STATUS, status); + positions.add(position); + } + if (!positions.isEmpty()) { + return positions; } - } else if (version == 4) { + } else if (type == MSG_SC_GPS_SLEEP) { - if (type == MSG_SC_HEARTBEAT) { + buf.readUnsignedInt(); // device time - sendResponse(channel, remoteAddress, version, id, MSG_SC_HEARTBEAT_RESPONSE, null); + return readPosition(deviceSession, buf); - } else if (type == MSG_SC_LOGIN || type == MSG_SC_LOGOUT || type == MSG_SC_GPS - || type == MSG_SC_ALARM || type == MSG_SC_CURRENT_LOCATION) { + } else if (type == MSG_SC_AGPS_REQUEST) { - if (type == MSG_SC_LOGIN) { - ChannelBuffer response = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 10); - response.writeInt(0xFFFFFFFF); - response.writeShort(0); - response.writeInt((int) (System.currentTimeMillis() / 1000)); - sendResponse(channel, remoteAddress, version, id, MSG_SC_LOGIN_RESPONSE, response); - } + return readPosition(deviceSession, buf); - if (type == MSG_SC_GPS) { - buf.readUnsignedByte(); // historical - } else if (type == MSG_SC_ALARM) { - buf.readUnsignedInt(); // alarm - } else if (type == MSG_SC_CURRENT_LOCATION) { - buf.readUnsignedShort(); - } + } + + return null; + } - buf.readUnsignedInt(); // ACC ON time - buf.readUnsignedInt(); // UTC time - long odometer = buf.readUnsignedInt(); - buf.readUnsignedInt(); // trip odometer - buf.readUnsignedInt(); // total fuel consumption - buf.readUnsignedShort(); // current fuel consumption - long status = buf.readUnsignedInt(); - buf.skipBytes(8); - int count = buf.readUnsignedByte(); + private Object decodeCc( + Channel channel, SocketAddress remoteAddress, ChannelBuffer buf, + int version, ChannelBuffer id, int type, DeviceSession deviceSession) { - List positions = new LinkedList<>(); + if (type == MSG_CC_HEARTBEAT) { - for (int i = 0; i < count; i++) { - Position position = readPosition(deviceSession, buf); - position.set(Position.KEY_ODOMETER, odometer); - position.set(Position.KEY_STATUS, status); - positions.add(position); - } + sendResponse(channel, remoteAddress, version, id, MSG_CC_HEARTBEAT_RESPONSE, null); - if (!positions.isEmpty()) { - return positions; - } + buf.readUnsignedByte(); // 0x01 for history + int count = buf.readUnsignedByte(); - } else if (type == MSG_SC_GPS_SLEEP) { + List positions = new LinkedList<>(); - buf.readUnsignedInt(); // device time + for (int i = 0; i < count; i++) { + Position position = readPosition(deviceSession, buf); - return readPosition(deviceSession, buf); + position.set(Position.KEY_STATUS, buf.readUnsignedInt()); + position.set(Position.KEY_BATTERY, buf.readUnsignedByte()); + position.set(Position.KEY_ODOMETER, buf.readUnsignedInt()); - } else if (type == MSG_SC_AGPS_REQUEST) { + buf.readUnsignedByte(); // geo-fencing id + buf.readUnsignedByte(); // geo-fencing flags + buf.readUnsignedByte(); // additional flags - return readPosition(deviceSession, buf); + position.set(Position.KEY_LAC, buf.readUnsignedShort()); + position.set(Position.KEY_CID, buf.readUnsignedShort()); + positions.add(position); } - } else { + return positions; - if (type == MSG_CC_HEARTBEAT) { + } else if (type == MSG_CC_LOGIN) { - sendResponse(channel, remoteAddress, version, id, MSG_CC_HEARTBEAT_RESPONSE, null); + sendResponse(channel, remoteAddress, version, id, MSG_CC_LOGIN_RESPONSE, null); - buf.readUnsignedByte(); // 0x01 for history - int count = buf.readUnsignedByte(); + Position position = readPosition(deviceSession, buf); - List positions = new LinkedList<>(); + position.set(Position.KEY_STATUS, buf.readUnsignedInt()); + position.set(Position.KEY_BATTERY, buf.readUnsignedByte()); + position.set(Position.KEY_ODOMETER, buf.readUnsignedInt()); - for (int i = 0; i < count; i++) { - Position position = readPosition(deviceSession, buf); + buf.readUnsignedByte(); // geo-fencing id + buf.readUnsignedByte(); // geo-fencing flags + buf.readUnsignedByte(); // additional flags - position.set(Position.KEY_STATUS, buf.readUnsignedInt()); - position.set(Position.KEY_BATTERY, buf.readUnsignedByte()); - position.set(Position.KEY_ODOMETER, buf.readUnsignedInt()); + // GSM_CELL_CODE + // STR_Z - firmware version + // STR_Z - hardware version - buf.readUnsignedByte(); // geo-fencing id - buf.readUnsignedByte(); // geo-fencing flags - buf.readUnsignedByte(); // additional flags + return position; - position.set(Position.KEY_LAC, buf.readUnsignedShort()); - position.set(Position.KEY_CID, buf.readUnsignedShort()); + } - positions.add(position); - } + return null; + } - return positions; + @Override + protected Object decode( + Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - } else if (type == MSG_CC_LOGIN) { + ChannelBuffer buf = (ChannelBuffer) msg; - sendResponse(channel, remoteAddress, version, id, MSG_CC_LOGIN_RESPONSE, null); + int header = buf.readUnsignedShort(); + buf.readUnsignedShort(); // length - Position position = readPosition(deviceSession, buf); + int version = -1; + if (header == 0x4040) { + version = buf.readUnsignedByte(); + } - position.set(Position.KEY_STATUS, buf.readUnsignedInt()); - position.set(Position.KEY_BATTERY, buf.readUnsignedByte()); - position.set(Position.KEY_ODOMETER, buf.readUnsignedInt()); + ChannelBuffer id = buf.readBytes(20); + int type = ChannelBuffers.swapShort(buf.readShort()); - buf.readUnsignedByte(); // geo-fencing id - buf.readUnsignedByte(); // geo-fencing flags - buf.readUnsignedByte(); // additional flags + DeviceSession deviceSession = getDeviceSession( + channel, remoteAddress, id.toString(StandardCharsets.US_ASCII).trim()); + if (deviceSession == null) { + return null; + } + + if (version == -1) { + + if (type == 0x2001) { + + sendResponse(channel, remoteAddress, id, (short) 0x1001); - // GSM_CELL_CODE - // STR_Z - firmware version - // STR_Z - hardware version + buf.readUnsignedInt(); // index + buf.readUnsignedInt(); // unix time + buf.readUnsignedByte(); - return position; + return readPosition(deviceSession, buf); } + } else if (version == 4) { + + return decodeSc(channel, remoteAddress, buf, version, id, type, deviceSession); + + } else { + + return decodeCc(channel, remoteAddress, buf, version, id, type, deviceSession); + } return null; -- cgit v1.2.3 From d5ee7543705d8424cd0d4eaa900a667ea5e21095 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 6 Aug 2016 11:09:07 +0300 Subject: Decode Teltonika parameters (fix #2171) --- .../traccar/protocol/TeltonikaProtocolDecoder.java | 39 +++++++++++++++++----- 1 file changed, 30 insertions(+), 9 deletions(-) (limited to 'src/org') diff --git a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java index d982b07b3..00ab90ce0 100644 --- a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java +++ b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java @@ -67,6 +67,32 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { } + private void decodeParameter(Position position, int id, long value) { + switch (id) { + case 9: + position.set(Position.PREFIX_ADC + 1, value); + break; + case 66: + position.set(Position.KEY_POWER, value); + break; + case 68: + position.set(Position.KEY_BATTERY, value); + break; + case 85: + position.set(Position.KEY_RPM, value); + break; + case 182: + position.set(Position.KEY_HDOP, value); + break; + case 239: + position.set(Position.KEY_IGNITION, value == 1); + break; + default: + position.set(Position.PREFIX_IO + id, value); + break; + } + } + private void decodeLocation(Position position, ChannelBuffer buf, int codec) { int globalMask = 0x0f; @@ -153,12 +179,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { if (BitUtil.check(globalMask, 1)) { int cnt = buf.readUnsignedByte(); for (int j = 0; j < cnt; j++) { - int id = buf.readUnsignedByte(); - if (id == 1) { - position.set(Position.KEY_POWER, buf.readUnsignedByte()); - } else { - position.set(Position.PREFIX_IO + id, buf.readUnsignedByte()); - } + decodeParameter(position, buf.readUnsignedByte(), buf.readUnsignedByte()); } } @@ -166,7 +187,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { if (BitUtil.check(globalMask, 2)) { int cnt = buf.readUnsignedByte(); for (int j = 0; j < cnt; j++) { - position.set(Position.PREFIX_IO + buf.readUnsignedByte(), buf.readUnsignedShort()); + decodeParameter(position, buf.readUnsignedByte(), buf.readUnsignedShort()); } } @@ -174,7 +195,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { if (BitUtil.check(globalMask, 3)) { int cnt = buf.readUnsignedByte(); for (int j = 0; j < cnt; j++) { - position.set(Position.PREFIX_IO + buf.readUnsignedByte(), buf.readUnsignedInt()); + decodeParameter(position, buf.readUnsignedByte(), buf.readUnsignedInt()); } } @@ -182,7 +203,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { if (codec == CODEC_FM4X00) { int cnt = buf.readUnsignedByte(); for (int j = 0; j < cnt; j++) { - position.set(Position.PREFIX_IO + buf.readUnsignedByte(), buf.readLong()); + decodeParameter(position, buf.readUnsignedByte(), buf.readLong()); } } -- cgit v1.2.3 From dea7617218de2cbc7ebd930b4342aa35ffedcd8b Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 7 Aug 2016 09:32:59 +0300 Subject: Fixed typo in notification formatter --- src/org/traccar/notification/NotificationFormatter.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/org') diff --git a/src/org/traccar/notification/NotificationFormatter.java b/src/org/traccar/notification/NotificationFormatter.java index 37bd7848c..449426df0 100644 --- a/src/org/traccar/notification/NotificationFormatter.java +++ b/src/org/traccar/notification/NotificationFormatter.java @@ -53,9 +53,9 @@ public final class NotificationFormatter { + "Point: http://www.openstreetmap.org/?mlat=%3$f&mlon=%4$f#map=16/%3$f/%4$f%n" + "Time: %2$tc%n"; - public static final String TITLE_TEMPLATE_TYPE_DEVICE_OVERSPEED = "%1$s: exeeds the speed"; + public static final String TITLE_TEMPLATE_TYPE_DEVICE_OVERSPEED = "%1$s: exceeds the speed"; public static final String MESSAGE_TEMPLATE_TYPE_DEVICE_OVERSPEED = "Device: %1$s%n" - + "Exeeds the speed: %5$f%n" + + "Exceeds the speed: %5$f%n" + "Point: http://www.openstreetmap.org/?mlat=%3$f&mlon=%4$f#map=16/%3$f/%4$f%n" + "Time: %2$tc%n"; -- cgit v1.2.3