Skip to content

Commit ec5ddbe

Browse files
committed
Have to commit this before I switch branch
1 parent a4f0525 commit ec5ddbe

File tree

3 files changed

+77
-82
lines changed

3 files changed

+77
-82
lines changed

adafruit_gps.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ def __init__(self, uart, debug=False):
9090
self.velocity_knots = None
9191
self.speed_knots = None
9292
self.track_angle_deg = None
93+
self.total_mess_num = None
94+
self.mess_num = None
95+
self.gps0 = None
96+
self.gps1 = None
97+
self.gps2 = None
9398
self.debug = debug
9499

95100
def update(self):
@@ -277,24 +282,32 @@ def _parse_gpgsv(self, args):
277282
if data is None:
278283
return # Unexpected number of params.
279284
# Parse number of messages
280-
self.total_mess_num = _parse_int(data[0])
285+
self.total_mess_num = _parse_int(data[0]) # Total number of messages
281286
# Parse message number
282-
self.mess_num = _parse_int(data[1])
287+
self.mess_num = _parse_int(data[1]) # Message number
283288
# Parse number of satellites in view
284-
self.satellites = _parse_int(data[2])
285-
289+
self.satellites = _parse_int(data[2]) # Number of satellites
290+
286291
sats = data[3:]
287292
satdict = {}
288293
for i in range(len(sats) / 4):
289294
j = i*4
290-
291295
key = "self.gps{}".format(i)
292-
satnum = self._parse_int(sats[0+j]) # Satellite number
293-
satdeg = self._parse_int(sats[1+j]) # Elevation in degrees
294-
satazim = self._parse_int(sats[2+j]) # Azimuth in degrees
295-
satsnr = self._parse_int(sats[3+j]) # SNR (signal-to-noise ratio) in dB
296+
satnum = _parse_int(sats[0+j]) # Satellite number
297+
satdeg = _parse_int(sats[1+j]) # Elevation in degrees
298+
satazim = _parse_int(sats[2+j]) # Azimuth in degrees
299+
satsnr = _parse_int(sats[3+j]) # SNR (signal-to-noise ratio) in dB
296300
value = (satnum, satdeg, satazim, satsnr)
297301
satdict[key] = value
298-
299-
for k,v in satdict.items()
300-
exec("%s=%s" % (k,v))
302+
"""
303+
params = {'self': self}
304+
for k, v in satdict.items():
305+
exec("%s=%s" % (k, v), params, params)
306+
"""
307+
globals().update(satdict)
308+
# Should be self.gps0, self.gps1, self.gps2, etc
309+
# Each should be a tuple with 4 values
310+
# gpsx[0] = satellite number
311+
# gpsx[1] = elevation in degrees
312+
# gpsx[2] = azimuth in degrees to true
313+
# gpsx[3] = Signal-to-noise ratio in dB

examples/gps_simpletest.py

Lines changed: 2 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,13 @@
88
import adafruit_gps
99

1010

11-
# Define RX and TX pins for the board's serial port connected to the GPS.
12-
# These are the defaults you should use for the GPS FeatherWing.
13-
# For other boards set RX = GPS module TX, and TX = GPS module RX pins.
1411
RX = board.RX
1512
TX = board.TX
1613

17-
# Create a serial connection for the GPS connection using default speed and
18-
# a slightly higher timeout (GPS modules typically update once a second).
1914
uart = busio.UART(TX, RX, baudrate=9600, timeout=30)
2015

21-
# for a computer, use the pyserial library for uart access
22-
#import serial
23-
#uart = serial.Serial("/dev/ttyUSB0", baudrate=9600, timeout=3000)
24-
25-
# Create a GPS module instance.
2616
gps = adafruit_gps.GPS(uart, debug=False)
2717

28-
# Initialize the GPS module by changing what data it sends and at what rate.
29-
# These are NMEA extensions for PMTK_314_SET_NMEA_OUTPUT and
30-
# PMTK_220_SET_NMEA_UPDATERATE but you can send anything from here to adjust
31-
# the GPS module behavior:
32-
# https://cdn-shop.adafruit.com/datasheets/PMTK_A11.pdf
33-
34-
# Turn on the basic GGA and RMC info (what you typically want)
3518
gps.send_command(b'PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0')
3619
# Turn on just minimum info (RMC only, location):
3720
#gps.send_command(b'PMTK314,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0')
@@ -40,55 +23,12 @@
4023
# Tuen on everything (not all of it is parsed!)
4124
#gps.send_command(b'PMTK314,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0')
4225

43-
# Set update rate to once a second (1hz) which is what you typically want.
4426
gps.send_command(b'PMTK220,1000')
45-
# Or decrease to once every two seconds by doubling the millisecond value.
46-
# Be sure to also increase your UART timeout above!
47-
#gps.send_command(b'PMTK220,2000')
48-
# You can also speed up the rate, but don't go too fast or else you can lose
49-
# data during parsing. This would be twice a second (2hz, 500ms delay):
50-
#gps.send_command(b'PMTK220,500')
5127

52-
# Main loop runs forever printing the location, etc. every second.
5328
last_print = time.monotonic()
5429
while True:
55-
# Make sure to call gps.update() every loop iteration and at least twice
56-
# as fast as data comes from the GPS unit (usually every second).
57-
# This returns a bool that's true if it parsed new data (you can ignore it
58-
# though if you don't care and instead look at the has_fix property).
59-
gps.update()
60-
# Every second print out current location details if there's a fix.
30+
a = gps.update()
6131
current = time.monotonic()
6232
if current - last_print >= 1.0:
6333
last_print = current
64-
if not gps.has_fix:
65-
# Try again if we don't have a fix yet.
66-
print('Waiting for fix...')
67-
continue
68-
# We have a fix! (gps.has_fix is true)
69-
# Print out details about the fix like location, date, etc.
70-
print('=' * 40) # Print a separator line.
71-
print('Fix timestamp: {}/{}/{} {:02}:{:02}:{:02}'.format(
72-
gps.timestamp_utc.tm_mon, # Grab parts of the time from the
73-
gps.timestamp_utc.tm_mday, # struct_time object that holds
74-
gps.timestamp_utc.tm_year, # the fix time. Note you might
75-
gps.timestamp_utc.tm_hour, # not get all data like year, day,
76-
gps.timestamp_utc.tm_min, # month!
77-
gps.timestamp_utc.tm_sec))
78-
print('Latitude: {0:.6f} degrees'.format(gps.latitude))
79-
print('Longitude: {0:.6f} degrees'.format(gps.longitude))
80-
print('Fix quality: {}'.format(gps.fix_quality))
81-
# Some attributes beyond latitude, longitude and timestamp are optional
82-
# and might not be present. Check if they're None before trying to use!
83-
if gps.satellites is not None:
84-
print('# satellites: {}'.format(gps.satellites))
85-
if gps.altitude_m is not None:
86-
print('Altitude: {} meters'.format(gps.altitude_m))
87-
if gps.speed_knots is not None:
88-
print('Speed: {} knots'.format(gps.speed_knots))
89-
if gps.track_angle_deg is not None:
90-
print('Track angle: {} degrees'.format(gps.track_angle_deg))
91-
if gps.horizontal_dilution is not None:
92-
print('Horizontal dilution: {}'.format(gps.horizontal_dilution))
93-
if gps.height_geoid is not None:
94-
print('Height geo ID: {} meters'.format(gps.height_geoid))
34+
print(a)

tester.py

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,66 @@
1111
RX = board.RX
1212
TX = board.TX
1313

14-
uart = busio.UART(TX, RX, baudrate=9600, timeout=30)
14+
uart = busio.UART(TX, RX, baudrate=9600, timeout=3)
1515

1616
gps = adafruit_gps.GPS(uart, debug=False)
1717

18-
gps.send_command(b'PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0')
18+
# 0: GLL
19+
# 1: RMC
20+
# 2: VTG
21+
# 3: GGA
22+
# 4: GSA
23+
# 5: GSV
24+
# 17: GPDZA
25+
# 18: PMTKCHN
26+
# gps.send_command(b'PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0')
1927
# Turn on just minimum info (RMC only, location):
20-
#gps.send_command(b'PMTK314,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0')
28+
time.sleep(2)
29+
gps.send_command(b'PMTK103*30')
30+
time.sleep(10)
31+
gps.send_command(b'PMTK314,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0')
2132
# Turn off everything:
22-
#gps.send_command(b'PMTK314,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0')
23-
# Tuen on everything (not all of it is parsed!)
33+
time.sleep(0.2)
34+
gps.send_command(b'PMTK314,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0')
35+
# Turn on everything (not all of it is parsed!)
2436
#gps.send_command(b'PMTK314,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0')
2537

26-
gps.send_command(b'PMTK220,1000')
38+
gps.send_command(b'PMTK220,100')
2739

2840
last_print = time.monotonic()
2941
while True:
30-
a = gps.update()
42+
gps.update()
3143
current = time.monotonic()
3244
if current - last_print >= 1.0:
3345
last_print = current
34-
print(a)
46+
if not gps.has_fix:
47+
print("Waiting for fix.")
48+
continue
49+
print(gps._parse_sentence())
50+
continue
51+
print("=" * 40)
52+
if gps.total_mess_num is not None:
53+
print("Total number of messages: {}".format(gps.total_mess_num))
54+
55+
if gps.mess_num is not None:
56+
print("Message number: {}".format(gps.mess_num))
57+
58+
if gps.satellites is not None:
59+
print("Number of satellites: {}".format(gps.satellites))
60+
61+
"""
62+
try:
63+
a = [gps.gps0, gps.gps1, gps.gps2, gps.gps3, gps.gps4, gps.gps5]
64+
except
65+
"""
66+
67+
try:
68+
if gps.gps0:
69+
print("GPS number: {}".format(gps.gps0[0]))
70+
print(" Elevation: {} m".format(gps.gps0[1]))
71+
print(" Azimuth: {} deg".format(gps.gps0[2]))
72+
print(" SNR: {}".format(gps.gps0[3]))
73+
74+
#print(gps.gps0)
75+
except AttributeError or TypeError:
76+
continue

0 commit comments

Comments
 (0)