diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2016-10-06 21:48:12 +1300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-06 21:48:12 +1300 |
commit | 453bd2ed647d66725790b35eaab4932bf86b3ad1 (patch) | |
tree | 46c95928f7ad89de3d30e905a6b4a3b58390baeb | |
parent | 534aa00430e507a43b581707a74ab08bce7d5827 (diff) | |
parent | c0d85d814cd6ca1cbbcc14ccefef7fb7e875f190 (diff) | |
download | trackermap-server-453bd2ed647d66725790b35eaab4932bf86b3ad1.tar.gz trackermap-server-453bd2ed647d66725790b35eaab4932bf86b3ad1.tar.bz2 trackermap-server-453bd2ed647d66725790b35eaab4932bf86b3ad1.zip |
Merge pull request #2413 from Abyss777/gl200
Handle GL200 ACK packets as command result
-rw-r--r-- | src/org/traccar/protocol/Gl200ProtocolDecoder.java | 103 | ||||
-rw-r--r-- | test/org/traccar/protocol/Gl200ProtocolDecoderTest.java | 9 |
2 files changed, 71 insertions, 41 deletions
diff --git a/src/org/traccar/protocol/Gl200ProtocolDecoder.java b/src/org/traccar/protocol/Gl200ProtocolDecoder.java index 9b215b32f..2d28ea199 100644 --- a/src/org/traccar/protocol/Gl200ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gl200ProtocolDecoder.java @@ -37,12 +37,15 @@ 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("...,") // type .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 +258,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 +640,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 (sentence.startsWith("+ACK")) { + 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")); + } } |