aboutsummaryrefslogtreecommitdiff
path: root/src/org
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2018-08-04 08:58:24 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2018-08-04 08:58:24 +1200
commit18e64c7118297d363a293e1c1af5a9d35033fee2 (patch)
treead6941eaeb8a379c0aa70b5d89dca91c96803f86 /src/org
parenta4ad1371690e6d0840e717ec8e65a88fc3b60033 (diff)
downloadtrackermap-server-18e64c7118297d363a293e1c1af5a9d35033fee2.tar.gz
trackermap-server-18e64c7118297d363a293e1c1af5a9d35033fee2.tar.bz2
trackermap-server-18e64c7118297d363a293e1c1af5a9d35033fee2.zip
Decode AquilaB emergency packets
Diffstat (limited to 'src/org')
-rw-r--r--src/org/traccar/protocol/AquilaProtocolDecoder.java78
1 files changed, 67 insertions, 11 deletions
diff --git a/src/org/traccar/protocol/AquilaProtocolDecoder.java b/src/org/traccar/protocol/AquilaProtocolDecoder.java
index 8e4343ac4..8c6dbf121 100644
--- a/src/org/traccar/protocol/AquilaProtocolDecoder.java
+++ b/src/org/traccar/protocol/AquilaProtocolDecoder.java
@@ -217,11 +217,12 @@ public class AquilaProtocolDecoder extends BaseProtocolDecoder {
return position;
}
- private static final Pattern PATTERN_B = new PatternBuilder()
- .text("$Header,")
+ private static final Pattern PATTERN_B_1 = new PatternBuilder()
+ .text("$")
+ .expression("[^,]+,") // header
.expression("[^,]+,") // client
.expression("[^,]+,") // firmware version
- .expression(".{2},") // type
+ .expression(".{2},") // packet type
.number("d+,") // message id
.expression("[LH],") // status
.number("(d+),") // imei
@@ -264,9 +265,62 @@ public class AquilaProtocolDecoder extends BaseProtocolDecoder {
.any()
.compile();
- private Position decodeB(Channel channel, SocketAddress remoteAddress, String sentence) {
+ private static final Pattern PATTERN_B_2 = new PatternBuilder()
+ .text("$")
+ .expression("[^,]+,") // header
+ .expression("[^,]+,") // client
+ .expression("(.{3}),") // message type
+ .number("(d+),") // imei
+ .expression(".{2},") // packet type
+ .number("(dd)(dd)(dddd)") // date (ddmmyyyy)
+ .number("(dd)(dd)(dd),") // time (hhmmss)
+ .expression("([AV]),") // validity
+ .number("(-?d+.d+),") // latitude
+ .expression("([NS]),")
+ .number("(-?d+.d+),") // longitude
+ .expression("([EW]),")
+ .number("(-?d+.d+),") // altitude
+ .number("(d+.d+),") // speed
+ .any()
+ .compile();
+
+ private Position decodeB2(Channel channel, SocketAddress remoteAddress, String sentence) {
+
+ Parser parser = new Parser(PATTERN_B_2, sentence);
+ if (!parser.matches()) {
+ return null;
+ }
+
+ String type = parser.next();
+ String id = parser.next();
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, id);
+ if (deviceSession == null) {
+ return null;
+ }
+
+ Position position = new Position(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
+ position.setValid(parser.next().equals("A"));
+ position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM));
+ position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM));
+ position.setAltitude(parser.nextDouble());
+ position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble()));
- Parser parser = new Parser(PATTERN_B, sentence);
+ if (type.equals("EMR") && channel != null) {
+ String password = Context.getIdentityManager().lookupAttributeString(
+ deviceSession.getDeviceId(), getProtocolName() + ".password", "aquila123", true);
+ channel.writeAndFlush(new NetworkMessage(
+ "#set$" + id + "@" + password + "#EMR_MODE:0*", remoteAddress));
+ }
+
+ return position;
+ }
+
+ private Position decodeB1(Channel channel, SocketAddress remoteAddress, String sentence) {
+
+ Parser parser = new Parser(PATTERN_B_1, sentence);
if (!parser.matches()) {
return null;
}
@@ -300,12 +354,6 @@ public class AquilaProtocolDecoder extends BaseProtocolDecoder {
if (parser.nextInt() == 1) {
position.set(Position.KEY_ALARM, Position.ALARM_SOS);
- if (channel != null) {
- String password = Context.getIdentityManager().lookupAttributeString(
- position.getDeviceId(), getProtocolName() + ".password", "aquila123", true);
- channel.writeAndFlush(new NetworkMessage(
- "#set$" + id + "@" + password + "#EMR_MODE:0*", remoteAddress));
- }
}
Network network = new Network();
@@ -330,6 +378,14 @@ public class AquilaProtocolDecoder extends BaseProtocolDecoder {
return position;
}
+ private Position decodeB(Channel channel, SocketAddress remoteAddress, String sentence) {
+ if (sentence.contains("EMR") || sentence.contains("SEM")) {
+ return decodeB2(channel, remoteAddress, sentence);
+ } else {
+ return decodeB1(channel, remoteAddress, sentence);
+ }
+ }
+
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {