Skip to main content

Crate smgw_cls

Crate smgw_cls 

Source
Expand description

§smgw-cls

A Rust library and loopback simulator for a Controllable Local System (CLS) communicating through a smart meter gateway. Drive a connection with a caller-supplied clock or read an IEC 61850 measurement over mutual TLS.

Project site · Developer guide · Published crate · Changelog

Use smgw-cls directly to select a protocol feature. Applications using the gateway facade can enable its cls feature to access the same session types through smgw::cls.

§Read a measurement on loopback

Run these commands from a workspace checkout with Rust 1.90 or later and OpenSSL development libraries with Brainpool support.

cargo run -p xtask -- gen-pki
cargo run -p smgw-cls --features simulator --example mms_read

The first command generates seven-day test identities in target/test-pki. The second runs the CLS, gateway and market participant on loopback. The market participant reads the meter over two mutually authenticated TLS connections.

CLSLD0/MMXU1$MX$TotW$mag$f = 1250 W (MMS read over HAN and WAN mutual TLS)

Use the same fixture for the mms_tariff example with simulator,fsch-tariff. For CLS.EEDI over MQTT 5, see the power control walkthrough. For a token-backed gateway key, see the TLS guide.

§Choose a feature

ConfigurationCapability
DefaultAllocation-free no_std session engine, logical FNN relay controls and Module 3 tariff lookup
runtimeTokio/OpenSSL endpoints and a bounded, single-session loopback proxy
eediTLS runtime and the CLS.EEDI protocol engines and MQTT 5 sessions under smgw_cls::eedi
simulatorRuntime and the read-only IEC 61850 example
fnn-bridgeMap IEC controls to EEBUS limits or logical relays, and serve power measurements or contact feedback over MMS
fsch-tariffImport fixed-start FSCH schedules over blocking or async MMS, check the provider’s clock quality and map prices to tariff levels

Run just bridge to exercise the controls and independent feedback. The guide covers TLS setup, commissioning and tariff schedules. Loopback simulator · EEBUS and relay controls

§Drive a session

use core::time::Duration;
use smgw_cls::engine::{Action, Policy, Session};

let mut session = Session::new(Policy::default());
let Some(Action::Connect { generation }) = session.start(Duration::ZERO) else {
    unreachable!("a fresh session admits one connection");
};
// Report success after the transport authenticates the peer and authorizes its route.
assert_eq!(session.connected(generation, Duration::from_secs(1)),
           Some(Action::Ready { generation }));
assert_eq!(session.cancel(), Some(Action::Close { generation }));

Arm a timer for Session::deadline(), call tick(now) when it expires, and execute each returned action. The generation identifies the attempt so a late callback cannot activate a newer connection.

Licensed under MIT OR Apache-2.0.

Re-exports§

pub use cls_eedi as eedi;

Modules§

bridge
Map commissioned IEC 61850 controls to EEBUS consumption (LPC) and production (LPP) limits.
engine
A caller-clocked lifecycle for one outgoing CLS connection.
fnn
Logical relay commands and operator-supplied tariff windows for local simulations.
transport
A bounded, one-session TLS proxy for loopback integration tests.

Functions§

reconnect_delay
Returns the reconnect delay after a failed connection attempt.