aboutsummaryrefslogtreecommitdiff
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
parentb149a7b71283f1a8481c9e3954d636afcff6169e (diff)
downloadtraccar-server-371edced45683da9a3b7195d48787b9f7a40b232.tar.gz
traccar-server-371edced45683da9a3b7195d48787b9f7a40b232.tar.bz2
traccar-server-371edced45683da9a3b7195d48787b9f7a40b232.zip
Implement new eeLink commands
-rw-r--r--src/org/traccar/protocol/EelinkProtocol.java5
-rw-r--r--src/org/traccar/protocol/EelinkProtocolEncoder.java38
-rw-r--r--test/org/traccar/protocol/EelinkProtocolDecoderTest.java3
-rw-r--r--test/org/traccar/protocol/EelinkProtocolEncoderTest.java2
4 files changed, 38 insertions, 10 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;
diff --git a/test/org/traccar/protocol/EelinkProtocolDecoderTest.java b/test/org/traccar/protocol/EelinkProtocolDecoderTest.java
index 83ca85c96..b029795e0 100644
--- a/test/org/traccar/protocol/EelinkProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/EelinkProtocolDecoderTest.java
@@ -17,6 +17,9 @@ public class EelinkProtocolDecoderTest extends ProtocolTest {
"454C0050EAE2035254407167747167671200410021590BD93803026B940D0C3952AD0021000000000501CC0001A53F0170F0AB1305890F11000000000000C2D0001C001600000000000000000000000000000000"));
verifyNull(decoder, binary(
+ "676780005E5788014C754C754C61743A4E32332E3131313734330A4C6F6E3A453131342E3430393233380A436F757273653A302E30300A53706565643A302E31374B4D2F480A446174652054696D653A323031352D30392D31332032303A32313A3230"));
+
+ verifyNull(decoder, binary(
"676701000c007b03525440717505180104"));
verifyPosition(decoder, binary(
diff --git a/test/org/traccar/protocol/EelinkProtocolEncoderTest.java b/test/org/traccar/protocol/EelinkProtocolEncoderTest.java
index 8a8cd5f6b..e0843b36d 100644
--- a/test/org/traccar/protocol/EelinkProtocolEncoderTest.java
+++ b/test/org/traccar/protocol/EelinkProtocolEncoderTest.java
@@ -9,7 +9,7 @@ public class EelinkProtocolEncoderTest extends ProtocolTest {
@Test
public void testEncode() throws Exception {
- EelinkProtocolEncoder encoder = new EelinkProtocolEncoder();
+ EelinkProtocolEncoder encoder = new EelinkProtocolEncoder(false);
Command command = new Command();
command.setDeviceId(1);