3-phase PV router
Loading...
Searching...
No Matches
override_masks.h
Go to the documentation of this file.
1
22
23#ifndef OVERRIDE_MASKS_H
24#define OVERRIDE_MASKS_H
25
26#include <stdint.h>
27
28#include "utils_dualtariff.h" // DualTariff::Boost, DualTariff::inWindow()
29
40{
41 uint16_t local;
42 uint8_t remote;
43};
44
47{
48 return { static_cast< uint16_t >(a.local | b.local), static_cast< uint8_t >(a.remote | b.remote) };
49}
50
51namespace Forcing
52{
60template< typename Pins, typename IsActive >
61inline OverrideMasks pinForcing(const Pins& pins, IsActive isActive)
62{
63 OverrideMasks masks{ 0, 0 };
64
65 if (0 == pins.size())
66 {
67 return masks;
68 }
69
70 // a do-while, as before the move: a for loop costs 22 bytes more on the AVR
71 uint8_t i{ pins.size() };
72 do
73 {
74 --i;
75 if (isActive(pins.getPin(i)))
76 {
77 masks.local |= pins.getLocalBitmask(i);
78 masks.remote |= pins.getRemoteBitmask(i);
79 }
80 } while (i);
81 return masks;
82}
83
100template< typename ReadBoost >
101inline OverrideMasks boostForcing(const bool bOffPeak, const uint32_t elapsed, const int16_t temperature_x100,
102 const int16_t threshold_x100, const uint8_t count, ReadBoost readBoost)
103{
104 if (!bOffPeak)
105 {
106 return { 0, 0 };
107 }
108
109 if (temperature_x100 > threshold_x100)
110 {
111 return { 0, 0 };
112 }
113
114 OverrideMasks forcing{ 0, 0 };
115 for (uint8_t i = 0; i != count; ++i)
116 {
117 const DualTariff::Boost boost{ readBoost(i) };
118
119 if (DualTariff::inWindow(elapsed, boost.start, boost.end))
120 {
121 forcing.local |= boost.local;
122 forcing.remote |= boost.remote;
123 }
124 }
125 return forcing;
126}
127} // namespace Forcing
128
129#endif // OVERRIDE_MASKS_H
uint8_t i
DualTariff::Boost readBoost(const uint8_t i)
Reads scheduled boost i from flash.
Definition dualtariff.h:62
OverrideMasks boostForcing(const bool bOffPeak, const uint32_t elapsed, const int16_t temperature_x100, const int16_t threshold_x100, const uint8_t count, ReadBoost readBoost)
The targets of the scheduled boosts whose window is open.
OverrideMasks pinForcing(const Pins &pins, IsActive isActive)
The targets of the override pins that are active (held LOW).
constexpr OverrideMasks operator|(const OverrideMasks &a, const OverrideMasks &b)
Both masks of a and b: what either forces.
Holds both local and remote override bitmasks.
Some utility functions for dual tariff feature.