aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2017-02-11 12:34:38 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2017-02-11 12:34:38 +1300
commitb70eddfcda8262ec4bf76213d414ef55950478d0 (patch)
treec302957f3999fcf571c93a62778defcd403b5851 /src/org/traccar/protocol
parentc8fa36318702acc9ff54d3811e1f32c1035e85f3 (diff)
downloadtraccar-server-b70eddfcda8262ec4bf76213d414ef55950478d0.tar.gz
traccar-server-b70eddfcda8262ec4bf76213d414ef55950478d0.tar.bz2
traccar-server-b70eddfcda8262ec4bf76213d414ef55950478d0.zip
Fix some code issues
Diffstat (limited to 'src/org/traccar/protocol')
-rw-r--r--src/org/traccar/protocol/AisProtocolDecoder.java5
-rw-r--r--src/org/traccar/protocol/At2000FrameDecoder.java11
-rw-r--r--src/org/traccar/protocol/H02FrameDecoder.java50
-rw-r--r--src/org/traccar/protocol/TmgProtocolDecoder.java3
4 files changed, 38 insertions, 31 deletions
diff --git a/src/org/traccar/protocol/AisProtocolDecoder.java b/src/org/traccar/protocol/AisProtocolDecoder.java
index 3ccca6dd3..f04c558c2 100644
--- a/src/org/traccar/protocol/AisProtocolDecoder.java
+++ b/src/org/traccar/protocol/AisProtocolDecoder.java
@@ -24,6 +24,7 @@ import org.traccar.helper.PatternBuilder;
import org.traccar.model.Position;
import java.net.SocketAddress;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
@@ -110,7 +111,7 @@ public class AisProtocolDecoder extends BaseProtocolDecoder {
if (count == 1) {
BitBuffer bits = new BitBuffer();
- bits.writeEncoded(parser.next().getBytes());
+ bits.writeEncoded(parser.next().getBytes(StandardCharsets.US_ASCII));
position = decodePayload(channel, remoteAddress, bits);
} else {
BitBuffer bits = buffers.get(id);
@@ -118,7 +119,7 @@ public class AisProtocolDecoder extends BaseProtocolDecoder {
bits = new BitBuffer();
buffers.put(id, bits);
}
- bits.writeEncoded(parser.next().getBytes());
+ bits.writeEncoded(parser.next().getBytes(StandardCharsets.US_ASCII));
if (count == index) {
position = decodePayload(channel, remoteAddress, bits);
buffers.remove(id);
diff --git a/src/org/traccar/protocol/At2000FrameDecoder.java b/src/org/traccar/protocol/At2000FrameDecoder.java
index f87dc3885..af257d0fb 100644
--- a/src/org/traccar/protocol/At2000FrameDecoder.java
+++ b/src/org/traccar/protocol/At2000FrameDecoder.java
@@ -65,12 +65,11 @@ public class At2000FrameDecoder extends FrameDecoder {
length = (length / BLOCK_LENGTH + 1) * BLOCK_LENGTH;
}
- if (buf.readableBytes() >= length || buf.readableBytes() % ACK_LENGTH == 0) {
- if (buf != currentBuffer || buf.readableBytes() > acknowledgedBytes) {
- sendResponse(channel);
- currentBuffer = buf;
- acknowledgedBytes = buf.readableBytes();
- }
+ if ((buf.readableBytes() >= length || buf.readableBytes() % ACK_LENGTH == 0)
+ && (buf != currentBuffer || buf.readableBytes() > acknowledgedBytes)) {
+ sendResponse(channel);
+ currentBuffer = buf;
+ acknowledgedBytes = buf.readableBytes();
}
if (buf.readableBytes() >= length) {
diff --git a/src/org/traccar/protocol/H02FrameDecoder.java b/src/org/traccar/protocol/H02FrameDecoder.java
index b2da64847..f1d305ab6 100644
--- a/src/org/traccar/protocol/H02FrameDecoder.java
+++ b/src/org/traccar/protocol/H02FrameDecoder.java
@@ -44,34 +44,44 @@ public class H02FrameDecoder extends FrameDecoder {
}
}
- if (marker == '*') {
+ switch (marker) {
+ case '*':
- // Return text message
- int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '#');
- if (index != -1) {
- return buf.readBytes(index + 1 - buf.readerIndex());
- }
+ // Return text message
+ int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '#');
+ if (index != -1) {
+ return buf.readBytes(index + 1 - buf.readerIndex());
+ }
+
+ break;
- } else if (marker == '$') {
+ case '$':
- if (messageLength == 0) {
- if (buf.readableBytes() == MESSAGE_LONG) {
- messageLength = MESSAGE_LONG;
- } else {
- messageLength = MESSAGE_SHORT;
+ if (messageLength == 0) {
+ if (buf.readableBytes() == MESSAGE_LONG) {
+ messageLength = MESSAGE_LONG;
+ } else {
+ messageLength = MESSAGE_SHORT;
+ }
}
- }
- if (buf.readableBytes() >= messageLength) {
- return buf.readBytes(messageLength);
- }
+ if (buf.readableBytes() >= messageLength) {
+ return buf.readBytes(messageLength);
+ }
- } else if (marker == 'X') {
+ break;
- if (buf.readableBytes() >= MESSAGE_SHORT) {
- return buf.readBytes(MESSAGE_SHORT);
- }
+ case 'X':
+
+ if (buf.readableBytes() >= MESSAGE_SHORT) {
+ return buf.readBytes(MESSAGE_SHORT);
+ }
+
+ break;
+
+ default:
+ throw new IllegalArgumentException();
}
return null;
diff --git a/src/org/traccar/protocol/TmgProtocolDecoder.java b/src/org/traccar/protocol/TmgProtocolDecoder.java
index 3a2af96fb..2f2dddf60 100644
--- a/src/org/traccar/protocol/TmgProtocolDecoder.java
+++ b/src/org/traccar/protocol/TmgProtocolDecoder.java
@@ -67,9 +67,6 @@ public class TmgProtocolDecoder extends BaseProtocolDecoder {
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
- org.traccar.helper.PatternUtil.MatchResult matchResult =
- org.traccar.helper.PatternUtil.checkPattern(PATTERN.pattern(), (String) msg);
-
Parser parser = new Parser(PATTERN, (String) msg);
if (!parser.matches()) {
return null;