Welcome, guest | Sign In | My Account | Store | Cart

This code will compute the checksum as used by GPS message strings ( $GPRMC, etc)

Python, 12 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
#don't include initial "$" or trailing "*XX"
item = "GPRMC,004422.767,A,3601.9719,N,07950.6023,W,0.00,,180804,,,A"
#should return a "*6F"    
s = 0
for i in range(len(item) ):
    s = s ^ ord(item[i])
checksum = "*"
#convert to hex
s = "%02X" % s
checksum += s
        
print "Checksum: %s" % checksum

Using the checksum helps verify the GPS data you are using. In my project this code helped isolate a communication problem that could have caused major problems later on.

Created by Brian Serviss on Sat, 11 Dec 2004 (PSF)
Python recipes (4591)
Brian Serviss's recipes (1)

Required Modules

  • (none specified)

Other Information and Tasks