From 8e567d133c3d342cebd505c6d2effe6b2a41cb7b Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 1 Dec 2017 00:18:44 +1300 Subject: Support eelink UDP response --- .../traccar/protocol/EelinkProtocolEncoder.java | 28 +++++++++++++++------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'src/org/traccar/protocol/EelinkProtocolEncoder.java') 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) { -- cgit v1.2.3