Created
November 24, 2018 09:53
-
-
Save mendhak/8d67b2412d97f593dbbb3abee06e5293 to your computer and use it in GitHub Desktop.
Calculate checksum from the data part of an NMEA sentence
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
import sys | |
import operator | |
# Given the data part of an NMEA sentence (Remove the $, remove the * onwards, keep the last comma) | |
# calculates the checksum | |
def checksum_calculate(nmeadata): | |
csum = 0 | |
for c in nmeadata: | |
csum ^= ord(c) | |
return csum | |
if __name__=='__main__': | |
nmeadata=sys.argv[1] if len(sys.argv)>1 else "GPGGA,174134.000,4345.9112,N,09643.8029,W,1,05,2.7,452.6,M,-27.1,M,,0000" | |
checksum=checksum_calculate(nmeadata) | |
print("$" + nmeadata + "*" + format(checksum,'x').zfill(2).upper()) | |
print(hex(checksum)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment