aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/org/traccar/protocol/TechTltProtocolDecoder.java53
-rw-r--r--src/test/java/org/traccar/protocol/TechTltProtocolDecoderTest.java2
2 files changed, 50 insertions, 5 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;
+ }
+ }
+
}
diff --git a/src/test/java/org/traccar/protocol/TechTltProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/TechTltProtocolDecoderTest.java
index 0fdd26a47..0e480d835 100644
--- a/src/test/java/org/traccar/protocol/TechTltProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/TechTltProtocolDecoderTest.java
@@ -14,7 +14,7 @@ public class TechTltProtocolDecoderTest extends ProtocolTest {
"002422269*POS=Y,16:21:20,25/11/09,3809.8063N,01444.7438E,4.17,117.23,0.4,09,40076,56341"),
position("2009-11-25 16:21:20.000", true, 38.16344, 14.74573));
- verifyNull(decoder, text(
+ verifyAttributes(decoder, text(
"002422269,INFOGPRS,V Bat=13.8,TEMP=23,I TIM,15"));
}