Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
574 B
3
Indexable
def checksum(nmea_data, type_msg):
    nmea_data = nmea_data.strip()

    start_index = nmea_data.find('$') + 1
    end_index = nmea_data.find('*')
    checksum_str = nmea_data[start_index:end_index]

    get_checksum = nmea_data[-2:]

    
    # Calculate XOR checksum
    checksum = 0
    for char in checksum_str:
        checksum ^= ord(char)
        
    # Convert checksum to hexadecimal
    checksum_hex = hex(checksum)[2:].upper().zfill(2)

    
    # Append checksum to NMEA data
    nmea_data_with_checksum = f"{nmea_data}${checksum_hex}"