Created
September 8, 2024 23:37
-
-
Save logston/67e8d1dff12fe194e04812753a871a4f to your computer and use it in GitHub Desktop.
Read GPS from VK-162 USB GPS Dongle
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
### Read from VK-162 USB GPS Dongle | |
# ie. https://www.amazon.com/VK-162-G-Mouse-External-Navigation-Raspberry/dp/B01EROIUEW | |
# https://www.gpsworld.com/what-exactly-is-gps-nmea-data/ | |
# https://gist.github.com/logston/67e8d1dff12fe194e04812753a871a4f | |
# | |
# Example data: | |
# $GPTXT,01,01,02,u-blox ag - www.u-blox.com*50 | |
# $GPTXT,01,01,02,HW UBX-G70xx 00070000 FF7FFFFFo*69 | |
# $GPTXT,01,01,02,ROM CORE 1.00 (59842) Jun 27 2012 17:43:52*59 | |
# $GPTXT,01,01,02,PROTVER 14.00*1E | |
# $GPTXT,01,01,02,ANTSUPERV=AC SD PDoS SR*20 | |
# $GPTXT,01,01,02,ANTSTATUS=OK*3B | |
# $GPTXT,01,01,02,LLC FFFFFFFF-FFFFFFFF-FFFFFFFF-FFFFFFFF-FFFFFFFD*2C | |
# $GPRMC,232047.00,A,3751.53046,N,12207.76361,W,0.795,,080924,,,A*69 | |
# $GPVTG,,T,,M,0.795,N,1.472,K,A*28 | |
# $GPGGA,232047.00,3751.53046,N,12207.76361,W,1,05,1.84,252.3,M,-29.3,M,,*62 | |
# $GPGSA,A,3,03,16,09,04,07,,,,,,,,3.27,1.84,2.71*03 | |
# $GPGSV,3,1,09,01,31,062,27,02,05,200,09,03,75,178,31,04,63,330,21*73 | |
# $GPGSV,3,2,09,07,18,234,28,09,33,297,26,16,41,118,27,26,38,069,08*76 | |
# $GPGSV,3,3,09,31,33,048,08*46 | |
# $GPGLL,3751.53046,N,12207.76361,W,232047.00,A,A*7C | |
# $GPRMC,232048.00,A,3751.53024,N,12207.76363,W,0.657,,080924,,,A*6F | |
def read_block(device_path: str) -> list[str]: | |
""" | |
Return block of GPS lines from device. | |
""" | |
with open(device_path) as fp: | |
should_break = False | |
block = [] | |
while line := fp.readline(): | |
line = line.strip() | |
if line.startswith('$GPTXT'): | |
continue | |
if line.startswith('$GPRMC'): | |
if should_break: | |
break | |
should_break = True | |
block.append(line) | |
return block | |
if __name__ == '__main__': | |
import argparse | |
parser = argparse.ArgumentParser() | |
parser.add_argument('device_path', help='eg. /dev/cu.usbmodem2101') | |
args = parser.parse_args() | |
print('\n'.join(read_block(args.device_path))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment