Skip to main content

Module sim

Module sim 

Source
Expand description

Write meter telegrams: for tests, simulators and fixtures.

Telegram writes what a basic meter pushes on its optical interface: an OpenResponse, one GetListResponse with the entries, and a CloseResponse, each with a correct message CRC, through the same SmlFile a client uses. Frame the result with encode_frame.

use sml_kit::{ListEntry, Obis, Unit, encode_frame, readout, sim::Telegram};

let entries = [
    ListEntry::bytes(Obis::MANUFACTURER, b"SIM"),
    ListEntry::number(Obis::ENERGY_IMPORT, Unit::WH, -1, 123_456_789),
];
let telegram = Telegram { server_id: b"\x0a\x01SIM\x00\x00\x00\x00\x01", file_id: b"F1", entries: &entries };
let mut payload = [0u8; 256];
let n = telegram.write(&mut payload)?;
assert_eq!(readout(&payload[..n])?.quantity(Obis::ENERGY_IMPORT).unwrap().to_string(), "12345678.9 Wh");

This is a simulator, not a model of any particular meter. Agreement between it and the decoder proves consistency only; the real-meter corpus (tests/corpus/) is the evidence that real meters decode.

Structsยง

Telegram
A simulated meter telegram.