Python Location & Time Utilities
The flexstack.utils package provides the ego position and ETSI time to every layer of the stack.
Location Services
A location service calls its registered callbacks with a position report, a dictionary in the format of a gpsd TPV message (lat, lon, altHAE, speed, track, time, …). Each consumer registers its callback with add_callback: the GeoNetworking router (gn_router.refresh_ego_position_vector), the LDM and the Facilities services.
Class |
Description |
|---|---|
|
Connects to a |
|
Sends a fixed position periodically from a background thread; for laboratories, tests and virtual links. |
|
The same, as an |
Both thread-based services start their thread when they are created; service.stop_event.set() stops it.
GPSDLocationService
from flexstack.utils.gpsd_location_service import GPSDLocationService
gps_service = GPSDLocationService(gpsd_host="127.0.0.1", gpsd_port=2947)
def on_position_update(tpv: dict) -> None:
print(f"Lat: {tpv['lat']}, Lon: {tpv['lon']}, Speed: {tpv.get('speed')} m/s")
gps_service.add_callback(on_position_update)
ThreadStaticLocationService
from flexstack.utils.static_location_service import ThreadStaticLocationService
location_service = ThreadStaticLocationService(
period=100, # ms between position reports
latitude=41.3851,
longitude=2.1734,
)
location_service.add_callback(on_position_update)
Time Service
ETSI timestamps count milliseconds of TAI since 2004-01-01 00:00:00 UTC (the ITS epoch), so they include the leap seconds since then:
from flexstack.utils.time_service import TimeService
its_now_ms = TimeService.timestamp_its() # ITS timestamp, ms
utc_now_s = TimeService.time() # UTC, s
print(f"ITS timestamp: {its_now_ms}")