aboutsummaryrefslogtreecommitdiff
path: root/src/org
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2016-10-08 12:49:17 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2016-10-08 12:49:17 +1300
commitf30f25164a3b9be08bad55f80481332b73d6e9e1 (patch)
treed7ba68c581a419fd38212f756d057f8ad09ab5b9 /src/org
parent5f7b0b7183e7b7bb10bc3b24afc4ecf5d8654c9b (diff)
downloadtrackermap-server-f30f25164a3b9be08bad55f80481332b73d6e9e1.tar.gz
trackermap-server-f30f25164a3b9be08bad55f80481332b73d6e9e1.tar.bz2
trackermap-server-f30f25164a3b9be08bad55f80481332b73d6e9e1.zip
Decode additional cGuard data (fix #2419)
Diffstat (limited to 'src/org')
-rw-r--r--src/org/traccar/protocol/CguardProtocolDecoder.java93
1 files changed, 77 insertions, 16 deletions
diff --git a/src/org/traccar/protocol/CguardProtocolDecoder.java b/src/org/traccar/protocol/CguardProtocolDecoder.java
index 1646363e5..6c528c559 100644
--- a/src/org/traccar/protocol/CguardProtocolDecoder.java
+++ b/src/org/traccar/protocol/CguardProtocolDecoder.java
@@ -33,7 +33,7 @@ public class CguardProtocolDecoder extends BaseProtocolDecoder {
super(protocol);
}
- private static final Pattern PATTERN = new PatternBuilder()
+ private static final Pattern PATTERN_NV = new PatternBuilder()
.text("NV:")
.number("(dd)(dd)(dd) ") // date
.number("(dd)(dd)(dd):") // time
@@ -45,23 +45,16 @@ public class CguardProtocolDecoder extends BaseProtocolDecoder {
.number("(?:NAN|(d+.?d*))") // altitude
.compile();
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- String sentence = (String) msg;
-
- if (sentence.startsWith("ID:") || sentence.startsWith("IDRO:")) {
- getDeviceSession(channel, remoteAddress, sentence.substring(sentence.indexOf(':') + 1));
- return null;
- }
+ private static final Pattern PATTERN_BC = new PatternBuilder()
+ .text("BC:")
+ .number("(dd)(dd)(dd) ") // date
+ .number("(dd)(dd)(dd):") // time
+ .expression("(.+)") // data
+ .compile();
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
- if (deviceSession == null) {
- return null;
- }
+ private Position decodePosition(DeviceSession deviceSession, String sentence) {
- Parser parser = new Parser(PATTERN, (String) msg);
+ Parser parser = new Parser(PATTERN_NV, sentence);
if (!parser.matches()) {
return null;
}
@@ -88,4 +81,72 @@ public class CguardProtocolDecoder extends BaseProtocolDecoder {
return position;
}
+ private Position decodeStatus(DeviceSession deviceSession, String sentence) {
+
+ Parser parser = new Parser(PATTERN_BC, sentence);
+ if (!parser.matches()) {
+ return null;
+ }
+
+ 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());
+
+ String[] data = parser.next().split(":");
+ for (int i = 0; i < data.length / 2; i++) {
+ String key = data[i * 2];
+ String value = data[i * 2 + 1];
+ switch (key) {
+ case "CSQ1":
+ position.set(Position.KEY_GSM, Integer.parseInt(value));
+ break;
+ case "NSQ1":
+ position.set(Position.KEY_SATELLITES, Integer.parseInt(value));
+ break;
+ case "BAT1":
+ position.set(Position.KEY_BATTERY, Integer.parseInt(value) + "%");
+ break;
+ case "PWR1":
+ position.set(Position.KEY_POWER, Double.parseDouble(value));
+ break;
+ default:
+ position.set(key.toLowerCase(), value);
+ break;
+ }
+ }
+
+ return position;
+ }
+
+ @Override
+ protected Object decode(
+ Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
+
+ String sentence = (String) msg;
+
+ if (sentence.startsWith("ID:") || sentence.startsWith("IDRO:")) {
+ getDeviceSession(channel, remoteAddress, sentence.substring(sentence.indexOf(':') + 1));
+ return null;
+ }
+
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
+ if (deviceSession == null) {
+ return null;
+ }
+
+ if (sentence.startsWith("NV:")) {
+ return decodePosition(deviceSession, sentence);
+ } else if (sentence.startsWith("BC:")) {
+ return decodeStatus(deviceSession, sentence);
+ }
+
+ return null;
+ }
+
}