aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2021-05-22 16:47:46 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2021-05-22 16:47:46 -0700
commit8b29c4b31db0a9552ed2106ca8d2030fca6edea9 (patch)
treed4db5516ff8261ebd54070d85a4cf72cc7c60269 /src/main/java/org/traccar
parent814dc83e21cdfbc563469c8adcdfbd278f26d551 (diff)
downloadtraccar-server-8b29c4b31db0a9552ed2106ca8d2030fca6edea9.tar.gz
traccar-server-8b29c4b31db0a9552ed2106ca8d2030fca6edea9.tar.bz2
traccar-server-8b29c4b31db0a9552ed2106ca8d2030fca6edea9.zip
Support Mictrack MT700 format
Diffstat (limited to 'src/main/java/org/traccar')
-rw-r--r--src/main/java/org/traccar/protocol/Tlt2hProtocolDecoder.java96
1 files changed, 72 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;