aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/protocol/TechTltProtocolDecoder.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2019-05-26 15:13:01 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2019-05-26 15:13:01 -0700
commitdecde70bcf90490a3fe8d24a9bd43a17074af718 (patch)
tree0b826aaa236458d275adf6083a3c8b41a024714b /src/main/java/org/traccar/protocol/TechTltProtocolDecoder.java
parent48b03a977aff2de4532930e4d84f25606d4e7074 (diff)
downloadtrackermap-server-decde70bcf90490a3fe8d24a9bd43a17074af718.tar.gz
trackermap-server-decde70bcf90490a3fe8d24a9bd43a17074af718.tar.bz2
trackermap-server-decde70bcf90490a3fe8d24a9bd43a17074af718.zip
Decode status messages
Diffstat (limited to 'src/main/java/org/traccar/protocol/TechTltProtocolDecoder.java')
-rw-r--r--src/main/java/org/traccar/protocol/TechTltProtocolDecoder.java53
1 files changed, 49 insertions, 4 deletions
diff --git a/src/main/java/org/traccar/protocol/TechTltProtocolDecoder.java b/src/main/java/org/traccar/protocol/TechTltProtocolDecoder.java
index bad289060..046e7a748 100644
--- a/src/main/java/org/traccar/protocol/TechTltProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/TechTltProtocolDecoder.java
@@ -35,6 +35,15 @@ public class TechTltProtocolDecoder extends BaseProtocolDecoder {
super(protocol);
}
+ private static final Pattern PATTERN_STATUS = new PatternBuilder()
+ .number("(d+),") // id
+ .text("INFOGPRS,")
+ .number("V Bat=(d+.d),") // battery
+ .number("TEMP=(d+),") // temperature
+ .expression("[^,]*,")
+ .number("(d+)") // rssi
+ .compile();
+
private static final Pattern PATTERN_POSITION = new PatternBuilder()
.number("(d+)") // id
.text("*POS=Y,")
@@ -52,11 +61,33 @@ public class TechTltProtocolDecoder extends BaseProtocolDecoder {
.number("(d+)") // cid
.compile();
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
+ private Position decodeStatus(Channel channel, SocketAddress remoteAddress, String sentence) {
- Parser parser = new Parser(PATTERN_POSITION, (String) msg);
+ Parser parser = new Parser(PATTERN_STATUS, sentence);
+ if (!parser.matches()) {
+ return null;
+ }
+
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
+ if (deviceSession == null) {
+ return null;
+ }
+
+ Position position = new Position(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ getLastLocation(position, null);
+
+ position.set(Position.KEY_BATTERY, parser.nextDouble());
+ position.set(Position.KEY_DEVICE_TEMP, parser.nextInt());
+ position.set(Position.KEY_RSSI, parser.nextInt());
+
+ return position;
+ }
+
+ private Position decodeLocation(Channel channel, SocketAddress remoteAddress, String sentence) {
+
+ Parser parser = new Parser(PATTERN_POSITION, sentence);
if (!parser.matches()) {
return null;
}
@@ -84,4 +115,18 @@ public class TechTltProtocolDecoder extends BaseProtocolDecoder {
return position;
}
+ @Override
+ protected Object decode(
+ Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
+
+ String sentence = (String) msg;
+ if (sentence.contains("INFO")) {
+ return decodeStatus(channel, remoteAddress, sentence);
+ } else if (sentence.contains("POS")) {
+ return decodeLocation(channel, remoteAddress, sentence);
+ } else {
+ return null;
+ }
+ }
+
}