aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol/Jt600FrameDecoder.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2013-07-31 20:56:53 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2013-07-31 20:56:53 +1200
commitd53db01813ee67e7578f55c162639aa61608ed0b (patch)
treed4e5228c196f59512278b18542510dc3551499a4 /src/org/traccar/protocol/Jt600FrameDecoder.java
parent016561b2060242e4d4cac25f352cec3dbe4c41a4 (diff)
downloadtrackermap-server-d53db01813ee67e7578f55c162639aa61608ed0b.tar.gz
trackermap-server-d53db01813ee67e7578f55c162639aa61608ed0b.tar.bz2
trackermap-server-d53db01813ee67e7578f55c162639aa61608ed0b.zip
Fix jt600 frame decoder (fix #290)
Diffstat (limited to 'src/org/traccar/protocol/Jt600FrameDecoder.java')
-rw-r--r--src/org/traccar/protocol/Jt600FrameDecoder.java21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/org/traccar/protocol/Jt600FrameDecoder.java b/src/org/traccar/protocol/Jt600FrameDecoder.java
index 2e2fd228b..d2fbc4ca8 100644
--- a/src/org/traccar/protocol/Jt600FrameDecoder.java
+++ b/src/org/traccar/protocol/Jt600FrameDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 - 2013 Anton Tananaev (anton.tananaev@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,25 +24,30 @@ import org.traccar.helper.ChannelBufferTools;
public class Jt600FrameDecoder extends FrameDecoder {
- private static int MESSAGE_LENGTH = 37;
-
+ @Override
protected Object decode(
ChannelHandlerContext ctx,
Channel channel,
ChannelBuffer buf) throws Exception {
+ // Check minimum length
+ int available = buf.readableBytes();
+ if (available < 10) {
+ return null;
+ }
+
// Message identifier
- char first = (char) buf.getByte(0);
- int length = buf.readableBytes();
+ char first = (char) buf.getByte(buf.readerIndex());
if (first == '$') {
// Check length
- if (length >= MESSAGE_LENGTH) {
- return buf.readBytes(MESSAGE_LENGTH);
+ int length = buf.getUnsignedShort(buf.readerIndex() + 7) + 10;
+ if (length >= available) {
+ return buf.readBytes(length);
}
} else if (first == '(') {
// Find ending
- Integer endIndex = ChannelBufferTools.find(buf, 0, length, ")");
+ Integer endIndex = ChannelBufferTools.find(buf, buf.readerIndex(), available, ")");
if (endIndex != null) {
return buf.readBytes(endIndex + 1);
}