15#ifndef UTILS_DUALTARIFF_H
16#define UTILS_DUALTARIFF_H
31template< u
int8_t N, u
int8_t MaxPins = 16 >
48 for (uint8_t
i = 0;
i < N; ++
i)
50 entries_[
i] = { boosts[
i].window, boosts[
i].targets.toLocalBitmask(), boosts[
i].targets.toRemoteBitmask() };
55 template<
typename Map >
58 for (uint8_t
i = 0;
i < N; ++
i)
65 constexpr uint8_t
size()
const
90template< u
int8_t MaxPins >
97 template<
typename Map >
124template< u
int8_t MaxPins, u
int8_t N >
132template< u
int8_t N, u
int8_t MaxPins,
typename Map >
148constexpr bool inWindow(
const uint32_t elapsed,
const uint32_t start,
const uint32_t end)
150 return (elapsed >= start) && (elapsed < end);
164 return minutes * 60000UL;
184 const int32_t periodInMin{
static_cast< int32_t
>(offPeakHours * 60L) };
193 return (startInMin >= 0) && (startInMin < offPeakHours * 60L);
227template< u
int8_t N, u
int8_t MaxPins >
constexpr BoostSchedule(const ScheduledBoosts< 0, MaxPins > &, const Map &)
No boost in config.h either.
constexpr uint8_t size() const
constexpr BoostSchedule()=default
constexpr uint16_t getLocalBitmask(uint8_t) const
constexpr BoostWindow getWindow(uint8_t) const
constexpr uint8_t getRemoteBitmask(uint8_t) const
The scheduled boosts: a window and the bitmasks of its targets, for each entry.
constexpr BoostSchedule(const ScheduledBoosts< N, MaxPins > &boosts, const Map &map)
Builds the boosts of config.h, their codes turned into pins by map (a TargetMap).
constexpr uint8_t size() const
The number of boosts.
constexpr uint8_t getRemoteBitmask(uint8_t i) const
The remote bitmask of boost i, or 0 if out of bounds.
constexpr BoostSchedule(const BoostEntry< MaxPins >(&boosts)[N])
Builds the boosts from their entries, with plain pins.
constexpr BoostWindow getWindow(uint8_t i) const
The window of boost i, or a window of length 0 if out of bounds.
constexpr uint16_t getLocalBitmask(uint8_t i) const
The local bitmask of boost i, or 0 if out of bounds.
The scheduled boosts, as in config.h: each window with the targets it forces.
constexpr const PinList< MaxPins > & getTargets(const uint8_t i) const
The targets of boost i, as codes.
constexpr BoostWindow getWindow(const uint8_t i) const
The window of boost i.
What config.h is written with: its types, constants and helpers.
constexpr BoostStart FROM_START(const Minutes m)
A start m after the beginning of the off-peak period.
constexpr uint16_t UNTIL_THE_END
The length of a boost that only the meter ends: the end of the off-peak period stops it anyway.
The windows of the scheduled boosts, in milliseconds from the start of the off-peak period.
constexpr Boost resolve(const BoostSchedule< N, MaxPins > &boosts, const uint8_t i, const uint8_t offPeakHours)
Boost i of boosts, for an off-peak period of offPeakHours.
constexpr bool hasLength(const BoostWindow &window)
Whether the boost lasts at all: a length of 0 is no boost.
constexpr bool inWindow(const uint32_t elapsed, const uint32_t start, const uint32_t end)
Whether the boost is in its window.
constexpr uint32_t windowEnd(const BoostWindow &window, const uint8_t offPeakHours)
The end of the boost window (excluded), in ms from the start of the off-peak period.
constexpr uint32_t windowStart(const BoostWindow &window, const uint8_t offPeakHours)
The start of the boost window, in ms from the start of the off-peak period.
constexpr int32_t startInMinutes(const BoostWindow &window, const uint8_t offPeakHours)
The start of the window, in minutes from the start of the off-peak period: negative if before it.
constexpr bool startsWithinOffPeak(const BoostWindow &window, const uint8_t offPeakHours)
Whether the window starts within the off-peak period: otherwise, it would never open.
constexpr bool endsWithinOffPeak(const BoostWindow &window, const uint8_t offPeakHours)
Whether a window with FOR() ends within the off-peak period (its end may be the end of the period): a...
When a set of loads is boosted: a window and the targets.
How long a boost lasts, in minutes, or UNTIL_THE_END.
When a load is boosted during the off-peak period.
A boost resolved for a given off-peak duration: its window in ms and its target masks.
#define MINUTES(value)
A compile-time number of minutes, as an integral_constant.
BoostSchedule() -> BoostSchedule< 0 >
Deduction guide: no argument, no boost.