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(OVERRIDE_PIN_PRESENT ^ (forcePin == unused_pin), "******** Wrong pin value for override command. Please check your config.h ! ********");
37static_assert(WATCHDOG_PIN_PRESENT ^ (watchDogPin == unused_pin), "******** Wrong pin value for watchdog. Please check your config.h ! ********");
38
39static_assert(DUAL_TARIFF ^ (dualTariffPin == unused_pin), "******** Wrong pin value for dual tariff. Please check your config.h ! ********");
40static_assert(!(DUAL_TARIFF & (ul_OFF_PEAK_DURATION == 0)), "******** Off-peak duration cannot be zero. Please check your config.h ! ********");
41static_assert(!(DUAL_TARIFF & (ul_OFF_PEAK_DURATION > 12)), "******** Off-peak duration cannot last more than 12 hours. Please check your config.h ! ********");
42
43static_assert(!EMONESP_CONTROL || (DIVERSION_PIN_PRESENT && (PRIORITY_ROTATION == RotationModes::PIN) && OVERRIDE_PIN_PRESENT), "******** Wrong configuration. Please check your config.h ! ********");
44
45static_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 ! ********");
46
47static_assert(NO_OF_DUMPLOADS > 0, "Number of dump loads must be greater than 0");
48static_assert(iTemperatureThreshold > 0, "Temperature threshold must be greater than 0");
49static_assert(iTemperatureThreshold <= 100, "Temperature threshold must be lower than 100");
50
51static_assert(REQUIRED_EXPORT_IN_WATTS >= -32768 && REQUIRED_EXPORT_IN_WATTS <= 32767, "******** REQUIRED_EXPORT_IN_WATTS out of range ! ********");
52static_assert(DIVERSION_START_THRESHOLD_WATTS >= 0 && DIVERSION_START_THRESHOLD_WATTS <= 32767, "******** DIVERSION_START_THRESHOLD_WATTS must be positive ! ********");
53
54static_assert(sizeof(physicalLoadPin) / sizeof(physicalLoadPin[0]) == NO_OF_DUMPLOADS, "******** physicalLoadPin array size mismatch ! ********");
55static_assert(sizeof(loadPrioritiesAtStartup) / sizeof(loadPrioritiesAtStartup[0]) == NO_OF_DUMPLOADS, "******** loadPrioritiesAtStartup array size mismatch ! ********");
56static_assert(sizeof(rg_ForceLoad) / sizeof(rg_ForceLoad[0]) == NO_OF_DUMPLOADS, "******** rg_ForceLoad array size mismatch ! ********");
57
58static_assert(ROTATION_AFTER_SECONDS > 0, "******** ROTATION_AFTER_SECONDS must be greater than 0 ! ********");
59static_assert(ROTATION_AFTER_SECONDS <= 86400UL, "******** ROTATION_AFTER_SECONDS cannot exceed 24 hours ! ********");
60
61static_assert(!TEMP_SENSOR_PRESENT || (temperatureSensing.get_size() > 0), "******** No temperature sensors configured but TEMP_SENSOR_PRESENT is true ! ********");
62static_assert(TEMP_RANGE_LOW < TEMP_RANGE_HIGH, "******** Invalid temperature range ! ********");
63
64constexpr uint16_t check_pins()
65{
66 uint16_t used_pins{ 0 };
67
68 if constexpr (TEMP_SENSOR_PRESENT)
69 {
70 if (temperatureSensing.get_pin() != unused_pin)
71 bit_set(used_pins, temperatureSensing.get_pin());
72 }
73
75 {
76 if (bit_read(used_pins, diversionPin))
77 return 0;
78
79 bit_set(used_pins, diversionPin);
80 }
81
83 {
84 if (bit_read(used_pins, rotationPin))
85 return 0;
86
87 bit_set(used_pins, rotationPin);
88 }
89
90 if (forcePin != unused_pin)
91 {
92 if (bit_read(used_pins, forcePin))
93 return 0;
94
95 bit_set(used_pins, forcePin);
96 }
97
99 {
100 if (bit_read(used_pins, watchDogPin))
101 return 0;
102
103 bit_set(used_pins, watchDogPin);
104 }
105
106 //physicalLoadPin for the TRIACS
107 for (const auto &loadPin : physicalLoadPin)
108 {
109 if (loadPin == unused_pin)
110 return 0;
111
112 if (bit_read(used_pins, loadPin))
113 return 0;
114
115 bit_set(used_pins, loadPin);
116 }
117
118 if constexpr (RELAY_DIVERSION)
119 {
120 for (uint8_t idx = 0; idx < relays.get_size(); ++idx)
121 {
122 const auto relayPin = relays.get_relay(idx).get_pin();
123
124 if (relayPin != unused_pin)
125 {
126 if (bit_read(used_pins, relayPin))
127 return 0;
128
129 bit_set(used_pins, relayPin);
130 }
131 }
132 }
133
134 return used_pins;
135}
136
137constexpr uint16_t check_relay_pins()
138{
139 bool pins_ok{ true };
140
141 for (uint8_t idx = 0; idx < relays.get_size(); ++idx)
142 {
143 const auto relayPin = relays.get_relay(idx).get_pin();
144
145 if constexpr (RELAY_DIVERSION)
146 {
147 pins_ok &= (relayPin != unused_pin);
148 }
149 else
150 {
151 pins_ok &= (relayPin == unused_pin);
152 }
153 }
154
155 return pins_ok;
156}
157
158constexpr bool check_load_priorities()
159{
160 uint8_t _sum{ 0 };
161 uint16_t _enum_val{ 0 };
162
163 for (const auto &loadPrio : loadPrioritiesAtStartup)
164 {
165 // we check if a prio is used twice
166 if (bit_read(_enum_val, loadPrio))
167 return 0;
168
169 bit_set(_enum_val, loadPrio);
170
171 _sum += loadPrio;
172 }
173
174 // check if we have all prio between 0 and (NO_OF_DUMPLOADS - 1)
175 return _sum == ((NO_OF_DUMPLOADS * (NO_OF_DUMPLOADS - 1)) >> 1);
176}
177
178static_assert(check_load_priorities(), "******** Load Priorities wrong ! Please check your config ! ********");
179static_assert(check_pins(), "******** Duplicate pin definition ! Please check your config ! ********");
180static_assert((check_pins() & B00000011) == 0, "******** Pins 0 & 1 are reserved for RX/TX ! Please check your config ! ********");
181static_assert((check_pins() & 0xC000) == 0, "******** Pins 14 and/or 15 do not exist ! Please check your config ! ********");
182static_assert(!(RF_CHIP_PRESENT && ((check_pins() & 0x3C04) != 0)), "******** Pins from RF chip are reserved ! Please check your config ! ********");
183static_assert(check_relay_pins(), "******** Wrong pin(s) configuration for relay(s) ********");
184
185#ifdef RF_PRESENT
186static_assert((nodeID >= 1 && nodeID <= 30), "******** RF nodeID must be between 1 and 30 ! ********");
187static_assert(networkGroup >= 1 && networkGroup <= 250, "******** RF networkGroup must be between 1 and 250 ! ********");
188#endif
189
190#endif /* VALIDATION_H */
Standard three-phase PVRouter setup with 2 dump loads.
constexpr uint8_t loadPrioritiesAtStartup[NO_OF_DUMPLOADS]
Definition config.h:114
constexpr bool RELAY_DIVERSION
Definition config.h:51
constexpr int networkGroup
Definition config.h:156
constexpr pairForceLoad rg_ForceLoad[NO_OF_DUMPLOADS]
Definition config.h:131
constexpr bool OVERRIDE_PIN_PRESENT
Definition config.h:48
constexpr uint32_t ROTATION_AFTER_SECONDS
Definition config.h:142
constexpr uint8_t dualTariffPin
Definition config.h:117
constexpr TemperatureSensing temperatureSensing
Definition config.h:135
constexpr uint8_t forcePin
Definition config.h:120
constexpr RelayEngine relays
Definition config.h:128
constexpr uint8_t physicalLoadPin[NO_OF_DUMPLOADS]
Definition config.h:113
constexpr int nodeID
Definition config.h:155
constexpr bool DUAL_TARIFF
Definition config.h:73
constexpr uint8_t diversionPin
Definition config.h:118
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:130
constexpr bool TEMP_SENSOR_PRESENT
Definition config.h:74
constexpr int16_t iTemperatureThreshold
Definition config.h:133
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:119
constexpr uint8_t watchDogPin
Definition config.h:121
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
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:64
constexpr uint16_t check_relay_pins()
Definition validation.h:137
constexpr bool check_load_priorities()
Definition validation.h:158