diff options
Diffstat (limited to 'src/org/traccar')
-rw-r--r-- | src/org/traccar/helper/Hashing.java | 1 | ||||
-rw-r--r-- | src/org/traccar/protocol/AisProtocolDecoder.java | 5 | ||||
-rw-r--r-- | src/org/traccar/protocol/At2000FrameDecoder.java | 11 | ||||
-rw-r--r-- | src/org/traccar/protocol/H02FrameDecoder.java | 50 | ||||
-rw-r--r-- | src/org/traccar/protocol/TmgProtocolDecoder.java | 3 |
5 files changed, 39 insertions, 31 deletions
diff --git a/src/org/traccar/helper/Hashing.java b/src/org/traccar/helper/Hashing.java index 7f36c6802..3fcc124fa 100644 --- a/src/org/traccar/helper/Hashing.java +++ b/src/org/traccar/helper/Hashing.java @@ -33,6 +33,7 @@ public final class Hashing { try { factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1"); } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); } } 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; |