1-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
18#include "config.h"
19
27
28static_assert(DATALOG_PERIOD_IN_SECONDS <= 40, "**** Data log duration is too long and will lead to overflow ! ****");
29
30static_assert(TEMP_SENSOR_PRESENT ^ (temperatureSensing.get_pin() == 0xff), "******** Wrong pin value for temperature sensor(s). Please check your config.h ! ********");
31static_assert(DIVERSION_PIN_PRESENT ^ (diversionPin == 0xff), "******** Wrong pin value for diversion command. Please check your config.h ! ********");
32static_assert((PRIORITY_ROTATION == RotationModes::PIN) ^ (rotationPin == 0xff), "******** Wrong pin value for rotation command. Please check your config.h ! ********");
33static_assert(OVERRIDE_PIN_PRESENT ^ (forcePin == 0xff), "******** Wrong pin value for override command. Please check your config.h ! ********");
34static_assert(WATCHDOG_PIN_PRESENT ^ (watchDogPin == 0xff), "******** Wrong pin value for watchdog. Please check your config.h ! ********");
35
36static_assert(DUAL_TARIFF ^ (dualTariffPin == 0xff), "******** Wrong pin value for dual tariff. Please check your config.h ! ********");
37static_assert(!DUAL_TARIFF | (ul_OFF_PEAK_DURATION == 0), "******** Off-peak duration cannot be zero. Please check your config.h ! ********");
38static_assert(!(DUAL_TARIFF & (ul_OFF_PEAK_DURATION > 12)), "******** Off-peak duration cannot last more than 12 hours. Please check your config.h ! ********");
39
40static_assert(!EMONESP_CONTROL || (DIVERSION_PIN_PRESENT && DIVERSION_PIN_PRESENT && (PRIORITY_ROTATION == RotationModes::PIN) && OVERRIDE_PIN_PRESENT), "******** Wrong configuration. Please check your config.h ! ********");
41
42static_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 ! ********");
43
44static_assert(NO_OF_DUMPLOADS > 0, "Number of dump loads must be greater than 0");
45
46static_assert(iTemperatureThreshold > 0, "Temperature threshold must be greater than 0");
47static_assert(iTemperatureThreshold <= 100, "Temperature threshold must be lower than 100");
48
49constexpr uint16_t check_pins()
50{
51 uint32_t used_pins{ 0 };
52
53 if constexpr (TEMP_SENSOR_PRESENT)
54 {
55 if (temperatureSensing.get_pin() != 0xff)
56 bit_set(used_pins, temperatureSensing.get_pin());
57 }
58
59 if (diversionPin != 0xff)
60 {
61 if (bit_read(used_pins, diversionPin))
62 return 0;
63
64 bit_set(used_pins, diversionPin);
65 }
66
67 if (rotationPin != 0xff)
68 {
69 if (bit_read(used_pins, rotationPin))
70 return 0;
71
72 bit_set(used_pins, rotationPin);
73 }
74
75 if (forcePin != 0xff)
76 {
77 if (bit_read(used_pins, forcePin))
78 return 0;
79
80 bit_set(used_pins, forcePin);
81 }
82
83 if (watchDogPin != 0xff)
84 {
85 if (bit_read(used_pins, watchDogPin))
86 return 0;
87
88 bit_set(used_pins, watchDogPin);
89 }
90
91 //physicalLoadPin for the TRIACS
92 for (const auto &loadPin : physicalLoadPin)
93 {
94 if (loadPin == 0xff)
95 return 0;
96
97 if (bit_read(used_pins, loadPin))
98 return 0;
99
100 bit_set(used_pins, loadPin);
101 }
102
103 if constexpr (RELAY_DIVERSION)
104 {
105 for (uint8_t idx = 0; idx < relays.get_size(); ++idx)
106 {
107 const auto relayPin = relays.get_relay(idx).get_pin();
108
109 if (relayPin != 0xff)
110 {
111 if (bit_read(used_pins, relayPin))
112 return 0;
113
114 bit_set(used_pins, relayPin);
115 }
116 }
117 }
118
119 if constexpr (TYPE_OF_DISPLAY == DisplayType::SEG)
120 {
121 for (const auto &segPin : digitSelectorPin)
122 {
123 if (segPin == 0xff)
124 return 0;
125
126 if (bit_read(used_pins, segPin))
127 return 0;
128
129 bit_set(used_pins, segPin);
130 }
131 for (const auto &segPin : segmentDrivePin)
132 {
133 if (segPin == 0xff)
134 return 0;
135
136 if (bit_read(used_pins, segPin))
137 return 0;
138
139 bit_set(used_pins, segPin);
140 }
141 }
142 else if constexpr (TYPE_OF_DISPLAY == DisplayType::SEG_HW)
143 {
144 for (const auto &segPin : digitLocationLine)
145 {
146 if (segPin == 0xff)
147 return 0;
148
149 if (bit_read(used_pins, segPin))
150 return 0;
151
152 bit_set(used_pins, segPin);
153 }
154 for (const auto &segPin : digitSelectionLine)
155 {
156 if (segPin == 0xff)
157 return 0;
158
159 if (bit_read(used_pins, segPin))
160 return 0;
161
162 bit_set(used_pins, segPin);
163 }
164 }
165
166 return used_pins;
167}
168
169constexpr uint16_t check_relay_pins()
170{
171 bool pins_ok{ true };
172
173 for (uint8_t idx = 0; idx < relays.get_size(); ++idx)
174 {
175 const auto relayPin = relays.get_relay(idx).get_pin();
176
177 if constexpr (RELAY_DIVERSION)
178 {
179 pins_ok &= (relayPin != 0xff);
180 }
181 else
182 {
183 pins_ok &= (relayPin == 0xff);
184 }
185 }
186
187 return pins_ok;
188}
189
190constexpr bool check_load_priorities()
191{
192 uint8_t _sum{ 0 };
193 uint16_t _enum_val{ 0 };
194
195 for (const auto &loadPrio : loadPrioritiesAtStartup)
196 {
197 // we check if a prio is used twice
198 if (bit_read(_enum_val, loadPrio))
199 return 0;
200
201 bit_set(_enum_val, loadPrio);
202
203 _sum += loadPrio;
204 }
205
206 // check if we have all prio between 0 and (NO_OF_DUMPLOADS - 1)
207 return _sum == ((NO_OF_DUMPLOADS * (NO_OF_DUMPLOADS - 1)) >> 1);
208}
209
210static_assert(check_load_priorities(), "******** Load Priorities wrong ! Please check your config ! ********");
211static_assert(check_pins(), "******** Duplicate pin definition ! Please check your config ! ********");
212static_assert((check_pins() & B00000011) == 0, "******** Pins 0 & 1 are reserved for RX/TX ! Please check your config ! ********");
213//static_assert((check_pins() & 0xC000) == 0, "******** Pins 14 and/or 15 do not exist ! Please check your config ! ********");
214//static_assert(!(RF_CHIP_PRESENT && ((check_pins() & 0x3C04) != 0)), "******** Pins from RF chip are reserved ! Please check your config ! ********");
215static_assert(check_relay_pins(), "******** Wrong pin(s) configuration for relay(s) ********");
216
217#endif /* VALIDATION_H */
Configuration values to be set by the end-user.
constexpr uint8_t loadPrioritiesAtStartup[NO_OF_DUMPLOADS]
Definition config.h:69
constexpr bool RELAY_DIVERSION
Definition config.h:43
constexpr bool OVERRIDE_PIN_PRESENT
Definition config.h:40
constexpr uint8_t dualTariffPin
Definition config.h:73
constexpr TemperatureSensing temperatureSensing
Definition config.h:89
constexpr uint8_t forcePin
Definition config.h:76
constexpr RelayEngine relays
Definition config.h:79
constexpr uint8_t physicalLoadPin[NO_OF_DUMPLOADS]
Definition config.h:68
constexpr bool DUAL_TARIFF
Definition config.h:44
constexpr uint8_t diversionPin
Definition config.h:74
constexpr bool EMONESP_CONTROL
Definition config.h:37
constexpr uint8_t NO_OF_DUMPLOADS
Definition config.h:35
constexpr DisplayType TYPE_OF_DISPLAY
Definition config.h:51
constexpr uint8_t ul_OFF_PEAK_DURATION
Definition config.h:83
constexpr bool TEMP_SENSOR_PRESENT
Definition config.h:45
constexpr int16_t iTemperatureThreshold
Definition config.h:88
constexpr bool WATCHDOG_PIN_PRESENT
Definition config.h:42
constexpr bool DIVERSION_PIN_PRESENT
Definition config.h:38
constexpr uint8_t rotationPin
Definition config.h:75
constexpr uint8_t watchDogPin
Definition config.h:77
Basic configuration values to be set by the end-user.
constexpr uint8_t DATALOG_PERIOD_IN_SECONDS
constexpr uint8_t digitLocationLine[noOfDigitLocationLines]
constexpr uint8_t digitSelectionLine[noOfDigitSelectionLines]
constexpr uint8_t digitSelectorPin[noOfDigitLocations]
constexpr uint8_t segmentDrivePin[noOfSegmentsPerDigit]
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 uint16_t check_pins()
Definition validation.h:49
constexpr uint16_t check_relay_pins()
Definition validation.h:169
constexpr bool check_load_priorities()
Definition validation.h:190