aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2019-02-11 20:26:19 -0800
committerAnton Tananaev <anton.tananaev@gmail.com>2019-02-11 20:26:19 -0800
commit437090f717e66bf3b41f9f812245022a81a827c2 (patch)
tree0f4feaafb73ef3b9c7a47e450626fbc4839180f8
parentc37ebc1b07ba7ea6eeccc0b04b2cac72041507e0 (diff)
downloadtraccar-server-437090f717e66bf3b41f9f812245022a81a827c2.tar.gz
traccar-server-437090f717e66bf3b41f9f812245022a81a827c2.tar.bz2
traccar-server-437090f717e66bf3b41f9f812245022a81a827c2.zip
Support power on and off messages
-rw-r--r--src/org/traccar/protocol/Gl200TextProtocolDecoder.java30
-rw-r--r--test/org/traccar/protocol/Gl200TextProtocolDecoderTest.java9
2 files changed, 39 insertions, 0 deletions
diff --git a/src/org/traccar/protocol/Gl200TextProtocolDecoder.java b/src/org/traccar/protocol/Gl200TextProtocolDecoder.java
index b258c97bf..aeb57a116 100644
--- a/src/org/traccar/protocol/Gl200TextProtocolDecoder.java
+++ b/src/org/traccar/protocol/Gl200TextProtocolDecoder.java
@@ -314,6 +314,18 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder {
.text("$").optional()
.compile();
+ private static final Pattern PATTERN_PNA = new PatternBuilder()
+ .text("+RESP:GT").expression("P[NF]A,")
+ .number("(?:[0-9A-Z]{2}xxxx)?,") // protocol version
+ .number("(d{15}|x{14}),") // imei
+ .expression("[^,]*,") // device name
+ .number("(dddd)(dd)(dd)") // date (yyyymmdd)
+ .number("(dd)(dd)(dd)").optional(2) // time (hhmmss)
+ .text(",")
+ .number("(xxxx)") // count number
+ .text("$").optional()
+ .compile();
+
private static final Pattern PATTERN = new PatternBuilder()
.text("+").expression("(?:RESP|BUFF):GT...,")
.number("(?:[0-9A-Z]{2}xxxx)?,") // protocol version
@@ -1038,6 +1050,20 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder {
return position;
}
+ private Object decodePna(Channel channel, SocketAddress remoteAddress, String sentence) {
+ Parser parser = new Parser(PATTERN_PNA, sentence);
+ Position position = initPosition(parser, channel, remoteAddress);
+ if (position == null) {
+ return null;
+ }
+
+ getLastLocation(position, null);
+
+ position.set(Position.KEY_ALARM, sentence.contains("PNA") ? Position.ALARM_POWER_ON : Position.ALARM_POWER_OFF);
+
+ return position;
+ }
+
private Object decodeOther(Channel channel, SocketAddress remoteAddress, String sentence, String type) {
Parser parser = new Parser(PATTERN, sentence);
Position position = initPosition(parser, channel, remoteAddress);
@@ -1210,6 +1236,10 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder {
case "VER":
result = decodeVer(channel, remoteAddress, sentence);
break;
+ case "PNA":
+ case "PFA":
+ result = decodePna(channel, remoteAddress, sentence);
+ break;
default:
result = decodeOther(channel, remoteAddress, sentence, type);
break;
diff --git a/test/org/traccar/protocol/Gl200TextProtocolDecoderTest.java b/test/org/traccar/protocol/Gl200TextProtocolDecoderTest.java
index ae4201f94..2fe860573 100644
--- a/test/org/traccar/protocol/Gl200TextProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/Gl200TextProtocolDecoderTest.java
@@ -2,6 +2,7 @@ package org.traccar.protocol;
import org.junit.Test;
import org.traccar.ProtocolTest;
+import org.traccar.model.Position;
public class Gl200TextProtocolDecoderTest extends ProtocolTest {
@@ -10,6 +11,14 @@ public class Gl200TextProtocolDecoderTest extends ProtocolTest {
Gl200TextProtocolDecoder decoder = new Gl200TextProtocolDecoder(null);
+ verifyAttribute(decoder, buffer(
+ "+RESP:GTPFA,F50201,866425030235982,GL300M,20190208124849,0BD4$"),
+ Position.KEY_ALARM, Position.ALARM_POWER_OFF);
+
+ verifyAttribute(decoder, buffer(
+ "+RESP:GTPNA,F50201,866425030235982,GL300M,20190208124909,0BD5$"),
+ Position.KEY_ALARM, Position.ALARM_POWER_ON);
+
verifyAttributes(decoder, buffer(
"+BUFF:GTSTC,410301,864802030022424,,,0,,,,,,,0228,0002,4EE8,1BFF489,00,20181207134332,EC90$"));