3-phase PV router
Loading...
Searching...
No Matches
validation.h
Go to the documentation of this file.
1
11
12#ifndef VALIDATION_H
13#define VALIDATION_H
14
15#include "config_system.h"
16#include "utils_pins.h"
17#include "utils_rf.h"
18
19#include "config.h"
20
28
29static_assert(SUPPLY_FREQUENCY == 50 || SUPPLY_FREQUENCY == 60, "******** SUPPLY_FREQUENCY must be 50 or 60 Hz ! ********");
30
31static_assert(DATALOG_PERIOD_IN_SECONDS <= 40, "**** Data log duration is too long and will lead to overflow ! ****");
32
33static_assert(TEMP_SENSOR_PRESENT ^ (temperatureSensing.get_pin() == unused_pin), "******** Wrong pin value for temperature sensor(s). Please check your config.h ! ********");
34static_assert(DIVERSION_PIN_PRESENT ^ (diversionPin == unused_pin), "******** Wrong pin value for diversion command. Please check your config.h ! ********");
35static_assert((PRIORITY_ROTATION == RotationModes::PIN) ^ (rotationPin == unused_pin), "******** Wrong pin value for rotation command. Please check your config.h ! ********");
36static_assert(WATCHDOG_PIN_PRESENT ^ (watchDogPin == unused_pin), "******** Wrong pin value for watchdog. Please check your config.h ! ********");
37
38static_assert(DUAL_TARIFF ^ (dualTariffPin == unused_pin), "******** Wrong pin value for dual tariff. Please check your config.h ! ********");
39static_assert(!(DUAL_TARIFF & (ul_OFF_PEAK_DURATION == 0)), "******** Off-peak duration cannot be zero. Please check your config.h ! ********");
40static_assert(!(DUAL_TARIFF & (ul_OFF_PEAK_DURATION > 12)), "******** Off-peak duration cannot last more than 12 hours. Please check your config.h ! ********");
41
42static_assert(!EMONESP_CONTROL || (DIVERSION_PIN_PRESENT && (PRIORITY_ROTATION == RotationModes::PIN) && OVERRIDE_PIN_PRESENT), "******** Wrong configuration. Please check your config.h ! ********");
43
44static_assert(!RELAY_DIVERSION | (60 / DATALOG_PERIOD_IN_SECONDS * DATALOG_PERIOD_IN_SECONDS == 60), "******** Wrong configuration. DATALOG_PERIOD_IN_SECONDS must be a divider of 60 ! ********");
45
46static_assert(NO_OF_DUMPLOADS > 0, "Number of dump loads must be greater than 0");
47static_assert(iTemperatureThreshold > 0, "Temperature threshold must be greater than 0");
48static_assert(iTemperatureThreshold <= 100, "Temperature threshold must be lower than 100");
49
50static_assert(REQUIRED_EXPORT_IN_WATTS >= -32768 && REQUIRED_EXPORT_IN_WATTS <= 32767, "******** REQUIRED_EXPORT_IN_WATTS out of range ! ********");
51static_assert(DIVERSION_START_THRESHOLD_WATTS >= 0 && DIVERSION_START_THRESHOLD_WATTS <= 32767, "******** DIVERSION_START_THRESHOLD_WATTS must be positive ! ********");
52
53static_assert(sizeof(physicalLoadPin) / sizeof(physicalLoadPin[0]) == NO_OF_DUMPLOADS, "******** physicalLoadPin array size mismatch ! ********");
54static_assert(sizeof(loadPrioritiesAtStartup) / sizeof(loadPrioritiesAtStartup[0]) == NO_OF_DUMPLOADS, "******** loadPrioritiesAtStartup array size mismatch ! ********");
55static_assert(sizeof(rg_ForceLoad) / sizeof(rg_ForceLoad[0]) == NO_OF_DUMPLOADS, "******** rg_ForceLoad array size mismatch ! ********");
56
57static_assert(ROTATION_AFTER_SECONDS > 0, "******** ROTATION_AFTER_SECONDS must be greater than 0 ! ********");
58static_assert(ROTATION_AFTER_SECONDS <= 86400UL, "******** ROTATION_AFTER_SECONDS cannot exceed 24 hours ! ********");
59
60static_assert(!TEMP_SENSOR_PRESENT || (temperatureSensing.size() > 0), "******** No temperature sensors configured but TEMP_SENSOR_PRESENT is true ! ********");
61static_assert(TEMP_RANGE_LOW < TEMP_RANGE_HIGH, "******** Invalid temperature range ! ********");
62
63constexpr uint16_t check_pins()
64{
65 uint16_t used_pins{ 0 };
66
67 if constexpr (TEMP_SENSOR_PRESENT)
68 {
69 if (temperatureSensing.get_pin() != unused_pin)
70 bit_set(used_pins, temperatureSensing.get_pin());
71 }
72
74 {
75 if (bit_read(used_pins, diversionPin))
76 return 0;
77
78 bit_set(used_pins, diversionPin);
79 }
80
82 {
83 if (bit_read(used_pins, rotationPin))
84 return 0;
85
86 bit_set(used_pins, rotationPin);
87 }
88
89 // Check override pins from the flexible override system
90 if constexpr (OVERRIDE_PIN_PRESENT)
91 {
92 for (uint8_t i = 0; i < overridePins.size(); ++i)
93 {
94 const uint8_t pin = overridePins.getPin(i);
95 if (pin != unused_pin)
96 {
97 if (bit_read(used_pins, pin))
98 return 0;
99
100 bit_set(used_pins, pin);
101 }
102 }
103 }
104
105 if (watchDogPin != unused_pin)
106 {
107 if (bit_read(used_pins, watchDogPin))
108 return 0;
109
110 bit_set(used_pins, watchDogPin);
111 }
112
113 //physicalLoadPin for the TRIACS
114 for (const auto &loadPin : physicalLoadPin)
115 {
116 if (loadPin == unused_pin)
117 return 0;
118
119 if (bit_read(used_pins, loadPin))
120 return 0;
121
122 bit_set(used_pins, loadPin);
123 }
124
125 if constexpr (RELAY_DIVERSION)
126 {
127 for (uint8_t idx = 0; idx < relays.size(); ++idx)
128 {
129 const auto relayPin = relays.get_relay(idx).get_pin();
130
131 if (relayPin != unused_pin)
132 {
133 if (bit_read(used_pins, relayPin))
134 return 0;
135
136 bit_set(used_pins, relayPin);
137 }
138 }
139 }
140
141 return used_pins;
142}
143
144constexpr bool check_load_priorities()
145{
146 uint8_t _sum{ 0 };
147 uint16_t _enum_val{ 0 };
148
149 for (const auto &loadPrio : loadPrioritiesAtStartup)
150 {
151 // we check if a prio is used twice
152 if (bit_read(_enum_val, loadPrio))
153 return 0;
154
155 bit_set(_enum_val, loadPrio);
156
157 _sum += loadPrio;
158 }
159
160 // check if we have all prio between 0 and (NO_OF_DUMPLOADS - 1)
161 return _sum == ((NO_OF_DUMPLOADS * (NO_OF_DUMPLOADS - 1)) >> 1);
162}
163
164constexpr uint16_t check_relay_pins()
165{
166 bool pins_ok{ true };
167
168 for (uint8_t idx = 0; idx < relays.size(); ++idx)
169 {
170 const auto relayPin = relays.get_relay(idx).get_pin();
171
172 if constexpr (RELAY_DIVERSION)
173 {
174 pins_ok &= (relayPin != unused_pin);
175 }
176 else
177 {
178 pins_ok &= (relayPin == unused_pin);
179 }
180 }
181
182 return pins_ok;
183}
184
185static_assert(check_load_priorities(), "******** Load Priorities wrong ! Please check your config ! ********");
186static_assert(check_pins(), "******** Duplicate pin definition ! Please check your config ! ********");
187static_assert((check_pins() & B00000011) == 0, "******** Pins 0 & 1 are reserved for RX/TX ! Please check your config ! ********");
188static_assert((check_pins() & 0xC000) == 0, "******** Pins 14 and/or 15 do not exist ! Please check your config ! ********");
189static_assert(!(RF_CHIP_PRESENT && ((check_pins() & 0x3C04) != 0)), "******** Pins from RF chip are reserved ! Please check your config ! ********");
190static_assert(check_relay_pins(), "******** Wrong pin(s) configuration for relay(s) ********");
191
192#ifdef RF_PRESENT
193static_assert((nodeID >= 1 && nodeID <= 30), "******** RF nodeID must be between 1 and 30 ! ********");
194static_assert(networkGroup >= 1 && networkGroup <= 250, "******** RF networkGroup must be between 1 and 250 ! ********");
195#endif
196
197#endif /* VALIDATION_H */
Standard three-phase PVRouter setup with 2 dump loads.
constexpr uint8_t loadPrioritiesAtStartup[NO_OF_DUMPLOADS]
Definition config.h:93
constexpr bool RELAY_DIVERSION
Definition config.h:51
constexpr int networkGroup
Definition config.h:168
constexpr pairForceLoad rg_ForceLoad[NO_OF_DUMPLOADS]
Definition config.h:146
constexpr bool OVERRIDE_PIN_PRESENT
Definition config.h:48
constexpr uint32_t ROTATION_AFTER_SECONDS
Definition config.h:154
constexpr uint8_t dualTariffPin
Definition config.h:96
constexpr TemperatureSensing temperatureSensing
Definition config.h:150
constexpr RelayEngine relays
Definition config.h:126
constexpr uint8_t physicalLoadPin[NO_OF_DUMPLOADS]
Definition config.h:92
constexpr int nodeID
Definition config.h:167
constexpr bool DUAL_TARIFF
Definition config.h:52
constexpr uint8_t diversionPin
Definition config.h:97
constexpr OverridePins overridePins
Definition config.h:143
constexpr bool EMONESP_CONTROL
Definition config.h:45
constexpr uint8_t NO_OF_DUMPLOADS
Definition config.h:42
constexpr uint8_t ul_OFF_PEAK_DURATION
Definition config.h:145
constexpr bool TEMP_SENSOR_PRESENT
Definition config.h:53
constexpr int16_t iTemperatureThreshold
Definition config.h:148
constexpr bool WATCHDOG_PIN_PRESENT
Definition config.h:50
constexpr bool DIVERSION_PIN_PRESENT
Definition config.h:46
constexpr uint8_t rotationPin
Definition config.h:98
constexpr uint8_t watchDogPin
Definition config.h:99
Basic configuration values to be set by the end-user.
constexpr int16_t REQUIRED_EXPORT_IN_WATTS
constexpr uint8_t DATALOG_PERIOD_IN_SECONDS
constexpr uint8_t SUPPLY_FREQUENCY
constexpr int16_t DIVERSION_START_THRESHOLD_WATTS
constexpr int16_t TEMP_RANGE_LOW
Definition constants.h:23
constexpr int16_t TEMP_RANGE_HIGH
Definition constants.h:24
uint8_t i
Some utility functions for pins manipulation.
constexpr void bit_set(T &_dest, const uint8_t bit)
Set the specified bit to 1.
Definition utils_pins.h:54
constexpr uint8_t bit_read(const T &_src, const uint8_t bit)
Read the specified bit.
Definition utils_pins.h:67
constexpr uint8_t unused_pin
Definition utils_pins.h:17
Some utility functions for the RF chip.
constexpr bool RF_CHIP_PRESENT
Definition utils_rf.h:18
constexpr uint16_t check_pins()
Definition validation.h:63
constexpr uint16_t check_relay_pins()
Definition validation.h:164
constexpr bool check_load_priorities()
Definition validation.h:144