aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2017-06-26 12:12:46 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2017-06-26 12:12:46 +1200
commit4e084ebd790286392225e44ce462f987a2c3046a (patch)
tree3e5dcc7c95f6194f7e4e95c005fbc3e11ca6a559 /src
parent9a597a7f902eea46405a345d4398139c13f69655 (diff)
downloadtraccar-server-4e084ebd790286392225e44ce462f987a2c3046a.tar.gz
traccar-server-4e084ebd790286392225e44ce462f987a2c3046a.tar.bz2
traccar-server-4e084ebd790286392225e44ce462f987a2c3046a.zip
Decode Atrack INFO messages
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/protocol/AtrackProtocolDecoder.java52
1 files changed, 44 insertions, 8 deletions
diff --git a/src/org/traccar/protocol/AtrackProtocolDecoder.java b/src/org/traccar/protocol/AtrackProtocolDecoder.java
index 3566631f0..79b3c36cc 100644
--- a/src/org/traccar/protocol/AtrackProtocolDecoder.java
+++ b/src/org/traccar/protocol/AtrackProtocolDecoder.java
@@ -22,6 +22,8 @@ import org.traccar.BaseProtocolDecoder;
import org.traccar.Context;
import org.traccar.DeviceSession;
import org.traccar.helper.DateBuilder;
+import org.traccar.helper.Parser;
+import org.traccar.helper.PatternBuilder;
import org.traccar.helper.UnitsConverter;
import org.traccar.model.CellTower;
import org.traccar.model.Network;
@@ -34,6 +36,7 @@ import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.regex.Pattern;
public class AtrackProtocolDecoder extends BaseProtocolDecoder {
@@ -195,29 +198,62 @@ public class AtrackProtocolDecoder extends BaseProtocolDecoder {
}
}
- private Position decodeString(Channel channel, SocketAddress remoteAddress, String sentence) {
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
- if (deviceSession == null) {
- return null;
- }
+ private static final Pattern PATTERN_INFO = new PatternBuilder()
+ .text("$INFO=")
+ .number("(d+),") // unit id
+ .expression("([^,]+),") // model
+ .expression("([^,]+),") // firmware version
+ .number("d+,") // imei
+ .number("d+,") // imsi
+ .number("d+,") // sim card id
+ .number("(d+),") // power
+ .number("(d+),") // battery
+ .number("(d+),") // satellites
+ .number("d+,") // gsm status
+ .number("(d+),") // rssi
+ .number("d+,") // connection status
+ .number("d+") // antenna status
+ .any()
+ .compile();
+ private Position decodeString(Channel channel, SocketAddress remoteAddress, String sentence) {
Position position = new Position();
position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
getLastLocation(position, null);
+ DeviceSession deviceSession;
+
if (sentence.startsWith("$INFO")) {
- return null;
+ Parser parser = new Parser(PATTERN_INFO, sentence);
+ if (!parser.matches()) {
+ return null;
+ }
+
+ deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
+
+ position.set("model", parser.next());
+ position.set(Position.KEY_VERSION_FW, parser.next());
+ position.set(Position.KEY_POWER, parser.nextInt() * 0.1);
+ position.set(Position.KEY_BATTERY, parser.nextInt() * 0.1);
+ position.set(Position.KEY_SATELLITES, parser.nextInt());
+ position.set(Position.KEY_RSSI, parser.nextInt());
} else {
+ deviceSession = getDeviceSession(channel, remoteAddress);
+
position.set(Position.KEY_RESULT, sentence);
}
- return position;
+ if (deviceSession == null) {
+ return null;
+ } else {
+ position.setDeviceId(deviceSession.getDeviceId());
+ return position;
+ }
}
@Override