aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2017-12-01 00:18:44 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2017-12-01 00:18:57 +1300
commit8e567d133c3d342cebd505c6d2effe6b2a41cb7b (patch)
tree93b23b7d59bba4028988efd813adc2f336897ea3
parenta37ade7f1bd6a0c5ab8b6c603734f94afad9337f (diff)
downloadtraccar-server-8e567d133c3d342cebd505c6d2effe6b2a41cb7b.tar.gz
traccar-server-8e567d133c3d342cebd505c6d2effe6b2a41cb7b.tar.bz2
traccar-server-8e567d133c3d342cebd505c6d2effe6b2a41cb7b.zip
Support eelink UDP response
-rw-r--r--src/org/traccar/protocol/EelinkProtocolDecoder.java18
-rw-r--r--src/org/traccar/protocol/EelinkProtocolEncoder.java28
2 files changed, 28 insertions, 18 deletions
diff --git a/src/org/traccar/protocol/EelinkProtocolDecoder.java b/src/org/traccar/protocol/EelinkProtocolDecoder.java
index a904601d6..30e94026c 100644
--- a/src/org/traccar/protocol/EelinkProtocolDecoder.java
+++ b/src/org/traccar/protocol/EelinkProtocolDecoder.java
@@ -18,6 +18,7 @@ package org.traccar.protocol;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.Channel;
+import org.jboss.netty.channel.socket.DatagramChannel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.DeviceSession;
import org.traccar.helper.BitUtil;
@@ -59,14 +60,10 @@ public class EelinkProtocolDecoder extends BaseProtocolDecoder {
public static final int MSG_CAMERA_INFO = 0x1E;
public static final int MSG_CAMERA_DATA = 0x1F;
- private void sendResponse(Channel channel, int type, int index) {
+ private void sendResponse(Channel channel, SocketAddress remoteAddress, String uniqueId, int type, int index) {
if (channel != null) {
- ChannelBuffer response = ChannelBuffers.buffer(7);
- response.writeByte(0x67); response.writeByte(0x67); // header
- response.writeByte(type);
- response.writeShort(2); // length
- response.writeShort(index);
- channel.write(response);
+ channel.write(EelinkProtocolEncoder.encodeContent(
+ channel instanceof DatagramChannel, uniqueId, type, index, null), remoteAddress);
}
}
@@ -321,12 +318,13 @@ public class EelinkProtocolDecoder extends BaseProtocolDecoder {
ChannelBuffer buf = (ChannelBuffer) msg;
+ String uniqueId = null;
DeviceSession deviceSession;
if (buf.getByte(0) == 'E' && buf.getByte(1) == 'L') {
buf.skipBytes(2 + 2 + 2); // udp header
- deviceSession = getDeviceSession(
- channel, remoteAddress, ChannelBuffers.hexDump(buf.readBytes(8)).substring(1));
+ uniqueId = ChannelBuffers.hexDump(buf.readBytes(8)).substring(1);
+ deviceSession = getDeviceSession(channel, remoteAddress, uniqueId);
} else {
deviceSession = getDeviceSession(channel, remoteAddress);
}
@@ -337,7 +335,7 @@ public class EelinkProtocolDecoder extends BaseProtocolDecoder {
int index = buf.readUnsignedShort();
if (type != MSG_GPS && type != MSG_DATA) {
- sendResponse(channel, type, index);
+ sendResponse(channel, remoteAddress, uniqueId, type, index);
}
if (type == MSG_LOGIN) {
diff --git a/src/org/traccar/protocol/EelinkProtocolEncoder.java b/src/org/traccar/protocol/EelinkProtocolEncoder.java
index 917f964fe..41d76b24a 100644
--- a/src/org/traccar/protocol/EelinkProtocolEncoder.java
+++ b/src/org/traccar/protocol/EelinkProtocolEncoder.java
@@ -41,23 +41,24 @@ public class EelinkProtocolEncoder extends BaseProtocolEncoder {
return sum;
}
- private ChannelBuffer encodeContent(long deviceId, String content) {
+ public static ChannelBuffer encodeContent(
+ boolean connectionless, String uniqueId, int type, int index, ChannelBuffer content) {
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
if (connectionless) {
- buf.writeBytes(ChannelBuffers.wrappedBuffer(DatatypeConverter.parseHexBinary('0' + getUniqueId(deviceId))));
+ buf.writeBytes(ChannelBuffers.wrappedBuffer(DatatypeConverter.parseHexBinary('0' + uniqueId)));
}
buf.writeByte(0x67);
buf.writeByte(0x67);
- buf.writeByte(EelinkProtocolDecoder.MSG_DOWNLINK);
- buf.writeShort(2 + 1 + 4 + content.length()); // length
- buf.writeShort(0); // index
+ buf.writeByte(type);
+ buf.writeShort(2 + (content != null ? content.readableBytes() : 0)); // length
+ buf.writeShort(index);
- buf.writeByte(0x01); // command
- buf.writeInt(0); // server id
- buf.writeBytes(content.getBytes(StandardCharsets.UTF_8));
+ if (content != null) {
+ buf.writeBytes(content);
+ }
ChannelBuffer result = ChannelBuffers.dynamicBuffer();
@@ -73,6 +74,17 @@ public class EelinkProtocolEncoder extends BaseProtocolEncoder {
return result;
}
+ private ChannelBuffer encodeContent(long deviceId, String content) {
+
+ ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
+
+ buf.writeByte(0x01); // command
+ buf.writeInt(0); // server id
+ buf.writeBytes(content.getBytes(StandardCharsets.UTF_8));
+
+ return encodeContent(connectionless, getUniqueId(deviceId), EelinkProtocolDecoder.MSG_DOWNLINK, 0, buf);
+ }
+
@Override
protected Object encodeCommand(Command command) {