Skip to main content

parse_data_records/
parse_data_records.rs

1use m_bus_application_layer::{parse_data_records, DataRecordError};
2
3fn main() -> Result<(), DataRecordError> {
4    // Application-layer records only: no wired/wireless frame or CI/TPL header.
5    let data = [
6        0x03, 0x13, 0x15, 0x31, 0x00, // Volume: 12_565 x 10^-3 m³
7        0x02, 0x5A, 0xD7, 0x04, // Flow temperature: 1_239 x 10^-1 °C
8    ];
9
10    for (index, record) in parse_data_records(&data).enumerate() {
11        let record = record?;
12
13        println!("Record {}", index + 1);
14        println!("  value: {:?}", record.value());
15        if let Some(value_information) = record.value_information() {
16            println!("  labels: {:?}", value_information.labels);
17            println!("  scale: 10^{}", value_information.decimal_scale_exponent);
18            println!("  units: {:?}", value_information.units);
19        }
20        println!("  raw bytes: {:02X?}", record.raw_bytes());
21    }
22
23    Ok(())
24}