3-phase PV router
Loading...
Searching...
No Matches
dualtariff.h
Go to the documentation of this file.
1
12
13#ifndef DUALTARIFF_H
14#define DUALTARIFF_H
15
16#include <avr/pgmspace.h>
17
18#include "config_derived.h"
19
20inline uint32_t ul_TimeOffPeak;
21
22inline constexpr uint8_t NO_OF_BOOSTS{ boostSchedule.size() };
23
33{
34 DualTariff::Boost boost[NO_OF_BOOSTS ? NO_OF_BOOSTS : 1];
35};
36
43{
44 BoostTable table{};
45 for (uint8_t i = 0; i != NO_OF_BOOSTS; ++i)
46 {
47 table.boost[i] = DualTariff::resolve(boostSchedule, i, ul_OFF_PEAK_DURATION);
48 }
49 return table;
50}
51
52inline constexpr BoostTable boostTable PROGMEM{ resolveBoosts() };
53
62inline DualTariff::Boost readBoost(const uint8_t i)
63{
64 DualTariff::Boost boost;
65 memcpy_P(&boost, &boostTable.boost[i], sizeof(boost));
66 return boost;
67}
68
74inline void printOffPeakTime(const uint32_t ms)
75{
76 const auto minutes{ static_cast< uint16_t >(ms / 60000UL) };
77 const uint8_t mm{ static_cast< uint8_t >(minutes % 60) };
78
79 info(minutes / 60);
80 info('h');
81 if (mm < 10)
82 {
83 info('0');
84 }
85 info(mm);
86}
87
94{
95 info(F("\tDuration of off-peak period is "));
97 infoln(F(" hours."));
98
99 if constexpr (TEMP_SENSOR_PRESENT)
100 {
101 info(F("\tTemperature threshold is "));
103 info(F(" C, on sensor #")); // ASCII: the IoT output is 7-bit
105 infoln(F("."));
106 }
107 else
108 {
109 infoln(F("\tNo temperature threshold (no temperature sensing)."));
110 }
111
112 for (uint8_t i = 0; i != NO_OF_BOOSTS; ++i)
113 {
114 const auto boost{ readBoost(i) };
115
116 info(F("\tBoost #"));
117 info(i + 1);
118 info(F(": from "));
119 printOffPeakTime(boost.start);
120 if (UINT32_MAX == boost.end)
121 {
122 info(F(" until the end"));
123 }
124 else
125 {
126 info(F(" to "));
127 printOffPeakTime(boost.end);
128 }
129 info(F(" of off-peak, forcing "));
130
131 bool first{ true };
132 for (uint8_t pin = 0; pin != LOCAL_MASK_BITS; ++pin)
133 {
134 if (bit_read(boost.local, pin))
135 {
136 if (!first)
137 {
138 info(F(", "));
139 }
140 first = false;
141 info('D');
142 info(pin);
143 }
144 }
145 for (uint8_t n = 0; n != REMOTE_MASK_BITS; ++n)
146 {
147 if (bit_read(boost.remote, n))
148 {
149 if (!first)
150 {
151 info(F(", "));
152 }
153 first = false;
154 info(F("remote load "));
155 info(n + 1);
156 }
157 }
158 if (first)
159 {
160 info(F("nothing"));
161 }
162 infoln('.');
163 }
164}
165
166#endif /* DUALTARIFF_H */
constexpr uint8_t ul_OFF_PEAK_DURATION
Definition config.h:159
constexpr bool TEMP_SENSOR_PRESENT
Definition config.h:65
constexpr int16_t iTemperatureThreshold
Definition config.h:174
constexpr uint8_t BOOST_TEMP_SENSOR
Definition config.h:175
The configuration as the firmware uses it: the settings, and what is built from them.
constexpr BoostSchedule boostSchedule
constexpr uint8_t REMOTE_MASK_BITS
constexpr uint8_t LOCAL_MASK_BITS
void infoln(const Args &... args)
Print an informational message and a line end, as Serial.println() does.
Definition debug.h:67
void info(const Args &... args)
Print an informational message, as Serial.print() does.
Definition debug.h:57
constexpr BoostTable boostTable PROGMEM
Definition dualtariff.h:52
uint32_t ul_TimeOffPeak
Definition dualtariff.h:20
constexpr uint8_t NO_OF_BOOSTS
Definition dualtariff.h:22
uint8_t i
constexpr BoostTable resolveBoosts()
Resolves each scheduled boost, at compile time.
Definition dualtariff.h:42
void printDualTariffConfiguration()
Print the settings for off-peak period.
Definition dualtariff.h:93
void printOffPeakTime(const uint32_t ms)
Prints a time in ms from the start of the off-peak period, as <h>h<mm>.
Definition dualtariff.h:74
DualTariff::Boost readBoost(const uint8_t i)
Reads scheduled boost i from flash.
Definition dualtariff.h:62
The scheduled boosts, resolved for the off-peak duration: window in ms and target masks.
Definition dualtariff.h:33
DualTariff::Boost boost[NO_OF_BOOSTS ? NO_OF_BOOSTS :1]
Definition dualtariff.h:34
constexpr uint8_t bit_read(const T &_src, const uint8_t bit)
Read the specified bit.
Definition utils_bits.h:44