Monthly Archives: November 2007

XOR calculation for NMEA checksums (GPS protocol)

IF you’ve ever seen the serial output of a GPS reader, you’ve seen a mystery string at the end like this:That’s the checksum of the whole string…. For example, if the sentence is this:LKLKJLKJLthen you run a checksum on this:KLKJLKJLKHere’s a Processing method to calculate the checksum, given the string between the $ and the *:char checkSum(String theseChars) { char check = 0; // iterate over the string, XOR each byte with the total sum: for (int c = 0; c < theseChars.length(); c++) { check = char(check ^ theseChars.charAt(c)); } // return the result return check;}And here’s a whole program to use the checksum with an Etek EB-85A reader:/* ETEK EB-85A GPS reader test.
Continue reading

Posted in Processing | 1 Comment