Skip to main content

Crate pamoja_core

Crate pamoja_core 

Source
Expand description

Core abstractions for the pamoja device SDK.

This crate defines the traits that every capability crate (for example pamoja-mqtt, pamoja-serial, or pamoja-ros2) implements. The core is protocol-agnostic: it models devices, sensors, actuators, transports, durable storage, and an event bus, and leaves concrete protocol support to the capability crates so that an application depends only on what it uses.

The primary abstractions are:

  • Device - a connectable physical or virtual device.
  • Sensor - a source of typed readings.
  • Actuator - a sink for typed commands.
  • Telemetry - a stream of telemetry frames.
  • Transport - the outbound half of a link: connect, send, subscribe.
  • Receive - the inbound half: the messages a subscription delivers.
  • Store - a durable store-and-forward queue.
  • EventBus - a typed publish/subscribe channel.
  • Map and MapCommand - adapters that reshape a reading or a command, so a multi-channel driver feeds a consumer that wants one number.
  • Error and Result - the shared error model.

§Examples

Implementing Sensor for a temperature probe:

use pamoja_core::{Result, Sensor};

struct Thermometer {
    celsius: f32,
}

impl Sensor for Thermometer {
    type Reading = f32;

    async fn read(&mut self) -> Result<Self::Reading> {
        Ok(self.celsius)
    }
}

let _probe = Thermometer { celsius: 20.5 };

Re-exports§

pub use adapt::Map;
pub use adapt::MapCommand;
pub use bus::EventBus;
pub use device::Actuator;
pub use device::Device;
pub use device::Sensor;
pub use device::Telemetry;
pub use error::Error;
pub use error::Result;
pub use store::Store;
pub use transport::topic_matches;
pub use transport::Message;
pub use transport::Receive;
pub use transport::Transport;

Modules§

adapt
Adapters that reshape what a sensor reads and what an actuator is told.
bus
A typed publish/subscribe event bus used internally and by application code.
device
Device-model traits implemented by capability crates.
error
The error model shared by every pamoja crate.
store
Durable local storage backing the offline-first synchronization layer.
transport
The transport abstraction: how bytes move between the SDK and a device or peer.