aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2021-03-16 22:07:33 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2021-03-16 22:07:33 -0700
commit9c8a8f12ef7ab8579101919a39f753d55e267583 (patch)
tree9c8a965eac42fd5b75dd6a3cc0b15d3fdb604fb4
parent3f790f5b10448d7993f9df6c4550afed4893c6a0 (diff)
downloadtraccar-server-9c8a8f12ef7ab8579101919a39f753d55e267583.tar.gz
traccar-server-9c8a8f12ef7ab8579101919a39f753d55e267583.tar.bz2
traccar-server-9c8a8f12ef7ab8579101919a39f753d55e267583.zip
Add Fifotrack result support
-rw-r--r--src/main/java/org/traccar/protocol/FifotrackProtocolDecoder.java48
-rw-r--r--src/test/java/org/traccar/protocol/FifotrackProtocolDecoderTest.java4
2 files changed, 48 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;
diff --git a/src/test/java/org/traccar/protocol/FifotrackProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/FifotrackProtocolDecoderTest.java
index 48b74c904..08a5ec244 100644
--- a/src/test/java/org/traccar/protocol/FifotrackProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/FifotrackProtocolDecoderTest.java
@@ -11,6 +11,10 @@ public class FifotrackProtocolDecoderTest extends ProtocolTest {
FifotrackProtocolDecoder decoder = new FifotrackProtocolDecoder(null);
+ verifyAttribute(decoder, buffer(
+ "$$25,863003046473534,1,B03,OK*4D"),
+ Position.KEY_RESULT, "OK");
+
verifyPosition(decoder, buffer(
"$$118,863003046473534,258,A01,,201007231735,V,3.067783,101.672858,0,176,96,189890,0,A0,03,0,502|19|5C1|93349F,196|4E0|6C,1,*13"));