diff --git a/adafruit_gps.py b/adafruit_gps.py index 82b4c0b..aa98d46 100644 --- a/adafruit_gps.py +++ b/adafruit_gps.py @@ -53,8 +53,9 @@ _GSV15 = 7 _GSV19 = 8 _RMC_4_1 = 9 +_VTG = 10 _ST_MIN = _GLL -_ST_MAX = _RMC_4_1 +_ST_MAX = _VTG _SENTENCE_PARAMS = ( # 0 - _GLL @@ -77,6 +78,8 @@ "iiiiiiIiiiIiiiIiiiI", # 9 - _RMC_4_1 "scdcdcffsDCCC", + # 10 - _VTG + "fcFCfcfcC", ) @@ -202,6 +205,12 @@ def _parse_data(sentence_type: int, data: List[str]) -> Optional[List]: elif pti == "f": # A floating point number params.append(_parse_float(dti)) + elif pti == "F": + # A floating point number or Nothing + if nothing: + params.append(None) + else: + params.append(_parse_float(dti)) elif pti == "i": # An integer params.append(_parse_int(dti)) @@ -289,6 +298,8 @@ def __init__(self, uart: UART, debug: bool = False) -> None: """Geoidal separation relative to WGS 84""" self.speed_knots = None """Ground speed in knots""" + self.speed_kmh = None + """Ground speed in km/h""" self.track_angle_deg = None """Track angle in degrees""" self._sats = None # Temporary holder for information from GSV messages @@ -368,6 +379,8 @@ def update(self) -> bool: result = self._parse_gsv(talker, args) elif sentence_type == b"GSA": # GPS DOP and active satellites result = self._parse_gsa(talker, args) + elif sentence_type == b"VTG": # Ground speed + result = self._parse_vtg(args) return result @@ -499,6 +512,30 @@ def _update_timestamp_utc(self, time_utc: str, date: Optional[str] = None) -> No (year, month, day, hours, mins, secs, 0, 0, -1) ) + def _parse_vtg(self, data: List[str]) -> bool: + # VTG - Course Over Ground and Ground Speed + + if data is None or len(data) != 9: + return False # Unexpected number of params + + parsed_data = _parse_data(_VTG, data) + if parsed_data is None: + return False # Params didn't parse + + # Track made good, degrees true + self.track_angle_deg = parsed_data[0] + + # Speed over ground, knots + self.speed_knots = parsed_data[4] + + # Speed over ground, kilometers / hour + self.speed_kmh = parsed_data[6] + + # Parse FAA mode indicator + self._mode_indicator = parsed_data[8] + + return True + def _parse_gll(self, data: List[str]) -> bool: # GLL - Geographic Position - Latitude/Longitude diff --git a/examples/gps_simpletest.py b/examples/gps_simpletest.py index ecf1ca7..96eeebe 100644 --- a/examples/gps_simpletest.py +++ b/examples/gps_simpletest.py @@ -36,6 +36,8 @@ # Turn on the basic GGA and RMC info (what you typically want) gps.send_command(b"PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0") +# Turn on the basic GGA and RMC info + VTG for speed in km/h +# gps.send_command(b"PMTK314,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0") # Turn on just minimum info (RMC only, location): # gps.send_command(b'PMTK314,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0') # Turn off everything: @@ -102,6 +104,8 @@ print("Altitude: {} meters".format(gps.altitude_m)) if gps.speed_knots is not None: print("Speed: {} knots".format(gps.speed_knots)) + if gps.speed_kmh is not None: + print("Speed: {} km/h".format(gps.speed_kmh)) if gps.track_angle_deg is not None: print("Track angle: {} degrees".format(gps.track_angle_deg)) if gps.horizontal_dilution is not None: