aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2017-11-28 00:12:55 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2017-11-28 00:12:55 +1300
commit371edced45683da9a3b7195d48787b9f7a40b232 (patch)
tree87da4c3fc8facb491d439e4af511feef5123f6a1 /src/org/traccar/protocol
parentb149a7b71283f1a8481c9e3954d636afcff6169e (diff)
downloadtrackermap-server-371edced45683da9a3b7195d48787b9f7a40b232.tar.gz
trackermap-server-371edced45683da9a3b7195d48787b9f7a40b232.tar.bz2
trackermap-server-371edced45683da9a3b7195d48787b9f7a40b232.zip
Implement new eeLink commands
Diffstat (limited to 'src/org/traccar/protocol')
-rw-r--r--src/org/traccar/protocol/EelinkProtocol.java5
-rw-r--r--src/org/traccar/protocol/EelinkProtocolEncoder.java38
2 files changed, 34 insertions, 9 deletions
diff --git a/src/org/traccar/protocol/EelinkProtocol.java b/src/org/traccar/protocol/EelinkProtocol.java
index 3c3424cd4..3d0a006de 100644
--- a/src/org/traccar/protocol/EelinkProtocol.java
+++ b/src/org/traccar/protocol/EelinkProtocol.java
@@ -31,6 +31,7 @@ public class EelinkProtocol extends BaseProtocol {
super("eelink");
setSupportedDataCommands(
Command.TYPE_CUSTOM,
+ Command.TYPE_POSITION_SINGLE,
Command.TYPE_ENGINE_STOP,
Command.TYPE_ENGINE_RESUME,
Command.TYPE_REBOOT_DEVICE);
@@ -42,14 +43,14 @@ public class EelinkProtocol extends BaseProtocol {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 3, 2));
- pipeline.addLast("objectEncoder", new EelinkProtocolEncoder());
+ pipeline.addLast("objectEncoder", new EelinkProtocolEncoder(false));
pipeline.addLast("objectDecoder", new EelinkProtocolDecoder(EelinkProtocol.this));
}
});
serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("objectEncoder", new EelinkProtocolEncoder());
+ pipeline.addLast("objectEncoder", new EelinkProtocolEncoder(true));
pipeline.addLast("objectDecoder", new EelinkProtocolDecoder(EelinkProtocol.this));
}
});
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;