aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/traccar/protocol/FifotrackProtocolDecoder.java48
1 files changed, 44 insertions, 4 deletions
diff --git a/src/main/java/org/traccar/protocol/FifotrackProtocolDecoder.java b/src/main/java/org/traccar/protocol/FifotrackProtocolDecoder.java
index fe42a44d7..9bed63266 100644
--- a/src/main/java/org/traccar/protocol/FifotrackProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/FifotrackProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 - 2020 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 - 2021 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.
@@ -95,6 +95,16 @@ public class FifotrackProtocolDecoder extends BaseProtocolDecoder {
.number("(d+),") // size
.compile();
+ private static final Pattern PATTERN_RESULT = new PatternBuilder()
+ .text("$$")
+ .number("d+,") // length
+ .number("(d+),") // imei
+ .any()
+ .expression(",([A-Z]+)") // result
+ .text("*")
+ .number("xx")
+ .compile();
+
private void requestPhoto(Channel channel, SocketAddress socketAddress, String imei, String file) {
if (channel != null) {
String content = "1,D06," + file + "," + photo.writerIndex() + "," + Math.min(1024, photo.writableBytes());
@@ -203,6 +213,27 @@ public class FifotrackProtocolDecoder extends BaseProtocolDecoder {
return position;
}
+ private Object decodeResult(
+ Channel channel, SocketAddress remoteAddress, String sentence) {
+
+ Parser parser = new Parser(PATTERN_RESULT, 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.set(Position.KEY_RESULT, parser.next());
+
+ return position;
+ }
+
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
@@ -213,7 +244,12 @@ public class FifotrackProtocolDecoder extends BaseProtocolDecoder {
typeIndex = buf.indexOf(typeIndex, buf.writerIndex(), (byte) ',') + 1;
String type = buf.toString(typeIndex, 3, StandardCharsets.US_ASCII);
- if (type.equals("D05")) {
+ if (type.startsWith("B")) {
+
+ return decodeResult(channel, remoteAddress, buf.toString(StandardCharsets.US_ASCII));
+
+ } else if (type.equals("D05")) {
+
String sentence = buf.toString(StandardCharsets.US_ASCII);
Parser parser = new Parser(PATTERN_PHOTO, sentence);
if (parser.matches()) {
@@ -223,7 +259,9 @@ public class FifotrackProtocolDecoder extends BaseProtocolDecoder {
photo = Unpooled.buffer(length);
requestPhoto(channel, remoteAddress, imei, photoId);
}
+
} else if (type.equals("D06")) {
+
if (photo == null) {
return null;
}
@@ -251,9 +289,11 @@ public class FifotrackProtocolDecoder extends BaseProtocolDecoder {
return position;
}
}
+
} else {
- String sentence = buf.toString(StandardCharsets.US_ASCII);
- return decodeLocation(channel, remoteAddress, sentence);
+
+ return decodeLocation(channel, remoteAddress, buf.toString(StandardCharsets.US_ASCII));
+
}
return null;