Created
September 27, 2015 10:44
-
-
Save tomazas/90c45719b15a1c9cc2bf to your computer and use it in GitHub Desktop.
GPS checksum validation using Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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