Skip to main content

Crate dlms_cosem_kit

Crate dlms_cosem_kit 

Source
Expand description

§dlms-cosem-kit

DLMS/COSEM (IEC 62056) in one Rust crate: sans-I/O, no_std, client and server.

crates.io docs.rs license

Documentation and guides →

Read meters, host COSEM objects, or receive push notifications. The protocol core works with caller-provided buffers. The blocking client drives TCP wrapper and HDLC connections.

[dependencies]
dlms-cosem-kit = "0.4"

§Read a profile

Pass an associated client and the capture-column count for the selection. The returned value borrows storage. Use Some(selector) to read a clock range or entry range; DateTime::from_unix_seconds builds the range ends.

use dlms_cosem_kit::client::{Client, ClientError, Transport};
use dlms_cosem_kit::cosem::ProfileBuffer;
use dlms_cosem_kit::obis::Obis;
use dlms_cosem_kit::security::CryptoProvider;
use dlms_cosem_kit::xdlms::AttributeDescriptor;

fn read_profile<T: Transport, P: CryptoProvider>(
    meter: &mut Client<T, P>,
    name: Obis,
    columns: usize,
    storage: &mut [u8],
) -> Result<(), ClientError> {
    let buffer = AttributeDescriptor::new(7, name, 2);
    let value = meter.get_into(buffer, None, storage)?;
    ProfileBuffer::new(&value)?.for_each_cell(columns, |row, col, cell| {
        println!("{row}/{col} {cell:?}");
        Ok(())
    })?;
    Ok(())
}

The client accepts up to 64 KiB of encoded result data by default. Set the client limit with with_response_capacity. A smaller output slice sets the limit for that GET. ResponseTooLarge indicates whether to reconnect. For owned values use get or get_selected.

release succeeds only when the meter confirms the release, so commit staged readings on it. WrapperTransport checks reply ports and lengths on the header, and set_deadline bounds a whole association.

§Features

default = ["std", "client", "server", "hdlc", "wrapper", "p1", "suite0", "obis-names"]

FeatureWhat it switches on
client / serverThe two engines. With std, client adds the blocking Client and its transports.
hdlc / wrapper / p1The HDLC data link, the TCP/UDP wrapper, the P1 customer interface.
snShort-name referencing, for pre-logical-name meters. Off by default.
suite0The AES-GCM provider: ciphering under suites 0, 1 and 2. Implies crypto.
cryptoZeroised key storage and constant-time comparison, without a cipher.
obis-namesNames for the well-known OBIS codes.
std / alloc / heaplessEnvironment. std implies alloc and brings OsRandom.

§Protocol support

The crate implements A-XDR and BER codecs, ACSE associations, logical-name services, optional short-name referencing, service blocks and general block transfer. Security includes symmetric ciphering for suites 0–2, HLS-GMAC and replay protection. Persist the next invocation counter before reusing a key across restarts.

For embedded or async applications, drive the sans-I/O ClientSession or Server with your transport. See the support matrix for supported security mechanisms and interoperability limits.

§Run the TCP examples

In separate terminals, start the simulator and read its profile.

cargo run --example meter
cargo run --example read

Add -- --ciphered to both commands for HLS-GMAC and authenticated encryption.

Cookbook · API reference · Changelog

§License

MIT OR Apache-2.0, at your option.

Re-exports§

pub use codec::Error;
pub use codec::ErrorKind;
pub use codec::Reader;
pub use codec::Result;
pub use codec::SliceWriter;
pub use codec::Writer;
pub use obis::Obis;
pub use xdlms::Apdu;

Modules§

acse
ACSE — establishing and releasing an application association.
axdr
A-XDR — the encoding xDLMS uses for data.
ber
Just enough BER for ACSE.
client
The client: a sans-I/O state machine that talks to a meter.
codec
The cursor codec: a reader, a writer, and an error that always knows where.
cookbook
Recipes for meter clients and servers using the default features. The examples use the default crate features unless stated otherwise.
cosem
The COSEM object model: interface classes, access rights, profiles.
obis
OBIS — the six-byte name every COSEM object carries.
security
Information security: suites, keys, protection and authentication.
server
The server: a sans-I/O meter.
transport
Transports: what carries an APDU.
xdlms
The DLMS application layer: every APDU, and the services they carry.