dsmr_parse/
lib.rs

1//! # dsmr-parse
2//!
3//! A small library for parsing DSMR 5 (Dutch Smart Meter Requirements) telegrams from Dutch electricity meters.
4//!
5//! The central struct is [Telegram] with its single method [Telegram::read_from]. Pass anything that implements `std::io::Read`
6//! to it, and it will try to read a valid and conforming DSMR telegram with the correct CRC from it.
7//!
8//! ## Usage
9//!
10//! ### Reading from a serial port
11//!
12//! ```no_run
13//! use dsmr_parse::Telegram;
14//!
15//! // Open serial port (example path)
16//! let port = serialport::new("/dev/ttyUSB0", 115_200);
17//!
18//! // Parse telegram
19//! match Telegram::read_from(port.open().unwrap()) {
20//!     Ok(Some(telegram)) => println!("Read telegram: {telegram:?}"),
21//!     Ok(None) => eprintln!("No complete telegram read"),
22//!     Err(e) => eprintln!("Parse error: {e}"),
23//! }
24//! ```
25//!
26//! ### Reading from a byte slice
27//!
28//! ```
29//! use dsmr_parse::Telegram;
30//!
31//! let telegram_data = b"/XMX5LGBBFG1009394887\r\n\r\n1-3:0.2.8(42)\r\n0-0:1.0.0(190101125431W)\r\n1-0:1.8.1(004169.415*kWh)\r\n!1234\r\n";
32//!
33//! match Telegram::read_from(telegram_data.as_slice()) {
34//!     Ok(Some(telegram)) => println!("Read telegram: {telegram:?}"),
35//!     Ok(None) => println!("No complete telegram in data"),
36//!     Err(e) => eprintln!("Parse error: {e}"),
37//! }
38//! ```
39//!
40//! ## Potential Pitfalls
41//!
42//! - CRC Validation: telegrams with incorrect CRC checksums will be rejected. Ensure data integrity during transmission,
43//!   especially when reading from serial ports with poor connections.
44//! - Serial Port Configuration: DSMR meters typically use 115200 baud, 8N1: 8 data bits, no parity, 1 stop bit. Incorrect
45//!   settings will result in garbled data and parse errors.
46//!
47//! ## Specification
48//!
49//! [P1 Companion Standard 5.0.2](https://www.netbeheernederland.nl/publicatie/dsmr-502-p1-companion-standard)
50
51pub use telegram::*;
52pub use tst::*;
53pub use unit_value::*;
54
55mod line_reader;
56mod telegram;
57mod tst;
58mod unit_value;