@@ -87,6 +87,33 @@ parser.set_skip_crc_check(true);
8787
8888This affects HDLC and M-Bus only. It has no effect in ` RAW ` mode.
8989
90+ ## Providing A Work Buffer
91+
92+ The parser performs all transforms (frame decoding, GBT reassembly, decryption,
93+ APDU unwrapping) in a single caller-owned work buffer. ** No heap allocation occurs
94+ during ` parse() ` .**
95+
96+ ``` cpp
97+ uint8_t work_buf[1024 ]; // stack, static, or PSRAM — caller controls placement
98+ parser.set_work_buffer(work_buf, sizeof (work_buf));
99+ ```
100+
101+ The work buffer must be at least as large as the biggest raw frame the meter sends.
102+ If no work buffer is set, or the frame exceeds its capacity, ` parse() ` returns
103+ ` {0, 0} ` and logs an error.
104+
105+ Typical sizes:
106+
107+ | Scenario | Recommended size |
108+ | ---| ---|
109+ | Unencrypted single-frame HDLC | 256–512 bytes |
110+ | Encrypted single-frame M-Bus | 512 bytes |
111+ | Multi-frame HDLC or GBT (e.g. Landis+Gyr E450) | 1024 bytes |
112+
113+ The input buffer passed to ` parse() ` is ** not modified** — data is copied into the
114+ work buffer first, then transformed in-place through each pipeline stage. Each stage
115+ produces output that is equal or smaller in size, so the buffer never grows.
116+
90117## Accumulating Frames
91118
92119Some meters split a single DLMS message across multiple transport frames (HDLC
@@ -311,9 +338,11 @@ ESPHome-style integration:
311338
312339class MyMeterComponent {
313340 dlms_parser::DlmsParser parser_ ;
341+ uint8_t work_buf_ [ 1024] {};
314342
315343public:
316344 void setup() {
345+ parser_ .set_work_buffer(work_buf_ , sizeof(work_buf_ ));
317346 parser_ .load_default_patterns();
318347 parser_ .set_frame_format(dlms_parser::FrameFormat::HDLC);
319348
@@ -353,6 +382,8 @@ Examples of meter-specific customization from the test suite:
353382
354383| Symptom | Likely cause |
355384|---|---|
385+ | `No work buffer set` error | call `set_work_buffer()` before `parse()` |
386+ | `Frame too large for work buffer` | increase work buffer size |
356387| `parse()` returns 0 | no patterns loaded |
357388| `parse()` returns 0 with patterns loaded | no pattern matched the AXDR layout |
358389| `HCS error` or `FCS error` | wrong frame format, damaged frame, or non-standard CRC |
0 commit comments