diff options
Diffstat (limited to 'src/main/java/org/traccar/protocol/ItsProtocolDecoder.java')
-rw-r--r-- | src/main/java/org/traccar/protocol/ItsProtocolDecoder.java | 79 |
1 files changed, 70 insertions, 9 deletions
diff --git a/src/main/java/org/traccar/protocol/ItsProtocolDecoder.java b/src/main/java/org/traccar/protocol/ItsProtocolDecoder.java index 482f34e65..313575f27 100644 --- a/src/main/java/org/traccar/protocol/ItsProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/ItsProtocolDecoder.java @@ -23,6 +23,8 @@ import org.traccar.Protocol; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; +import org.traccar.model.CellTower; +import org.traccar.model.Network; import org.traccar.model.Position; import java.net.SocketAddress; @@ -41,11 +43,11 @@ public class ItsProtocolDecoder extends BaseProtocolDecoder { .groupBegin() .expression("[^,]+,") // vendor .expression("[^,]+,") // firmware version - .expression("[^,]+,") // type - .number("d+,") - .expression("[LH],") // history + .expression("(..),") // status + .number("(d+),") // event + .expression("([LH]),") // history .or() - .expression("[^,]+,") // type + .expression("([^,]+),") // type .groupEnd() .number("(d{15}),") // imei .groupBegin() @@ -72,12 +74,17 @@ public class ItsProtocolDecoder extends BaseProtocolDecoder { .number("([01]),") // charging .number("(d+.?d*),") // power .number("(d+.?d*),") // battery - .number("[01],") // emergency + .number("([01]),") // emergency .expression("[CO]?,") // tamper - .number("(?:x+,){5}") // main cell - .number("(?:-?x+,){12}") // other cells + .number("((?:x+,){5}") // main cell + .number("(?:-?x+,){12})") // other cells .number("([01]{4}),") // inputs .number("([01]{2}),") // outputs + .groupBegin() + .number("d+,") // index + .number("(d+.d+),") // adc1 + .number("(d+.d+),") // adc2 + .groupEnd("?") .groupEnd("?") .or() .number("(-?d+.d+),") // altitude @@ -101,6 +108,12 @@ public class ItsProtocolDecoder extends BaseProtocolDecoder { return Position.ALARM_CORNERING; case "OS": return Position.ALARM_OVERSPEED; + case "TA": + return Position.ALARM_TAMPERING; + case "BD": + return Position.ALARM_POWER_CUT; + case "BR": + return Position.ALARM_POWER_RESTORED; default: return null; } @@ -121,6 +134,11 @@ public class ItsProtocolDecoder extends BaseProtocolDecoder { return null; } + String status = parser.next(); + Integer event = parser.nextInt(); + boolean history = "H".equals(parser.next()); + String type = parser.next(); + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next()); if (deviceSession == null) { return null; @@ -129,8 +147,28 @@ public class ItsProtocolDecoder extends BaseProtocolDecoder { Position position = new Position(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); + if (type != null && type.equals("EMR")) { + position.set(Position.KEY_ALARM, Position.ALARM_SOS); + } + + if (event != null) { + position.set(Position.KEY_EVENT, event); + } + if (history) { + position.set(Position.KEY_ARCHIVE, true); + } + if (parser.hasNext()) { - position.set(Position.KEY_ALARM, decodeAlarm(parser.next())); + status = parser.next(); + } + if (status != null) { + if (status.equals("IN")) { + position.set(Position.KEY_IGNITION, true); + } else if (status.equals("IF")) { + position.set(Position.KEY_IGNITION, false); + } else { + position.set(Position.KEY_ALARM, decodeAlarm(status)); + } } if (parser.hasNext()) { @@ -149,17 +187,40 @@ public class ItsProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_SATELLITES, parser.nextInt()); } - if (parser.hasNext(7)) { + if (parser.hasNext(8)) { position.setAltitude(parser.nextDouble()); position.set(Position.KEY_IGNITION, parser.nextInt() > 0); position.set(Position.KEY_CHARGE, parser.nextInt() > 0); position.set(Position.KEY_POWER, parser.nextDouble()); position.set(Position.KEY_BATTERY, parser.nextDouble()); + + position.set("emergency", parser.nextInt() > 0); + + String[] cells = parser.next().split(","); + int mcc = Integer.parseInt(cells[1]); + int mnc = Integer.parseInt(cells[2]); + int lac = Integer.parseInt(cells[3], 16); + int cid = Integer.parseInt(cells[4], 16); + Network network = new Network(CellTower.from(mcc, mnc, lac, cid, Integer.parseInt(cells[0]))); + for (int i = 0; i < 4; i++) { + lac = Integer.parseInt(cells[5 + 3 * i + 1], 16); + cid = Integer.parseInt(cells[5 + 3 * i + 2], 16); + if (lac > 0 && cid > 0) { + network.addCellTower(CellTower.from(mcc, mnc, lac, cid)); + } + } + position.setNetwork(network); + position.set(Position.KEY_INPUT, parser.nextBinInt()); position.set(Position.KEY_OUTPUT, parser.nextBinInt()); } if (parser.hasNext(2)) { + position.set(Position.PREFIX_ADC + 1, parser.nextDouble()); + position.set(Position.PREFIX_ADC + 2, parser.nextDouble()); + } + + if (parser.hasNext(2)) { position.setAltitude(parser.nextDouble()); position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble())); } |