aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2016-11-06 08:34:02 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2016-11-06 08:34:02 +1300
commit850734d2f1bef8aba5761f540caa40c23608acc6 (patch)
treee4c3fb58a3a67f3daa5c31423db9858c6e8aae82
parent77d193bf840ceb5294a6cb0d0cd6e1512e2b1efb (diff)
downloadtrackermap-server-850734d2f1bef8aba5761f540caa40c23608acc6.tar.gz
trackermap-server-850734d2f1bef8aba5761f540caa40c23608acc6.tar.bz2
trackermap-server-850734d2f1bef8aba5761f540caa40c23608acc6.zip
Fix NMEA checksum calculation (fix #2405)
-rw-r--r--src/org/traccar/helper/Checksum.java5
-rw-r--r--test/org/traccar/WebDataHandlerTest.java2
2 files changed, 4 insertions, 3 deletions
diff --git a/src/org/traccar/helper/Checksum.java b/src/org/traccar/helper/Checksum.java
index 629f6e7ca..f08292392 100644
--- a/src/org/traccar/helper/Checksum.java
+++ b/src/org/traccar/helper/Checksum.java
@@ -204,8 +204,9 @@ public final class 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();
}
diff --git a/test/org/traccar/WebDataHandlerTest.java b/test/org/traccar/WebDataHandlerTest.java
index e68eaf74e..2a8205ad1 100644
--- a/test/org/traccar/WebDataHandlerTest.java
+++ b/test/org/traccar/WebDataHandlerTest.java
@@ -14,7 +14,7 @@ public class WebDataHandlerTest extends ProtocolTest {
WebDataHandler handler = new WebDataHandler("http://localhost/?fixTime={fixTime}&gprmc={gprmc}&name={name}");
Assert.assertEquals(
- "http://localhost/?fixTime=1451610123000&gprmc=$GPRMC,010203.000,A,2000.0000,N,03000.0000,E,0.00,0.00,010116,,*21&name=test",
+ "http://localhost/?fixTime=1451610123000&gprmc=$GPRMC,010203.000,A,2000.0000,N,03000.0000,E,0.00,0.00,010116,,*05&name=test",
handler.formatRequest(p));
}