gpsd client driver for bench automation — GPS position, speed, altitude, heading, fix quality
Project description
rf-bench-drivers-gpsd
gpsd client driver for the rf-bench bench automation framework.
Connects to a running gpsd daemon over its JSON/TCP protocol and exposes GPS position, speed, altitude, heading, and fix quality. Both metric and imperial units are provided. A background thread maintains the connection and auto-reconnects with exponential back-off on any failure or data stall.
Requirements
- Python ≥ 3.9
gpsdrunning and accessible (default:localhost:2947)- No additional Python dependencies — uses stdlib
socket,json,threadingonly
Installation
pip install rf-bench-drivers-gpsd
Or as part of the full rf-bench suite:
pip install rf-bench
Quick start
from rf_bench.gpsd import GPSD, GPSDNoFixError
with GPSD() as gps:
# Block until 2D fix (or raise GPSDNoFixError after 30 s)
fix = gps.wait_for_fix(timeout=30)
print(f"Position : {fix.latitude:.6f}, {fix.longitude:.6f}")
print(f"Altitude : {fix.altitude_m:.1f} m / {fix.altitude_ft:.0f} ft")
print(f"Speed : {fix.speed_kmh:.1f} km/h / {fix.speed_knots:.1f} kn / {fix.speed_mph:.1f} mph")
print(f"Heading : {fix.heading}°")
print(f"Fix mode : {fix.fix_mode} (sats used: {fix.satellites_used})")
print(f"HDOP : {fix.hdop} VDOP: {fix.vdop} PDOP: {fix.pdop}")
API
GPSD(host='localhost', port=2947, stale_timeout=10, reconnect_delay=2, max_reconnect_delay=60)
The main driver class. Spawns a background daemon thread on construction.
| Method / property | Description |
|---|---|
get_fix() |
Return a GPSFix snapshot (non-blocking, may have no fix) |
wait_for_fix(timeout=30, require_3d=False) |
Block until fix; raises GPSDNoFixError on timeout |
is_connected |
True while TCP socket to gpsd is open |
is_stale |
True if no TPV update received within stale_timeout seconds |
has_fix |
True if 2D or 3D fix is available |
has_3d_fix |
True if 3D fix with altitude is available |
fix_mode |
FIX_UNKNOWN/FIX_NONE/FIX_2D/FIX_3D (0–3) |
latitude |
Decimal degrees, +N |
longitude |
Decimal degrees, +E |
altitude_m |
Metres MSL (or HAE fallback) |
altitude_ft |
Feet |
speed_ms |
m/s over ground |
speed_kmh |
km/h |
speed_mph |
mph |
speed_knots |
knots |
heading |
True heading, 0–360° |
hdop / vdop / pdop |
Dilution of precision |
satellites_used / satellites_visible |
Satellite counts |
close() |
Stop background thread |
GPSD is a context manager (with GPSD() as gps: ...).
GPSFix
Dataclass snapshot returned by get_fix() and wait_for_fix(). Contains all the same fields as the GPSD properties above, plus:
time_utc— ISO 8601 timestamp from the GPS receiverreceived_at—time.monotonic()when the fix was storedage_s— seconds sincereceived_aterror_lat_m,error_lon_m,error_alt_m,error_speed_ms— 1-sigma error estimates in SI unitsas_dict(units='metric')— all fields as a plain dict; pass'imperial'for ft/mph/knots
Fix mode constants
from rf_bench.gpsd import FIX_UNKNOWN, FIX_NONE, FIX_2D, FIX_3D
Exceptions
from rf_bench.gpsd import GPSDError, GPSDNoFixError
GPSDNoFixError is raised by wait_for_fix() on timeout.
Remote gpsd
gps = GPSD(host="10.1.0.20", port=2947)
Auto-reconnect behaviour
The background thread reconnects automatically on:
- Connection refused or network error
- Socket read error or remote disconnect
- No TPV update received for
stale_timeoutseconds (default 10 s)
Reconnect delay starts at reconnect_delay seconds (default 2 s), doubles on each consecutive failure, and caps at max_reconnect_delay (default 60 s). The delay resets to the initial value after a successful connection cycle.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rf_bench_drivers_gpsd-0.1.1.tar.gz.
File metadata
- Download URL: rf_bench_drivers_gpsd-0.1.1.tar.gz
- Upload date:
- Size: 10.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2e21a73b255c8fa6d78f1801c12a9e164f02632330897af1988ec4298796270a
|
|
| MD5 |
6159933545bb3f7d8bd7949c27160efb
|
|
| BLAKE2b-256 |
b9c33fe869c66c0b939330397b57e43199561b01b5a7e17db8e7f7c92fb7eef7
|
File details
Details for the file rf_bench_drivers_gpsd-0.1.1-py3-none-any.whl.
File metadata
- Download URL: rf_bench_drivers_gpsd-0.1.1-py3-none-any.whl
- Upload date:
- Size: 10.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cb6d80eb32c2836449331a62afc10a821fd74803e648d3965fb06d49024faede
|
|
| MD5 |
364755432407b1c564c7f2db08e34637
|
|
| BLAKE2b-256 |
6bb87b35610b20c5070b7828f89aaa3f89dbf25fa1c0f24e2c3cff7b0d713f70
|