Last active
July 22, 2024 08:45
-
-
Save mlichvar/04bbb664937c2d7651f28866ae16994b to your computer and use it in GitHub Desktop.
Simulate NMEA RMC stream with leap second
This file contains hidden or 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
#!/usr/bin/python | |
# nmealeap.py [+1|-1] | |
import time, math, sys | |
month=6 | |
day=30 | |
hour=23 | |
minute=59 | |
second=30 | |
leap=int(sys.argv[1]) | |
for i in range(120): | |
while True: | |
f = math.modf(time.time())[0] | |
if f >= 0.1 and f <= 0.4: | |
break | |
time.sleep(0.1) | |
second += 1 | |
if (minute == 59 and second == 60 + leap) or (minute != 59 and second > 59): | |
second = 0 | |
minute += 1 | |
if minute > 59: | |
minute = 0 | |
hour += 1 | |
if hour > 23: | |
hour = 0 | |
day += 1 | |
if day > 30: | |
day = 1 | |
month += 1 | |
msg="GNRMC,{:02d}{:02d}{:02d}.00,A,0000.00000,N,00000.00000,W,0.000,,{:02d}{:02d}24,,,A,V".format( | |
hour, minute, second, day, month) | |
csum = 0 | |
for c in msg: | |
csum ^= ord(c) | |
print("${}*{:02X}\r\n".format(msg, csum), end='', flush=True) | |
time.sleep(0.5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment