diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2017-11-28 00:12:55 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2017-11-28 00:12:55 +1300 |
commit | 371edced45683da9a3b7195d48787b9f7a40b232 (patch) | |
tree | 87da4c3fc8facb491d439e4af511feef5123f6a1 /src/org/traccar/protocol/EelinkProtocolEncoder.java | |
parent | b149a7b71283f1a8481c9e3954d636afcff6169e (diff) | |
download | trackermap-server-371edced45683da9a3b7195d48787b9f7a40b232.tar.gz trackermap-server-371edced45683da9a3b7195d48787b9f7a40b232.tar.bz2 trackermap-server-371edced45683da9a3b7195d48787b9f7a40b232.zip |
Implement new eeLink commands
Diffstat (limited to 'src/org/traccar/protocol/EelinkProtocolEncoder.java')
-rw-r--r-- | src/org/traccar/protocol/EelinkProtocolEncoder.java | 38 |
1 files changed, 31 insertions, 7 deletions
diff --git a/src/org/traccar/protocol/EelinkProtocolEncoder.java b/src/org/traccar/protocol/EelinkProtocolEncoder.java index 5a28733f7..b9be684a3 100644 --- a/src/org/traccar/protocol/EelinkProtocolEncoder.java +++ b/src/org/traccar/protocol/EelinkProtocolEncoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Anton Tananaev (anton@traccar.org) + * Copyright 2016 - 2017 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,14 +21,25 @@ import org.traccar.BaseProtocolEncoder; import org.traccar.helper.Log; import org.traccar.model.Command; +import javax.xml.bind.DatatypeConverter; import java.nio.charset.StandardCharsets; public class EelinkProtocolEncoder extends BaseProtocolEncoder { - private ChannelBuffer encodeContent(String content) { + private boolean connectionless; + + public EelinkProtocolEncoder(boolean connectionless) { + this.connectionless = connectionless; + } + + private ChannelBuffer encodeContent(long deviceId, String content) { ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); + if (connectionless) { + buf.writeBytes(ChannelBuffers.wrappedBuffer(DatatypeConverter.parseHexBinary('0' + getUniqueId(deviceId)))); + } + buf.writeByte(0x67); buf.writeByte(0x67); buf.writeByte(EelinkProtocolDecoder.MSG_DOWNLINK); @@ -39,7 +50,18 @@ public class EelinkProtocolEncoder extends BaseProtocolEncoder { buf.writeInt(0); // server id buf.writeBytes(content.getBytes(StandardCharsets.UTF_8)); - return buf; + ChannelBuffer result = ChannelBuffers.dynamicBuffer(); + + if (connectionless) { + result.writeByte('E'); + result.writeByte('L'); + result.writeShort(2 + 2 + 2 + buf.readableBytes()); // length + result.writeShort(0); // checksum + } + + result.writeBytes(buf); + + return result; } @Override @@ -47,13 +69,15 @@ public class EelinkProtocolEncoder extends BaseProtocolEncoder { switch (command.getType()) { case Command.TYPE_CUSTOM: - return encodeContent(command.getString(Command.KEY_DATA)); + return encodeContent(command.getDeviceId(), command.getString(Command.KEY_DATA)); + case Command.TYPE_POSITION_SINGLE: + return encodeContent(command.getDeviceId(), "WHERE#"); case Command.TYPE_ENGINE_STOP: - return encodeContent("RELAY,1#"); + return encodeContent(command.getDeviceId(), "RELAY,1#"); case Command.TYPE_ENGINE_RESUME: - return encodeContent("RELAY,0#"); + return encodeContent(command.getDeviceId(), "RELAY,0#"); case Command.TYPE_REBOOT_DEVICE: - return encodeContent("RESET#"); + return encodeContent(command.getDeviceId(), "RESET#"); default: Log.warning(new UnsupportedOperationException(command.getType())); break; |