LSH-Core
Deterministic firmware core for Controllino-based Labo Smart Home nodes
 
Loading...
Searching...
No Matches
config.hpp
Go to the documentation of this file.
1
21#ifndef LSH_CORE_COMMUNICATION_CONSTANTS_CONFIG_HPP
22#define LSH_CORE_COMMUNICATION_CONSTANTS_CONFIG_HPP
23
24#include <ArduinoJson.h>
25#include <stdint.h>
26
27#include "internal/etl_bit.hpp"
32namespace constants
33{
37namespace bridgeSerial
38{
39// Ping timers
40#ifndef CONFIG_PING_INTERVAL_MS
41static constexpr const uint16_t PING_INTERVAL_MS = 10000U;
42#else
43static_assert(CONFIG_PING_INTERVAL_MS >= 0, "CONFIG_PING_INTERVAL_MS must be non-negative.");
44static_assert(CONFIG_PING_INTERVAL_MS < UINT16_MAX, "CONFIG_PING_INTERVAL_MS must be below UINT16_MAX so saturated timers can pass it.");
45static constexpr const uint16_t PING_INTERVAL_MS = CONFIG_PING_INTERVAL_MS;
46#endif // CONFIG_PING_INTERVAL_MS
47
48#ifndef CONFIG_CONNECTION_TIMEOUT_MS
49static_assert(PING_INTERVAL_MS <= static_cast<uint16_t>(UINT16_MAX - 200U),
50 "CONFIG_PING_INTERVAL_MS is too high for the default CONFIG_CONNECTION_TIMEOUT_MS.");
51static constexpr const uint16_t CONNECTION_TIMEOUT_MS = PING_INTERVAL_MS + 200U;
52#else
53static_assert(CONFIG_CONNECTION_TIMEOUT_MS > 0, "CONFIG_CONNECTION_TIMEOUT_MS must be greater than zero.");
54static_assert(CONFIG_CONNECTION_TIMEOUT_MS <= UINT16_MAX, "CONFIG_CONNECTION_TIMEOUT_MS must fit in uint16_t.");
55static constexpr const uint16_t CONNECTION_TIMEOUT_MS = CONFIG_CONNECTION_TIMEOUT_MS;
56#endif // CONFIG_CONNECTION_TIMEOUT_MS
57
58#ifndef CONFIG_BRIDGE_BOOT_RETRY_INTERVAL_MS
59static constexpr const uint16_t BRIDGE_BOOT_RETRY_INTERVAL_MS =
60 250U;
61#else
62static_assert(CONFIG_BRIDGE_BOOT_RETRY_INTERVAL_MS > 0, "CONFIG_BRIDGE_BOOT_RETRY_INTERVAL_MS must be greater than zero.");
63static_assert(CONFIG_BRIDGE_BOOT_RETRY_INTERVAL_MS <= UINT16_MAX, "CONFIG_BRIDGE_BOOT_RETRY_INTERVAL_MS must fit in uint16_t.");
64static constexpr const uint16_t BRIDGE_BOOT_RETRY_INTERVAL_MS = CONFIG_BRIDGE_BOOT_RETRY_INTERVAL_MS;
65#endif // CONFIG_BRIDGE_BOOT_RETRY_INTERVAL_MS
66
67#ifndef CONFIG_BRIDGE_AWAIT_STATE_TIMEOUT_MS
68static constexpr const uint16_t BRIDGE_AWAIT_STATE_TIMEOUT_MS =
69 1500U;
70#else
71static_assert(CONFIG_BRIDGE_AWAIT_STATE_TIMEOUT_MS > 0, "CONFIG_BRIDGE_AWAIT_STATE_TIMEOUT_MS must be greater than zero.");
72static_assert(CONFIG_BRIDGE_AWAIT_STATE_TIMEOUT_MS <= UINT16_MAX, "CONFIG_BRIDGE_AWAIT_STATE_TIMEOUT_MS must fit in uint16_t.");
73static constexpr const uint16_t BRIDGE_AWAIT_STATE_TIMEOUT_MS = CONFIG_BRIDGE_AWAIT_STATE_TIMEOUT_MS;
74#endif // CONFIG_BRIDGE_AWAIT_STATE_TIMEOUT_MS
75
76#ifndef CONFIG_COM_SERIAL_BAUD
77static constexpr const uint32_t COM_SERIAL_BAUD = 250000U;
78#else
79static constexpr const uint32_t COM_SERIAL_BAUD = CONFIG_COM_SERIAL_BAUD;
80#endif // CONFIG_COM_SERIAL_BAUD
81
82#ifndef CONFIG_COM_SERIAL_TIMEOUT_MS
83static constexpr const uint8_t COM_SERIAL_TIMEOUT_MS =
84 5U;
85#else
86static_assert(CONFIG_COM_SERIAL_TIMEOUT_MS >= 0, "CONFIG_COM_SERIAL_TIMEOUT_MS must be non-negative.");
87static_assert(CONFIG_COM_SERIAL_TIMEOUT_MS <= UINT8_MAX, "CONFIG_COM_SERIAL_TIMEOUT_MS must fit in uint8_t.");
88static constexpr const uint8_t COM_SERIAL_TIMEOUT_MS =
89 CONFIG_COM_SERIAL_TIMEOUT_MS;
90#endif // CONFIG_COM_SERIAL_TIMEOUT_MS
91
92#ifndef CONFIG_COM_SERIAL_MSGPACK_FRAME_IDLE_TIMEOUT_MS
93static constexpr const uint8_t COM_SERIAL_MSGPACK_FRAME_IDLE_TIMEOUT_MS =
94 COM_SERIAL_TIMEOUT_MS;
95#else
96static_assert(CONFIG_COM_SERIAL_MSGPACK_FRAME_IDLE_TIMEOUT_MS >= 0,
97 "CONFIG_COM_SERIAL_MSGPACK_FRAME_IDLE_TIMEOUT_MS must be non-negative.");
98static_assert(CONFIG_COM_SERIAL_MSGPACK_FRAME_IDLE_TIMEOUT_MS <= UINT8_MAX,
99 "CONFIG_COM_SERIAL_MSGPACK_FRAME_IDLE_TIMEOUT_MS must fit in uint8_t.");
100static constexpr const uint8_t COM_SERIAL_MSGPACK_FRAME_IDLE_TIMEOUT_MS =
101 CONFIG_COM_SERIAL_MSGPACK_FRAME_IDLE_TIMEOUT_MS;
102#endif // CONFIG_COM_SERIAL_MSGPACK_FRAME_IDLE_TIMEOUT_MS
103
104#ifndef CONFIG_COM_SERIAL_MAX_RX_PAYLOADS_PER_LOOP
105static constexpr const uint8_t COM_SERIAL_MAX_RX_PAYLOADS_PER_LOOP =
106 4U;
107#else
108static_assert(CONFIG_COM_SERIAL_MAX_RX_PAYLOADS_PER_LOOP > 0, "CONFIG_COM_SERIAL_MAX_RX_PAYLOADS_PER_LOOP must be greater than zero.");
109static_assert(CONFIG_COM_SERIAL_MAX_RX_PAYLOADS_PER_LOOP <= UINT8_MAX, "CONFIG_COM_SERIAL_MAX_RX_PAYLOADS_PER_LOOP must fit in uint8_t.");
110static constexpr const uint8_t COM_SERIAL_MAX_RX_PAYLOADS_PER_LOOP = CONFIG_COM_SERIAL_MAX_RX_PAYLOADS_PER_LOOP;
111#endif // CONFIG_COM_SERIAL_MAX_RX_PAYLOADS_PER_LOOP
112static_assert(COM_SERIAL_MAX_RX_PAYLOADS_PER_LOOP > 0U, "COM_SERIAL_MAX_RX_PAYLOADS_PER_LOOP must be greater than zero.");
113
114#ifndef CONFIG_COM_SERIAL_FLUSH_AFTER_SEND
115#ifdef LSH_DEBUG
116static constexpr const bool COM_SERIAL_FLUSH_AFTER_SEND = true;
117#else
118static constexpr const bool COM_SERIAL_FLUSH_AFTER_SEND = false;
119#endif // LSH_DEBUG
120#else
121static constexpr const bool COM_SERIAL_FLUSH_AFTER_SEND = (CONFIG_COM_SERIAL_FLUSH_AFTER_SEND != 0);
122#endif // CONFIG_COM_SERIAL_FLUSH_AFTER_SEND
123
124constexpr uint16_t PACKED_STATE_BYTES =
125 CONFIG_PACKED_ACTUATOR_STATE_BYTES;
126
127/*
128 Received ArduinoJson document storage, computed from the widest
129 decoded bridge command. Both JSON and MsgPack deserialize into
130 this JsonDocument-shaped pool.
131 Processor: AVR, Mode: Deserialize, Input Type: Stream
132 {"p":10} -> min: 10, recommended: 24
133 -> (JSON_OBJECT_SIZE(1) + number of strings + string characters number)
134 -> (8 + 2 + 6 = 16)
135 {"p":12,"s":[90,3]} -> min: JSON_ARRAY_SIZE(ceil(CONFIG_MAX_ACTUATORS / 8)) + JSON_OBJECT_SIZE(2) + 4
136 because `SET_STATE` uses packed state bytes, not one JSON element per actuator.
137 {"p":17,"t":2,"i":255,"c":255} -> min: JSON_OBJECT_SIZE(4)
138 {"p":13,"i":5,"s":0} -> min: 30, recommended: 48
139 -> (JSON_OBJECT_SIZE(3) + number of strings + string characters number)
140 -> (24 + 3 + 3 = 30)
141 We can use 48 as base minimum size
142 */
143constexpr uint16_t RECEIVED_DOC_MIN_SIZE = etl::bit_ceil(JSON_ARRAY_SIZE(PACKED_STATE_BYTES) + JSON_OBJECT_SIZE(2) +
144 4U);
145constexpr uint16_t RECEIVED_DOC_SIZE =
147 ? 48U
149static_assert(RECEIVED_DOC_SIZE >= JSON_OBJECT_SIZE(4), "RECEIVED_DOC_SIZE must fit network click responses with correlation ID.");
150
151#ifdef CONFIG_MSG_PACK
160constexpr uint16_t PACKED_STATE_MSGPACK_ARRAY_HEADER_SIZE =
161 (PACKED_STATE_BYTES < 16U) ? 1U : 3U;
162
169constexpr uint16_t RAW_INPUT_BUFFER_FIXED_CMD_SIZE = 13U;
170
181constexpr uint16_t RAW_INPUT_BUFFER_VARIABLE_CMD_SIZE = 6U + PACKED_STATE_MSGPACK_ARRAY_HEADER_SIZE + PACKED_STATE_BYTES;
182
183#else
188 etl::bit_ceil(31U);
189
194 etl::bit_ceil(17U + (4U * PACKED_STATE_BYTES));
195#endif
196
197constexpr uint16_t RAW_INPUT_BUFFER_SIZE =
201
202#ifdef CONFIG_MSG_PACK
209constexpr uint16_t MSGPACK_SERIAL_MAX_FRAME_SIZE = static_cast<uint16_t>(2U + (RAW_INPUT_BUFFER_SIZE * 2U));
210
211static_assert(RAW_INPUT_BUFFER_SIZE >= 13U, "RAW_INPUT_BUFFER_SIZE must fit fixed-size network click commands in MsgPack mode.");
212#else
213static_assert(RAW_INPUT_BUFFER_SIZE >= 31U, "RAW_INPUT_BUFFER_SIZE must fit fixed-size click/failover commands plus null terminator.");
214#endif
215
216#ifndef CONFIG_COM_SERIAL_MAX_RX_BYTES_PER_LOOP
217static constexpr const uint16_t COM_SERIAL_MAX_RX_BYTES_PER_LOOP =
218#ifdef CONFIG_MSG_PACK
219 MSGPACK_SERIAL_MAX_FRAME_SIZE;
220#else
222#endif
223#else
224static_assert(CONFIG_COM_SERIAL_MAX_RX_BYTES_PER_LOOP > 0, "CONFIG_COM_SERIAL_MAX_RX_BYTES_PER_LOOP must be greater than zero.");
225static_assert(CONFIG_COM_SERIAL_MAX_RX_BYTES_PER_LOOP <= UINT16_MAX, "CONFIG_COM_SERIAL_MAX_RX_BYTES_PER_LOOP must fit in uint16_t.");
226static constexpr const uint16_t COM_SERIAL_MAX_RX_BYTES_PER_LOOP =
227 CONFIG_COM_SERIAL_MAX_RX_BYTES_PER_LOOP;
228#endif // CONFIG_COM_SERIAL_MAX_RX_BYTES_PER_LOOP
229static_assert(COM_SERIAL_MAX_RX_BYTES_PER_LOOP > 0U, "CONFIG_COM_SERIAL_MAX_RX_BYTES_PER_LOOP must be greater than zero.");
230
231} // namespace bridgeSerial
232} // namespace constants
233
234#endif // LSH_CORE_COMMUNICATION_CONSTANTS_CONFIG_HPP
Safe wrapper for ETL bit utilities with Arduino min/max macros neutralized locally.
constexpr uint16_t RAW_INPUT_BUFFER_FIXED_CMD_SIZE
Minimum JSON-line buffer size required by the widest fixed-width command.
Definition config.hpp:187
constexpr uint16_t RAW_INPUT_BUFFER_VARIABLE_CMD_SIZE
Maximum JSON-line size of a packed SET_STATE command.
Definition config.hpp:193
constexpr uint16_t PACKED_STATE_BYTES
Number of bytes required to represent all actuator states on wire.
Definition config.hpp:124
constexpr uint16_t RECEIVED_DOC_SIZE
Final allocated size for the received document, ensuring a minimum of 48 bytes.
Definition config.hpp:145
constexpr uint16_t RECEIVED_DOC_MIN_SIZE
Calculated minimum size for the decoded bridge document.
Definition config.hpp:143
constexpr uint16_t RAW_INPUT_BUFFER_SIZE
Final allocated size for the raw serial input buffer used by the active codec.
Definition config.hpp:197
Namespace that groups compile-time constants.
Definition config.hpp:33
Internal bridge that imports static profile resources into the library's scope.