Skip to content

Commit

Permalink
Merge pull request #113 from snkYmkrct/main
Browse files Browse the repository at this point in the history
Added VTG sentence parse for the km/h speed value
  • Loading branch information
tannewt authored Oct 8, 2024
2 parents 70298f4 + 0466e45 commit 0178520
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
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

0 comments on commit 0178520

Please sign in to comment.