diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2013-02-08 19:49:56 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2013-02-08 19:49:56 +1300 |
commit | ab72e6b1295f4f86ee2873c039f35f7c2da70395 (patch) | |
tree | 73e8a33391c24410e02660c12fd5ac78d5dc37dc /src/org/traccar/helper/Crc.java | |
parent | 60c92c0c3efa2fdd7133bb9c0488b614a0409f5f (diff) | |
download | traccar-server-ab72e6b1295f4f86ee2873c039f35f7c2da70395.tar.gz traccar-server-ab72e6b1295f4f86ee2873c039f35f7c2da70395.tar.bz2 traccar-server-ab72e6b1295f4f86ee2873c039f35f7c2da70395.zip |
Added GpsGate protocol (fix #138)
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(); + } } |