diff options
author | Philipp Prangenberg <philipp.prangenberg@derkurier.de> | 2016-12-05 12:03:08 +0100 |
---|---|---|
committer | Philipp Prangenberg <philipp.prangenberg@derkurier.de> | 2016-12-05 12:03:08 +0100 |
commit | a21f436a58133f7da0cae06366d729665f3b8f9c (patch) | |
tree | 72ff1743d96f79e4a9d85b0d48715e5f9aa67cf9 /src/org/traccar/helper/Checksum.java | |
parent | 960bf899414d89221e92138fdb98777c3f4f73ec (diff) | |
parent | 40607036c5aa6385a7ae3f3a283bf107238a5944 (diff) | |
download | trackermap-server-a21f436a58133f7da0cae06366d729665f3b8f9c.tar.gz trackermap-server-a21f436a58133f7da0cae06366d729665f3b8f9c.tar.bz2 trackermap-server-a21f436a58133f7da0cae06366d729665f3b8f9c.zip |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'src/org/traccar/helper/Checksum.java')
-rw-r--r-- | src/org/traccar/helper/Checksum.java | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/org/traccar/helper/Checksum.java b/src/org/traccar/helper/Checksum.java index 2a4b1191d..f08292392 100644 --- a/src/org/traccar/helper/Checksum.java +++ b/src/org/traccar/helper/Checksum.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 - 2015 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2012 - 2015 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -194,10 +194,19 @@ public final class Checksum { return checksum; } + public static int xor(String string) { + byte checksum = 0; + for (byte b : string.getBytes(StandardCharsets.US_ASCII)) { + checksum ^= b; + } + return checksum; + } + public static String nmea(String msg) { int checksum = 0; - for (byte b : msg.getBytes(StandardCharsets.US_ASCII)) { - checksum ^= b; + byte[] bytes = msg.getBytes(StandardCharsets.US_ASCII); + for (int i = 1; i < bytes.length; i++) { + checksum ^= bytes[i]; } return String.format("*%02x", checksum).toUpperCase(); } |