diff options
-rw-r--r-- | src/main/java/org/traccar/protocol/Tlt2hProtocolDecoder.java | 96 | ||||
-rw-r--r-- | src/test/java/org/traccar/protocol/Tlt2hProtocolDecoderTest.java | 8 |
2 files changed, 80 insertions, 24 deletions
diff --git a/src/main/java/org/traccar/protocol/Tlt2hProtocolDecoder.java b/src/main/java/org/traccar/protocol/Tlt2hProtocolDecoder.java index 3ce6438f8..2bfc08c75 100644 --- a/src/main/java/org/traccar/protocol/Tlt2hProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/Tlt2hProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 - 2019 Anton Tananaev (anton@traccar.org) + * Copyright 2013 - 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. @@ -22,7 +22,9 @@ import org.traccar.Protocol; import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; +import org.traccar.model.Network; import org.traccar.model.Position; +import org.traccar.model.WifiAccessPoint; import java.net.SocketAddress; import java.util.LinkedList; @@ -51,10 +53,11 @@ public class Tlt2hProtocolDecoder extends BaseProtocolDecoder { .compile(); private static final Pattern PATTERN_POSITION = new PatternBuilder() - .number("#(x+)?") // cell info + .text("#") + .number("(?:(dd)|x*)") // cell or voltage .text("$GPRMC,") .number("(dd)(dd)(dd).d+,") // time (hhmmss.sss) - .expression("([AV]),") // validity + .expression("([AVL]),") // validity .number("(d+)(dd.d+),") // latitude .expression("([NS]),") .number("(d+)(dd.d+),") // longitude @@ -65,6 +68,18 @@ public class Tlt2hProtocolDecoder extends BaseProtocolDecoder { .any() .compile(); + private static final Pattern PATTERN_WIFI = new PatternBuilder() + .text("#") + .number("(?:(dd)|x+)") // cell or voltage + .text("$WIFI,") + .number("(dd)(dd)(dd).d+,") // time (hhmmss.sss) + .expression("[AVL],") // validity + .expression("(.*)") // access points + .number("(dd)(dd)(dd)") // date (ddmmyy) + .text("*") + .number("xx") // checksum + .compile(); + private void decodeStatus(Position position, String status) { switch (status) { case "AUTOSTART": @@ -141,35 +156,68 @@ public class Tlt2hProtocolDecoder extends BaseProtocolDecoder { List<Position> positions = new LinkedList<>(); for (String message : messages) { - parser = new Parser(PATTERN_POSITION, message); - if (parser.matches()) { + Position position = new Position(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + + if (message.contains("$GPRMC")) { + + parser = new Parser(PATTERN_POSITION, message); + if (parser.matches()) { + + if (parser.hasNext()) { + position.set(Position.KEY_BATTERY, parser.nextInt() * 0.1); + } + + DateBuilder dateBuilder = new DateBuilder() + .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - Position position = new Position(getProtocolName()); - position.setDeviceId(deviceSession.getDeviceId()); + position.setValid(parser.next().equals("A")); + position.setLatitude(parser.nextCoordinate()); + position.setLongitude(parser.nextCoordinate()); + position.setSpeed(parser.nextDouble(0)); + position.setCourse(parser.nextDouble(0)); - parser.next(); // base station info + dateBuilder.setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()); + position.setTime(dateBuilder.getDate()); + } - DateBuilder dateBuilder = new DateBuilder() - .setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0)); + } else if (message.contains("$WIFI")) { - position.setValid(parser.next().equals("A")); - position.setLatitude(parser.nextCoordinate()); - position.setLongitude(parser.nextCoordinate()); - position.setSpeed(parser.nextDouble(0)); - position.setCourse(parser.nextDouble(0)); + parser = new Parser(PATTERN_WIFI, message); + if (parser.matches()) { - dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0)); - position.setTime(dateBuilder.getDate()); + position.set(Position.KEY_BATTERY, parser.nextInt() * 0.1); - position.set(Position.KEY_DOOR, door); - position.set(Position.PREFIX_ADC + 1, adc); - position.set(Position.KEY_POWER, power); - position.set(Position.KEY_BATTERY, battery); - position.set(Position.PREFIX_TEMP + 1, temperature); - decodeStatus(position, status); + DateBuilder dateBuilder = new DateBuilder() + .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); + + String[] values = parser.next().split(","); + Network network = new Network(); + for (int i = 0; i < values.length / 2; i++) { + String mac = values[i * 2 + 1].replaceAll("(..)", "$1:").substring(0, 17); + network.addWifiAccessPoint(WifiAccessPoint.from(mac, Integer.parseInt(values[i * 2]))); + } + position.setNetwork(network); + + dateBuilder.setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()); + + getLastLocation(position, dateBuilder.getDate()); + } + + } else { + + getLastLocation(position, null); - positions.add(position); } + + position.set(Position.KEY_DOOR, door); + position.set(Position.PREFIX_ADC + 1, adc); + position.set(Position.KEY_POWER, power); + position.set(Position.KEY_BATTERY, battery); + position.set(Position.PREFIX_TEMP + 1, temperature); + decodeStatus(position, status); + + positions.add(position); } return positions; diff --git a/src/test/java/org/traccar/protocol/Tlt2hProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/Tlt2hProtocolDecoderTest.java index 6b65b2c4c..bc1c8e112 100644 --- a/src/test/java/org/traccar/protocol/Tlt2hProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/Tlt2hProtocolDecoderTest.java @@ -12,6 +12,14 @@ public class Tlt2hProtocolDecoderTest extends ProtocolTest { var decoder = new Tlt2hProtocolDecoder(null); verifyPositions(decoder, text( + "#867198059727390#MT700#0000#AUTO#1\r\n", + "#38$GPRMC,105721.00,A,2238.3071,N,11401.7575,E,,96.70,250321,,,A*74\r\n")); + + verifyPositions(decoder, false, text( + "#867198059727390#MT700#0000#AUTO#1\r\n", + "#40$WIFI,123532.00,A,-62,D8325A0ABADD,-64,EC172F8965BC,-64,7405A5D457D4,260321*07\r\n")); + + verifyPositions(decoder, text( "#860425040088567#MT600+#0000#0#1#129#40#0#AUTOLOW#1\r\n", "#000321901$GPRMC,172030.00,A,4845.2906,N,01910.2742,E,0.01,,041219,,,A*43\r\n")); |