ESPHome 2026.3.0-dev
Loading...
Searching...
No Matches
mbus.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4
5namespace esphome::dlms_meter {
6
7/*
8+----------------------------------------------------+ -
9| Start Character [0x68] | \
10+----------------------------------------------------+ |
11| Data Length (L) | |
12+----------------------------------------------------+ |
13| Data Length Repeat (L) | |
14+----------------------------------------------------+ > M-Bus Data link layer
15| Start Character Repeat [0x68] | |
16+----------------------------------------------------+ |
17| Control/Function Field (C) | |
18+----------------------------------------------------+ |
19| Address Field (A) | /
20+----------------------------------------------------+ -
21| Control Information Field (CI) | \
22+----------------------------------------------------+ |
23| Source Transport Service Access Point (STSAP) | > DLMS/COSEM M-Bus transport layer
24+----------------------------------------------------+ |
25| Destination Transport Service Access Point (DTSAP) | /
26+----------------------------------------------------+ -
27| | \
28~ ~ |
29 Data > DLMS/COSEM Application Layer
30~ ~ |
31| | /
32+----------------------------------------------------+ -
33| Checksum | \
34+----------------------------------------------------+ > M-Bus Data link layer
35| Stop Character [0x16] | /
36+----------------------------------------------------+ -
37
38Data_Length = L - C - A - CI
39Each line (except Data) is one Byte
40
41Possible Values found in publicly available docs:
42- C: 0x53/0x73 (SND_UD)
43- A: FF (Broadcast)
44- CI: 0x00-0x1F/0x60/0x61/0x7C/0x7D
45- STSAP: 0x01 (Management Logical Device ID 1 of the meter)
46- DTSAP: 0x67 (Consumer Information Push Client ID 103)
47 */
48
49// MBUS start bytes for different telegram formats:
50// - Single Character: 0xE5 (length=1)
51// - Short Frame: 0x10 (length=5)
52// - Control Frame: 0x68 (length=9)
53// - Long Frame: 0x68 (length=9+data_length)
54// This component currently only uses Long Frame.
55static constexpr uint8_t START_BYTE_SINGLE_CHARACTER = 0xE5;
56static constexpr uint8_t START_BYTE_SHORT_FRAME = 0x10;
57static constexpr uint8_t START_BYTE_CONTROL_FRAME = 0x68;
58static constexpr uint8_t START_BYTE_LONG_FRAME = 0x68;
59static constexpr uint8_t MBUS_HEADER_INTRO_LENGTH = 4; // Header length for the intro (0x68, length, length, 0x68)
60static constexpr uint8_t MBUS_FULL_HEADER_LENGTH = 9; // Total header length
61static constexpr uint8_t MBUS_FOOTER_LENGTH = 2; // Footer after frame
62static constexpr uint8_t MBUS_MAX_FRAME_LENGTH = 250; // Maximum size of frame
63static constexpr uint8_t MBUS_START1_OFFSET = 0; // Offset of first start byte
64static constexpr uint8_t MBUS_LENGTH1_OFFSET = 1; // Offset of first length byte
65static constexpr uint8_t MBUS_LENGTH2_OFFSET = 2; // Offset of (duplicated) second length byte
66static constexpr uint8_t MBUS_START2_OFFSET = 3; // Offset of (duplicated) second start byte
67static constexpr uint8_t STOP_BYTE = 0x16;
68
69} // namespace esphome::dlms_meter