diff options
author | Stefan Clark <stefanclark@gmail.com> | 2022-07-28 22:37:15 +0100 |
---|---|---|
committer | Stefan Clark <stefanclark@gmail.com> | 2022-07-28 22:37:15 +0100 |
commit | 42e88c2bf95962f1274a8bbb6e8fc09af95f627f (patch) | |
tree | 40fc4b9ef9de16e634e706895c27a46f934d7cac /src/main/java/org/traccar/helper | |
parent | de2219565e4a61aa0d64b03650ec36ef6d17de93 (diff) | |
download | trackermap-server-42e88c2bf95962f1274a8bbb6e8fc09af95f627f.tar.gz trackermap-server-42e88c2bf95962f1274a8bbb6e8fc09af95f627f.tar.bz2 trackermap-server-42e88c2bf95962f1274a8bbb6e8fc09af95f627f.zip |
Added udp() to Checksum helper and Updated Xexun2 procotol
Diffstat (limited to 'src/main/java/org/traccar/helper')
-rw-r--r-- | src/main/java/org/traccar/helper/Checksum.java | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/main/java/org/traccar/helper/Checksum.java b/src/main/java/org/traccar/helper/Checksum.java index 8c3d0063a..e660790ef 100644 --- a/src/main/java/org/traccar/helper/Checksum.java +++ b/src/main/java/org/traccar/helper/Checksum.java @@ -200,4 +200,23 @@ public final class Checksum { return (10 - (checksum % 10)) % 10; } + public static int udp(ByteBuffer data) { + int sum = 0; + int len = data.capacity(); + for (int j = 0; len > 1; len--) { + sum += data.get() & 0xff; + if ((sum & 0x80000000) > 0) { + sum = (sum & 0xffff) + (sum >> 16); + } + } + if (len == 1) { + sum += data.get() & 0xff; + } + while ((sum >> 16) > 0) { + sum = (sum & 0xffff) + sum >> 16; + } + sum = (sum == 0xffff) ? sum & 0xffff : (~sum) & 0xffff; + return sum; + } + } |