aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/org/traccar/protocol/AquilaProtocolDecoder.java78
-rw-r--r--test/org/traccar/protocol/AquilaProtocolDecoderTest.java6
2 files changed, 73 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 {
diff --git a/test/org/traccar/protocol/AquilaProtocolDecoderTest.java b/test/org/traccar/protocol/AquilaProtocolDecoderTest.java
index d14f00ff1..7de4526f1 100644
--- a/test/org/traccar/protocol/AquilaProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/AquilaProtocolDecoderTest.java
@@ -57,6 +57,12 @@ public class AquilaProtocolDecoderTest extends ProtocolTest {
AquilaProtocolDecoder decoder = new AquilaProtocolDecoder(new AquilaProtocol());
verifyPosition(decoder, text(
+ "$Header,nliven,EMR,861693034634154,NM,09112017155133,A,12.976495,N,77.549713,E,906.0,0.0,23,G,KA01I2000,+919844098440*4B"));
+
+ verifyPosition(decoder, text(
+ "$EPB,iTriangle1,EMR,864495034445822,SP,03082018110730,A,22.829292,N,75.935806,E,543.0,0.0,0,G,KA01G1234,+9164061023*13"));
+
+ verifyPosition(decoder, text(
"$Header,iTriangle,1_37T02B0164MAIS_2,NR,1,L,864495034490141,KA01I2000,1,19042018,102926,22.846401,N,75.948952,E,0.0,311,5,578.0,3.80,3.67,AirTel,0,1,12.5,4.3,1,C,14,404,93,0456,16db,29,ebd8,0458,28,3843,18ab,25,072e,18ab,22,35da,0458,0000,00,031181,0.0,0.0,0,()*34"));
verifyPosition(decoder, text(