aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/org/traccar/protocol/MictrackProtocolDecoder.java44
-rw-r--r--src/test/java/org/traccar/protocol/MictrackProtocolDecoderTest.java10
2 files changed, 50 insertions, 4 deletions
diff --git a/src/main/java/org/traccar/protocol/MictrackProtocolDecoder.java b/src/main/java/org/traccar/protocol/MictrackProtocolDecoder.java
index 5ea9f148c..029e7d99c 100644
--- a/src/main/java/org/traccar/protocol/MictrackProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/MictrackProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2019 Anton Tananaev (anton@traccar.org)
+ * Copyright 2019 - 2021 Anton Tananaev (anton@traccar.org)
* Copyright 2020 Roeland Boeters (roeland@geodelta.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -168,8 +168,48 @@ public class MictrackProtocolDecoder extends BaseProtocolDecoder {
if (sentence.startsWith("MT")) {
return decodeStandard(channel, remoteAddress, sentence);
- } else {
+ } else if (sentence.contains("$")) {
return decodeLowAltitude(channel, remoteAddress, sentence);
+ } else {
+ return decodeResult(channel, remoteAddress, sentence);
+ }
+ }
+
+ private Object decodeResult(
+ Channel channel, SocketAddress remoteAddress, String sentence) throws Exception {
+
+ if (sentence.matches("\\d{15} .+")) {
+
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, sentence.substring(0, 15));
+ if (deviceSession == null) {
+ return null;
+ }
+
+ Position position = new Position(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ getLastLocation(position, null);
+
+ position.set(Position.KEY_RESULT, sentence.substring(16, sentence.length() - 1));
+
+ return position;
+
+ } else {
+
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
+ if (deviceSession == null) {
+ return null;
+ }
+
+ Position position = new Position(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ getLastLocation(position, null);
+
+ position.set(Position.KEY_RESULT, sentence.substring(0, sentence.length() - 1));
+
+ return position;
+
}
}
diff --git a/src/test/java/org/traccar/protocol/MictrackProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/MictrackProtocolDecoderTest.java
index 3360d968b..5c9e74a2d 100644
--- a/src/test/java/org/traccar/protocol/MictrackProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/MictrackProtocolDecoderTest.java
@@ -2,6 +2,7 @@ package org.traccar.protocol;
import org.junit.Test;
import org.traccar.ProtocolTest;
+import org.traccar.model.Position;
public class MictrackProtocolDecoderTest extends ProtocolTest {
@@ -10,8 +11,13 @@ public class MictrackProtocolDecoderTest extends ProtocolTest {
var decoder = new MictrackProtocolDecoder(null);
- verifyNull(decoder, text(
- "mode=Success!"));
+ verifyAttribute(decoder, text(
+ "867035041390699 netlock=Success!"),
+ Position.KEY_RESULT, "netlock=Success");
+
+ verifyAttribute(decoder, text(
+ "mode=Success!"),
+ Position.KEY_RESULT, "mode=Success");
verifyPosition(decoder, text(
"MT;6;866425031361423;R0;10+190109091803+22.63827+114.02922+2.14+69+2+3744+113"),