diff options
Diffstat (limited to 'src/org/traccar/helper/Crc.java')
-rw-r--r-- | src/org/traccar/helper/Crc.java | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/org/traccar/helper/Crc.java b/src/org/traccar/helper/Crc.java index cef0cc482..a7adca874 100644 --- a/src/org/traccar/helper/Crc.java +++ b/src/org/traccar/helper/Crc.java @@ -16,6 +16,7 @@ package org.traccar.helper; import java.nio.ByteBuffer; +import java.nio.charset.Charset; /** * CRC functions @@ -126,5 +127,14 @@ public class Crc { public static int crc16CcittSeed(ByteBuffer buf, int seed) { return crc16Reflected(buf, seed, crc16CcittTableReverse) ^ crc16CcittXorout; } + + public static String nmeaChecksum(String msg) { + int checksum = 0; + byte bytes[] = msg.getBytes(Charset.defaultCharset()); + for (int i = 1; i < msg.length(); i++) { + checksum ^= bytes[i]; + } + return String.format("*%02x", checksum).toUpperCase(); + } } |