aboutsummaryrefslogtreecommitdiff
path: root/src/org
diff options
context:
space:
mode:
Diffstat (limited to 'src/org')
-rw-r--r--src/org/traccar/protocol/AtrackFrameDecoder.java4
-rw-r--r--src/org/traccar/protocol/AtrackProtocolDecoder.java18
2 files changed, 16 insertions, 6 deletions
diff --git a/src/org/traccar/protocol/AtrackFrameDecoder.java b/src/org/traccar/protocol/AtrackFrameDecoder.java
index 90dfa68b6..35db02baf 100644
--- a/src/org/traccar/protocol/AtrackFrameDecoder.java
+++ b/src/org/traccar/protocol/AtrackFrameDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2013 - 2014 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.
@@ -37,7 +37,7 @@ public class AtrackFrameDecoder extends LengthFieldBasedFrameDecoder {
// Keep alive message
if (buf.readableBytes() >= KEEPALIVE_LENGTH &&
buf.getUnsignedShort(buf.readerIndex()) == 0xfe02) {
- channel.write(buf.readBytes(KEEPALIVE_LENGTH));
+ return buf.readBytes(KEEPALIVE_LENGTH);
}
return super.decode(ctx, channel, buf);
diff --git a/src/org/traccar/protocol/AtrackProtocolDecoder.java b/src/org/traccar/protocol/AtrackProtocolDecoder.java
index db6cdb7e1..1323ce8a3 100644
--- a/src/org/traccar/protocol/AtrackProtocolDecoder.java
+++ b/src/org/traccar/protocol/AtrackProtocolDecoder.java
@@ -15,6 +15,7 @@
*/
package org.traccar.protocol;
+import java.net.SocketAddress;
import java.nio.charset.Charset;
import java.util.Date;
import java.util.LinkedList;
@@ -41,13 +42,13 @@ public class AtrackProtocolDecoder extends BaseProtocolDecoder {
private static final int MSG_HEARTBEAT = 0x1A;
private static final int MSG_DATA = 0x10;
- private static void sendResponse(Channel channel, long rawId, int index) {
+ private static void sendResponse(Channel channel, SocketAddress remoteAddress, long rawId, int index) {
if (channel != null) {
ChannelBuffer response = ChannelBuffers.directBuffer(12);
response.writeShort(0xfe02);
response.writeLong(rawId);
response.writeShort(index);
- channel.write(response);
+ channel.write(response, remoteAddress);
}
}
@@ -69,10 +70,19 @@ public class AtrackProtocolDecoder extends BaseProtocolDecoder {
@Override
protected Object decode(
- ChannelHandlerContext ctx, Channel channel, Object msg)
+ ChannelHandlerContext ctx, Channel channel, SocketAddress remoteAddress, Object msg)
throws Exception {
ChannelBuffer buf = (ChannelBuffer) msg;
+
+ // Keep alive message
+ if (buf.getUnsignedShort(buf.readerIndex()) == 0xfe02) {
+ if (channel != null) {
+ channel.write(buf, remoteAddress);
+ }
+ return null;
+ }
+
buf.skipBytes(2); // prefix
buf.readUnsignedShort(); // checksum
buf.readUnsignedShort(); // length
@@ -90,7 +100,7 @@ public class AtrackProtocolDecoder extends BaseProtocolDecoder {
}
// Send acknowledgement
- sendResponse(channel, rawId, index);
+ sendResponse(channel, remoteAddress, rawId, index);
List<Position> positions = new LinkedList<Position>();