ESPHome 2026.3.0-dev
Loading...
Searching...
No Matches
dlms.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4
6
7/*
8+-------------------------------+
9| Ciphering Service |
10+-------------------------------+
11| System Title Length |
12+-------------------------------+
13| |
14| |
15| |
16| System |
17| Title |
18| |
19| |
20| |
21+-------------------------------+
22| Length | (1 or 3 Bytes)
23+-------------------------------+
24| Security Control Byte |
25+-------------------------------+
26| |
27| Frame |
28| Counter |
29| |
30+-------------------------------+
31| |
32~ ~
33 Encrypted Payload
34~ ~
35| |
36+-------------------------------+
37
38Ciphering Service: 0xDB (General-Glo-Ciphering)
39System Title Length: 0x08
40System Title: Unique ID of meter
41Length: 1 Byte=Length <= 127, 3 Bytes=Length > 127 (0x82 & 2 Bytes length)
42Security Control Byte:
43- Bit 3…0: Security_Suite_Id
44- Bit 4: "A" subfield: indicates that authentication is applied
45- Bit 5: "E" subfield: indicates that encryption is applied
46- Bit 6: Key_Set subfield: 0 = Unicast, 1 = Broadcast
47- Bit 7: Indicates the use of compression.
48 */
49
50static constexpr uint8_t DLMS_HEADER_LENGTH = 16;
51static constexpr uint8_t DLMS_HEADER_EXT_OFFSET = 2; // Extra offset for extended length header
52static constexpr uint8_t DLMS_CIPHER_OFFSET = 0;
53static constexpr uint8_t DLMS_SYST_OFFSET = 1;
54static constexpr uint8_t DLMS_LENGTH_OFFSET = 10;
55static constexpr uint8_t TWO_BYTE_LENGTH = 0x82;
56static constexpr uint8_t DLMS_LENGTH_CORRECTION = 5; // Header bytes included in length field
57static constexpr uint8_t DLMS_SECBYTE_OFFSET = 11;
58static constexpr uint8_t DLMS_FRAMECOUNTER_OFFSET = 12;
59static constexpr uint8_t DLMS_FRAMECOUNTER_LENGTH = 4;
60static constexpr uint8_t DLMS_PAYLOAD_OFFSET = 16;
61static constexpr uint8_t GLO_CIPHERING = 0xDB;
62static constexpr uint8_t DATA_NOTIFICATION = 0x0F;
63static constexpr uint8_t TIMESTAMP_DATETIME = 0x0C;
64static constexpr uint16_t MAX_MESSAGE_LENGTH = 512; // Maximum size of message (when having 2 bytes length in header).
65
66// Provider specific quirks
67static constexpr uint8_t NETZ_NOE_MAGIC_BYTE = 0x81; // Magic length byte used by Netz NOE
68static constexpr uint8_t NETZ_NOE_EXPECTED_MESSAGE_LENGTH = 0xF8;
69static constexpr uint8_t NETZ_NOE_EXPECTED_SECURITY_CONTROL_BYTE = 0x20;
70
71} // namespace esphome::dlms_meter