aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-10-26 12:27:41 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2015-10-26 12:27:41 +1300
commit4acc359d664db81242f6c3a1a7a6dedcf2ab465a (patch)
treee901c5d89922147e551f241d1e5bc9801de3b9d3 /src/org/traccar/protocol
parent96f529e32083d916883c3757ac88012758fdc90c (diff)
downloadtrackermap-server-4acc359d664db81242f6c3a1a7a6dedcf2ab465a.tar.gz
trackermap-server-4acc359d664db81242f6c3a1a7a6dedcf2ab465a.tar.bz2
trackermap-server-4acc359d664db81242f6c3a1a7a6dedcf2ab465a.zip
Modify JT600 frame decoder
Diffstat (limited to 'src/org/traccar/protocol')
-rw-r--r--src/org/traccar/protocol/Jt600FrameDecoder.java26
1 files changed, 9 insertions, 17 deletions
diff --git a/src/org/traccar/protocol/Jt600FrameDecoder.java b/src/org/traccar/protocol/Jt600FrameDecoder.java
index 8b8f4f642..22bbd5514 100644
--- a/src/org/traccar/protocol/Jt600FrameDecoder.java
+++ b/src/org/traccar/protocol/Jt600FrameDecoder.java
@@ -26,34 +26,26 @@ public class Jt600FrameDecoder extends FrameDecoder {
@Override
protected Object decode(
- ChannelHandlerContext ctx,
- Channel channel,
- ChannelBuffer buf) throws Exception {
+ ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
- // Check minimum length
- int available = buf.readableBytes();
- if (available < 10) {
+ if (buf.readableBytes() < 10) {
return null;
}
- // Message identifier
- char first = (char) buf.getByte(buf.readerIndex());
+ char type = (char) buf.getByte(buf.readerIndex());
- if (first == '$') {
- // Check length
+ if (type == '$') {
int length = buf.getUnsignedShort(buf.readerIndex() + 7) + 10;
- if (length >= available) {
+ if (length >= buf.readableBytes()) {
return buf.readBytes(length);
}
- } else if (first == '(') {
- // Find ending
- Integer endIndex = ChannelBufferTools.find(buf, buf.readerIndex(), available, ")");
- if (endIndex != null) {
+ } else if (type == '(') {
+ int endIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ')');
+ if (endIndex != -1) {
return buf.readBytes(endIndex + 1);
}
} else {
- // Unknown message
- throw new ParseException(null, 0);
+ throw new ParseException(null, 0); // unknown message
}
return null;