NMEA Checksum Calculator

I’ve been doing a lot of GPS work lately. Here’s a little utility I wrote which I’d like to share with you all. It’s an NMEA checksum calculator written in PHP.

Try it out here: http://siliconsparrow.com/demos/nmeachecksum.php

Here’s the source code:


NMEA Checksum Calculator

// Simple NMEA Checksum calculator by Adam Pierce
// Created 12-Jan-2012.
// This code is public domain. Copy & share it all you like for any purpose.

if(array_key_exists('nmea',$_REQUEST))
{
$nmea = $_REQUEST['nmea'];
print "

Calculating checksum for: ".htmlspecialchars($nmea)."

rn";

$checksum = 0;
for($i = 0; $i < strlen($nmea); $i++)
{
$c = substr($nmea,$i,1);
$n = ord($c);
if($c == '$')
$checksum = 0;
else if($c == '*')
break;
else
$checksum ^= $n;
}
print "

Checksum is ".dechex($checksum)."

rn";
}
?>

Enter an NMEA String: