Skip to content

Commit 0178520

Browse files
authored
Merge pull request #113 from snkYmkrct/main
Added VTG sentence parse for the km/h speed value
2 parents 70298f4 + 0466e45 commit 0178520

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

adafruit_gps.py

+38-1
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@
5353
_GSV15 = 7
5454
_GSV19 = 8
5555
_RMC_4_1 = 9
56+
_VTG = 10
5657
_ST_MIN = _GLL
57-
_ST_MAX = _RMC_4_1
58+
_ST_MAX = _VTG
5859

5960
_SENTENCE_PARAMS = (
6061
# 0 - _GLL
@@ -77,6 +78,8 @@
7778
"iiiiiiIiiiIiiiIiiiI",
7879
# 9 - _RMC_4_1
7980
"scdcdcffsDCCC",
81+
# 10 - _VTG
82+
"fcFCfcfcC",
8083
)
8184

8285

@@ -202,6 +205,12 @@ def _parse_data(sentence_type: int, data: List[str]) -> Optional[List]:
202205
elif pti == "f":
203206
# A floating point number
204207
params.append(_parse_float(dti))
208+
elif pti == "F":
209+
# A floating point number or Nothing
210+
if nothing:
211+
params.append(None)
212+
else:
213+
params.append(_parse_float(dti))
205214
elif pti == "i":
206215
# An integer
207216
params.append(_parse_int(dti))
@@ -289,6 +298,8 @@ def __init__(self, uart: UART, debug: bool = False) -> None:
289298
"""Geoidal separation relative to WGS 84"""
290299
self.speed_knots = None
291300
"""Ground speed in knots"""
301+
self.speed_kmh = None
302+
"""Ground speed in km/h"""
292303
self.track_angle_deg = None
293304
"""Track angle in degrees"""
294305
self._sats = None # Temporary holder for information from GSV messages
@@ -368,6 +379,8 @@ def update(self) -> bool:
368379
result = self._parse_gsv(talker, args)
369380
elif sentence_type == b"GSA": # GPS DOP and active satellites
370381
result = self._parse_gsa(talker, args)
382+
elif sentence_type == b"VTG": # Ground speed
383+
result = self._parse_vtg(args)
371384

372385
return result
373386

@@ -499,6 +512,30 @@ def _update_timestamp_utc(self, time_utc: str, date: Optional[str] = None) -> No
499512
(year, month, day, hours, mins, secs, 0, 0, -1)
500513
)
501514

515+
def _parse_vtg(self, data: List[str]) -> bool:
516+
# VTG - Course Over Ground and Ground Speed
517+
518+
if data is None or len(data) != 9:
519+
return False # Unexpected number of params
520+
521+
parsed_data = _parse_data(_VTG, data)
522+
if parsed_data is None:
523+
return False # Params didn't parse
524+
525+
# Track made good, degrees true
526+
self.track_angle_deg = parsed_data[0]
527+
528+
# Speed over ground, knots
529+
self.speed_knots = parsed_data[4]
530+
531+
# Speed over ground, kilometers / hour
532+
self.speed_kmh = parsed_data[6]
533+
534+
# Parse FAA mode indicator
535+
self._mode_indicator = parsed_data[8]
536+
537+
return True
538+
502539
def _parse_gll(self, data: List[str]) -> bool:
503540
# GLL - Geographic Position - Latitude/Longitude
504541

examples/gps_simpletest.py

+4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636

3737
# Turn on the basic GGA and RMC info (what you typically want)
3838
gps.send_command(b"PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0")
39+
# Turn on the basic GGA and RMC info + VTG for speed in km/h
40+
# gps.send_command(b"PMTK314,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0")
3941
# Turn on just minimum info (RMC only, location):
4042
# gps.send_command(b'PMTK314,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0')
4143
# Turn off everything:
@@ -102,6 +104,8 @@
102104
print("Altitude: {} meters".format(gps.altitude_m))
103105
if gps.speed_knots is not None:
104106
print("Speed: {} knots".format(gps.speed_knots))
107+
if gps.speed_kmh is not None:
108+
print("Speed: {} km/h".format(gps.speed_kmh))
105109
if gps.track_angle_deg is not None:
106110
print("Track angle: {} degrees".format(gps.track_angle_deg))
107111
if gps.horizontal_dilution is not None:

0 commit comments

Comments
 (0)