aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2021-10-26 22:58:23 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2021-10-26 22:58:23 -0700
commit3593d6075cbc40460e91cfccb4f2fb7c9913e315 (patch)
treefc0b2f70cd544c9b78cf0d9d4289bac0e2be8193
parent0dab261a9ec77811c073b328018675d5f9d71fe6 (diff)
downloadtraccar-server-3593d6075cbc40460e91cfccb4f2fb7c9913e315.tar.gz
traccar-server-3593d6075cbc40460e91cfccb4f2fb7c9913e315.tar.bz2
traccar-server-3593d6075cbc40460e91cfccb4f2fb7c9913e315.zip
Fix responses
-rw-r--r--src/main/java/org/traccar/protocol/MobilogixProtocolDecoder.java6
-rw-r--r--src/test/java/org/traccar/protocol/MobilogixProtocolDecoderTest.java38
2 files changed, 41 insertions, 3 deletions
diff --git a/src/main/java/org/traccar/protocol/MobilogixProtocolDecoder.java b/src/main/java/org/traccar/protocol/MobilogixProtocolDecoder.java
index 00e297faa..ba70a8884 100644
--- a/src/main/java/org/traccar/protocol/MobilogixProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/MobilogixProtocolDecoder.java
@@ -60,7 +60,7 @@ public class MobilogixProtocolDecoder extends BaseProtocolDecoder {
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
String sentence = (String) msg;
- String type = sentence.substring(21, 21 + 2);
+ String type = sentence.substring(21, sentence.indexOf(',', 21));
if (channel != null) {
String time = sentence.substring(1, 20);
@@ -68,12 +68,12 @@ public class MobilogixProtocolDecoder extends BaseProtocolDecoder {
if (type.equals("T1")) {
response = String.format("[%s,S1,1]", time);
} else {
- response = String.format("[%s,S%c]", time, type.charAt(1));
+ response = String.format("[%s,S%s]", time, type.substring(1));
}
channel.writeAndFlush(new NetworkMessage(response, remoteAddress));
}
- Parser parser = new Parser(PATTERN, (String) msg);
+ Parser parser = new Parser(PATTERN, sentence);
if (!parser.matches()) {
return null;
}
diff --git a/src/test/java/org/traccar/protocol/MobilogixProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/MobilogixProtocolDecoderTest.java
index aff4e42a6..efa46b9f6 100644
--- a/src/test/java/org/traccar/protocol/MobilogixProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/MobilogixProtocolDecoderTest.java
@@ -2,6 +2,7 @@ package org.traccar.protocol;
import org.junit.Test;
import org.traccar.ProtocolTest;
+import org.traccar.model.Position;
public class MobilogixProtocolDecoderTest extends ProtocolTest {
@@ -13,6 +14,43 @@ public class MobilogixProtocolDecoderTest extends ProtocolTest {
verifyNull(decoder, text(
"[2020-12-01 14:00:22,T1,1,V1.1.1,201951132031,,,12345678,724108005415815,359366080211420"));
+ verifyNull(decoder, text(
+ "[2020-10-25 20:44:08,T8,1,V1.2.3,201951132044,3596"));
+
+ verifyPosition(decoder, text(
+ "[2020-10-25 20:45:09,T9,1,V1.2.3,201951132044,59,10.50,701,-25.236860,-45.708530,0,314"));
+
+ verifyPosition(decoder, text(
+ "[2021-10-25 20:46:10,T10,1,V1.2.3,201951132044,59,0.50,082,-25.909590,-47.045387,0,145"));
+
+ verifyPosition(decoder, text(
+ "[2021-10-25 20:47:11,T11,1,V1.2.3,201951132044,3F,9.23,991,-25.909262,-47.045387,1,341"));
+
+ verifyPosition(decoder, text(
+ "[2021-10-25 20:54:11,T12,1,V1.2.3,201951132044,3F,9.23,991,-25.909262,-47.045387,1,341"));
+
+ verifyNull(decoder, text(
+ "[2021-10-25 20:48:14,T14,1,V1.2.3,201951132044,51,0.50"));
+
+ verifyPosition(decoder, text(
+ "[2021-10-25 20:49:15,T15,1,V1.2.3,201951132044,59,0.50,591,-25.908621,-47.045971,2,127"));
+
+ verifyNull(decoder, text(
+ "[2021-10-25 20:50:16,T16,1,V1.2.3,201951132044,1"));
+
+ verifyPosition(decoder, text(
+ "[2021-10-25 20:51:21,T21,1,V1.2.3,201951132044,37,12.18,961,-25.932310,-47.022415,0,82"));
+
+ verifyPosition(decoder, text(
+ "[2021-10-25 20:52:22,T22,1,V1.2.3,201951132044,1B,12.05,082,-25.909590,-47.045387,0,145"));
+
+ verifyPosition(decoder, text(
+ "[2021-10-25 20:53:31,T31,1,V1.2.3,201951132044,D3,26.17,961,-23.458092,-46.392132,0,8"));
+
+ verifyAttribute(decoder, text(
+ "[2021-10-25 20:55:11,T13,1,V1.2.3,201951132044,3F,9.23,991,-25.909262,-47.045387,1,341"),
+ Position.KEY_TYPE, "T13");
+
verifyPosition(decoder, text(
"[2020-12-01 12:01:09,T3,1,V1.1.1,201951132031,3B,12.99,022,-23.563410,-46.588055,0,0"));