Skip to main content

readout/
readout.rs

1//! The water meter telegram from the M-Bus documentation, decoded.
2//!
3//! `cargo run --example readout`
4
5use mbus_kit::wired::Frame;
6use mbus_kit::{Application, Body, Header};
7
8const TELEGRAM: [u8; 37] = [
9    0x68, 0x1F, 0x1F, 0x68, 0x08, 0x02, 0x72, 0x78, 0x56, 0x34, 0x12, 0x24, 0x40, 0x01, 0x07, 0x55, 0x00,
10    0x00, 0x00, 0x03, 0x13, 0x15, 0x31, 0x00, 0xDA, 0x02, 0x3B, 0x13, 0x01, 0x8B, 0x60, 0x04, 0x37, 0x18,
11    0x02, 0x18, 0x16,
12];
13
14fn main() -> Result<(), mbus_kit::Error> {
15    let Some((Frame::Long { ci, data, .. }, _)) = Frame::parse(&TELEGRAM)? else {
16        return Err(mbus_kit::Error::UnexpectedEnd);
17    };
18    let app = Application::parse(ci, data)?;
19    if let Header::Long(h) = app.header {
20        println!(
21            "{} meter {:08} by {}, version {}",
22            h.address.medium,
23            h.address.id_number().unwrap_or(0),
24            h.address.manufacturer,
25            h.address.version
26        );
27    }
28    if let Body::Records(records) = app.body {
29        for record in records {
30            // e.g. "volume flow · maximum · storage 5 — 0.113 m³/h"
31            println!("  {}", record?);
32        }
33    }
34    Ok(())
35}