Add NMEA VTG sentence parse for the km/h speed value
This commit is contained in:
parent
3e13731cae
commit
dffaebcc23
2 changed files with 42 additions and 1 deletions
|
|
@ -53,8 +53,9 @@ _GSV11 = 6
|
|||
_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 @@ _SENTENCE_PARAMS = (
|
|||
"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 @@ class GPS:
|
|||
"""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 @@ class GPS:
|
|||
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 @@ class GPS:
|
|||
(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
|
||||
|
||||
|
|
|
|||
|
|
@ -36,6 +36,8 @@ gps = adafruit_gps.GPS(uart, debug=False) # Use UART/pyserial
|
|||
|
||||
# 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 @@ while True:
|
|||
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:
|
||||
|
|
|
|||
Loading…
Reference in a new issue