diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2020-02-02 16:26:46 -0800 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2020-02-02 16:26:46 -0800 |
commit | 71735f0c9b17ad1c64a4335a196b4c765b4499c1 (patch) | |
tree | 62bb4891d5405b72bdd7a8301bdb5be063b05602 /src/main/java/org | |
parent | 00f8b1ff552f49ebcb5c1d13c85bd84911a2ac8d (diff) | |
download | trackermap-server-71735f0c9b17ad1c64a4335a196b4c765b4499c1.tar.gz trackermap-server-71735f0c9b17ad1c64a4335a196b4c765b4499c1.tar.bz2 trackermap-server-71735f0c9b17ad1c64a4335a196b4c765b4499c1.zip |
Rename classes
Diffstat (limited to 'src/main/java/org')
-rw-r--r-- | src/main/java/org/traccar/protocol/Arnavi4Protocol.java | 35 | ||||
-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.java | 2 | ||||
-rw-r--r-- | src/main/java/org/traccar/protocol/ArnaviTextProtocolDecoder.java (renamed from src/main/java/org/traccar/protocol/ArnaviProtocolDecoder.java) | 4 |
5 files changed, 38 insertions, 58 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); } |