From 82b4ebc742f8801d6a0ef97514f163dd66cb5327 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 12 Jan 2019 12:01:10 -0800 Subject: Support H10 cell and wifi --- src/org/traccar/protocol/TrvProtocolDecoder.java | 59 ++++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'src/org/traccar/protocol') diff --git a/src/org/traccar/protocol/TrvProtocolDecoder.java b/src/org/traccar/protocol/TrvProtocolDecoder.java index 3d27be9d4..b63385187 100644 --- a/src/org/traccar/protocol/TrvProtocolDecoder.java +++ b/src/org/traccar/protocol/TrvProtocolDecoder.java @@ -27,6 +27,7 @@ import org.traccar.helper.UnitsConverter; import org.traccar.model.CellTower; import org.traccar.model.Network; import org.traccar.model.Position; +import org.traccar.model.WifiAccessPoint; import java.net.SocketAddress; import java.text.SimpleDateFormat; @@ -86,6 +87,25 @@ public class TrvProtocolDecoder extends BaseProtocolDecoder { .any() .compile(); + private static final Pattern PATTERN_LBS = new PatternBuilder() + .expression("[A-Z]{2,3}") + .text("AP02,") + .expression("[^,]+,") // language + .number("[01],") // reply + .number("d+,") // cell count + .number("(d+),") // mcc + .number("(d+),") // mnc + .expression("(") + .groupBegin() + .number("d+|") // lac + .number("d+|") // cid + .number("d+,") // rssi + .groupEnd("+") + .expression(")") + .number("d+,") // wifi count + .expression("(.*)") // wifi + .compile(); + private Boolean decodeOptionalValue(Parser parser, int activeValue) { int value = parser.nextInt(); if (value != 0) { @@ -191,6 +211,45 @@ public class TrvProtocolDecoder extends BaseProtocolDecoder { return position; + } else if (type.equals("AP02")) { + + Parser parser = new Parser(PATTERN_LBS, sentence); + if (!parser.matches()) { + return null; + } + + Position position = new Position(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + + getLastLocation(position, null); + + int mcc = parser.nextInt(); + int mnc = parser.nextInt(); + + Network network = new Network(); + + for (String cell : parser.next().split(",")) { + if (!cell.isEmpty()) { + String[] values = cell.split("\\|"); + network.addCellTower(CellTower.from( + mcc, mnc, + Integer.parseInt(values[0]), + Integer.parseInt(values[1]), + Integer.parseInt(values[2]))); + } + } + + for (String wifi : parser.next().split("&")) { + if (!wifi.isEmpty()) { + String[] values = wifi.split("\\|"); + network.addWifiAccessPoint(WifiAccessPoint.from(values[1], Integer.parseInt(values[2]))); + } + } + + position.setNetwork(network); + + return position; + } return null; -- cgit v1.2.3