aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol/EelinkProtocolEncoder.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2017-11-28 20:01:45 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2017-11-28 20:01:58 +1300
commit818fff6daf87a9e90a225122d04dc8b93694a8c6 (patch)
tree8f24ab85903d404023a27c35566efe6320da5dee /src/org/traccar/protocol/EelinkProtocolEncoder.java
parent97360131f2f5f53c79e4d41a3e5b3bfebe49d960 (diff)
downloadtrackermap-server-818fff6daf87a9e90a225122d04dc8b93694a8c6.tar.gz
trackermap-server-818fff6daf87a9e90a225122d04dc8b93694a8c6.tar.bz2
trackermap-server-818fff6daf87a9e90a225122d04dc8b93694a8c6.zip
Fix eelink checksum and decode result
Diffstat (limited to 'src/org/traccar/protocol/EelinkProtocolEncoder.java')
-rw-r--r--src/org/traccar/protocol/EelinkProtocolEncoder.java11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/org/traccar/protocol/EelinkProtocolEncoder.java b/src/org/traccar/protocol/EelinkProtocolEncoder.java
index b9be684a3..917f964fe 100644
--- a/src/org/traccar/protocol/EelinkProtocolEncoder.java
+++ b/src/org/traccar/protocol/EelinkProtocolEncoder.java
@@ -22,6 +22,7 @@ import org.traccar.helper.Log;
import org.traccar.model.Command;
import javax.xml.bind.DatatypeConverter;
+import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
public class EelinkProtocolEncoder extends BaseProtocolEncoder {
@@ -32,6 +33,14 @@ public class EelinkProtocolEncoder extends BaseProtocolEncoder {
this.connectionless = connectionless;
}
+ public static int checksum(ByteBuffer buf) {
+ int sum = 0;
+ while (buf.hasRemaining()) {
+ sum = (((sum << 1) | (sum >> 15)) + (buf.get() & 0xFF)) & 0xFFFF;
+ }
+ return sum;
+ }
+
private ChannelBuffer encodeContent(long deviceId, String content) {
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
@@ -56,7 +65,7 @@ public class EelinkProtocolEncoder extends BaseProtocolEncoder {
result.writeByte('E');
result.writeByte('L');
result.writeShort(2 + 2 + 2 + buf.readableBytes()); // length
- result.writeShort(0); // checksum
+ result.writeShort(checksum(buf.toByteBuffer()));
}
result.writeBytes(buf);