Expand description
Location Service — GPS fix publisher.
Mirrors FlexStack/src/flexstack/utils/location_service.py.
LocationService acts as a fan-out hub: a GPS driver (GPSD thread,
simulated sensor, hardware UART, …) calls LocationService::publish
whenever a new fix arrives. Any number of subscribers may listen by
calling LocationService::subscribe, which returns a
Receiver<GpsFix> that delivers every subsequent fix. Dead receivers
(subscriber dropped) are pruned automatically on the next publish.
§Example
use rustflexstack::facilities::location_service::{LocationService, GpsFix};
use std::thread;
use std::time::Duration;
let mut svc = LocationService::new();
let rx = svc.subscribe();
// Simulate a GPS driver publishing fixes at 1 Hz
thread::spawn(move || loop {
thread::sleep(Duration::from_secs(1));
svc.publish(GpsFix {
latitude: 41.552,
longitude: 2.134,
altitude_m: 120.0,
speed_mps: 0.0,
heading_deg: 0.0,
pai: true,
});
});
while let Ok(fix) = rx.recv() {
println!("lat={} lon={}", fix.latitude, fix.longitude);
}Structs§
- GpsFix
- A single GPS position fix with the fields needed by the CA Basic Service and GeoNetworking position vector.
- Location
Service - Fan-out GPS fix publisher.