3-phase PV router
Loading...
Searching...
No Matches
validation.h
Go to the documentation of this file.
1
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
29static_assert(DATALOG_PERIOD_IN_SECONDS <= 40, "**** Data log duration is too long and will lead to overflow ! ****");
30
31static_assert(TEMP_SENSOR_PRESENT ^ (temperatureSensing.get_pin() == 0xff), "******** Wrong pin value for temperature sensor(s). Please check your config.h ! ********");
32static_assert(DIVERSION_PIN_PRESENT ^ (diversionPin == 0xff), "******** Wrong pin value for diversion command. Please check your config.h ! ********");
33static_assert((PRIORITY_ROTATION == RotationModes::PIN) ^ (rotationPin == 0xff), "******** Wrong pin value for rotation command. Please check your config.h ! ********");
34static_assert(OVERRIDE_PIN_PRESENT ^ (forcePin == 0xff), "******** Wrong pin value for override command. Please check your config.h ! ********");
35static_assert(WATCHDOG_PIN_PRESENT ^ (watchDogPin == 0xff), "******** Wrong pin value for watchdog. Please check your config.h ! ********");
36
37static_assert(DUAL_TARIFF ^ (dualTariffPin == 0xff), "******** Wrong pin value for dual tariff. Please check your config.h ! ********");
38static_assert(!DUAL_TARIFF | (ul_OFF_PEAK_DURATION == 0), "******** Off-peak duration cannot be zero. Please check your config.h ! ********");
39static_assert(!(DUAL_TARIFF & (ul_OFF_PEAK_DURATION > 12)), "******** Off-peak duration cannot last more than 12 hours. Please check your config.h ! ********");
40
41static_assert(!EMONESP_CONTROL || (DIVERSION_PIN_PRESENT && DIVERSION_PIN_PRESENT && (PRIORITY_ROTATION == RotationModes::PIN) && OVERRIDE_PIN_PRESENT), "******** Wrong configuration. Please check your config.h ! ********");
42
43static_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 ! ********");
44
45static_assert(NO_OF_DUMPLOADS > 0, "Number of dump loads must be greater than 0");
46static_assert(iTemperatureThreshold > 0, "Temperature threshold must be greater than 0");
47static_assert(iTemperatureThreshold <= 100, "Temperature threshold must be lower than 100");
48
50{
51 uint16_t used_pins{ 0 };
52
53 if constexpr (TEMP_SENSOR_PRESENT)
54 {
55 if (temperatureSensing.get_pin() != 0xff)
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 return used_pins;
120}
121
123{
124 bool pins_ok{ true };
125
126 for (uint8_t idx = 0; idx < relays.get_size(); ++idx)
127 {
128 const auto relayPin = relays.get_relay(idx).get_pin();
129
130 if constexpr (RELAY_DIVERSION)
131 {
132 pins_ok &= (relayPin != 0xff);
133 }
134 else
135 {
136 pins_ok &= (relayPin == 0xff);
137 }
138 }
139
140 return pins_ok;
141}
142
143constexpr bool check_load_priorities()
144{
145 uint8_t _sum{ 0 };
146 uint16_t _enum_val{ 0 };
147
148 for (const auto &loadPrio : loadPrioritiesAtStartup)
149 {
150 // we check if a prio is used twice
151 if (bit_read(_enum_val, loadPrio))
152 return 0;
153
154 bit_set(_enum_val, loadPrio);
155
156 _sum += loadPrio;
157 }
158
159 // check if we have all prio between 0 and (NO_OF_DUMPLOADS - 1)
160 return _sum == ((NO_OF_DUMPLOADS * (NO_OF_DUMPLOADS - 1)) >> 1);
161}
162
163static_assert(check_load_priorities(), "******** Load Priorities wrong ! Please check your config ! ********");
164static_assert(check_pins(), "******** Duplicate pin definition ! Please check your config ! ********");
165static_assert((check_pins() & B00000011) == 0, "******** Pins 0 & 1 are reserved for RX/TX ! Please check your config ! ********");
166static_assert((check_pins() & 0xC000) == 0, "******** Pins 14 and/or 15 do not exist ! Please check your config ! ********");
167static_assert(!(RF_CHIP_PRESENT && ((check_pins() & 0x3C04) != 0)), "******** Pins from RF chip are reserved ! Please check your config ! ********");
168static_assert(check_relay_pins(), "******** Wrong pin(s) configuration for relay(s) ********");
169
170#endif /* VALIDATION_H */
constexpr auto get_size() const
Get the number of relays.
Definition: utils_relay.h:278
constexpr const auto & get_relay(uint8_t idx) const
Get the relay object.
Definition: utils_relay.h:289
constexpr auto get_pin() const
Get the pin of the sensor(s)
Definition: utils_temp.h:104
Configuration values to be set by the end-user.
constexpr uint8_t loadPrioritiesAtStartup[NO_OF_DUMPLOADS]
Definition: config.h:75
constexpr bool RELAY_DIVERSION
Definition: config.h:53
constexpr bool OVERRIDE_PIN_PRESENT
Definition: config.h:49
constexpr uint8_t dualTariffPin
Definition: config.h:78
constexpr TemperatureSensing temperatureSensing
Definition: config.h:91
constexpr uint8_t forcePin
Definition: config.h:81
constexpr RelayEngine relays
Definition: config.h:84
constexpr uint8_t physicalLoadPin[NO_OF_DUMPLOADS]
Definition: config.h:74
constexpr bool DUAL_TARIFF
Definition: config.h:54
constexpr uint8_t diversionPin
Definition: config.h:79
constexpr bool EMONESP_CONTROL
Definition: config.h:46
constexpr uint8_t NO_OF_DUMPLOADS
Definition: config.h:38
constexpr uint8_t ul_OFF_PEAK_DURATION
Definition: config.h:86
constexpr int16_t iTemperatureThreshold
Definition: config.h:89
constexpr bool WATCHDOG_PIN_PRESENT
Definition: config.h:52
constexpr bool DIVERSION_PIN_PRESENT
Definition: config.h:47
constexpr uint8_t rotationPin
Definition: config.h:80
constexpr uint8_t watchDogPin
Definition: config.h:82
Basic configuration values to be set by the end-user.
constexpr uint16_t
Definition: config_system.h:33
constexpr uint8_t DATALOG_PERIOD_IN_SECONDS
Definition: config_system.h:31
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:46
constexpr uint8_t bit_read(const T &_src, const uint8_t bit)
Read the specified bit.
Definition: utils_pins.h:59
Some utility functions for the RF chip.
constexpr bool RF_CHIP_PRESENT
Definition: utils_rf.h:18
constexpr bool TEMP_SENSOR_PRESENT
Definition: utils_temp.h:23
constexpr uint16_t check_pins()
Definition: validation.h:49
constexpr uint16_t check_relay_pins()
Definition: validation.h:122
constexpr bool check_load_priorities()
Definition: validation.h:143