aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2018-04-05 16:31:40 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2018-04-05 16:31:40 +1200
commitdfcfcf741e8a8365f026916fc8c99596557cd29a (patch)
tree01d00ff8920db71114aba713764a231c6037e93d
parentb0a63981a99bbef156c8801ad40d29f3bb2aae8e (diff)
downloadtraccar-server-dfcfcf741e8a8365f026916fc8c99596557cd29a.tar.gz
traccar-server-dfcfcf741e8a8365f026916fc8c99596557cd29a.tar.bz2
traccar-server-dfcfcf741e8a8365f026916fc8c99596557cd29a.zip
Implement Aquila B protocol
-rw-r--r--src/org/traccar/protocol/AquilaProtocolDecoder.java127
-rw-r--r--test/org/traccar/protocol/AquilaProtocolDecoderTest.java18
2 files changed, 138 insertions, 7 deletions
diff --git a/src/org/traccar/protocol/AquilaProtocolDecoder.java b/src/org/traccar/protocol/AquilaProtocolDecoder.java
index d8081612d..960139b3f 100644
--- a/src/org/traccar/protocol/AquilaProtocolDecoder.java
+++ b/src/org/traccar/protocol/AquilaProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,6 +21,8 @@ import org.traccar.DeviceSession;
import org.traccar.helper.Parser;
import org.traccar.helper.PatternBuilder;
import org.traccar.helper.UnitsConverter;
+import org.traccar.model.CellTower;
+import org.traccar.model.Network;
import org.traccar.model.Position;
import java.net.SocketAddress;
@@ -32,7 +34,7 @@ public class AquilaProtocolDecoder extends BaseProtocolDecoder {
super(protocol);
}
- private static final Pattern PATTERN = new PatternBuilder()
+ private static final Pattern PATTERN_A = new PatternBuilder()
.text("$$")
.expression("[^,]*,") // client
.number("(d+),") // device serial number
@@ -129,11 +131,9 @@ public class AquilaProtocolDecoder extends BaseProtocolDecoder {
.number("xx") // checksum
.compile();
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
+ private Position decodeA(Channel channel, SocketAddress remoteAddress, String sentence) {
- Parser parser = new Parser(PATTERN, (String) msg);
+ Parser parser = new Parser(PATTERN_A, sentence);
if (!parser.matches()) {
return null;
}
@@ -215,4 +215,119 @@ public class AquilaProtocolDecoder extends BaseProtocolDecoder {
return position;
}
+ private static final Pattern PATTERN_B = new PatternBuilder()
+ .text("$Header,")
+ .expression("[^,]+,") // client
+ .expression("[^,]+,") // firmware version
+ .expression(".{2},") // type
+ .number("d+,") // message id
+ .expression("[LH],") // status
+ .number("(d+),") // imei
+ .expression("[^,]+,") // registration number
+ .number("([01]),") // validity
+ .number("(dd)(dd)(dddd),") // date (ddmmyyyy)
+ .number("(dd)(dd)(dd),") // time (hhmmss)
+ .number("(-?d+.d+),") // latitude
+ .expression("([NS]),")
+ .number("(-?d+.d+),") // longitude
+ .expression("([EW]),")
+ .number("(d+.d+),") // speed
+ .number("(d+),") // course
+ .number("(d+),") // satellites
+ .number("(-?d+.d+),") // altitude
+ .number("(d+.d+),") // pdop
+ .number("(d+.d+),") // hdop
+ .expression("[^,]+,") // operator
+ .number("([01]),") // ignition
+ .number("([01]),") // charge
+ .number("(d+.d+),") // power
+ .number("(d+.d+),") // battery
+ .number("[01],") // emergency
+ .expression("[CO],") // tamper
+ .number("(d+),") // rssi
+ .number("(d+),") // mcc
+ .number("(d+),") // mnc
+ .number("(x+),") // lac
+ .number("(x+),") // cid
+ .number("(d+),(x+),(x+),") // cell 1
+ .number("(d+),(x+),(x+),") // cell 2
+ .number("(d+),(x+),(x+),") // cell 3
+ .number("(d+),(x+),(x+),") // cell 4
+ .number("([01])+,") // inputs
+ .number("([01])+,") // outputs
+ .number("d+,") // frame number
+ .number("(d+.d+),") // adc1
+ .number("(d+.d+),") // adc2
+ .number("d+,") // delta distance
+ .any()
+ .compile();
+
+ private Position decodeB(Channel channel, SocketAddress remoteAddress, String sentence) {
+
+ Parser parser = new Parser(PATTERN_B, sentence);
+ if (!parser.matches()) {
+ return null;
+ }
+
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
+ if (deviceSession == null) {
+ return null;
+ }
+
+ Position position = new Position(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ position.setValid(parser.nextInt() == 1);
+ position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
+ position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM));
+ position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM));
+ position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble()));
+ position.setCourse(parser.nextInt());
+
+ position.set(Position.KEY_SATELLITES, parser.nextInt());
+
+ position.setAltitude(parser.nextDouble());
+
+ position.set(Position.KEY_PDOP, parser.nextDouble());
+ position.set(Position.KEY_HDOP, parser.nextDouble());
+ position.set(Position.KEY_IGNITION, parser.nextInt() == 1);
+ position.set(Position.KEY_CHARGE, parser.nextInt() == 1);
+ position.set(Position.KEY_POWER, parser.nextDouble());
+ position.set(Position.KEY_BATTERY, parser.nextDouble());
+
+ Network network = new Network();
+
+ int rssi = parser.nextInt();
+ int mcc = parser.nextInt();
+ int mnc = parser.nextInt();
+
+ network.addCellTower(CellTower.from(mcc, mnc, parser.nextHexInt(), parser.nextHexInt(), rssi));
+ for (int i = 0; i < 4; i++) {
+ rssi = parser.nextInt();
+ network.addCellTower(CellTower.from(mcc, mnc, parser.nextHexInt(), parser.nextHexInt(), rssi));
+ }
+
+ position.setNetwork(network);
+
+ position.set(Position.KEY_INPUT, parser.nextBinInt());
+ position.set(Position.KEY_OUTPUT, parser.nextBinInt());
+ position.set(Position.PREFIX_ADC + 1, parser.nextDouble());
+ position.set(Position.PREFIX_ADC + 2, parser.nextDouble());
+
+ return position;
+ }
+
+ @Override
+ protected Object decode(
+ Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
+
+ String sentence = (String) msg;
+
+ if (sentence.startsWith("$$")) {
+ return decodeA(channel, remoteAddress, sentence);
+ } else {
+ return decodeB(channel, remoteAddress, sentence);
+ }
+ }
+
}
diff --git a/test/org/traccar/protocol/AquilaProtocolDecoderTest.java b/test/org/traccar/protocol/AquilaProtocolDecoderTest.java
index 1148896c1..8984cfcb3 100644
--- a/test/org/traccar/protocol/AquilaProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/AquilaProtocolDecoderTest.java
@@ -6,7 +6,7 @@ import org.traccar.ProtocolTest;
public class AquilaProtocolDecoderTest extends ProtocolTest {
@Test
- public void testDecode() throws Exception {
+ public void testDecodeA() throws Exception {
AquilaProtocolDecoder decoder = new AquilaProtocolDecoder(new AquilaProtocol());
@@ -51,4 +51,20 @@ public class AquilaProtocolDecoderTest extends ProtocolTest {
}
+ @Test
+ public void testDecodeB() throws Exception {
+
+ AquilaProtocolDecoder decoder = new AquilaProtocolDecoder(new AquilaProtocol());
+
+ verifyPosition(decoder, text(
+ "$Header,nliven,1_37T02B0164MAIS,BR,6,L,861693034634154,KA01I2000,1,09112017,160702,12.976593,N,77.549782,E,25.1,344,15,911.0,1.04,0.68,Airtel,1,1,11.8,3.8,1,C,24,404,45,61b4,9ad9,31,9adb,61b4,35,ffff,0000,33,ffff,0000,31,ffff,0000,0001,00,000014,0.0,0.1,4,()*1E"));
+
+ verifyPosition(decoder, text(
+ "$Header,iTriangle,1_37T02B0164MAIS_2,NR,1,L,864495034490141,KA01I2000,1,31032018,122247,22.845999,N,75.949005,E,0.0,44,16,545.0,1.19,0.65,AirTel,1,1,12.0,4.3,0,C,13,404,93,0456,16db,27,16dd,0456,22,3843,18ab,19,ebd8,0458,14,072c,18ab,0101,00,003735,0.0,0.0,0,()*48"));
+
+ verifyNull(decoder, text(
+ "$Header,nliven,KA01I2000,861693034634154,1_37T02B0164MAIS,AIS140,12.976545,N,77.549759,E*50"));
+
+ }
+
}