aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/protocol/AquilaProtocolDecoder.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2019-06-02 12:00:25 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2019-06-02 12:00:25 -0700
commitaa421b17d86b70f80f84c4d7c086a1e56bb80059 (patch)
tree95761c3c61ad5950cf88f0cef292499bc86a79a2 /src/main/java/org/traccar/protocol/AquilaProtocolDecoder.java
parent7976f916d31c8efde8cf37471d665c1958b3ee1d (diff)
downloadtrackermap-server-aa421b17d86b70f80f84c4d7c086a1e56bb80059.tar.gz
trackermap-server-aa421b17d86b70f80f84c4d7c086a1e56bb80059.tar.bz2
trackermap-server-aa421b17d86b70f80f84c4d7c086a1e56bb80059.zip
Merge Aquila B and ITS
Diffstat (limited to 'src/main/java/org/traccar/protocol/AquilaProtocolDecoder.java')
-rw-r--r--src/main/java/org/traccar/protocol/AquilaProtocolDecoder.java194
1 files changed, 5 insertions, 189 deletions
diff --git a/src/main/java/org/traccar/protocol/AquilaProtocolDecoder.java b/src/main/java/org/traccar/protocol/AquilaProtocolDecoder.java
index 57af5e366..3c43ddf2a 100644
--- a/src/main/java/org/traccar/protocol/AquilaProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/AquilaProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2019 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.
@@ -17,15 +17,11 @@ package org.traccar.protocol;
import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
-import org.traccar.Context;
import org.traccar.DeviceSession;
-import org.traccar.NetworkMessage;
import org.traccar.Protocol;
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;
@@ -134,9 +130,11 @@ public class AquilaProtocolDecoder extends BaseProtocolDecoder {
.number("xx") // checksum
.compile();
- private Position decodeA(Channel channel, SocketAddress remoteAddress, String sentence) {
+ @Override
+ protected Object decode(
+ Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
- Parser parser = new Parser(PATTERN_A, sentence);
+ Parser parser = new Parser(PATTERN_A, (String) msg);
if (!parser.matches()) {
return null;
}
@@ -218,186 +216,4 @@ public class AquilaProtocolDecoder extends BaseProtocolDecoder {
return position;
}
- private static final Pattern PATTERN_B_1 = new PatternBuilder()
- .text("$")
- .expression("[^,]+,") // header
- .expression("[^,]+,") // client
- .expression("[^,]+,") // firmware version
- .expression(".{2},") // packet 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 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()));
-
- 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;
- }
-
- 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.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());
-
- if (parser.nextInt() == 1) {
- position.set(Position.KEY_ALARM, Position.ALARM_SOS);
- }
-
- 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;
- }
-
- 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 {
-
- String sentence = (String) msg;
-
- if (sentence.startsWith("$$")) {
- return decodeA(channel, remoteAddress, sentence);
- } else {
- return decodeB(channel, remoteAddress, sentence);
- }
- }
-
}