diff options
Diffstat (limited to 'src/org/traccar/protocol/AtrackProtocolDecoder.java')
-rw-r--r-- | src/org/traccar/protocol/AtrackProtocolDecoder.java | 127 |
1 files changed, 115 insertions, 12 deletions
diff --git a/src/org/traccar/protocol/AtrackProtocolDecoder.java b/src/org/traccar/protocol/AtrackProtocolDecoder.java index 4a2d4b848..49f44a4f0 100644 --- a/src/org/traccar/protocol/AtrackProtocolDecoder.java +++ b/src/org/traccar/protocol/AtrackProtocolDecoder.java @@ -104,20 +104,81 @@ public class AtrackProtocolDecoder extends BaseProtocolDecoder { } private void readTextCustomData(Position position, String data, String form) { + CellTower cellTower = new CellTower(); String[] keys = form.substring(1).split("%"); String[] values = data.split(",|\r\n"); for (int i = 0; i < Math.min(keys.length, values.length); i++) { switch (keys[i]) { + case "SA": + position.set(Position.KEY_SATELLITES, Integer.parseInt(values[i])); + break; case "MV": position.set(Position.KEY_POWER, Integer.parseInt(values[i]) * 0.1); break; case "BV": position.set(Position.KEY_BATTERY, Integer.parseInt(values[i]) * 0.1); break; + case "GQ": + cellTower.setSignalStrength(Integer.parseInt(values[i])); + break; + case "CE": + cellTower.setCellId(Long.parseLong(values[i])); + break; + case "LC": + cellTower.setLocationAreaCode(Integer.parseInt(values[i])); + break; + case "CN": + if (values[i].length() > 3) { + cellTower.setMobileCountryCode(Integer.parseInt(values[i].substring(0, 3))); + cellTower.setMobileNetworkCode(Integer.parseInt(values[i].substring(3))); + } + break; + case "PC": + position.set(Position.PREFIX_COUNT + 1, Integer.parseInt(values[i])); + break; + case "AT": + position.setAltitude(Integer.parseInt(values[i])); + break; + case "RP": + position.set(Position.KEY_RPM, Integer.parseInt(values[i])); + break; + case "GS": + position.set(Position.KEY_RSSI, Integer.parseInt(values[i])); + break; + case "DT": + position.set(Position.KEY_ARCHIVE, Integer.parseInt(values[i]) == 1); + break; + case "VN": + position.set(Position.KEY_VIN, values[i]); + break; + case "TR": + position.set(Position.KEY_THROTTLE, Integer.parseInt(values[i])); + break; + case "ET": + position.set(Position.PREFIX_TEMP + 1, Integer.parseInt(values[i])); + break; + case "FL": + position.set(Position.KEY_FUEL_LEVEL, Integer.parseInt(values[i])); + break; + case "FC": + position.set(Position.KEY_FUEL_CONSUMPTION, Integer.parseInt(values[i])); + break; + case "AV1": + position.set(Position.PREFIX_ADC + 1, Integer.parseInt(values[i])); + break; default: break; } } + + if (cellTower.getMobileCountryCode() != null + && cellTower.getMobileNetworkCode() != null + && cellTower.getCellId() != null + && cellTower.getLocationAreaCode() != null) { + position.setNetwork(new Network(cellTower)); + } else if (cellTower.getSignalStrength() != null) { + position.set(Position.KEY_RSSI, cellTower.getSignalStrength()); + } } private void readBinaryCustomData(Position position, ByteBuf buf, String form) { @@ -208,6 +269,30 @@ public class AtrackProtocolDecoder extends BaseProtocolDecoder { case "MA": readString(buf); // mac address break; + case "PD": + buf.readUnsignedByte(); // pending code status + break; + case "CD": + readString(buf); // sim cid + break; + case "CM": + buf.readLong(); // imsi + break; + case "GN": + buf.skipBytes(60); // g sensor data + break; + case "GV": + buf.skipBytes(6); // maximum g force + break; + case "ME": + buf.readLong(); // imei + break; + case "IA": + buf.readUnsignedByte(); // intake air temperature + break; + case "MP": + buf.readUnsignedByte(); // manifold absolute pressure + break; default: break; } @@ -215,7 +300,7 @@ public class AtrackProtocolDecoder extends BaseProtocolDecoder { if (cellTower.getMobileCountryCode() != null && cellTower.getMobileNetworkCode() != null - && cellTower.getCellId() != null + && cellTower.getCellId() != null && cellTower.getCellId() != 0 && cellTower.getLocationAreaCode() != null) { position.setNetwork(new Network(cellTower)); } else if (cellTower.getSignalStrength() != null) { @@ -282,11 +367,6 @@ public class AtrackProtocolDecoder extends BaseProtocolDecoder { } private static final Pattern PATTERN = new PatternBuilder() - .text("@P,") - .number("x+,") // checksum - .number("d+,") // length - .number("d+,") // index - .number("(d+),") // imei .number("(d+),") // date and time .number("d+,") // rtc date and time .number("d+,") // device date and time @@ -308,18 +388,41 @@ public class AtrackProtocolDecoder extends BaseProtocolDecoder { .optional(2) .compile(); - private Position decodeText(Channel channel, SocketAddress remoteAddress, String sentence) { + private List<Position> decodeText(Channel channel, SocketAddress remoteAddress, String sentence) { - Parser parser = new Parser(PATTERN, sentence); - if (!parser.matches()) { - return null; + int startIndex = 0; + for (int i = 0; i < 4; i++) { + startIndex = sentence.indexOf(',', startIndex + 1); } + int endIndex = sentence.indexOf(',', startIndex + 1); - DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next()); + String imei = sentence.substring(startIndex + 1, endIndex); + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei); if (deviceSession == null) { return null; } + List<Position> positions = new LinkedList<>(); + String[] lines = sentence.substring(endIndex + 1).split("\r\n"); + + for (String line : lines) { + Position position = decodeTextLine(deviceSession, line); + if (position != null) { + positions.add(position); + } + } + + return positions; + } + + + private Position decodeTextLine(DeviceSession deviceSession, String sentence) { + + Parser parser = new Parser(PATTERN, sentence); + if (!parser.matches()) { + return null; + } + Position position = new Position(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); @@ -442,7 +545,7 @@ public class AtrackProtocolDecoder extends BaseProtocolDecoder { if (custom) { String form = this.form; if (form == null) { - form = readString(buf).substring("%CI".length()); + form = readString(buf).trim().substring("%CI".length()); } readBinaryCustomData(position, buf, form); } |