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 ++++++++++++++++++++++ .../traccar/protocol/TrvProtocolDecoderTest.java | 5 +- 2 files changed, 63 insertions(+), 1 deletion(-) 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; diff --git a/test/org/traccar/protocol/TrvProtocolDecoderTest.java b/test/org/traccar/protocol/TrvProtocolDecoderTest.java index 1a352d1ab..2fdb86218 100644 --- a/test/org/traccar/protocol/TrvProtocolDecoderTest.java +++ b/test/org/traccar/protocol/TrvProtocolDecoderTest.java @@ -13,6 +13,9 @@ public class TrvProtocolDecoderTest extends ProtocolTest { verifyNull(decoder, text( "TRVAP00352121088015548")); + verifyNotNull(decoder, text( + "IWAP02,zh_cn,0,6,260,1,11002|39252|9,11002|35112|23,11002|11043|24,11002|39253|24,11002|13751|24,11018|8102|26,3,a|c0-4a-00-b6-9c-f5|64&a|c0-4a-00-b6-9c-f5|64&a|18-a6-f7-92-35-da|84")); + verifyPosition(decoder, text( "TRVAP01170905A5227.1382N00541.4256E001.7095844000.0008100610020100,204,8,3230,13007")); @@ -25,7 +28,7 @@ public class TrvProtocolDecoderTest extends ProtocolTest { verifyPosition(decoder, text( "IWAP01080524A2232.9806N11404.9355E000.1061830323.8706000908000102,460,0,9520,3671,Home|74-DE-2B-44-88-8C|97& Home1|74-DE-2B-44-88-8C|97&Home2|74-DE-2B-44-88-8C|97& Home3|74-DE-2B-44-88-8C|97")); - verifyNull(decoder, text( + verifyNotNull(decoder, text( "IWAP02,zh_cn,0,7,460,0,9520|3671|13,9520|3672|12,9520|3673|11,9520|3674|10,9520|3675|9,9520|3676|8,9520|3677|7,4,1|D8-24-BD-79-FA-1F|59&2|3C-46-D8-6D-CE-01|81&3|0C-4C-39-1A-7C-65|69&4|70-A8-E3-5D-D7-C0|65")); verifyPosition(decoder, text( -- cgit v1.2.3