Last active
June 16, 2024 01:01
-
-
Save pepitooo/2d911cf49fc88ffd3555cbe49d276bd0 to your computer and use it in GitHub Desktop.
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
#!/bin/python | |
# cat /dev/ttyACM3 | python /home/user/fix_gpsrollover.py | gpsd -n -N /dev/stdin | |
# where /dev/ttyACM3 is your gps serial output. | |
from datetime import datetime, timedelta | |
import sys | |
import os | |
from signal import signal, SIGPIPE, SIG_DFL | |
signal(SIGPIPE,SIG_DFL) | |
separator = ',' | |
def calculate_checksum(nmea_data): | |
nmea_data_buffer = '' | |
nmea_checksum = 0 | |
for c in nmea_data: | |
if c == '*': | |
break | |
if c != '$': | |
nmea_data_buffer = nmea_data_buffer + c | |
nmea_checksum = ord(c) ^ nmea_checksum | |
return '$' + nmea_data_buffer + '*' + format(nmea_checksum, 'X') + os.linesep | |
def write_to_stdout(line): | |
sys.stdout.write(line) | |
sys.stdout.flush() | |
for line in iter(sys.stdin.readline, b''): | |
if line.startswith('$GPRMC'): | |
rmc_data = line.split(separator) | |
if len(rmc_data) > 10: | |
date = rmc_data[9] | |
if date: | |
corrected_date = (datetime.strptime(date, '%d%m%y') + timedelta(days=1024*7)).strftime('%d%m%y') | |
rmc_data[9] = corrected_date | |
rmc_line = calculate_checksum(separator.join(rmc_data)) | |
write_to_stdout(rmc_line) | |
continue | |
write_to_stdout(line) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment