aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol/OrionFrameDecoder.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2014-08-30 20:22:08 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2014-08-30 20:22:08 +1200
commit419b1f981fe8b108e053258719da2cc33de76dfa (patch)
treefd6de1916a20d391adf8e0909b81e580cb3ac263 /src/org/traccar/protocol/OrionFrameDecoder.java
parente7d203230ff48e849b0b50a858c73bab8c2dd2e5 (diff)
downloadtrackermap-server-419b1f981fe8b108e053258719da2cc33de76dfa.tar.gz
trackermap-server-419b1f981fe8b108e053258719da2cc33de76dfa.tar.bz2
trackermap-server-419b1f981fe8b108e053258719da2cc33de76dfa.zip
Implement Orion protocol
Diffstat (limited to 'src/org/traccar/protocol/OrionFrameDecoder.java')
-rw-r--r--src/org/traccar/protocol/OrionFrameDecoder.java50
1 files changed, 36 insertions, 14 deletions
diff --git a/src/org/traccar/protocol/OrionFrameDecoder.java b/src/org/traccar/protocol/OrionFrameDecoder.java
index 92236225b..cc3efa6a5 100644
--- a/src/org/traccar/protocol/OrionFrameDecoder.java
+++ b/src/org/traccar/protocol/OrionFrameDecoder.java
@@ -21,6 +21,9 @@ import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.handler.codec.frame.FrameDecoder;
public class OrionFrameDecoder extends FrameDecoder {
+
+ private static final int TYPE_USERLOG = 0;
+ private static final int TYPE_SYSLOG = 3;
@Override
protected Object decode(
@@ -28,22 +31,41 @@ public class OrionFrameDecoder extends FrameDecoder {
Channel channel,
ChannelBuffer buf) throws Exception {
- // Check minimum length
- if (buf.readableBytes() < 5) {
- return null;
- }
-
- int length = 2 + 2; // head and tail
-
- if (buf.getByte(buf.readerIndex()) == 0x78) {
- length += 1 + buf.getByte(buf.readerIndex() + 2);
- } else {
- length += 2 + buf.getShort(buf.readerIndex() + 2);
- }
+ int length = 6;
- // Check length and return buffer
if (buf.readableBytes() >= length) {
- return buf.readBytes(length);
+
+ int type = buf.getUnsignedByte(buf.readerIndex() + 2) & 0x0f;
+
+ if (type == TYPE_USERLOG) {
+ if (buf.readableBytes() >= length + 5) {
+
+ int index = buf.readerIndex() + 3;
+ int count = buf.getUnsignedByte(index) & 0x0f;
+ index += 5;
+ length += 5;
+
+ for (int i = 0; i < count; i++) {
+ if (buf.readableBytes() < length) {
+ return null;
+ }
+ int logLength = buf.getUnsignedByte(index + 1);
+ index += logLength;
+ length += logLength;
+ }
+
+ if (buf.readableBytes() >= length) {
+ return buf.readBytes(length);
+ }
+ }
+ } else if (type == TYPE_SYSLOG) {
+ if (buf.readableBytes() >= length + 12) {
+ length += buf.getUnsignedShort(buf.readerIndex() + 8);
+ if (buf.readableBytes() >= length) {
+ return buf.readBytes(length);
+ }
+ }
+ }
}
return null;