Skip to main content

adamo/
lib.rs

1//! Rust SDK for the Adamo Network.
2//!
3//! This crate is a safe, idiomatic wrapper over the precompiled Adamo
4//! shared library (shipped via [`adamo-sys`]).
5//!
6//! ```no_run
7//! use adamo::Session;
8//!
9//! let session = Session::open_default("my-api-key")?;
10//! session.put("telemetry/heartbeat", b"hello", Default::default())?;
11//! # Ok::<_, adamo::Error>(())
12//! ```
13
14mod error;
15pub mod control;
16mod session;
17pub mod stats;
18
19#[cfg(feature = "video")]
20pub mod camera;
21
22#[cfg(feature = "video")]
23mod robot;
24
25// Audio send (source-driven). `audio` implies `video` (Cargo), so `robot` is
26// present and this can add `attach_audio*` methods on the same Robot handle.
27#[cfg(feature = "audio")]
28mod audio;
29
30pub use error::{Error, Result, StreamError};
31pub use control::{ControlMessage, JointState, Joy, JoystickCommand, decode_control};
32pub use session::{
33    CallbackSubscriber, LivelinessSubscriber, LivelinessToken, Priority, Protocol, PublishOptions,
34    Publisher, PublisherOptions, Sample, Session, StateStore, Subscriber, TaskRunner,
35};
36pub use stats::{LatencyStats, Regime, heartbeat_topic, ping_topic, pong_topic};
37
38/// Microseconds since the Unix epoch on the **adamo fabric clock** — the
39/// shared time axis every robot, browser, and relay on this network sees.
40///
41/// Backed by `zenoh-plugin-adamo-time` running on each router and a
42/// background ping/pong that maintains the offset estimate. Falls back to
43/// the local wall clock until the first sync completes (usually <100 ms
44/// after [`Session::open`]). Check [`fabric_synced`] to distinguish.
45///
46/// Use this instead of `SystemTime::now()` whenever a timestamp will be
47/// subtracted from a stamp produced on a different node.
48pub fn fabric_now_us() -> u64 {
49    // SAFETY: free function, no preconditions.
50    unsafe { adamo_sys::adamo_fabric_now_us() }
51}
52
53/// `true` once the client has completed at least one ping/pong with the
54/// timehub plugin and [`fabric_now_us`] is reading from the synced clock
55/// rather than the local wall-clock fallback.
56pub fn fabric_synced() -> bool {
57    unsafe { adamo_sys::adamo_fabric_synced() != 0 }
58}
59
60#[cfg(feature = "video")]
61pub use robot::{Robot, VideoBackend, VideoOptions, VideoTrack, detect_encoder};
62
63#[cfg(feature = "audio")]
64pub use audio::AudioOptions;
65
66#[cfg(feature = "video")]
67pub use camera::{AttachOptions, CameraInfo, attach_all, attach_camera, discover, discover_v4l2};