From adb0e8c004db89c4248b91613a126cd81efb4587 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Mon, 15 Oct 2018 11:02:00 +1300 Subject: Handle alternative ITS message types --- src/org/traccar/protocol/ItsProtocolDecoder.java | 31 ++++++++++++++++++------ 1 file changed, 23 insertions(+), 8 deletions(-) (limited to 'src/org') diff --git a/src/org/traccar/protocol/ItsProtocolDecoder.java b/src/org/traccar/protocol/ItsProtocolDecoder.java index 53d796b03..79eca21ce 100644 --- a/src/org/traccar/protocol/ItsProtocolDecoder.java +++ b/src/org/traccar/protocol/ItsProtocolDecoder.java @@ -34,18 +34,30 @@ public class ItsProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN = new PatternBuilder() .text("$,") - .expression("[^,]+,") // header + .expression("[^,]+,") // event + .groupBegin() + .expression("[^,]+,") // vendor + .number("d+.d+.d+,") // firmware version + .groupEnd("?") .expression("[^,]+,") // type + .groupBegin() + .number("d+,") + .expression("[LH],") // history + .groupEnd("?") .number("(d{15}),") // imei + .groupBegin() .expression("(?:NM|SP),") // status + .or() + .expression("[^,]+,") // vehicle registration + .number("([01]),") // valid + .groupEnd() .number("(dd),(dd),(dddd),") // date (ddmmyyyy) .number("(dd),(dd),(dd),") // time (hhmmss) - .expression("([AV]),") // valid + .expression("([AV]),").optional() // valid .number("(d+.d+),([NS]),") // latitude .number("(d+.d+),([EW]),") // longitude - .number("(-?d+.d+),") // altitude + .number("(-?d+.d+),").optional() // altitude .number("(d+.d+),") // speed - .number("(d+.d+),") // distance .any() .compile(); @@ -66,15 +78,18 @@ public class ItsProtocolDecoder extends BaseProtocolDecoder { Position position = new Position(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); + if (parser.hasNext()) { + position.setValid(parser.nextInt() == 1); + } position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS)); - position.setValid(parser.next().equals("A")); + if (parser.hasNext()) { + position.setValid(parser.next().equals("A")); + } position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM)); position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM)); - position.setAltitude(parser.nextDouble()); + position.setAltitude(parser.nextDouble(0)); position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble())); - position.set(Position.KEY_ODOMETER, parser.nextDouble()); - return position; } -- cgit v1.2.3