diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2017-11-28 20:01:45 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2017-11-28 20:01:58 +1300 |
commit | 818fff6daf87a9e90a225122d04dc8b93694a8c6 (patch) | |
tree | 8f24ab85903d404023a27c35566efe6320da5dee /src/org/traccar/protocol/EelinkProtocolEncoder.java | |
parent | 97360131f2f5f53c79e4d41a3e5b3bfebe49d960 (diff) | |
download | traccar-server-818fff6daf87a9e90a225122d04dc8b93694a8c6.tar.gz traccar-server-818fff6daf87a9e90a225122d04dc8b93694a8c6.tar.bz2 traccar-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.java | 11 |
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); |