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/nmeachecksum.php
Here’s the source code:
<html>
<head>
<title>NMEA Checksum Calculator</title>
</head>
<body>
<h1>NMEA Checksum Calculator</h1>
<?php
// Simple NMEA Checksum calculator by Adam Pierce <adam@siliconsparrow.com>
// 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 "<p>Calculating checksum for: ".htmlspecialchars($nmea)."</p>\r\n";
$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 "<p>Checksum is ".dechex($checksum)."</p>\r\n";
}
?>
<form action="nmeachecksum.php">
<p>Enter an NMEA String: <input name="nmea" size="100" />
<input type="submit" />
</form>
</body>
</html>