Skip to main content

ados_hal_probe/
lib.rs

1#![doc = include_str!("../README.md")]
2
3pub mod bindings;
4pub mod board_sidecar;
5pub mod camera_probe;
6pub mod daemon;
7pub mod host_facts;
8pub mod probe;
9pub mod runner;
10pub mod sensor_hub;
11
12pub use ados_protocol::hwcaps::{
13    AbsenceReason, CoreCluster, EncoderDevice, Evidence, HardwareCapabilities, Midr, ProbePhase,
14    Probed, SerialPort, SocCompatible, UsbId, V4l2Node,
15};
16
17pub use probe::{
18    cpu::probe_cores, serial::probe_serial_ports, soc::probe_soc, usb::probe_usb_ids,
19    video::probe_h264_encoder,
20};
21
22pub use runner::{run_probe_sandboxed, ProbeOutcome};
23
24/// Run every probe and assemble a full [`HardwareCapabilities`] snapshot.
25///
26/// `phase` gates the destructive probes: the H.264 encoder trial-init runs only
27/// when [`ProbePhase::allows_destructive`] is true; otherwise it is left
28/// [`Probed::NotProbed`] so a reader knows it was deferred, not absent. The
29/// read-only probes (CPU, SoC, USB, serial) always run.
30///
31/// `crsf_pin` is the pinned CRSF/ELRS RC-module device (`radio.crsf.device`),
32/// if configured: the future wiring must pass it so the serial inventory
33/// scores that port 0 (never an FC candidate), mirroring the exclusion the
34/// MAVLink router's live discovery path enforces. `None` = no pin configured.
35pub fn probe_all(phase: ProbePhase, crsf_pin: Option<&str>) -> HardwareCapabilities {
36    HardwareCapabilities {
37        cpu: probe_cores(),
38        soc: probe_soc(),
39        h264_encoder: probe_h264_encoder(phase),
40        usb: probe_usb_ids(),
41        serial: probe_serial_ports(crsf_pin),
42    }
43}
44
45#[cfg(test)]
46mod tests {
47    use super::*;
48
49    #[test]
50    fn probe_all_runtime_defers_destructive_encoder_probe() {
51        // In armed runtime the encoder trial-init must not run; the stub returns
52        // NotProbed (and on a real rig the runtime gate keeps it deferred).
53        let caps = probe_all(ProbePhase::Runtime, None);
54        assert!(matches!(caps.h264_encoder, Probed::NotProbed));
55    }
56}