aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2020-02-02 16:26:46 -0800
committerAnton Tananaev <anton.tananaev@gmail.com>2020-02-02 16:26:46 -0800
commit71735f0c9b17ad1c64a4335a196b4c765b4499c1 (patch)
tree62bb4891d5405b72bdd7a8301bdb5be063b05602 /src
parent00f8b1ff552f49ebcb5c1d13c85bd84911a2ac8d (diff)
downloadtrackermap-server-71735f0c9b17ad1c64a4335a196b4c765b4499c1.tar.gz
trackermap-server-71735f0c9b17ad1c64a4335a196b4c765b4499c1.tar.bz2
trackermap-server-71735f0c9b17ad1c64a4335a196b4c765b4499c1.zip
Rename classes
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/traccar/protocol/Arnavi4Protocol.java35
-rw-r--r--src/main/java/org/traccar/protocol/ArnaviBinaryProtocolDecoder.java (renamed from src/main/java/org/traccar/protocol/Arnavi4ProtocolDecoder.java)5
-rw-r--r--src/main/java/org/traccar/protocol/ArnaviFrameDecoder.java (renamed from src/main/java/org/traccar/protocol/Arnavi4FrameDecoder.java)50
-rw-r--r--src/main/java/org/traccar/protocol/ArnaviProtocol.java2
-rw-r--r--src/main/java/org/traccar/protocol/ArnaviTextProtocolDecoder.java (renamed from src/main/java/org/traccar/protocol/ArnaviProtocolDecoder.java)4
-rw-r--r--src/test/java/org/traccar/protocol/ArnaviBinaryProtocolDecoderTest.java (renamed from src/test/java/org/traccar/protocol/Arnavi4ProtocolDecoderTest.java)10
-rw-r--r--src/test/java/org/traccar/protocol/ArnaviFrameDecoderTest.java (renamed from src/test/java/org/traccar/protocol/Arnavi4FrameDecoderTest.java)8
-rw-r--r--src/test/java/org/traccar/protocol/ArnaviTextProtocolDecoderTest.java (renamed from src/test/java/org/traccar/protocol/ArnaviProtocolDecoderTest.java)4
8 files changed, 51 insertions, 67 deletions
diff --git a/src/main/java/org/traccar/protocol/Arnavi4Protocol.java b/src/main/java/org/traccar/protocol/Arnavi4Protocol.java
deleted file mode 100644
index 8a9337b56..000000000
--- a/src/main/java/org/traccar/protocol/Arnavi4Protocol.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright 2020 Anton Tananaev (anton@traccar.org)
- * Copyright 2017 Ivan Muratov (binakot@gmail.com)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.traccar.protocol;
-
-import org.traccar.BaseProtocol;
-import org.traccar.PipelineBuilder;
-import org.traccar.TrackerServer;
-
-public class Arnavi4Protocol extends BaseProtocol {
-
- public Arnavi4Protocol() {
- TrackerServer server = new TrackerServer(false, getName()) {
- @Override
- protected void addProtocolHandlers(PipelineBuilder pipeline) {
- pipeline.addLast(new Arnavi4FrameDecoder());
- pipeline.addLast(new Arnavi4ProtocolDecoder(Arnavi4Protocol.this));
- }
- };
- }
-
-}
diff --git a/src/main/java/org/traccar/protocol/Arnavi4ProtocolDecoder.java b/src/main/java/org/traccar/protocol/ArnaviBinaryProtocolDecoder.java
index 3e0fa5d9f..0924cfc40 100644
--- a/src/main/java/org/traccar/protocol/Arnavi4ProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/ArnaviBinaryProtocolDecoder.java
@@ -22,6 +22,7 @@ import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.DeviceSession;
import org.traccar.NetworkMessage;
+import org.traccar.Protocol;
import org.traccar.helper.Checksum;
import org.traccar.model.Position;
@@ -31,7 +32,7 @@ import java.util.Date;
import java.util.LinkedList;
import java.util.List;
-public class Arnavi4ProtocolDecoder extends BaseProtocolDecoder {
+public class ArnaviBinaryProtocolDecoder extends BaseProtocolDecoder {
private static final byte HEADER_START_SIGN = (byte) 0xff;
private static final byte HEADER_VERSION_1 = 0x22;
@@ -47,7 +48,7 @@ public class Arnavi4ProtocolDecoder extends BaseProtocolDecoder {
private static final byte TAG_LONGITUDE = 4;
private static final byte TAG_COORD_PARAMS = 5;
- public Arnavi4ProtocolDecoder(Arnavi4Protocol protocol) {
+ public ArnaviBinaryProtocolDecoder(Protocol protocol) {
super(protocol);
}
diff --git a/src/main/java/org/traccar/protocol/Arnavi4FrameDecoder.java b/src/main/java/org/traccar/protocol/ArnaviFrameDecoder.java
index 8a2681b55..3db11113d 100644
--- a/src/main/java/org/traccar/protocol/Arnavi4FrameDecoder.java
+++ b/src/main/java/org/traccar/protocol/ArnaviFrameDecoder.java
@@ -20,8 +20,9 @@ import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import org.traccar.BaseFrameDecoder;
+import org.traccar.helper.BufferUtil;
-public class Arnavi4FrameDecoder extends BaseFrameDecoder {
+public class ArnaviFrameDecoder extends BaseFrameDecoder {
private static final int HEADER_LENGTH = 10;
private static final int PACKET_WRAPPER_LENGTH = 8;
@@ -37,28 +38,41 @@ public class Arnavi4FrameDecoder extends BaseFrameDecoder {
return null;
}
- int length;
- if (firstPacket) {
- firstPacket = false;
- length = HEADER_LENGTH;
+ if (buf.getByte(buf.readerIndex()) == '$') {
+
+ int index = BufferUtil.indexOf("\r\n", buf);
+ if (index > 0) {
+ ByteBuf frame = buf.readRetainedSlice(index - buf.readerIndex());
+ buf.skipBytes(2);
+ return frame;
+ }
+
} else {
- int type = buf.getUnsignedByte(1);
- if (type == RESULT_TYPE) {
- length = 4;
+
+ int length;
+ if (firstPacket) {
+ firstPacket = false;
+ length = HEADER_LENGTH;
} else {
- int index = 2;
- while (index + PACKET_WRAPPER_LENGTH < buf.readableBytes() && buf.getByte(index) != PACKAGE_END_SIGN) {
- index += PACKET_WRAPPER_LENGTH + buf.getUnsignedShortLE(index + 1);
+ int type = buf.getUnsignedByte(1);
+ if (type == RESULT_TYPE) {
+ length = 4;
+ } else {
+ int index = 2;
+ while (index + PACKET_WRAPPER_LENGTH < buf.readableBytes() && buf.getByte(index) != PACKAGE_END_SIGN) {
+ index += PACKET_WRAPPER_LENGTH + buf.getUnsignedShortLE(index + 1);
+ }
+ if (buf.getByte(index) != PACKAGE_END_SIGN) {
+ return null;
+ }
+ length = index + 1;
}
- if (buf.getByte(index) != PACKAGE_END_SIGN) {
- return null;
- }
- length = index + 1;
}
- }
- if (buf.readableBytes() >= length) {
- return buf.readBytes(length);
+ if (buf.readableBytes() >= length) {
+ return buf.readRetainedSlice(length);
+ }
+
}
return null;
diff --git a/src/main/java/org/traccar/protocol/ArnaviProtocol.java b/src/main/java/org/traccar/protocol/ArnaviProtocol.java
index afe491865..11101097b 100644
--- a/src/main/java/org/traccar/protocol/ArnaviProtocol.java
+++ b/src/main/java/org/traccar/protocol/ArnaviProtocol.java
@@ -31,7 +31,7 @@ public class ArnaviProtocol extends BaseProtocol {
pipeline.addLast(new LineBasedFrameDecoder(1024));
pipeline.addLast(new StringDecoder());
pipeline.addLast(new StringEncoder());
- pipeline.addLast(new ArnaviProtocolDecoder(ArnaviProtocol.this));
+ pipeline.addLast(new ArnaviTextProtocolDecoder(ArnaviProtocol.this));
}
});
}
diff --git a/src/main/java/org/traccar/protocol/ArnaviProtocolDecoder.java b/src/main/java/org/traccar/protocol/ArnaviTextProtocolDecoder.java
index 7996cf429..8c4f743bc 100644
--- a/src/main/java/org/traccar/protocol/ArnaviProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/ArnaviTextProtocolDecoder.java
@@ -27,9 +27,9 @@ import org.traccar.model.Position;
import java.net.SocketAddress;
import java.util.regex.Pattern;
-public class ArnaviProtocolDecoder extends BaseProtocolDecoder {
+public class ArnaviTextProtocolDecoder extends BaseProtocolDecoder {
- public ArnaviProtocolDecoder(Protocol protocol) {
+ public ArnaviTextProtocolDecoder(Protocol protocol) {
super(protocol);
}
diff --git a/src/test/java/org/traccar/protocol/Arnavi4ProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/ArnaviBinaryProtocolDecoderTest.java
index 2628188b9..f2940de59 100644
--- a/src/test/java/org/traccar/protocol/Arnavi4ProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/ArnaviBinaryProtocolDecoderTest.java
@@ -3,14 +3,14 @@ package org.traccar.protocol;
import org.junit.Test;
import org.traccar.ProtocolTest;
-public class Arnavi4ProtocolDecoderTest extends ProtocolTest {
+public class ArnaviBinaryProtocolDecoderTest extends ProtocolTest {
@Test
public void testHeader1Decode() throws Exception {
- Arnavi4ProtocolDecoder decoder;
+ ArnaviBinaryProtocolDecoder decoder;
- decoder = new Arnavi4ProtocolDecoder(new Arnavi4Protocol());
+ decoder = new ArnaviBinaryProtocolDecoder(null);
verifyNull(decoder, binary(
"ff22f30c45f5c90f0300"));
@@ -23,9 +23,9 @@ public class Arnavi4ProtocolDecoderTest extends ProtocolTest {
@Test
public void testHeader2Decode() throws Exception {
- Arnavi4ProtocolDecoder decoder;
+ ArnaviBinaryProtocolDecoder decoder;
- decoder = new Arnavi4ProtocolDecoder(new Arnavi4Protocol());
+ decoder = new ArnaviBinaryProtocolDecoder(null);
verifyNull(decoder, binary(
"ff23f30c45f5c90f0300"));
diff --git a/src/test/java/org/traccar/protocol/Arnavi4FrameDecoderTest.java b/src/test/java/org/traccar/protocol/ArnaviFrameDecoderTest.java
index aa3f85820..90eb20296 100644
--- a/src/test/java/org/traccar/protocol/Arnavi4FrameDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/ArnaviFrameDecoderTest.java
@@ -3,12 +3,16 @@ package org.traccar.protocol;
import org.junit.Test;
import org.traccar.ProtocolTest;
-public class Arnavi4FrameDecoderTest extends ProtocolTest {
+public class ArnaviFrameDecoderTest extends ProtocolTest {
@Test
public void testDecodeValidPackets() throws Exception {
- Arnavi4FrameDecoder decoder = new Arnavi4FrameDecoder();
+ ArnaviFrameDecoder decoder = new ArnaviFrameDecoder();
+
+ verifyFrame(
+ binary("2441562c563344492c38353136342c3231342c2d312c31392c30303030344634462c30303030303935452c30433030303030322c3836333037313031333034313631382c38393939373031353630333832353236363232462c2a3039"),
+ decoder.decode(null, null, binary("2441562c563344492c38353136342c3231342c2d312c31392c30303030344634462c30303030303935452c30433030303030322c3836333037313031333034313631382c38393939373031353630333832353236363232462c2a30390d0a")));
verifyFrame(
binary("ff22f30c45f5c90f0300"),
diff --git a/src/test/java/org/traccar/protocol/ArnaviProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/ArnaviTextProtocolDecoderTest.java
index 6b075facc..065a28580 100644
--- a/src/test/java/org/traccar/protocol/ArnaviProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/ArnaviTextProtocolDecoderTest.java
@@ -3,12 +3,12 @@ package org.traccar.protocol;
import org.junit.Test;
import org.traccar.ProtocolTest;
-public class ArnaviProtocolDecoderTest extends ProtocolTest {
+public class ArnaviTextProtocolDecoderTest extends ProtocolTest {
@Test
public void testDecode() throws Exception {
- ArnaviProtocolDecoder decoder = new ArnaviProtocolDecoder(null);
+ ArnaviTextProtocolDecoder decoder = new ArnaviTextProtocolDecoder(null);
verifyPosition(decoder, text(
"$AV,V4,999999,12487,2277,203,65534,0,0,193,65535,65535,65535,65535,1,13,80.0,56.1,200741,5950.6773N,03029.1043E,300.0,360.0,121012,65535,65535,65535,SF*6E"));