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
46{
47 uint16_t used_pins{ 0 };
48
49 if constexpr (TEMP_SENSOR_PRESENT)
50 {
51 if (temperatureSensing.get_pin() != 0xff)
53 }
54
55 if (diversionPin != 0xff)
56 {
57 if (bit_read(used_pins, diversionPin))
58 return 0;
59
60 bit_set(used_pins, diversionPin);
61 }
62
63 if (rotationPin != 0xff)
64 {
65 if (bit_read(used_pins, rotationPin))
66 return 0;
67
68 bit_set(used_pins, rotationPin);
69 }
70
71 if (forcePin != 0xff)
72 {
73 if (bit_read(used_pins, forcePin))
74 return 0;
75
76 bit_set(used_pins, forcePin);
77 }
78
79 if (watchDogPin != 0xff)
80 {
81 if (bit_read(used_pins, watchDogPin))
82 return 0;
83
84 bit_set(used_pins, watchDogPin);
85 }
86
87 //physicalLoadPin for the TRIACS
88 for (const auto &loadPin : physicalLoadPin)
89 {
90 if (loadPin == 0xff)
91 return 0;
92
93 if (bitRead(used_pins, loadPin))
94 return 0;
95
96 bit_set(used_pins, loadPin);
97 }
98
99 if constexpr (RELAY_DIVERSION)
100 {
101 for (uint8_t idx = 0; idx < relays.get_size(); ++idx)
102 {
103 const auto relayPin = relays.get_relay(idx).get_pin();
104
105 if (relayPin != 0xff)
106 {
107 if (bitRead(used_pins, relayPin))
108 return 0;
109
110 bit_set(used_pins, relayPin);
111 }
112 }
113 }
114
115 return used_pins;
116}
117
119{
120 bool pins_ok{ true };
121
122 for (uint8_t idx = 0; idx < relays.get_size(); ++idx)
123 {
124 const auto relayPin = relays.get_relay(idx).get_pin();
125
126 if constexpr (RELAY_DIVERSION)
127 {
128 pins_ok &= (relayPin != 0xff);
129 }
130 else
131 {
132 pins_ok &= (relayPin == 0xff);
133 }
134 }
135
136 return pins_ok;
137}
138
139constexpr bool check_load_priorities()
140{
141 uint8_t _sum{ 0 };
142 uint16_t _enum_val{ 0 };
143
144 for (const auto &loadPrio : loadPrioritiesAtStartup)
145 {
146 // we check if a prio is used twice
147 if (bit_read(_enum_val, loadPrio))
148 return 0;
149
150 bit_set(_enum_val, loadPrio);
151
152 _sum += loadPrio;
153 }
154
155 // check if we have all prio between 0 and (NO_OF_DUMPLOADS - 1)
156 return _sum == ((NO_OF_DUMPLOADS * (NO_OF_DUMPLOADS - 1)) >> 1);
157}
158
159static_assert(check_load_priorities(), "******** Load Priorities wrong ! Please check your config ! ********");
160static_assert(check_pins(), "******** Duplicate pin definition ! Please check your config ! ********");
161static_assert((check_pins() & B00000011) == 0, "******** Pins 0 & 1 are reserved for RX/TX ! Please check your config ! ********");
162static_assert((check_pins() & 0xC000) == 0, "******** Pins 14 and/or 15 do not exist ! Please check your config ! ********");
163static_assert(!(RF_CHIP_PRESENT && ((check_pins() & 0x3C04) != 0)), "******** Pins from RF chip are reserved ! Please check your config ! ********");
164static_assert(check_relay_pins(), "******** Wrong pin(s) configuration for relay(s) ********");
165
166#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 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:32
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:45
constexpr uint16_t check_relay_pins()
Definition: validation.h:118
constexpr bool check_load_priorities()
Definition: validation.h:139