Skip to main content

cls_eedi/
lib.rs

1//! Backend and local-device components for KEO CLS.EEDI 1.2.0.
2//!
3//! Decode envelopes with [`wire::Message`], apply protocol transitions in
4//! [`engine`] and bind provisioned topic routes with [`transport`]. Enable
5//! `mqtt` for broker I/O and `eebus` for equipment limits and meter snapshots.
6//! Use [`metering`] to sum signed active power across provisioned devices.
7//! Enable `eebus-pairing` to confirm commissioning from an authenticated SHIP session.
8//!
9//! `mqtt` and `eebus-pairing` need exactly one TLS crypto provider: `aws-lc-rs`
10//! or `ring`. Both transports use it, and neither installs or reads the rustls
11//! process default.
12//!
13//! ```
14//! use cls_eedi::wire::{Control, Limit, Message, Power};
15//!
16//! // A 4,200 W consumption ceiling for one minute.
17//! let control = Control::limits(Power::consumption(Limit::active(4200).lasting(60)));
18//! let message = Message::new("limit-1", "operator", control);
19//! assert_eq!(Message::decode(&message.encode()?)?, message);
20//! # Ok::<(), Box<dyn std::error::Error>>(())
21//! ```
22#![forbid(unsafe_code)]
23
24#[cfg(all(
25    any(feature = "mqtt", feature = "eebus-pairing"),
26    not(any(feature = "aws-lc-rs", feature = "ring"))
27))]
28compile_error!("cls-eedi: `mqtt` and `eebus-pairing` need a TLS crypto provider: enable `aws-lc-rs` or `ring`.");
29#[cfg(all(feature = "aws-lc-rs", feature = "ring"))]
30compile_error!(
31    "cls-eedi: `aws-lc-rs` and `ring` are both enabled. Enable exactly one TLS crypto provider."
32);
33
34/// TLS crypto provider compiled into `mqtt` and `eebus-pairing`.
35///
36/// ```
37/// assert!(["aws-lc-rs", "ring"].contains(&cls_eedi::CRYPTO_PROVIDER));
38/// ```
39#[cfg(any(feature = "aws-lc-rs", feature = "ring"))]
40pub const CRYPTO_PROVIDER: &str = if cfg!(feature = "aws-lc-rs") {
41    "aws-lc-rs"
42} else {
43    "ring"
44};
45
46#[cfg(feature = "eebus")]
47pub mod eebus;
48pub mod engine;
49pub mod metering;
50pub mod transport;
51pub mod wire;