diff options
Diffstat (limited to 'src/main/java/org/traccar/protocol/MobilogixProtocolDecoder.java')
-rw-r--r-- | src/main/java/org/traccar/protocol/MobilogixProtocolDecoder.java | 75 |
1 files changed, 57 insertions, 18 deletions
diff --git a/src/main/java/org/traccar/protocol/MobilogixProtocolDecoder.java b/src/main/java/org/traccar/protocol/MobilogixProtocolDecoder.java index 8677ba9ec..86c89e336 100644 --- a/src/main/java/org/traccar/protocol/MobilogixProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/MobilogixProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 Anton Tananaev (anton@traccar.org) + * Copyright 2020 - 2021 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,28 +39,52 @@ public class MobilogixProtocolDecoder extends BaseProtocolDecoder { .text("[") .number("(dddd)-(dd)-(dd) ") // date (yyyymmdd) .number("(dd):(dd):(dd),") // time (hhmmss) - .number("Td,") // type - .number("d+,") // device type + .number("Td+,") // type + .number("(d),") // archive .expression("[^,]+,") // protocol version .expression("([^,]+),") // serial number .number("(xx),") // status - .number("(d+.d+),") // battery - .number("(d)") // valid + .number("(d+.d+)") // battery + .groupBegin() + .text(",") + .number("(d)") // satellites .number("(d)") // rssi - .number("(d),") // satellites + .number("(d),") // valid .number("(-?d+.d+),") // latitude .number("(-?d+.d+),") // longitude .number("(d+.?d*),") // speed .number("(d+.?d*)") // course + .groupEnd("?") .any() .compile(); + private String decodeAlarm(String type) { + switch (type) { + case "T8": + return Position.ALARM_LOW_BATTERY; + case "T9": + return Position.ALARM_VIBRATION; + case "T10": + return Position.ALARM_POWER_CUT; + case "T11": + return Position.ALARM_LOW_POWER; + case "T12": + return Position.ALARM_GEOFENCE_EXIT; + case "T13": + return Position.ALARM_OVERSPEED; + case "T15": + return Position.ALARM_TOW; + default: + return null; + } + } + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - String sentence = (String) msg; - String type = sentence.substring(21, 21 + 2); + String sentence = ((String) msg).trim(); + String type = sentence.substring(21, sentence.indexOf(',', 21)); if (channel != null) { String time = sentence.substring(1, 20); @@ -68,19 +92,22 @@ public class MobilogixProtocolDecoder extends BaseProtocolDecoder { if (type.equals("T1")) { response = String.format("[%s,S1,1]", time); } else { - response = String.format("[%s,S%c]", time, type.charAt(1)); + response = String.format("[%s,S%s]", time, type.substring(1)); } channel.writeAndFlush(new NetworkMessage(response, remoteAddress)); } - Parser parser = new Parser(PATTERN, (String) msg); + Parser parser = new Parser(PATTERN, sentence); if (!parser.matches()) { return null; } Position position = new Position(getProtocolName()); - position.setTime(parser.nextDateTime()); + position.setDeviceTime(parser.nextDateTime()); + if (parser.nextInt() == 0) { + position.set(Position.KEY_ARCHIVE, true); + } DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next()); if (deviceSession == null) { @@ -88,6 +115,9 @@ public class MobilogixProtocolDecoder extends BaseProtocolDecoder { } position.setDeviceId(deviceSession.getDeviceId()); + position.set(Position.KEY_TYPE, type); + position.set(Position.KEY_ALARM, decodeAlarm(type)); + int status = parser.nextHexInt(); position.set(Position.KEY_IGNITION, BitUtil.check(status, 2)); position.set(Position.KEY_MOTION, BitUtil.check(status, 3)); @@ -95,15 +125,24 @@ public class MobilogixProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_BATTERY, parser.nextDouble()); - position.setValid(parser.nextInt() > 0); + if (parser.hasNext(7)) { - position.set(Position.KEY_RSSI, parser.nextInt()); - position.set(Position.KEY_SATELLITES, parser.nextInt()); + position.set(Position.KEY_SATELLITES, parser.nextInt()); + position.set(Position.KEY_RSSI, 6 * parser.nextInt() - 111); - position.setLatitude(parser.nextDouble()); - position.setLongitude(parser.nextDouble()); - position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble())); - position.setCourse(parser.nextDouble()); + position.setValid(parser.nextInt() > 0); + position.setFixTime(position.getDeviceTime()); + + position.setLatitude(parser.nextDouble()); + position.setLongitude(parser.nextDouble()); + position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble())); + position.setCourse(parser.nextDouble()); + + } else { + + getLastLocation(position, position.getDeviceTime()); + + } return position; } |