From 90ae1911e712813351f1caec1cf6964115dfa479 Mon Sep 17 00:00:00 2001 From: jon-stumpf Date: Sat, 11 Feb 2017 20:16:50 -0500 Subject: Fixed typo in Position.ALARM_ACCELERATION; --- src/org/traccar/model/Position.java | 2 +- src/org/traccar/protocol/Pt502ProtocolDecoder.java | 2 +- src/org/traccar/protocol/TzoneProtocolDecoder.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/org/traccar/model/Position.java b/src/org/traccar/model/Position.java index a88e16804..038bae8bb 100644 --- a/src/org/traccar/model/Position.java +++ b/src/org/traccar/model/Position.java @@ -86,7 +86,7 @@ public class Position extends Message { public static final String ALARM_GPS_ANTENNA_CUT = "gpsAntennaCut"; public static final String ALARM_ACCIDENT = "accident"; public static final String ALARM_TOW = "tow"; - public static final String ALARM_ACCELETATION = "hardAcceleration"; + public static final String ALARM_ACCELERATION = "hardAcceleration"; public static final String ALARM_BREAKING = "hardBreaking"; public static final String ALARM_FATIGUE_DRIVING = "fatigueDriving"; public static final String ALARM_POWER_CUT = "powerCut"; diff --git a/src/org/traccar/protocol/Pt502ProtocolDecoder.java b/src/org/traccar/protocol/Pt502ProtocolDecoder.java index 54f54d392..a72d237d3 100644 --- a/src/org/traccar/protocol/Pt502ProtocolDecoder.java +++ b/src/org/traccar/protocol/Pt502ProtocolDecoder.java @@ -65,7 +65,7 @@ public class Pt502ProtocolDecoder extends BaseProtocolDecoder { case "TOW": return Position.ALARM_TOW; case "HDA": - return Position.ALARM_ACCELETATION; + return Position.ALARM_ACCELERATION; case "HDB": return Position.ALARM_BREAKING; case "FDA": diff --git a/src/org/traccar/protocol/TzoneProtocolDecoder.java b/src/org/traccar/protocol/TzoneProtocolDecoder.java index 2b5d90e7a..0fc93a03c 100644 --- a/src/org/traccar/protocol/TzoneProtocolDecoder.java +++ b/src/org/traccar/protocol/TzoneProtocolDecoder.java @@ -45,7 +45,7 @@ public class TzoneProtocolDecoder extends BaseProtocolDecoder { case 0x14: return Position.ALARM_BREAKING; case 0x15: - return Position.ALARM_ACCELETATION; + return Position.ALARM_ACCELERATION; case 0x30: return Position.ALARM_PARKING; case 0x42: -- cgit v1.2.3 From 37d4bd765541a925bdf67ad134475dd1aaf92ca4 Mon Sep 17 00:00:00 2001 From: jon-stumpf Date: Sat, 11 Feb 2017 20:28:53 -0500 Subject: Added new keys: KEY_SATELLITES_VISIBLE and KEY_FIX; --- src/org/traccar/model/Position.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/org/traccar/model/Position.java b/src/org/traccar/model/Position.java index 038bae8bb..2df6e35b7 100644 --- a/src/org/traccar/model/Position.java +++ b/src/org/traccar/model/Position.java @@ -22,9 +22,11 @@ public class Position extends Message { public static final String KEY_ORIGINAL = "raw"; public static final String KEY_INDEX = "index"; public static final String KEY_HDOP = "hdop"; - public static final String KEY_SATELLITES = "sat"; + public static final String KEY_SATELLITES = "sat"; // in use + public static final String KEY_SATELLITES_VISIBLE = "satVisible"; public static final String KEY_RSSI = "rssi"; public static final String KEY_GPS = "gps"; + public static final String KEY_FIX = "fix"; // GPS, GSM, none public static final String KEY_EVENT = "event"; public static final String KEY_ALARM = "alarm"; public static final String KEY_STATUS = "status"; @@ -98,6 +100,7 @@ public class Position extends Message { public static final String ALARM_FOOT_BRAKE = "footBrake"; public static final String ALARM_OIL_LEAK = "oilLeak"; + private String protocol; public String getProtocol() { -- cgit v1.2.3 From 9c5e97ce6176850bf4a88e90f6d758055a28f60e Mon Sep 17 00:00:00 2001 From: jon-stumpf Date: Sat, 11 Feb 2017 21:10:20 -0500 Subject: Fixed MiniFinder protocol to work as per the Eview EV-07S documentation (from the original manufacturer); --- .../protocol/MiniFinderProtocolDecoder.java | 28 ++++++++-------------- 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/src/org/traccar/protocol/MiniFinderProtocolDecoder.java b/src/org/traccar/protocol/MiniFinderProtocolDecoder.java index 360df726a..738fd57b4 100644 --- a/src/org/traccar/protocol/MiniFinderProtocolDecoder.java +++ b/src/org/traccar/protocol/MiniFinderProtocolDecoder.java @@ -35,23 +35,19 @@ public class MiniFinderProtocolDecoder extends BaseProtocolDecoder { } private static final Pattern PATTERN = new PatternBuilder() - .expression("![A-D],") + .expression("![BD],") .number("(d+)/(d+)/(d+),") // date .number("(d+):(d+):(d+),") // time .number("(-?d+.d+),") // latitude .number("(-?d+.d+),") // longitude - .number("(d+.?d*),") // speed + .number("(d+.?d*),") // speed (km/h) .number("(d+.?d*),") // course - .groupBegin() .number("(x+),") // flags - .number("(-?d+.d+),") // altitude - .number("(d+),") // battery + .number("(-?d+.d+),") // altitude (meters) + .number("(d+),") // battery (percentage) .number("(d+),") // satellites in use .number("(d+),") // satellites in view - .text("0") - .or() - .any() - .groupEnd() + .number("(d+.?d*)") // HDOP, confirmed with Eview manufacturer .compile(); @Override @@ -64,7 +60,7 @@ public class MiniFinderProtocolDecoder extends BaseProtocolDecoder { getDeviceSession(channel, remoteAddress, sentence.substring(3, sentence.length())); - } else if (sentence.matches("![A-D].*")) { + } else if (sentence.matches("![BD].*")) { DeviceSession deviceSession = getDeviceSession(channel, remoteAddress); if (deviceSession == null) { @@ -94,8 +90,6 @@ public class MiniFinderProtocolDecoder extends BaseProtocolDecoder { position.setCourse(0); } - if (parser.hasNext(5)) { - int flags = parser.nextInt(16); position.setValid(BitUtil.check(flags, 0)); @@ -127,16 +121,14 @@ public class MiniFinderProtocolDecoder extends BaseProtocolDecoder { position.setAltitude(parser.nextDouble()); - position.set(Position.KEY_BATTERY, parser.next()); - position.set(Position.KEY_SATELLITES, parser.next()); - - } + position.set(Position.KEY_BATTERY, parser.nextInt()); + position.set(Position.KEY_SATELLITES, parser.nextInt()); + position.set(Position.KEY_SATELLITES_VISIBLE, parser.nextInt()); + position.set(Position.KEY_HDOP, parser.nextDouble()); return position; - } return null; } - } -- cgit v1.2.3 From 99e806e515b2bbb59565f693aaf54b26d0ed7466 Mon Sep 17 00:00:00 2001 From: jon-stumpf Date: Sat, 11 Feb 2017 21:11:18 -0500 Subject: Fixed formatting in MiniFinder; --- .../protocol/MiniFinderProtocolDecoder.java | 70 +++++++++++----------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/src/org/traccar/protocol/MiniFinderProtocolDecoder.java b/src/org/traccar/protocol/MiniFinderProtocolDecoder.java index 738fd57b4..62a4c48fb 100644 --- a/src/org/traccar/protocol/MiniFinderProtocolDecoder.java +++ b/src/org/traccar/protocol/MiniFinderProtocolDecoder.java @@ -90,41 +90,41 @@ public class MiniFinderProtocolDecoder extends BaseProtocolDecoder { position.setCourse(0); } - int flags = parser.nextInt(16); - - position.setValid(BitUtil.check(flags, 0)); - - if (BitUtil.check(flags, 2)) { - position.set(Position.KEY_ALARM, Position.ALARM_FAULT); - } - if (BitUtil.check(flags, 6)) { - position.set(Position.KEY_ALARM, Position.ALARM_SOS); - } - if (BitUtil.check(flags, 7)) { - position.set(Position.KEY_ALARM, Position.ALARM_OVERSPEED); - } - if (BitUtil.check(flags, 8)) { - position.set(Position.KEY_ALARM, Position.ALARM_FALL_DOWN); - } - if (BitUtil.check(flags, 9) || BitUtil.check(flags, 10) || BitUtil.check(flags, 11)) { - position.set(Position.KEY_ALARM, Position.ALARM_GEOFENCE); - } - if (BitUtil.check(flags, 12)) { - position.set(Position.KEY_ALARM, Position.ALARM_LOW_BATTERY); - } - if (BitUtil.check(flags, 15) || BitUtil.check(flags, 14)) { - position.set(Position.KEY_ALARM, Position.ALARM_MOVEMENT); - } - - position.set(Position.KEY_RSSI, BitUtil.between(flags, 16, 20)); - position.set(Position.KEY_CHARGE, BitUtil.check(flags, 22)); - - position.setAltitude(parser.nextDouble()); - - position.set(Position.KEY_BATTERY, parser.nextInt()); - position.set(Position.KEY_SATELLITES, parser.nextInt()); - position.set(Position.KEY_SATELLITES_VISIBLE, parser.nextInt()); - position.set(Position.KEY_HDOP, parser.nextDouble()); + int flags = parser.nextInt(16); + + position.setValid(BitUtil.check(flags, 0)); + + if (BitUtil.check(flags, 2)) { + position.set(Position.KEY_ALARM, Position.ALARM_FAULT); + } + if (BitUtil.check(flags, 6)) { + position.set(Position.KEY_ALARM, Position.ALARM_SOS); + } + if (BitUtil.check(flags, 7)) { + position.set(Position.KEY_ALARM, Position.ALARM_OVERSPEED); + } + if (BitUtil.check(flags, 8)) { + position.set(Position.KEY_ALARM, Position.ALARM_FALL_DOWN); + } + if (BitUtil.check(flags, 9) || BitUtil.check(flags, 10) || BitUtil.check(flags, 11)) { + position.set(Position.KEY_ALARM, Position.ALARM_GEOFENCE); + } + if (BitUtil.check(flags, 12)) { + position.set(Position.KEY_ALARM, Position.ALARM_LOW_BATTERY); + } + if (BitUtil.check(flags, 15) || BitUtil.check(flags, 14)) { + position.set(Position.KEY_ALARM, Position.ALARM_MOVEMENT); + } + + position.set(Position.KEY_RSSI, BitUtil.between(flags, 16, 20)); + position.set(Position.KEY_CHARGE, BitUtil.check(flags, 22)); + + position.setAltitude(parser.nextDouble()); + + position.set(Position.KEY_BATTERY, parser.nextInt()); + position.set(Position.KEY_SATELLITES, parser.nextInt()); + position.set(Position.KEY_SATELLITES_VISIBLE, parser.nextInt()); + position.set(Position.KEY_HDOP, parser.nextDouble()); return position; } -- cgit v1.2.3 From dfd09a62ed8df49228eb9a147e497bdfd81f1b18 Mon Sep 17 00:00:00 2001 From: jon-stumpf Date: Sun, 12 Feb 2017 12:58:32 -0500 Subject: Removed frame delimiter from MiniFinder test data; --- test/org/traccar/protocol/MiniFinderProtocolDecoderTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/org/traccar/protocol/MiniFinderProtocolDecoderTest.java b/test/org/traccar/protocol/MiniFinderProtocolDecoderTest.java index ccefee049..57201670f 100644 --- a/test/org/traccar/protocol/MiniFinderProtocolDecoderTest.java +++ b/test/org/traccar/protocol/MiniFinderProtocolDecoderTest.java @@ -20,7 +20,7 @@ public class MiniFinderProtocolDecoderTest extends ProtocolTest { "!1,860719027585011")); verifyPosition(decoder, text( - "!D,28/11/16,00:04:09,42.926067,-85.747589,124,236,140001,179.8,60,11,16,0;")); + "!D,28/11/16,00:04:09,42.926067,-85.747589,124,236,140001,179.8,60,11,16,0")); verifyPosition(decoder, text( "!C,30/1/16,1:1:6,31.259157,30.020910,0,0,100001,25.32,100,0.03,0.01,0")); -- cgit v1.2.3 From 95d8f99db0183dcf1c6ccce460a9082cc2dbf6b3 Mon Sep 17 00:00:00 2001 From: jon-stumpf Date: Sun, 12 Feb 2017 17:02:26 -0500 Subject: Added !A and !C records as per data found in MiniFinderDecoderTest.java; --- .../protocol/MiniFinderProtocolDecoder.java | 174 +++++++++++++++++---- 1 file changed, 140 insertions(+), 34 deletions(-) diff --git a/src/org/traccar/protocol/MiniFinderProtocolDecoder.java b/src/org/traccar/protocol/MiniFinderProtocolDecoder.java index 62a4c48fb..009b3cc9f 100644 --- a/src/org/traccar/protocol/MiniFinderProtocolDecoder.java +++ b/src/org/traccar/protocol/MiniFinderProtocolDecoder.java @@ -34,7 +34,42 @@ public class MiniFinderProtocolDecoder extends BaseProtocolDecoder { super(protocol); } - private static final Pattern PATTERN = new PatternBuilder() + // The !A record is not in the documentation for MiniFinder or EV-07S. + // Eview, the manufacturer, indicated that resellers could implement new record types. + // Using the data in MiniFinderProtocolDecoderTest.java as a guide + private static final Pattern PATTERN_A = new PatternBuilder() + .expression("!A,") + .number("(d+)/(d+)/(d+),") // date + .number("(d+):(d+):(d+),") // time + .number("(-?d+.d+),") // latitude + .number("(-?d+.d+),") // longitude + .number("(d+.?d*),") // unknown + .number("(d+.?d*),") // unknown + .number("(d+.?d*)") // unknown + .compile(); + + // The !C record is not in the documentation for MiniFinder or EV-07S + // Eview, the manufacturer, indicated that resellers could implement new record types. + // Using the data in MiniFinderProtocolDecoderTest.java as a guide + private static final Pattern PATTERN_C = new PatternBuilder() + .expression("!C,") + .number("(d+)/(d+)/(d+),") // date + .number("(d+):(d+):(d+),") // time + .number("(-?d+.d+),") // latitude + .number("(-?d+.d+),") // longitude + .number("(d+.?d*),") // speed (km/h) + .number("(d+.?d*),") // course + .number("(x+),") // flags + .number("(-?d+.d+),") // altitude (meters) + .number("(d+),") // battery (percentage) + .number("(d+.?d*),") // unknown + .number("(d+.?d*),") // unknown + .number("(d+.?d*)") // unknown + .compile(); + + // The !B (buffered data) records are the same as !D (live data) records. + // This was confirmed with the manufacturer, Eview. + private static final Pattern PATTERN_BD = new PatternBuilder() .expression("![BD],") .number("(d+)/(d+)/(d+),") // date .number("(d+):(d+):(d+),") // time @@ -50,24 +85,56 @@ public class MiniFinderProtocolDecoder extends BaseProtocolDecoder { .number("(d+.?d*)") // HDOP, confirmed with Eview manufacturer .compile(); + private void decodeFlags(Position position, int flags) { + + position.setValid(BitUtil.check(flags, 0)); + + if (BitUtil.check(flags, 2)) { + position.set(Position.KEY_ALARM, Position.ALARM_FAULT); + } + if (BitUtil.check(flags, 6)) { + position.set(Position.KEY_ALARM, Position.ALARM_SOS); + } + if (BitUtil.check(flags, 7)) { + position.set(Position.KEY_ALARM, Position.ALARM_OVERSPEED); + } + if (BitUtil.check(flags, 8)) { + position.set(Position.KEY_ALARM, Position.ALARM_FALL_DOWN); + } + if (BitUtil.check(flags, 9) || BitUtil.check(flags, 10) || BitUtil.check(flags, 11)) { + position.set(Position.KEY_ALARM, Position.ALARM_GEOFENCE); + } + if (BitUtil.check(flags, 12)) { + position.set(Position.KEY_ALARM, Position.ALARM_LOW_BATTERY); + } + if (BitUtil.check(flags, 15) || BitUtil.check(flags, 14)) { + position.set(Position.KEY_ALARM, Position.ALARM_MOVEMENT); + } + + position.set(Position.KEY_RSSI, BitUtil.between(flags, 16, 20)); + position.set(Position.KEY_CHARGE, BitUtil.check(flags, 22)); + } + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { String sentence = (String) msg; - if (sentence.startsWith("!1")) { + if (sentence.startsWith("!1,")) { getDeviceSession(channel, remoteAddress, sentence.substring(3, sentence.length())); - } else if (sentence.matches("![BD].*")) { + return null; + } - DeviceSession deviceSession = getDeviceSession(channel, remoteAddress); - if (deviceSession == null) { - return null; - } + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress); + if (deviceSession == null) { + return null; + } - Parser parser = new Parser(PATTERN, sentence); + if (sentence.startsWith("!B,") || sentence.startsWith("!D,")) { + Parser parser = new Parser(PATTERN_BD, sentence); if (!parser.matches()) { return null; } @@ -90,45 +157,84 @@ public class MiniFinderProtocolDecoder extends BaseProtocolDecoder { position.setCourse(0); } - int flags = parser.nextInt(16); + decodeFlags(position, parser.nextInt(16)); - position.setValid(BitUtil.check(flags, 0)); + position.setAltitude(parser.nextDouble()); - if (BitUtil.check(flags, 2)) { - position.set(Position.KEY_ALARM, Position.ALARM_FAULT); - } - if (BitUtil.check(flags, 6)) { - position.set(Position.KEY_ALARM, Position.ALARM_SOS); - } - if (BitUtil.check(flags, 7)) { - position.set(Position.KEY_ALARM, Position.ALARM_OVERSPEED); - } - if (BitUtil.check(flags, 8)) { - position.set(Position.KEY_ALARM, Position.ALARM_FALL_DOWN); - } - if (BitUtil.check(flags, 9) || BitUtil.check(flags, 10) || BitUtil.check(flags, 11)) { - position.set(Position.KEY_ALARM, Position.ALARM_GEOFENCE); - } - if (BitUtil.check(flags, 12)) { - position.set(Position.KEY_ALARM, Position.ALARM_LOW_BATTERY); + position.set(Position.KEY_BATTERY, parser.nextInt()); + position.set(Position.KEY_SATELLITES, parser.nextInt()); + position.set(Position.KEY_SATELLITES_VISIBLE, parser.nextInt()); + position.set(Position.KEY_HDOP, parser.nextDouble()); + + position.set(Position.KEY_TYPE, sentence.substring(1, 2)); + + return position; + } + + if (sentence.startsWith("!C,")) { + Parser parser = new Parser(PATTERN_C, sentence); + if (!parser.matches()) { + return null; } - if (BitUtil.check(flags, 15) || BitUtil.check(flags, 14)) { - position.set(Position.KEY_ALARM, Position.ALARM_MOVEMENT); + + Position position = new Position(); + position.setProtocol(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + + DateBuilder dateBuilder = new DateBuilder() + .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()) + .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); + position.setTime(dateBuilder.getDate()); + + position.setLatitude(parser.nextDouble()); + position.setLongitude(parser.nextDouble()); + position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble())); + + position.setCourse(parser.nextDouble()); + if (position.getCourse() > 360) { + position.setCourse(0); } - position.set(Position.KEY_RSSI, BitUtil.between(flags, 16, 20)); - position.set(Position.KEY_CHARGE, BitUtil.check(flags, 22)); + decodeFlags(position, parser.nextInt(16)); position.setAltitude(parser.nextDouble()); position.set(Position.KEY_BATTERY, parser.nextInt()); - position.set(Position.KEY_SATELLITES, parser.nextInt()); - position.set(Position.KEY_SATELLITES_VISIBLE, parser.nextInt()); - position.set(Position.KEY_HDOP, parser.nextDouble()); + + // Ignoring last three fields, unknown + position.set("unknown", parser.next() + "," + parser.next() + "," + parser.next()); + + position.set(Position.KEY_TYPE, sentence.substring(1, 2)); return position; } + if (sentence.startsWith("!A,")) { + Parser parser = new Parser(PATTERN_A, sentence); + if (!parser.matches()) { + return null; + } + + Position position = new Position(); + position.setProtocol(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + + DateBuilder dateBuilder = new DateBuilder() + .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()) + .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); + position.setTime(dateBuilder.getDate()); + + position.setLatitude(parser.nextDouble()); + position.setLongitude(parser.nextDouble()); + + // Ignoring last three fields, unknown + position.set("unknown", parser.next() + "," + parser.next() + "," + parser.next()); + + return position; + } + + // If we get here, we didn't understand the message + return null; } } -- cgit v1.2.3 From 354bd0ee9074c6b6ba6f29eead1bd07f978d880f Mon Sep 17 00:00:00 2001 From: jon-stumpf Date: Thu, 16 Feb 2017 21:31:11 -0500 Subject: Implemented changes to pull request as recommended by Anton; --- .../protocol/MiniFinderProtocolDecoder.java | 27 +++++----------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/src/org/traccar/protocol/MiniFinderProtocolDecoder.java b/src/org/traccar/protocol/MiniFinderProtocolDecoder.java index 009b3cc9f..37acbfd2d 100644 --- a/src/org/traccar/protocol/MiniFinderProtocolDecoder.java +++ b/src/org/traccar/protocol/MiniFinderProtocolDecoder.java @@ -34,24 +34,16 @@ public class MiniFinderProtocolDecoder extends BaseProtocolDecoder { super(protocol); } - // The !A record is not in the documentation for MiniFinder or EV-07S. - // Eview, the manufacturer, indicated that resellers could implement new record types. - // Using the data in MiniFinderProtocolDecoderTest.java as a guide private static final Pattern PATTERN_A = new PatternBuilder() .expression("!A,") .number("(d+)/(d+)/(d+),") // date .number("(d+):(d+):(d+),") // time .number("(-?d+.d+),") // latitude .number("(-?d+.d+),") // longitude - .number("(d+.?d*),") // unknown - .number("(d+.?d*),") // unknown - .number("(d+.?d*)") // unknown + .any() .compile(); - // The !C record is not in the documentation for MiniFinder or EV-07S - // Eview, the manufacturer, indicated that resellers could implement new record types. - // Using the data in MiniFinderProtocolDecoderTest.java as a guide - private static final Pattern PATTERN_C = new PatternBuilder() + private static final Pattern PATTERN_C = new PatternBuilder() .expression("!C,") .number("(d+)/(d+)/(d+),") // date .number("(d+):(d+):(d+),") // time @@ -62,9 +54,7 @@ public class MiniFinderProtocolDecoder extends BaseProtocolDecoder { .number("(x+),") // flags .number("(-?d+.d+),") // altitude (meters) .number("(d+),") // battery (percentage) - .number("(d+.?d*),") // unknown - .number("(d+.?d*),") // unknown - .number("(d+.?d*)") // unknown + .any() .compile(); // The !B (buffered data) records are the same as !D (live data) records. @@ -82,7 +72,7 @@ public class MiniFinderProtocolDecoder extends BaseProtocolDecoder { .number("(d+),") // battery (percentage) .number("(d+),") // satellites in use .number("(d+),") // satellites in view - .number("(d+.?d*)") // HDOP, confirmed with Eview manufacturer + .number("(d+.?d*)") // hdop .compile(); private void decodeFlags(Position position, int flags) { @@ -201,9 +191,6 @@ public class MiniFinderProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_BATTERY, parser.nextInt()); - // Ignoring last three fields, unknown - position.set("unknown", parser.next() + "," + parser.next() + "," + parser.next()); - position.set(Position.KEY_TYPE, sentence.substring(1, 2)); return position; @@ -227,14 +214,12 @@ public class MiniFinderProtocolDecoder extends BaseProtocolDecoder { position.setLatitude(parser.nextDouble()); position.setLongitude(parser.nextDouble()); - // Ignoring last three fields, unknown - position.set("unknown", parser.next() + "," + parser.next() + "," + parser.next()); + position.set(Position.KEY_TYPE, sentence.substring(1, 2)); return position; } - // If we get here, we didn't understand the message - return null; } + } -- cgit v1.2.3 From ed6a26f161f91e9e6ea3d306135e26657b4b8416 Mon Sep 17 00:00:00 2001 From: jon-stumpf Date: Sat, 18 Feb 2017 09:27:16 -0500 Subject: Updated two other protocols to provide "satVisible" information; --- src/org/traccar/protocol/Avl301ProtocolDecoder.java | 2 +- src/org/traccar/protocol/NavigilProtocolDecoder.java | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/org/traccar/protocol/Avl301ProtocolDecoder.java b/src/org/traccar/protocol/Avl301ProtocolDecoder.java index c19b96cb9..cc61be91b 100644 --- a/src/org/traccar/protocol/Avl301ProtocolDecoder.java +++ b/src/org/traccar/protocol/Avl301ProtocolDecoder.java @@ -100,7 +100,7 @@ public class Avl301ProtocolDecoder extends BaseProtocolDecoder { int gpsLength = buf.readUnsignedByte(); // gps len and sat position.set(Position.KEY_SATELLITES, gpsLength & 0xf); - buf.readUnsignedByte(); // satellites + position.set(Position.KEY_SATELLITES_VISIBLE, buf.readUnsignedByte()); // satellites double latitude = buf.readUnsignedInt() / 600000.0; double longitude = buf.readUnsignedInt() / 600000.0; diff --git a/src/org/traccar/protocol/NavigilProtocolDecoder.java b/src/org/traccar/protocol/NavigilProtocolDecoder.java index d18217861..263e5fc2b 100644 --- a/src/org/traccar/protocol/NavigilProtocolDecoder.java +++ b/src/org/traccar/protocol/NavigilProtocolDecoder.java @@ -95,8 +95,8 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder { position.setLongitude(buf.readInt() * 0.0000001); position.setAltitude(buf.readUnsignedShort()); - buf.readUnsignedShort(); // satellites in fix - buf.readUnsignedShort(); // satellites in track + position.set(Position.KEY_SATELLITES, buf.readUnsignedShort()); // satellites in fix + position.set(Position.KEY_SATELLITES_VISIBLE, buf.readUnsignedShort()); // satellites in track buf.readUnsignedShort(); // GPS antenna state position.setSpeed(buf.readUnsignedShort() * 0.194384); @@ -107,7 +107,7 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.001); - buf.readUnsignedShort(); // battery charger status + position.set(Position.KEY_CHARGE, buf.readUnsignedShort()); // battery charger status position.setTime(convertTimestamp(buf.readUnsignedInt())); @@ -133,8 +133,8 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder { position.setLongitude(buf.readInt() * 0.0000001); position.setAltitude(buf.readUnsignedShort()); - buf.readUnsignedByte(); // satellites in fix - buf.readUnsignedByte(); // satellites in track + position.set(Position.KEY_SATELLITES, buf.readUnsignedByte()); // satellites in fix + position.set(Position.KEY_SATELLITES_VISIBLE, buf.readUnsignedByte()); // satellites in track position.setSpeed(buf.readUnsignedShort() * 0.194384); position.setCourse(buf.readUnsignedShort()); @@ -219,8 +219,8 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder { position.setLongitude(buf.readInt() * 0.0000001); position.setAltitude(buf.readUnsignedShort()); - buf.readUnsignedByte(); // satellites in fix - buf.readUnsignedByte(); // satellites in track + position.set(Position.KEY_SATELLITES, buf.readUnsignedByte()); // satellites in fix + position.set(Position.KEY_SATELLITES_VISIBLE, buf.readUnsignedByte()); // satellites in track position.setSpeed(buf.readUnsignedShort() * 0.194384); position.setCourse(buf.readUnsignedShort() * 0.1); @@ -258,7 +258,7 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder { position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte())); position.setCourse(buf.readUnsignedByte() * 2.0); - buf.readUnsignedByte(); // satellites in fix + position.set(Position.KEY_SATELLITES, buf.readUnsignedByte()); // satellites in fix position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.001); -- cgit v1.2.3 From a1ada79197cd95d71bef743056bfe6e5837df81e Mon Sep 17 00:00:00 2001 From: jon-stumpf Date: Sat, 18 Feb 2017 09:38:38 -0500 Subject: Removed suggested KEY_FIX as requested; --- src/org/traccar/model/Position.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/org/traccar/model/Position.java b/src/org/traccar/model/Position.java index 2df6e35b7..288901430 100644 --- a/src/org/traccar/model/Position.java +++ b/src/org/traccar/model/Position.java @@ -26,7 +26,6 @@ public class Position extends Message { public static final String KEY_SATELLITES_VISIBLE = "satVisible"; public static final String KEY_RSSI = "rssi"; public static final String KEY_GPS = "gps"; - public static final String KEY_FIX = "fix"; // GPS, GSM, none public static final String KEY_EVENT = "event"; public static final String KEY_ALARM = "alarm"; public static final String KEY_STATUS = "status"; @@ -100,7 +99,6 @@ public class Position extends Message { public static final String ALARM_FOOT_BRAKE = "footBrake"; public static final String ALARM_OIL_LEAK = "oilLeak"; - private String protocol; public String getProtocol() { -- cgit v1.2.3 From eaf45eeb3b43bfc6c7838352b12d3c14ec33ccdd Mon Sep 17 00:00:00 2001 From: jon-stumpf Date: Sat, 18 Feb 2017 22:32:49 -0500 Subject: Minimized duplication of code as requested; --- .../protocol/MiniFinderProtocolDecoder.java | 170 ++++++++++----------- 1 file changed, 78 insertions(+), 92 deletions(-) diff --git a/src/org/traccar/protocol/MiniFinderProtocolDecoder.java b/src/org/traccar/protocol/MiniFinderProtocolDecoder.java index 37acbfd2d..94c67b616 100644 --- a/src/org/traccar/protocol/MiniFinderProtocolDecoder.java +++ b/src/org/traccar/protocol/MiniFinderProtocolDecoder.java @@ -34,47 +34,59 @@ public class MiniFinderProtocolDecoder extends BaseProtocolDecoder { super(protocol); } - private static final Pattern PATTERN_A = new PatternBuilder() - .expression("!A,") + private static final Pattern PATTERN_FIX = new PatternBuilder() .number("(d+)/(d+)/(d+),") // date .number("(d+):(d+):(d+),") // time .number("(-?d+.d+),") // latitude .number("(-?d+.d+),") // longitude - .any() .compile(); - private static final Pattern PATTERN_C = new PatternBuilder() - .expression("!C,") - .number("(d+)/(d+)/(d+),") // date - .number("(d+):(d+):(d+),") // time - .number("(-?d+.d+),") // latitude - .number("(-?d+.d+),") // longitude + private static final Pattern PATTERN_STATE = new PatternBuilder() .number("(d+.?d*),") // speed (km/h) .number("(d+.?d*),") // course .number("(x+),") // flags .number("(-?d+.d+),") // altitude (meters) .number("(d+),") // battery (percentage) - .any() .compile(); - // The !B (buffered data) records are the same as !D (live data) records. - // This was confirmed with the manufacturer, Eview. - private static final Pattern PATTERN_BD = new PatternBuilder() - .expression("![BD],") - .number("(d+)/(d+)/(d+),") // date - .number("(d+):(d+):(d+),") // time - .number("(-?d+.d+),") // latitude - .number("(-?d+.d+),") // longitude - .number("(d+.?d*),") // speed (km/h) - .number("(d+.?d*),") // course - .number("(x+),") // flags - .number("(-?d+.d+),") // altitude (meters) - .number("(d+),") // battery (percentage) + private static final Pattern PATTERN_GPS_PRECISION = new PatternBuilder() .number("(d+),") // satellites in use .number("(d+),") // satellites in view .number("(d+.?d*)") // hdop .compile(); + private static final Pattern PATTERN_A = new PatternBuilder() + .text("!A,") + .expression(PATTERN_FIX.pattern()) + .any() // unknown 3 fields + .compile(); + + private static final Pattern PATTERN_C = new PatternBuilder() + .text("!C,") + .expression(PATTERN_FIX.pattern()) + .expression(PATTERN_STATE.pattern()) + .any() // unknown 3 fields + .compile(); + + // The !B (buffered data) records are the same as !D (live data) records. + private static final Pattern PATTERN_BD = new PatternBuilder() + .expression("![BD],") + .expression(PATTERN_FIX.pattern()) + .expression(PATTERN_STATE.pattern()) + .expression(PATTERN_GPS_PRECISION.pattern()) + .compile(); + + private void decodeFix(Position position, Parser parser) { + + DateBuilder dateBuilder = new DateBuilder() + .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()) + .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); + position.setTime(dateBuilder.getDate()); + + position.setLatitude(parser.nextDouble()); + position.setLongitude(parser.nextDouble()); + } + private void decodeFlags(Position position, int flags) { position.setValid(BitUtil.check(flags, 0)); @@ -105,6 +117,29 @@ public class MiniFinderProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_CHARGE, BitUtil.check(flags, 22)); } + private void decodeState(Position position, Parser parser) { + + position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble())); + + position.setCourse(parser.nextDouble()); + if (position.getCourse() > 360) { + position.setCourse(0); + } + + decodeFlags(position, parser.nextInt(16)); + + position.setAltitude(parser.nextDouble()); + + position.set(Position.KEY_BATTERY, parser.nextInt()); + } + + private void decodeGPSPrecision(Position position, Parser parser) { + + position.set(Position.KEY_SATELLITES, parser.nextInt()); + position.set(Position.KEY_SATELLITES_VISIBLE, parser.nextInt()); + position.set(Position.KEY_HDOP, parser.nextDouble()); + } + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { @@ -123,98 +158,49 @@ public class MiniFinderProtocolDecoder extends BaseProtocolDecoder { return null; } - if (sentence.startsWith("!B,") || sentence.startsWith("!D,")) { - Parser parser = new Parser(PATTERN_BD, sentence); - if (!parser.matches()) { - return null; - } - - Position position = new Position(); - position.setProtocol(getProtocolName()); - position.setDeviceId(deviceSession.getDeviceId()); + if (!sentence.matches("![A-D],.*")) { + return null; + } - DateBuilder dateBuilder = new DateBuilder() - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + Position position = new Position(); + position.setProtocol(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); - position.setLatitude(parser.nextDouble()); - position.setLongitude(parser.nextDouble()); - position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble())); + String recordType = sentence.substring(1, 2); + position.set(Position.KEY_TYPE, recordType); - position.setCourse(parser.nextDouble()); - if (position.getCourse() > 360) { - position.setCourse(0); + if (recordType.matches("[BD]")) { + Parser parser = new Parser(PATTERN_BD, sentence); + if (!parser.matches()) { + return null; } - decodeFlags(position, parser.nextInt(16)); - - position.setAltitude(parser.nextDouble()); - - position.set(Position.KEY_BATTERY, parser.nextInt()); - position.set(Position.KEY_SATELLITES, parser.nextInt()); - position.set(Position.KEY_SATELLITES_VISIBLE, parser.nextInt()); - position.set(Position.KEY_HDOP, parser.nextDouble()); - - position.set(Position.KEY_TYPE, sentence.substring(1, 2)); + decodeFix(position, parser); + decodeState(position, parser); + decodeGPSPrecision(position, parser); return position; } - if (sentence.startsWith("!C,")) { + if (recordType.matches("C")) { Parser parser = new Parser(PATTERN_C, sentence); if (!parser.matches()) { return null; } - Position position = new Position(); - position.setProtocol(getProtocolName()); - position.setDeviceId(deviceSession.getDeviceId()); - - DateBuilder dateBuilder = new DateBuilder() - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); - - position.setLatitude(parser.nextDouble()); - position.setLongitude(parser.nextDouble()); - position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble())); - - position.setCourse(parser.nextDouble()); - if (position.getCourse() > 360) { - position.setCourse(0); - } - - decodeFlags(position, parser.nextInt(16)); - - position.setAltitude(parser.nextDouble()); - - position.set(Position.KEY_BATTERY, parser.nextInt()); - - position.set(Position.KEY_TYPE, sentence.substring(1, 2)); + decodeFix(position, parser); + decodeState(position, parser); return position; } - if (sentence.startsWith("!A,")) { + if (recordType.matches("A")) { Parser parser = new Parser(PATTERN_A, sentence); if (!parser.matches()) { return null; } - Position position = new Position(); - position.setProtocol(getProtocolName()); - position.setDeviceId(deviceSession.getDeviceId()); - - DateBuilder dateBuilder = new DateBuilder() - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); - - position.setLatitude(parser.nextDouble()); - position.setLongitude(parser.nextDouble()); - - position.set(Position.KEY_TYPE, sentence.substring(1, 2)); + decodeFix(position, parser); return position; } -- cgit v1.2.3 From a709867c15dc3752af487ac1c053d4ee982bc8cd Mon Sep 17 00:00:00 2001 From: jon-stumpf Date: Sat, 18 Feb 2017 23:33:23 -0500 Subject: Added KEY_RSSI for protocols that had yet to record them; --- src/org/traccar/protocol/At2000ProtocolDecoder.java | 2 +- src/org/traccar/protocol/AtrackProtocolDecoder.java | 2 +- src/org/traccar/protocol/TeltonikaProtocolDecoder.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/org/traccar/protocol/At2000ProtocolDecoder.java b/src/org/traccar/protocol/At2000ProtocolDecoder.java index 00973f2aa..dc799054d 100644 --- a/src/org/traccar/protocol/At2000ProtocolDecoder.java +++ b/src/org/traccar/protocol/At2000ProtocolDecoder.java @@ -139,7 +139,7 @@ public class At2000ProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_POWER, buf.readUnsignedShort() + "mV"); buf.readUnsignedShort(); // cid - buf.readUnsignedByte(); // rssi + position.set(Position.KEY_RSSI, buf.readUnsignedByte()); buf.readUnsignedByte(); // current profile position.set(Position.KEY_BATTERY, buf.readUnsignedByte()); diff --git a/src/org/traccar/protocol/AtrackProtocolDecoder.java b/src/org/traccar/protocol/AtrackProtocolDecoder.java index 8e3cd2089..d80c19706 100644 --- a/src/org/traccar/protocol/AtrackProtocolDecoder.java +++ b/src/org/traccar/protocol/AtrackProtocolDecoder.java @@ -93,7 +93,7 @@ public class AtrackProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_BATTERY, buf.readUnsignedShort()); break; case "GQ": - buf.readUnsignedByte(); // rssi + position.set(Position.KEY_RSSI, buf.readUnsignedByte()); break; case "CE": buf.readUnsignedInt(); // cid diff --git a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java index 411915400..e647a33a0 100644 --- a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java +++ b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java @@ -162,7 +162,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { } if (BitUtil.check(locationMask, 6)) { - buf.readUnsignedByte(); // rssi + position.set(Position.KEY_RSSI, buf.readUnsignedByte()); } if (BitUtil.check(locationMask, 7)) { -- cgit v1.2.3 From 38249673287b908c0ca55847a35ca16a7b6a0c50 Mon Sep 17 00:00:00 2001 From: jon-stumpf Date: Sun, 19 Feb 2017 11:45:13 -0500 Subject: Updated TmpProtocolDecoder to record KEY_SATELLITES_VISIBLE, KEY_RSSI, and "operator"; --- src/org/traccar/protocol/TmgProtocolDecoder.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/org/traccar/protocol/TmgProtocolDecoder.java b/src/org/traccar/protocol/TmgProtocolDecoder.java index 2f2dddf60..9fa8759a0 100644 --- a/src/org/traccar/protocol/TmgProtocolDecoder.java +++ b/src/org/traccar/protocol/TmgProtocolDecoder.java @@ -50,9 +50,9 @@ public class TmgProtocolDecoder extends BaseProtocolDecoder { .number("(-?d+.?d*),") // altitude .number("(d+.d+),") // hdop .number("(d+),") // satellites - .number("d+,") // visible satellites - .number("[^,]*,") // operator - .number("d+,") // rssi + .number("(d+),") // visible satellites + .number("([^,]*),") // operator + .number("(d+),") // rssi .number("x+,") // cid .expression("([01]),") // ignition .number("(d+.?d*),") // battery @@ -95,6 +95,9 @@ public class TmgProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_HDOP, parser.nextDouble()); position.set(Position.KEY_SATELLITES, parser.nextInt()); + position.set(Position.KEY_SATELLITES_VISIBLE, parser.nextInt()); + position.set("operator", parser.next()); + position.set(Position.KEY_RSSI, parser.nextInt()); position.set(Position.KEY_IGNITION, parser.nextInt() == 1); position.set(Position.KEY_BATTERY, parser.nextDouble()); position.set(Position.KEY_POWER, parser.nextDouble()); -- cgit v1.2.3