19constexpr uint32_t MINUTE{ 60UL * 1000UL };
20constexpr uint32_t HOUR{ 60UL * MINUTE };
32 TEST_ASSERT_EQUAL_UINT16(120,
HOURS(2).value);
33 TEST_ASSERT_EQUAL_UINT16(720,
HOURS(12).value);
34 TEST_ASSERT_EQUAL_UINT16(90,
MINUTES(90).value);
39 TEST_ASSERT_EQUAL_UINT32(0, DualTariff::windowStart(
FIRST(
HOURS(2)), 8));
40 TEST_ASSERT_EQUAL_UINT32(7200000UL, DualTariff::windowEnd(
FIRST(
HOURS(2)), 8));
45 TEST_ASSERT_EQUAL_UINT32(21600000UL, DualTariff::windowStart(
LAST(
HOURS(2)), 8));
46 TEST_ASSERT_EQUAL_UINT32(UINT32_MAX, DualTariff::windowEnd(
LAST(
HOURS(2)), 8));
52 TEST_ASSERT_EQUAL_UINT32(7200000UL, DualTariff::windowStart(w, 8));
53 TEST_ASSERT_EQUAL_UINT32(14400000UL, DualTariff::windowEnd(w, 8));
59 TEST_ASSERT_EQUAL_UINT32(18000000UL, DualTariff::windowStart(w, 8));
60 TEST_ASSERT_EQUAL_UINT32(23400000UL, DualTariff::windowEnd(w, 8));
66 TEST_ASSERT_EQUAL_UINT32(3600000UL, DualTariff::windowStart(w, 8));
67 TEST_ASSERT_EQUAL_UINT32(UINT32_MAX, DualTariff::windowEnd(w, 8));
72 TEST_ASSERT_EQUAL_UINT32(0, DualTariff::windowStart(
LAST(
HOURS(12)), 12));
73 TEST_ASSERT_EQUAL_UINT32(43140000UL, DualTariff::windowStart(
LAST(
MINUTES(1)), 12));
74 TEST_ASSERT_EQUAL_UINT32(43200000UL, DualTariff::windowEnd(
FIRST(
HOURS(12)), 12));
81 for (uint8_t hours = 3; hours <= 12; ++hours)
84 TEST_ASSERT_EQUAL_UINT32((hours - 3) * HOUR, DualTariff::windowStart(a, hours));
85 TEST_ASSERT_EQUAL_UINT32((hours - 1) * HOUR, DualTariff::windowEnd(a, hours));
86 TEST_ASSERT_TRUE(DualTariff::startsWithinOffPeak(a, hours));
87 TEST_ASSERT_TRUE(DualTariff::endsWithinOffPeak(a, hours));
90 TEST_ASSERT_EQUAL_UINT32(hours * HOUR - 90 * MINUTE, DualTariff::windowStart(b, hours));
91 TEST_ASSERT_EQUAL_UINT32(hours * HOUR - 30 * MINUTE, DualTariff::windowEnd(b, hours));
100 TEST_ASSERT_FALSE(DualTariff::endsWithinOffPeak(w, 12));
105 TEST_ASSERT_TRUE(DualTariff::startsWithinOffPeak(
FIRST(
HOURS(10)), 8));
106 TEST_ASSERT_TRUE(DualTariff::startsWithinOffPeak(
LAST(
HOURS(8)), 8));
107 TEST_ASSERT_FALSE(DualTariff::startsWithinOffPeak(
LAST(
MINUTES(481)), 8));
108 TEST_ASSERT_FALSE(DualTariff::startsWithinOffPeak(
LAST(
MINUTES(0)), 8));
115 TEST_ASSERT_FALSE(DualTariff::endsWithinOffPeak(
FIRST(
HOURS(10)), 8));
116 TEST_ASSERT_TRUE(DualTariff::endsWithinOffPeak(
FIRST(
HOURS(8)), 8));
121 TEST_ASSERT_TRUE(DualTariff::endsWithinOffPeak(
LAST(
HOURS(8)), 8));
123 TEST_ASSERT_TRUE(DualTariff::endsWithinOffPeak(
FIRST(
HOURS(12)), 12));
128 TEST_ASSERT_FALSE(DualTariff::hasLength(
FIRST(
MINUTES(0))));
130 TEST_ASSERT_TRUE(DualTariff::hasLength(
LAST(
HOURS(2))));
135 static_assert(DualTariff::windowEnd(
FIRST(
HOURS(2)), 8) == 7200000UL,
"computed at compile time");
142 const uint32_t start{ DualTariff::windowStart(w, 8) };
143 const uint32_t end{ DualTariff::windowEnd(w, 8) };
145 TEST_ASSERT_FALSE(DualTariff::inWindow(2 * HOUR - 1, start, end));
146 TEST_ASSERT_TRUE(DualTariff::inWindow(2 * HOUR, start, end));
147 TEST_ASSERT_TRUE(DualTariff::inWindow(5 * HOUR - 1, start, end));
148 TEST_ASSERT_FALSE(DualTariff::inWindow(5 * HOUR, start, end));
149 TEST_ASSERT_TRUE(DualTariff::inWindow(UINT32_MAX - 1, DualTariff::windowStart(
LAST(
HOURS(2)), 8), DualTariff::windowEnd(
LAST(
HOURS(2)), 8)));
154 const uint32_t offPeakStart{ UINT32_MAX - MINUTE + 1 };
155 const uint32_t start{ DualTariff::windowStart(
LAST(
HOURS(3)), 8) };
156 const uint32_t end{ DualTariff::windowEnd(
LAST(
HOURS(3)), 8) };
158 const uint32_t at6h{ offPeakStart + 6 * HOUR };
159 const uint32_t at4h{ offPeakStart + 4 * HOUR };
161 TEST_ASSERT_TRUE(at6h < offPeakStart);
162 TEST_ASSERT_TRUE(DualTariff::inWindow(at6h - offPeakStart, start, end));
163 TEST_ASSERT_FALSE(DualTariff::inWindow(at4h - offPeakStart, start, end));
175static_assert(boosts.size() == 4);
180 TEST_ASSERT_EQUAL_UINT16((1U << 5) | (1U << 7), boosts.getLocalBitmask(0));
181 TEST_ASSERT_EQUAL_UINT8(0, boosts.getRemoteBitmask(0));
182 TEST_ASSERT_EQUAL_UINT16(0, boosts.getLocalBitmask(1));
183 TEST_ASSERT_EQUAL_UINT8(0b10, boosts.getRemoteBitmask(1));
188 TEST_ASSERT_EQUAL_UINT32(3600000UL, DualTariff::resolve(boosts, 2, 8).start);
189 TEST_ASSERT_EQUAL_UINT32(UINT32_MAX, DualTariff::resolve(boosts, 2, 8).end);
194 constexpr auto b{ DualTariff::resolve(boosts, 3, 8) };
195 static_assert(b.start == 18000000UL && b.end == 23400000UL && b.local == (1U << 9) && b.remote == 0);
196 TEST_ASSERT_EQUAL_UINT32(18000000UL, b.start);
201 TEST_ASSERT_TRUE(boosts.getLocalBitmask(0) & boosts.getLocalBitmask(2));
207 static_assert(none.size() == 0);
208 TEST_ASSERT_EQUAL_UINT8(0, none.size());
222 static_assert(fromSettings.size() == 2);
223 TEST_ASSERT_EQUAL_UINT16((1U << 5) | (1U << 8), fromSettings.getLocalBitmask(0));
224 TEST_ASSERT_EQUAL_UINT8(0, fromSettings.getRemoteBitmask(0));
225 TEST_ASSERT_EQUAL_UINT16(0, fromSettings.getLocalBitmask(1));
226 TEST_ASSERT_EQUAL_UINT8(0b1, fromSettings.getRemoteBitmask(1));
227 TEST_ASSERT_EQUAL_UINT16(90, fromSettings.getWindow(1).start.minutes);
228 TEST_ASSERT_TRUE(fromSettings.getWindow(1).start.fromEnd);
238 static_assert(none.size() == 0);
239 TEST_ASSERT_EQUAL_UINT8(0, none.size());
247 TEST_ASSERT_EQUAL_UINT32(
static_cast< uint32_t
>(-60) * 60000UL, DualTariff::windowStart(w, 1));
The scheduled boosts: a window and the bitmasks of its targets, for each entry.
The relays, as in config.h: the sliding average and the settings of each relay.
The scheduled boosts, as in config.h: each window with the targets it forces.
What the target codes of config.h stand for, once the load map and the relays are known.
constexpr RelayEngine relays
constexpr BoostStart BEFORE_END(const Minutes m)
A start m before the end of the off-peak period.
constexpr uint8_t REMOTE_PIN_BASE
Base value for virtual pins representing remote loads.
constexpr BoostLength FOR(const Minutes m)
A boost lasting m.
constexpr BoostWindow FIRST(const Minutes d)
The first d of the off-peak period.
constexpr BoostWindow LAST(const Minutes d)
The last d of the off-peak period, until the end.
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.
constexpr uint8_t RELAY(const uint8_t relayNum)
Relay relayNum of relays (0, no relay, if out of range or without relay diversion).
constexpr uint8_t LOAD(const uint8_t loadNum)
Load loadNum of physicalLoadPin[], local or remote (0, no load, if out of range).
constexpr uint8_t local(uint8_t pin)
Declares a load driven locally by the router.
constexpr uint8_t remote(uint8_t unit, uint8_t ledPin=0)
Declares a load driven by a remote unit over RF.
void test_until_the_end_has_no_end(void)
void test_from_start_for(void)
void test_boost_window_includes_its_start_and_excludes_its_end(void)
void test_without_for_lasts_until_the_end(void)
void test_ends_within_off_peak(void)
void test_hours_and_minutes(void)
void test_boost_window_across_the_millis_wraparound(void)
void test_a_target_may_be_in_several_boosts(void)
void test_first_starts_at_the_start_and_lasts_its_duration(void)
void test_before_end_for(void)
void test_before_end_from_3_to_12_hours(void)
void test_no_boost_in_the_settings(void)
void test_targets_become_masks(void)
void test_twelve_hours(void)
void test_boosts_from_the_settings(void)
void test_last_starts_back_from_the_end_and_has_no_end(void)
void test_starts_within_off_peak(void)
void test_an_empty_list(void)
void test_a_start_before_the_period_wraps_to_a_large_value(void)
void test_for_the_largest_minutes_is_not_until_the_end(void)
void test_boost_windows_are_computed_at_compile_time(void)
void test_a_boost_of_zero_minutes_has_no_length(void)
How long a boost lasts, in minutes, or UNTIL_THE_END.
When a load is boosted during the off-peak period.
The settings of one relay, as in config.h: { pin, surplus, import, minON, minOFF }...
#define MINUTES(value)
A compile-time number of minutes, as an integral_constant.
#define HOURS(value)
A compile-time number of hours, as MINUTES().
Some utility functions for dual tariff feature.
Compile-time utilities for managing override pins and index-to-bitmask mapping.