Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

checksum gen isn't right when the 2 hex digits should have leading zero. (string formatting) #2

Open
knormoyle opened this issue Jul 15, 2023 · 0 comments

Comments

@knormoyle
Copy link

Hi Steve.
Just realized the check sum doesn't create two hex digits when the leading hex is supposed to be 0. That means some NMEA sentences get ignored due to bad checksum.

Also, be good to add a comment about why NMEA chars are always ascii so the ord(s) is always 0-127...that bounds the range of the check in hex to be < 255, i.e. two hex digits.

here's the change (just one line and comment add, but this shows the context. Used the newer style string formating

    # the xor of the ord() won't have an int value of more than 127 (2 hex digits) because they are ascii chars 
    # (ord is 0-127 for ascii). Could range check the ord(s) result to make sure all chars are ascii, not other unicode?
    checksumInt = reduce(operator.xor, (ord(s) for s in nmeaData), 0)
 
    # change it to base 16
    # return a string, but without the 0x
    # better, use string formatting to make it hex without 0x

    # always make sure it's 2 hex digits when there's leading 0. And use the newer string format style
    checksumHex = '{:02X}'.format(checksumInt)
    # was:
    # checksumHex = '%x' % checksumInt

can add a test case for this after the existing test case:

    # test with leading zero in checksum
    checksum = NMEA_checksum_gen('GPGSA,A,1,,,,,,,,,,,,,25.5,25.5,25.5')
    if checksum!="02":
        print("ERROR: checksum gen test failed. checksum", checksum,  "should be '02'")
        sys.exit(1)

The leading zero checksum seems to be more frequent when the NMEA sentences are relatively empty.
I guess the ublox and pygpsclient ignored those sentences when the 1 digit checksum was passed? (guess).
not common, but should fix.

I noticed there were some missing GBGSV sentences in the console, and I believe this is the reason why.

Tested feeding to pygpsclient and it looks good.

-kevin

apparently I can't submit an issue without a file. this is just an empty file.

nofile.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant