Skip to content

Added VTG sentence parse for the km/h speed value #113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion adafruit_gps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -77,6 +78,8 @@
"iiiiiiIiiiIiiiIiiiI",
# 9 - _RMC_4_1
"scdcdcffsDCCC",
# 10 - _VTG
"fcFCfcfcC",
)


Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions examples/gps_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down