modem-mgmt 0.3.0

The management plane of zenoh-modem as a library: serve every device on a host over Zenoh, for any driver that links the contract
Documentation
//! Where a bearer stands with its network, as `state` (#123).
//!
//! `state/modem/device/{device}/radio`: registration and access technology,
//! for a device that registers with a network — a cellular modem, an SBD
//! terminal. Read from the same [`Report`](modem_device::Report) the
//! telemetry loop publishes from, at the state cadence, and **silent** for a
//! device whose report carries no registration: the subject is gated on
//! `capability:registration`, and a point-to-point radio does not have it.

use std::time::Duration;

use modem_contract::registry::modem::{Subject, key};
use zenkey::origin::LocalOrigin;
use zenoh::Session;

use crate::oper::Source;

pub(super) async fn publish_loop(
    session: Session,
    origin: LocalOrigin,
    device: String,
    source: Source,
    ttl_s: u64,
) {
    let subject = Subject::device_radio(&device);
    let doc_key = key(&origin, &subject);
    let qos = subject.qos();
    let refresh = Duration::from_secs((ttl_s / 2).max(1));
    loop {
        if let Some(doc) = super::RadioState::of(&device, &source.report()) {
            crate::state::put(&session, &doc_key, &doc, qos).await;
        }
        tokio::time::sleep(refresh).await;
    }
}