Skip to main content

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
  • gpsd running and accessible (default: localhost:2947)
  • No additional Python dependencies — uses stdlib socket, json, threading only

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 receiver
  • received_attime.monotonic() when the fix was stored
  • age_s — seconds since received_at
  • error_lat_m, error_lon_m, error_alt_m, error_speed_ms — 1-sigma error estimates in SI units
  • as_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_timeout seconds (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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rf_bench_drivers_gpsd-0.1.0.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rf_bench_drivers_gpsd-0.1.0-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

Details for the file rf_bench_drivers_gpsd-0.1.0.tar.gz.

File metadata

  • Download URL: rf_bench_drivers_gpsd-0.1.0.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

Hashes for rf_bench_drivers_gpsd-0.1.0.tar.gz
Algorithm Hash digest
SHA256 10e55f39d30eeb32c8fb9e90a09b27eaa9e16ef1c30efeb9eea19087429d264d
MD5 a7d0badff266d5bd0e36835a62cf7d82
BLAKE2b-256 6a260af8600a62692df53457512d4910fb89a4afd44290c43d79cafef5eaebfb

See more details on using hashes here.

File details

Details for the file rf_bench_drivers_gpsd-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for rf_bench_drivers_gpsd-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4458ce5b1f7295ed089eae42073f1aabdb11434fbcb073cd50267674d4af6775
MD5 9ea40675c3793650caf40c356efbdf6e
BLAKE2b-256 4973a544c4ec131b41b2d67b431631fa8121159170cd9be3259b63086e1f6085

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page