Skip to content

Commit

Permalink
Add scripts to monkey about with NMEA commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Gadgetoid committed Feb 9, 2022
1 parent dedd8d2 commit 33a9443
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
50 changes: 50 additions & 0 deletions examples/cmd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env python3
import time
import sys

from pa1010d import PA1010D


"""
Run raw commands against the PA1010D GPS and return the respones.
Eg:
PMTK605 = Query Firmware Release Info
PMTK430 = Query Datum
PMTK414 = Query NMEA Output Frequency
PMTK400 = Query Update Rate
PMTK225,<1 or 0> = Enable/Disable PPS
"""

def timeout(err=None, timeout=5.0):
if err is None:
err = "Timed out!"
t_start = time.time()
while time.time() - t_start < timeout:
yield
raise TimeoutError(err)


responses = {
}

if len(sys.argv) < 2:
print(f"Usage: {sys.argv[0]} <command>")
sys.exit()

command = sys.argv[1]
response = responses.get(command, f"$PMTK{int(command[4:]) + 100}")

gps = PA1010D()

gps.update()

gps.send_command(sys.argv[1])

if response:
print(f"Waiting for {response}...")
for t in timeout("Timed out waiting for command response."):
message = gps.read_sentence()
if message.startswith(response):
print(message)
break
21 changes: 21 additions & 0 deletions examples/pps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env python3
import time
import sys

from pa1010d import PA1010D


if len(sys.argv) < 2:
print(f"Usage: {sys.argv[0]} <on/off>")
sys.exit()

gps = PA1010D()

if sys.argv[1] == "on":
gps.send_command("PMTK255,1")
else:
gps.send_command("PMTK255,0")

result = gps.update()

print("OK" if result else "Uh oh!")

0 comments on commit 33a9443

Please sign in to comment.