ados-protocol 0.106.2

Wire contracts for the ADOS Drone Agent: length-prefixed IPC framing, plugin RPC envelope and capability tokens, the vision frame bus, MSP and MAVLink helpers.
Documentation
// @generated by ados-capabilities-codegen from contracts.toml. Do not edit by hand.
//! Generated runtime path registry.
//!
//! Every sidecar and socket file the agent's services share, named once,
//! with the run-directory resolver and each sidecar's freshness window.
//! Source: contracts.toml; run ados-capabilities-codegen.

use std::path::PathBuf;
use std::time::Duration;

/// The run directory when `ADOS_RUN_DIR` is unset or empty.
pub const RUN_DIR_DEFAULT: &str = "/run/ados";

/// The environment variable that relocates the run directory.
pub const RUN_DIR_ENV: &str = "ADOS_RUN_DIR";

/// One registered state sidecar.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct SidecarPath {
    pub id: &'static str,
    /// The default absolute path.
    pub path: &'static str,
    /// The freshness window in milliseconds; `None` when mtime is not age.
    pub max_age_ms: Option<u64>,
    /// The service that writes the file.
    pub writer: &'static str,
}

impl SidecarPath {
    /// The freshness window, or `None` when the sidecar has none.
    pub const fn max_age(&self) -> Option<Duration> {
        match self.max_age_ms {
            Some(ms) => Some(Duration::from_millis(ms)),
            None => None,
        }
    }
}

/// One registered Unix socket.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct SocketPath {
    pub id: &'static str,
    /// The default absolute path.
    pub path: &'static str,
    /// The service that binds the socket.
    pub owner: &'static str,
}

// Sidecar file names and freshness windows.
pub const CLOUD_LINK_JSON: &str = "cloud-link.json";
pub const OFFLOAD_LINK_JSON: &str = "offload-link.json";
pub const WFB_STATS_JSON: &str = "wfb-stats.json";
pub const WFB_STATS_MAX_AGE_MS: u64 = 10000;
pub const HOP_SUPERVISOR_JSON: &str = "hop-supervisor.json";
pub const HOP_SUPERVISOR_MAX_AGE_MS: u64 = 10000;
pub const PEER_PRESENCE_JSON: &str = "peer-presence.json";
pub const PEER_PRESENCE_MAX_AGE_MS: u64 = 10000;
pub const MGMT_LINK_JSON: &str = "mgmt-link.json";
pub const MGMT_LINK_MAX_AGE_MS: u64 = 90000;
pub const MGMT_FAILOVER_JSON: &str = "mgmt-failover.json";
pub const MGMT_FAILOVER_MAX_AGE_MS: u64 = 90000;
pub const USB_REHOME_JSON: &str = "usb-rehome.json";
pub const USB_REHOME_MAX_AGE_MS: u64 = 600000;
pub const WIFI_POWERSAVE_JSON: &str = "wifi-powersave.json";
pub const WIFI_POWERSAVE_MAX_AGE_MS: u64 = 120000;
pub const WFB_FAILOVER_JSON: &str = "wfb_failover.json";
pub const WFB_FAILOVER_MAX_AGE_MS: u64 = 10000;
pub const WFB_PAIR_PROOF_JSON: &str = "wfb-pair-proof.json";
pub const BIND_STATE_JSON: &str = "bind-state.json";
pub const CRSF_STATS_JSON: &str = "crsf-stats.json";
pub const CRSF_STATS_MAX_AGE_MS: u64 = 10000;
pub const LORA_JSON: &str = "lora.json";
pub const LORA_MAX_AGE_MS: u64 = 10000;
pub const LORA_BEACONS_JSON: &str = "lora-beacons.json";
pub const LORA_BEACONS_MAX_AGE_MS: u64 = 10000;
pub const TUNNEL_CONFIG_JSON: &str = "tunnel-config.json";
pub const TUNNEL_CONFIG_MAX_AGE_MS: u64 = 30000;
pub const RELAYED_STATUS_JSON: &str = "relayed-status.json";
pub const RELAYED_STATUS_MAX_AGE_MS: u64 = 20000;
pub const LINKED_PEERS_JSON: &str = "linked-peers.json";
pub const MESH_STATE_JSON: &str = "mesh-state.json";
pub const MESH_STATE_MAX_AGE_MS: u64 = 10000;
pub const WFB_RELAY_JSON: &str = "wfb-relay.json";
pub const WFB_RELAY_MAX_AGE_MS: u64 = 10000;
pub const WFB_RECEIVER_JSON: &str = "wfb-receiver.json";
pub const WFB_RECEIVER_MAX_AGE_MS: u64 = 10000;
pub const FLEET_HERO_JSON: &str = "fleet-hero.json";
pub const CAMERA_STATE_JSON: &str = "camera-state.json";
pub const CAMERA_STATE_MAX_AGE_MS: u64 = 300000;
pub const CAMERAS_DISCOVERED_JSON: &str = "cameras-discovered.json";
pub const VIDEO_STREAMS_JSON: &str = "video-streams.json";
pub const VIDEO_STREAMS_MAX_AGE_MS: u64 = 20000;
pub const VIDEO_PROFILE_JSON: &str = "video-profile.json";
pub const CAMERA_USB_RECOVERY_JSON: &str = "camera-usb-recovery.json";
pub const CAMERA_USB_RECOVERY_MAX_AGE_MS: u64 = 60000;
pub const JANITOR_JSON: &str = "janitor.json";
pub const PIC_STATE_JSON: &str = "pic-state.json";
pub const GROUND_STATION_INPUT_JSON: &str = "ground-station-input.json";
pub const GPIO_OUTPUT_JSON: &str = "gpio-output.json";
pub const BOARD_JSON: &str = "board.json";
pub const FC_IDENTITY_JSON: &str = "fc-identity.json";
pub const MAVLINK_ROUTER_JSON: &str = "mavlink-router.json";
pub const MAVLINK_ROUTER_MAX_AGE_MS: u64 = 15000;
pub const LINK_FEEDBACK_JSON: &str = "link-feedback.json";
pub const PLUGIN_LOOPBACK_GUARD_JSON: &str = "plugin-loopback-guard.json";
pub const PLUGIN_STATE_MAX_AGE_MS: u64 = 10000;
pub const AP_GUARD_JSON: &str = "ap-guard.json";
pub const LOGD_PUSH_REQUEST_JSON: &str = "logd-push-request.json";
pub const LOGD_PUSH_RESULT_JSON: &str = "logd-push-result.json";
pub const LCD_LATENCY_JSON: &str = "lcd-latency.json";
pub const LCD_LATENCY_MAX_AGE_MS: u64 = 10000;
pub const LCD_FB_STATS_JSON: &str = "lcd-fb-stats.json";
pub const LCD_FB_STATS_MAX_AGE_MS: u64 = 10000;
pub const LCD_STATE_JSON: &str = "lcd-state.json";
pub const LCD_PAGE_REQUEST_JSON: &str = "lcd-page-request.json";
pub const LCD_PLUGIN_PAGE_JSON: &str = "lcd-plugin-page.json";
pub const LCD_PLUGIN_TAP_JSON: &str = "lcd-plugin-tap.json";
pub const CLOCK_JSON: &str = "clock.json";
pub const CLOCK_MAX_AGE_MS: u64 = 5000;
pub const SENSORS_JSON: &str = "sensors.json";
pub const SENSORS_MAX_AGE_MS: u64 = 5000;
pub const SENSORHUB_JSON: &str = "sensorhub.json";
pub const SENSORHUB_MAX_AGE_MS: u64 = 5000;
pub const GNSS_JSON: &str = "gnss.json";
pub const GNSS_MAX_AGE_MS: u64 = 5000;
pub const CAPTURE_STORAGE_JSON: &str = "capture-storage.json";
pub const CAPTURE_STORAGE_MAX_AGE_MS: u64 = 30000;

// Socket file names.
pub const API_INTERNAL_SOCK: &str = "api-internal.sock";
pub const AUX_CMD_SOCK: &str = "aux-cmd.sock";
pub const AUX_RPC_RESPONSES_SOCK: &str = "aux-rpc-responses.sock";
pub const BUTTONS_SOCK: &str = "buttons.sock";
pub const CLOUD_PUBLISH_SOCK: &str = "cloud-publish.sock";
pub const CRSF_CMD_SOCK: &str = "crsf-cmd.sock";
pub const GPIO_CMD_SOCK: &str = "gpio-cmd.sock";
pub const GROUNDLINK_CMD_SOCK: &str = "groundlink-cmd.sock";
pub const HID_CMD_SOCK: &str = "hid-cmd.sock";
pub const LOGD_SOCK: &str = "logd.sock";
pub const LOGD_QUERY_SOCK: &str = "logd-query.sock";
pub const MAVLINK_SOCK: &str = "mavlink.sock";
pub const MAVLINK_INGEST_SOCK: &str = "mavlink-ingest.sock";
pub const MSP_SOCK: &str = "msp.sock";
pub const GNSS_CMD_SOCK: &str = "gnss-cmd.sock";
pub const PAIRING_SOCK: &str = "pairing.sock";
pub const PIC_SOCK: &str = "pic.sock";
pub const RADIO_AUX_SOCK: &str = "radio-aux.sock";
pub const RADIO_CMD_SOCK: &str = "radio-cmd.sock";
pub const STATE_SOCK: &str = "state.sock";
pub const SUPERVISOR_SOCK: &str = "supervisor.sock";
pub const SWARM_SOCK: &str = "swarm.sock";
pub const TUNNEL_CONFIG_CMD_SOCK: &str = "tunnel-config-cmd.sock";
pub const VIDEO_CMD_SOCK: &str = "video-cmd.sock";
pub const VIDEO_ENCODER_SOCK: &str = "video-encoder.sock";
pub const SENSOR_BUS_SOCK: &str = "sensors.sock";
pub const VISION_SOCK: &str = "vision.sock";
pub const WFB_CMD_SOCK: &str = "wfb-cmd.sock";
pub const WIFI_CMD_SOCK: &str = "wifi-cmd.sock";

/// Every registered sidecar.
#[rustfmt::skip]
pub const SIDECARS: &[SidecarPath] = &[
    SidecarPath { id: "cloud-link", path: "/run/ados/cloud-link.json", max_age_ms: None, writer: "ados-cloud" },
    SidecarPath { id: "offload-link", path: "/run/ados/offload-link.json", max_age_ms: None, writer: "ados-plugin-host" },
    SidecarPath { id: "wfb-stats", path: "/run/ados/wfb-stats.json", max_age_ms: Some(10000), writer: "ados-radio, ados-groundlink" },
    SidecarPath { id: "hop-supervisor", path: "/run/ados/hop-supervisor.json", max_age_ms: Some(10000), writer: "ados-radio" },
    SidecarPath { id: "peer-presence", path: "/run/ados/peer-presence.json", max_age_ms: Some(10000), writer: "ados-radio" },
    SidecarPath { id: "mgmt-link", path: "/run/ados/mgmt-link.json", max_age_ms: Some(90000), writer: "ados-supervisor" },
    SidecarPath { id: "mgmt-failover", path: "/run/ados/mgmt-failover.json", max_age_ms: Some(90000), writer: "ados-supervisor" },
    SidecarPath { id: "usb-rehome", path: "/run/ados/usb-rehome.json", max_age_ms: Some(600000), writer: "ados-supervisor" },
    SidecarPath { id: "wifi-powersave", path: "/run/ados/wifi-powersave.json", max_age_ms: Some(120000), writer: "ados-supervisor" },
    SidecarPath { id: "wfb_failover", path: "/run/ados/wfb_failover.json", max_age_ms: Some(10000), writer: "ados-supervisor" },
    SidecarPath { id: "wfb-pair-proof", path: "/var/lib/ados/wfb-pair-proof.json", max_age_ms: None, writer: "ados-radio, ados-groundlink" },
    SidecarPath { id: "bind-state", path: "/run/ados/bind-state.json", max_age_ms: None, writer: "ados-radio" },
    SidecarPath { id: "crsf-stats", path: "/run/ados/crsf-stats.json", max_age_ms: Some(10000), writer: "ados-crsf" },
    SidecarPath { id: "lora", path: "/run/ados/lora.json", max_age_ms: Some(10000), writer: "ados-lora" },
    SidecarPath { id: "lora-beacons", path: "/run/ados/lora-beacons.json", max_age_ms: Some(10000), writer: "ados-lora" },
    SidecarPath { id: "tunnel-config", path: "/run/ados/tunnel-config.json", max_age_ms: Some(30000), writer: "ados-config-tunnel" },
    SidecarPath { id: "relayed-status", path: "/run/ados/relayed-status.json", max_age_ms: Some(20000), writer: "ados-groundlink" },
    SidecarPath { id: "linked-peers", path: "/run/ados/linked-peers.json", max_age_ms: None, writer: "ados-groundlink" },
    SidecarPath { id: "mesh-state", path: "/run/ados/mesh-state.json", max_age_ms: Some(10000), writer: "ados-groundlink" },
    SidecarPath { id: "wfb-relay", path: "/run/ados/wfb-relay.json", max_age_ms: Some(10000), writer: "ados-groundlink" },
    SidecarPath { id: "wfb-receiver", path: "/run/ados/wfb-receiver.json", max_age_ms: Some(10000), writer: "ados-groundlink" },
    SidecarPath { id: "fleet-hero", path: "/run/ados/fleet-hero.json", max_age_ms: None, writer: "ados-control" },
    SidecarPath { id: "camera-state", path: "/run/ados/camera-state.json", max_age_ms: Some(300000), writer: "ados-video" },
    SidecarPath { id: "cameras-discovered", path: "/run/ados/cameras-discovered.json", max_age_ms: None, writer: "ados.hal.camera" },
    SidecarPath { id: "video-streams", path: "/run/ados/video-streams.json", max_age_ms: Some(20000), writer: "ados-video" },
    SidecarPath { id: "video-profile", path: "/run/ados/video-profile.json", max_age_ms: None, writer: "ados-video" },
    SidecarPath { id: "camera-usb-recovery", path: "/run/ados/camera-usb-recovery.json", max_age_ms: Some(60000), writer: "ados-supervisor" },
    SidecarPath { id: "janitor", path: "/run/ados/janitor.json", max_age_ms: None, writer: "ados-supervisor" },
    SidecarPath { id: "pic-state", path: "/run/ados/pic-state.json", max_age_ms: None, writer: "ados-hid" },
    SidecarPath { id: "ground-station-input", path: "/etc/ados/ground-station-input.json", max_age_ms: None, writer: "ados-hid" },
    SidecarPath { id: "gpio-output", path: "/run/ados/gpio-output.json", max_age_ms: None, writer: "ados-gpio" },
    SidecarPath { id: "board", path: "/run/ados/board.json", max_age_ms: None, writer: "ados-hal-probe" },
    SidecarPath { id: "config-status", path: "/run/ados/config-status-<service>.json", max_age_ms: None, writer: "ados-config" },
    SidecarPath { id: "fc-identity", path: "/run/ados/fc-identity.json", max_age_ms: None, writer: "ados-control" },
    SidecarPath { id: "mavlink-router", path: "/run/ados/mavlink-router.json", max_age_ms: Some(15000), writer: "ados-mavlink-router" },
    SidecarPath { id: "link-feedback", path: "/run/ados/link-feedback.json", max_age_ms: None, writer: "ados-mavlink-router" },
    SidecarPath { id: "plugin-loopback-guard", path: "/run/ados/plugin-loopback-guard.json", max_age_ms: None, writer: "ados-plugin-host" },
    SidecarPath { id: "plugin-state", path: "/run/ados/plugins/<plugin_id>-state.json", max_age_ms: Some(10000), writer: "ados-plugin-host" },
    SidecarPath { id: "ap-guard", path: "/run/ados/ap-guard.json", max_age_ms: None, writer: "ados-net" },
    SidecarPath { id: "logd-push-request", path: "/run/ados/logd-push-request.json", max_age_ms: None, writer: "ados-control" },
    SidecarPath { id: "logd-push-result", path: "/run/ados/logd-push-result.json", max_age_ms: None, writer: "ados-cloud" },
    SidecarPath { id: "lcd-latency", path: "/run/ados/lcd-latency.json", max_age_ms: Some(10000), writer: "ados-video" },
    SidecarPath { id: "lcd-fb-stats", path: "/run/ados/lcd-fb-stats.json", max_age_ms: Some(10000), writer: "ados-display" },
    SidecarPath { id: "lcd-state", path: "/run/ados/lcd-state.json", max_age_ms: None, writer: "ados-display" },
    SidecarPath { id: "lcd-page-request", path: "/run/ados/lcd-page-request.json", max_age_ms: None, writer: "ados-api" },
    SidecarPath { id: "lcd-plugin-page", path: "/run/ados/lcd-plugin-page.json", max_age_ms: None, writer: "ados-plugin-host" },
    SidecarPath { id: "lcd-plugin-tap", path: "/run/ados/lcd-plugin-tap.json", max_age_ms: None, writer: "ados-display" },
    SidecarPath { id: "clock", path: "/run/ados/sensing/clock.json", max_age_ms: Some(5000), writer: "ados-clock" },
    SidecarPath { id: "sensors", path: "/run/ados/sensors.json", max_age_ms: Some(5000), writer: "ados-clock" },
    SidecarPath { id: "sensorhub", path: "/run/ados/sensorhub.json", max_age_ms: Some(5000), writer: "ados-sensorhub" },
    SidecarPath { id: "gnss", path: "/run/ados/gnss.json", max_age_ms: Some(5000), writer: "ados-gnss" },
    SidecarPath { id: "capture-storage", path: "/run/ados/capture-storage/capture-storage.json", max_age_ms: Some(30000), writer: "ados-supervisor" },
];

/// Every registered socket.
#[rustfmt::skip]
pub const SOCKETS: &[SocketPath] = &[
    SocketPath { id: "api-internal", path: "/run/ados/api-internal.sock", owner: "ados-api" },
    SocketPath { id: "aux-cmd", path: "/run/ados/aux-cmd.sock", owner: "ados-radio" },
    SocketPath { id: "aux-rpc-responses", path: "/run/ados/aux-rpc-responses.sock", owner: "ados-control" },
    SocketPath { id: "buttons", path: "/run/ados/buttons.sock", owner: "ados-hid" },
    SocketPath { id: "cloud-publish", path: "/run/ados/cloud-publish.sock", owner: "ados-cloud" },
    SocketPath { id: "crsf-cmd", path: "/run/ados/crsf-cmd.sock", owner: "ados-crsf" },
    SocketPath { id: "gpio-cmd", path: "/run/ados/gpio-cmd.sock", owner: "ados-gpio" },
    SocketPath { id: "groundlink-cmd", path: "/run/ados/groundlink-cmd.sock", owner: "ados-groundlink" },
    SocketPath { id: "hid-cmd", path: "/run/ados/hid-cmd.sock", owner: "ados-hid" },
    SocketPath { id: "logd", path: "/run/ados/logd.sock", owner: "ados-logd" },
    SocketPath { id: "logd-query", path: "/run/ados/logd-query.sock", owner: "ados-logd" },
    SocketPath { id: "mavlink", path: "/run/ados/mavlink.sock", owner: "ados-mavlink-router" },
    SocketPath { id: "mavlink-ingest", path: "/run/ados/mavlink-ingest.sock", owner: "ados-mavlink-router" },
    SocketPath { id: "msp", path: "/run/ados/msp.sock", owner: "ados-mavlink-router" },
    SocketPath { id: "gnss-cmd", path: "/run/ados/gnss-cmd.sock", owner: "ados-gnss" },
    SocketPath { id: "pairing", path: "/run/ados/pairing.sock", owner: "ados-groundlink" },
    SocketPath { id: "pic", path: "/run/ados/pic.sock", owner: "ados-hid" },
    SocketPath { id: "radio-aux", path: "/run/ados/radio-aux.sock", owner: "ados-radio" },
    SocketPath { id: "radio-cmd", path: "/run/ados/radio-cmd.sock", owner: "ados-radio" },
    SocketPath { id: "state", path: "/run/ados/state.sock", owner: "ados-mavlink-router" },
    SocketPath { id: "supervisor", path: "/run/ados/supervisor.sock", owner: "ados-supervisor" },
    SocketPath { id: "swarm", path: "/run/ados/swarm.sock", owner: "ados-swarmbus" },
    SocketPath { id: "tunnel-config-cmd", path: "/run/ados/tunnel-config-cmd.sock", owner: "ados-config-tunnel" },
    SocketPath { id: "video-cmd", path: "/run/ados/video-cmd.sock", owner: "ados-supervisor" },
    SocketPath { id: "video-encoder", path: "/run/ados/video-encoder.sock", owner: "ados-video" },
    SocketPath { id: "sensor-bus", path: "/run/ados/sensing/sensors.sock", owner: "ados-clock" },
    SocketPath { id: "vision", path: "/run/ados/vision.sock", owner: "ados-vision" },
    SocketPath { id: "wfb-cmd", path: "/run/ados/wfb-cmd.sock", owner: "ados-radio" },
    SocketPath { id: "wifi-cmd", path: "/run/ados/wifi-cmd.sock", owner: "ados-net" },
];

/// The run directory: `ADOS_RUN_DIR` when set and non-empty, else
/// [`RUN_DIR_DEFAULT`].
pub fn run_dir() -> PathBuf {
    std::env::var_os(RUN_DIR_ENV)
        .filter(|v| !v.is_empty())
        .map(PathBuf::from)
        .unwrap_or_else(|| PathBuf::from(RUN_DIR_DEFAULT))
}

/// The registered sidecar with this id.
pub fn sidecar(id: &str) -> Option<&'static SidecarPath> {
    SIDECARS.iter().find(|s| s.id == id)
}

/// The registered socket with this id.
pub fn socket(id: &str) -> Option<&'static SocketPath> {
    SOCKETS.iter().find(|s| s.id == id)
}

/// Resolve a registry path: a `/run/ados/...` path moves under [`run_dir`], any
/// other absolute path is returned as registered.
pub fn resolve(path: &str) -> PathBuf {
    match path
        .strip_prefix(RUN_DIR_DEFAULT)
        .and_then(|r| r.strip_prefix('/'))
    {
        Some(rest) => run_dir().join(rest),
        None => PathBuf::from(path),
    }
}

/// The resolved path of a registered sidecar or socket id. An id with no
/// registry row is taken as a file name under [`run_dir`], so an unregistered
/// sentinel or journal (`uplink-active`, `mesh-events.jsonl`) resolves the same
/// way.
pub fn run_path(id: &str) -> PathBuf {
    match sidecar(id)
        .map(|s| s.path)
        .or_else(|| socket(id).map(|s| s.path))
    {
        Some(path) => resolve(path),
        None => run_dir().join(id),
    }
}

/// The freshness window of a registered sidecar, or `None` when the id is not
/// registered or the sidecar has no window.
pub fn max_age(id: &str) -> Option<Duration> {
    sidecar(id).and_then(SidecarPath::max_age)
}