Skip to content

Instantly share code, notes, and snippets.

@tomazas
Created September 27, 2015 10:44
Show Gist options
  • Save tomazas/90c45719b15a1c9cc2bf to your computer and use it in GitHub Desktop.
Save tomazas/90c45719b15a1c9cc2bf to your computer and use it in GitHub Desktop.
GPS checksum validation using Python
def chksum(inp): # GPS message checksum verification
if not inp.startswith("$"): return False
if not inp[-3:].startswith("*"): return False
payload = inp[1:-3]
checksum = 0
for i in xrange(len(payload)):
checksum = checksum ^ ord(payload[i])
return ("%02X" % checksum) == inp[-2:]
# do simple test
line = "$GPVTG,,T,,M,0.129,N,0.239,K,D*24"
print "Checksum correct:", chksum(line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment