LSH-Core
A robust C++ framework for Arduino-based home automation nodes
Loading...
Searching...
No Matches
config.hpp
Go to the documentation of this file.
1
21#ifndef LSHCORE_COMMUNICATION_CONSTANTS_CONFIGS_HPP
22#define LSHCORE_COMMUNICATION_CONSTANTS_CONFIGS_HPP
23
24#include <ArduinoJson.h>
25#include <etl/bit.h>
26#include <stdint.h>
27
32namespace constants
33{
37 namespace espComConfigs
38 {
39 // Ping timers
40#ifndef CONFIG_PING_INTERVAL_MS
41 static constexpr const uint16_t PING_INTERVAL_MS = 10000U;
42#else
43 static constexpr const uint16_t PING_INTERVAL_MS = CONFIG_PING_INTERVAL_MS;
44#endif // CONFIG_PING_INTERVAL_MS
45
46#ifndef CONFIG_CONNECTION_TIMEOUT_MS
47 static constexpr const uint16_t CONNECTION_TIMEOUT_MS = PING_INTERVAL_MS + 200U;
48#else
49 static constexpr const uint16_t CONNECTION_TIMEOUT_MS = CONFIG_CONNECTION_TIMEOUT_MS;
50#endif // CONFIG_CONNECTION_TIMEOUT_MS
51
52#ifndef CONFIG_COM_SERIAL_BAUD
53 static constexpr const uint32_t COM_SERIAL_BAUD = 250000U;
54#else
55 static constexpr const uint32_t COM_SERIAL_BAUD = CONFIG_COM_SERIAL_BAUD;
56#endif // CONFIG_COM_SERIAL_BAUD
57
58#ifndef CONFIG_COM_SERIAL_TIMEOUT_MS
59 static constexpr const uint8_t COM_SERIAL_TIMEOUT_MS = 5U;
60#else
61 static constexpr const uint8_t COM_SERIAL_TIMEOUT_MS = CONFIG_COM_SERIAL_TIMEOUT_MS;
62#endif // CONFIG_COM_SERIAL_TIMEOUT_MS
63
64 /*
65 Received Json Document Size, the size is computed here https://arduinojson.org/v6/assistant/
66 Processor: AVR, Mode: Deserialize, Input Type: Stream
67 {"p":"10} -> min: 10, recommended: 24
68 -> (JSON_OBJECT_SIZE(1) + number of strings + string characters number)
69 -> (8 + 2 + 6 = 16)
70 {"p":12,"s":[0,1,0,1,0,...]} -> min: JSON_ARRAY_SIZE(N) + JSON_OBJECT_SIZE(2) + number of strings + string characters number
71 -> (N actuator) (JSON_ARRAY_SIZE(N) + JSON_OBJECT_SIZE(2) + 2 + 2)
72 -> 0 actuators: 20 | 10 actuators: 100
73 {"p":13,"i":5,"s":0} -> min: 30, recommended: 48
74 -> (JSON_OBJECT_SIZE(3) + number of strings + string characters number)
75 -> (24 + 3 + 3 = 30)
76 We can use 48 as base minimum size
77 */
78 constexpr uint16_t RECEIVED_DOC_MIN_SIZE = etl::bit_ceil(JSON_ARRAY_SIZE(CONFIG_MAX_ACTUATORS) + JSON_OBJECT_SIZE(2) + 4U);
80
84 constexpr uint16_t RAW_INPUT_BUFFER_MIN_SIZE = etl::bit_ceil(22U);
85
89 constexpr uint16_t RAW_INPUT_BUFFER_VARIABLE_CMD_SIZE = (CONFIG_MAX_ACTUATORS > 0U)
90 ? etl::bit_ceil(16U + (2U * CONFIG_MAX_ACTUATORS)) // {"p":12,"s":[0,1,0,1,0,...]} -> 16 + CONFIG_MAX_ACTUATORS *2
91 : etl::bit_ceil(17U); // Special case for 0 actuators. ({"p":12,"s":[]} -> 15 +1 for '\n' +1 for '\0' )
92
94 /*
95 Sent details Json Document size, the size is computed here https://arduinojson.org/v6/assistant/
96 IMPORTANT: We are assuming that all keys strings and values strings are const char *
97 {"p":1,"n":"c1","a":[1,2,...],"b":[1,3,...]} -> JSON_ARRAY_SIZE(CONFIG_MAX_ACTUATORS) + JSON_ARRAY_SIZE(CONFIG_MAX_CLICKABLES) + JSON_OBJECT_SIZE(4)
98 -> 8*CONFIG_MAX_ACTUATORS + 8*CONFIG_MAX_CLICKABLES + 32
99 The bare minimum is 32 with no actuators nor clickables
100 */
101 constexpr uint16_t SENT_DOC_DETAILS_SIZE = JSON_ARRAY_SIZE(CONFIG_MAX_ACTUATORS) + JSON_ARRAY_SIZE(CONFIG_MAX_CLICKABLES) + JSON_OBJECT_SIZE(4);
102
103 /*
104 Sent state Json Document size, the size is computed here https://arduinojson.org/v6/assistant/
105 IMPORTANT: We are assuming that all keys strings are const char * but not values
106 {"p":2,"s":[0,1,0,1,...]}-> JSON_ARRAY_SIZE(CONFIG_MAX_ACTUATORS) + JSON_OBJECT_SIZE(2)
107 The bare minimum is 16 with no actuators
108 */
109 constexpr uint16_t SENT_DOC_STATE_SIZE = JSON_ARRAY_SIZE(CONFIG_MAX_ACTUATORS) + JSON_OBJECT_SIZE(2);
110
111 /*
112 Sent network click Json Document, the size is computed here https://arduinojson.org/v6/assistant/
113 IMPORTANT: We are assuming that all keys strings and values strings are const char *
114 {"p":3,"t":1,"i":1,"c":0} -> JSON_OBJECT_SIZE(4) -> 32
115 */
116 constexpr uint16_t SENT_DOC_NETWORK_CLICK_SIZE = JSON_OBJECT_SIZE(4);
117
119 } // namespace espComConfigs
120} // namespace constants
121
122#endif // LSHCORE_COMMUNICATION_CONSTANTS_CONFIGS_HPP
constexpr uint16_t RECEIVED_DOC_MIN_SIZE
Calculated minimum size for the JSON document received from the bridge.
Definition config.hpp:78
constexpr uint16_t SENT_DOC_NETWORK_CLICK_SIZE
Calculated size for the JSON document sent for network clicks.
Definition config.hpp:116
constexpr uint16_t RAW_INPUT_BUFFER_VARIABLE_CMD_SIZE
Calculated size for the longest variable-length command ({"p":12,"s":[0,1,0,1,0,.....
Definition config.hpp:89
constexpr uint16_t SENT_DOC_MAX_SIZE
The maximum possible size for any JSON document sent by the device.
Definition config.hpp:118
constexpr uint16_t RAW_INPUT_BUFFER_MIN_SIZE
Defines the size of the temporary on-stack buffer for reading raw serial messages.
Definition config.hpp:84
constexpr uint16_t SENT_DOC_DETAILS_SIZE
Calculated size for the JSON document sent with device details.
Definition config.hpp:101
constexpr uint16_t RECEIVED_DOC_SIZE
Final allocated size for the received JSON document, ensuring a minimum of 48 bytes.
Definition config.hpp:79
constexpr uint16_t SENT_DOC_STATE_SIZE
Calculated size for the JSON document sent with actuator states.
Definition config.hpp:109
constexpr uint16_t RAW_INPUT_BUFFER_SIZE
Final allocated size for the raw serial input buffer.
Definition config.hpp:93
namespace for constants.
Definition config.hpp:33
Internal bridge that imports user-defined macros into the library's scope.