aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbyss777 <abyss@fox5.ru>2016-10-06 11:58:05 +0500
committerAbyss777 <abyss@fox5.ru>2016-10-06 11:58:05 +0500
commita076c67bbdc2ed7d293f6044f4b51493b7e2d3c3 (patch)
tree2e1e3cc6de95801e5adc6fcc1e8c9c68ca23dbc2
parent534aa00430e507a43b581707a74ab08bce7d5827 (diff)
downloadtrackermap-server-a076c67bbdc2ed7d293f6044f4b51493b7e2d3c3.tar.gz
trackermap-server-a076c67bbdc2ed7d293f6044f4b51493b7e2d3c3.tar.bz2
trackermap-server-a076c67bbdc2ed7d293f6044f4b51493b7e2d3c3.zip
Handle ACK packets as command result
-rw-r--r--src/org/traccar/protocol/Gl200ProtocolDecoder.java102
-rw-r--r--test/org/traccar/protocol/Gl200ProtocolDecoderTest.java9
2 files changed, 70 insertions, 41 deletions
diff --git a/src/org/traccar/protocol/Gl200ProtocolDecoder.java b/src/org/traccar/protocol/Gl200ProtocolDecoder.java
index 9b215b32f..e2ddccaa7 100644
--- a/src/org/traccar/protocol/Gl200ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Gl200ProtocolDecoder.java
@@ -37,12 +37,14 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
super(protocol);
}
- private static final Pattern PATTERN_HBD = new PatternBuilder()
- .text("+ACK:GTHBD,")
+ private static final Pattern PATTERN_ACK = new PatternBuilder()
+ .text("+ACK:GT").expression("...,")
.number("([0-9A-Z]{2}xxxx),") // protocol version
.number("(d{15}),") // imei
.any().text(",")
- .number("(xxxx)")
+ .number("(dddd)(dd)(dd)") // date
+ .number("(dd)(dd)(dd),") // time
+ .number("(xxxx)") // counter
.text("$").optional()
.compile();
@@ -255,13 +257,30 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
.text("$").optional()
.compile();
- private Object decodeHbd(Channel channel, SocketAddress remoteAddress, String sentence) {
- Parser parser = new Parser(PATTERN_HBD, sentence);
- if (parser.matches() && channel != null) {
+ private Object decodeAck(Channel channel, SocketAddress remoteAddress, String sentence, String type) {
+ Parser parser = new Parser(PATTERN_ACK, sentence);
+ if (parser.matches()) {
String protocolVersion = parser.next();
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
- if (deviceSession != null) {
- channel.write("+SACK:GTHBD," + protocolVersion + "," + parser.next() + "$", remoteAddress);
+ if (deviceSession == null) {
+ return null;
+ }
+ if (type.equals("HBD")) {
+ if (channel != null) {
+ parser.skip(6);
+ channel.write("+SACK:GTHBD," + protocolVersion + "," + parser.next() + "$", remoteAddress);
+ }
+ } else {
+ Position position = new Position();
+ position.setProtocol(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+ DateBuilder dateBuilder = new DateBuilder()
+ .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt())
+ .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt());
+ getLastLocation(position, dateBuilder.getDate());
+ position.setValid(false);
+ position.set(Position.KEY_RESULT, "Command " + type + " accepted");
+ return position;
}
}
return null;
@@ -620,41 +639,42 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
Object result;
String type = sentence.substring(typeIndex + 3, typeIndex + 6);
- switch (type) {
- case "HBD":
- result = decodeHbd(channel, remoteAddress, sentence);
- break;
- case "INF":
- result = decodeInf(channel, remoteAddress, sentence);
- break;
- case "OBD":
- result = decodeObd(channel, remoteAddress, sentence);
- break;
- case "FRI":
- result = decodeFri(channel, remoteAddress, sentence);
- break;
- case "IGN":
- case "IGF":
- result = decodeIgn(channel, remoteAddress, sentence);
- break;
- case "IDA":
- result = decodeIda(channel, remoteAddress, sentence);
- break;
- default:
- result = decodeOther(channel, remoteAddress, sentence, type);
- break;
- }
+ if (typeIndex >= 4 && sentence.startsWith("+ACK", typeIndex - 4)) {
+ result = decodeAck(channel, remoteAddress, sentence, type);
+ } else {
+ switch (type) {
+ case "INF":
+ result = decodeInf(channel, remoteAddress, sentence);
+ break;
+ case "OBD":
+ result = decodeObd(channel, remoteAddress, sentence);
+ break;
+ case "FRI":
+ result = decodeFri(channel, remoteAddress, sentence);
+ break;
+ case "IGN":
+ case "IGF":
+ result = decodeIgn(channel, remoteAddress, sentence);
+ break;
+ case "IDA":
+ result = decodeIda(channel, remoteAddress, sentence);
+ break;
+ default:
+ result = decodeOther(channel, remoteAddress, sentence, type);
+ break;
+ }
- if (result == null) {
- result = decodeBasic(channel, remoteAddress, sentence);
- }
+ if (result == null) {
+ result = decodeBasic(channel, remoteAddress, sentence);
+ }
- if (result != null) {
- if (result instanceof Position) {
- ((Position) result).set(Position.KEY_TYPE, type);
- } else {
- for (Position p : (List<Position>) result) {
- p.set(Position.KEY_TYPE, type);
+ if (result != null) {
+ if (result instanceof Position) {
+ ((Position) result).set(Position.KEY_TYPE, type);
+ } else {
+ for (Position p : (List<Position>) result) {
+ p.set(Position.KEY_TYPE, type);
+ }
}
}
}
diff --git a/test/org/traccar/protocol/Gl200ProtocolDecoderTest.java b/test/org/traccar/protocol/Gl200ProtocolDecoderTest.java
index 68c4b66a0..914db782e 100644
--- a/test/org/traccar/protocol/Gl200ProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/Gl200ProtocolDecoderTest.java
@@ -163,6 +163,15 @@ public class Gl200ProtocolDecoderTest extends ProtocolTest {
verifyNothing(decoder, text(
"+ACK:GTHBD,1A0401,135790246811220,,20100214093254,11F0"));
+ verifyAttributes(decoder, text(
+ "+ACK:GTRTO,1A0800,860599000773978,GL300,VER,FFFF,20161006053520,0C19"));
+
+ verifyAttributes(decoder, text(
+ "+ACK:GTJDC,0A0102,135790246811220,,0016,20090214093254,11F0"));
+
+ verifyAttributes(decoder, text(
+ "+ACK:GTGEO,1A0102,135790246811220,,0,0008,20100310172830,11F0"));
+
}
}