aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol/EelinkProtocolEncoder.java
diff options
context:
space:
mode:
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);