aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/protocol/Xexun2ProtocolEncoder.java
diff options
context:
space:
mode:
authorStefan Clark <stefanclark@gmail.com>2022-07-27 15:47:18 +0100
committerStefan Clark <stefan.clark@jlgb.org>2022-07-27 18:37:29 +0100
commitde2219565e4a61aa0d64b03650ec36ef6d17de93 (patch)
treeb36651dd2f94895236fe0b3ffcf022c2dd60ee9b /src/main/java/org/traccar/protocol/Xexun2ProtocolEncoder.java
parente91402cddad8763658572eb8e383fa8a16d69190 (diff)
downloadtrackermap-server-de2219565e4a61aa0d64b03650ec36ef6d17de93.tar.gz
trackermap-server-de2219565e4a61aa0d64b03650ec36ef6d17de93.tar.bz2
trackermap-server-de2219565e4a61aa0d64b03650ec36ef6d17de93.zip
Update Xexun2 Encoder
Diffstat (limited to 'src/main/java/org/traccar/protocol/Xexun2ProtocolEncoder.java')
-rw-r--r--src/main/java/org/traccar/protocol/Xexun2ProtocolEncoder.java15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/main/java/org/traccar/protocol/Xexun2ProtocolEncoder.java b/src/main/java/org/traccar/protocol/Xexun2ProtocolEncoder.java
index c31d6e747..f876853bf 100644
--- a/src/main/java/org/traccar/protocol/Xexun2ProtocolEncoder.java
+++ b/src/main/java/org/traccar/protocol/Xexun2ProtocolEncoder.java
@@ -62,17 +62,17 @@ public class Xexun2ProtocolEncoder extends BaseProtocolEncoder {
return result;
}
- private static int checksum(byte[] data) {
+ private static int udpchecksum(ByteBuf data) {
int sum = 0;
- int len = data.length;
+ int len = data.capacity();
for (int j = 0; len > 1; len--) {
- sum += data[j++] & 0xff;
+ sum += data.readByte() & 0xff;
if ((sum & 0x80000000) > 0) {
sum = (sum & 0xffff) + (sum >> 16);
}
}
if (len == 1) {
- sum += data[data.length - 1] & 0xff;
+ sum += data.readByte() & 0xff;
}
while ((sum >> 16) > 0) {
sum = (sum & 0xffff) + sum >> 16;
@@ -85,14 +85,15 @@ public class Xexun2ProtocolEncoder extends BaseProtocolEncoder {
private static ByteBuf encodeContent(String uniqueId, String content) {
ByteBuf buf = Unpooled.buffer();
- byte[] message = content.getBytes();
+ ByteBuf message = Unpooled.copiedBuffer(content.getBytes());
buf.writeShort(FLAG);
buf.writeShort(MSG_COMMAND);
buf.writeShort(1); // index
buf.writeBytes(DataConverter.parseHex(uniqueId + "0"));
- buf.writeShort(message.length);
- buf.writeShort(checksum(message));
+ buf.writeShort(message.capacity());
+ buf.writeShort(udpchecksum(message));
+ message.resetReaderIndex();
buf.writeBytes(message);
buf.writeShort(FLAG);