31 TEST_ASSERT_EQUAL((1U << 2) | (1U << 4) | (1U << 7), mask);
37 TEST_ASSERT_EQUAL(0b01111000, mask);
42 constexpr uint16_t mask =
indicesToBitmask< 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 >();
43 TEST_ASSERT_EQUAL(0xFFFF, mask);
55 TEST_ASSERT_TRUE((
are_pins_valid< 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 >()));
84 TEST_ASSERT_EQUAL(0, list.count);
85 TEST_ASSERT_EQUAL(0, list.toLocalBitmask());
91 TEST_ASSERT_EQUAL(3, list.count);
92 TEST_ASSERT_EQUAL(3, list.pins[0]);
93 TEST_ASSERT_EQUAL(6, list.pins[1]);
94 TEST_ASSERT_EQUAL(9, list.pins[2]);
100 TEST_ASSERT_EQUAL(1, list.count);
101 TEST_ASSERT_EQUAL(7, list.pins[0]);
102 TEST_ASSERT_EQUAL(1U << 7, list.toLocalBitmask());
108 TEST_ASSERT_EQUAL(4, list.count);
109 TEST_ASSERT_EQUAL((1U << 2) | (1U << 5) | (1U << 8) | (1U << 11), list.toLocalBitmask());
115 constexpr uint16_t expected = (1U << 2) | (1U << 5) | (1U << 8);
116 TEST_ASSERT_EQUAL(expected, list.toLocalBitmask());
121 constexpr PinList< 8 > list{
static_cast< uint16_t
>(0b10100100) };
122 TEST_ASSERT_EQUAL(3, list.count);
123 TEST_ASSERT_EQUAL(2, list.pins[0]);
124 TEST_ASSERT_EQUAL(5, list.pins[1]);
125 TEST_ASSERT_EQUAL(7, list.pins[2]);
126 TEST_ASSERT_EQUAL(0b10100100, list.toLocalBitmask());
131 constexpr PinList< 4 > list{
static_cast< uint16_t
>(0) };
132 TEST_ASSERT_EQUAL(0, list.count);
133 TEST_ASSERT_EQUAL(0, list.toLocalBitmask());
138 constexpr PinList< 16 > list{
static_cast< uint16_t
>(0xFFFF) };
139 TEST_ASSERT_EQUAL(16, list.count);
140 TEST_ASSERT_EQUAL(0xFFFF, list.toLocalBitmask());
152 TEST_ASSERT_EQUAL(2, pair.pin);
160 TEST_ASSERT_EQUAL((1U << 4) | (1U << 5) | (1U << 6), pair.getLocalBitmask());
166 TEST_ASSERT_EQUAL(10, pair.pin);
167 TEST_ASSERT_EQUAL(1U << 7, pair.getLocalBitmask());
173 TEST_ASSERT_EQUAL(3, pair.pin);
174 TEST_ASSERT_EQUAL(0b11110000, pair.getLocalBitmask());
187 TEST_ASSERT_EQUAL(1, pins.size());
188 TEST_ASSERT_EQUAL(9, pins.getPin(0));
189 TEST_ASSERT_EQUAL((1U << 2) | (1U << 3) | (1U << 4), pins.getLocalBitmask(0));
199 TEST_ASSERT_EQUAL(2, pins.size());
200 TEST_ASSERT_EQUAL(2, pins.getPin(0));
201 TEST_ASSERT_EQUAL(3, pins.getPin(1));
202 TEST_ASSERT_EQUAL((1U << 4) | (1U << 5), pins.getLocalBitmask(0));
203 TEST_ASSERT_EQUAL((1U << 6) | (1U << 7), pins.getLocalBitmask(1));
212 TEST_ASSERT_EQUAL(0, pins.getPin(1));
213 TEST_ASSERT_EQUAL(0, pins.getPin(99));
222 TEST_ASSERT_EQUAL(0, pins.getLocalBitmask(1));
223 TEST_ASSERT_EQUAL(0, pins.getLocalBitmask(99));
234 TEST_ASSERT_EQUAL((1U << 4) | (1U << 5), pins.findLocalBitmask(10));
235 TEST_ASSERT_EQUAL((1U << 6) | (1U << 7), pins.findLocalBitmask(11));
236 TEST_ASSERT_EQUAL((1U << 8) | (1U << 9), pins.findLocalBitmask(12));
245 TEST_ASSERT_EQUAL(0, pins.findLocalBitmask(99));
246 TEST_ASSERT_EQUAL(0, pins.findLocalBitmask(0));
256 TEST_ASSERT_EQUAL(5, pins.getPin(0));
257 TEST_ASSERT_EQUAL(0b11100, pins.getLocalBitmask(0));
269 TEST_ASSERT_EQUAL(4, pins.size());
270 TEST_ASSERT_EQUAL((1U << 11) | (1U << 12), pins.findLocalBitmask(5));
278#define REMOTE_LOAD(n) (REMOTE_PIN_BASE + (n))
283 TEST_ASSERT_EQUAL(0, list.toRemoteBitmask());
290 TEST_ASSERT_EQUAL(0, list.toRemoteBitmask());
296 TEST_ASSERT_EQUAL(1U << 0, list.toRemoteBitmask());
302 TEST_ASSERT_EQUAL((1U << 0) | (1U << 2) | (1U << 5), list.toRemoteBitmask());
309 TEST_ASSERT_EQUAL((1U << 5) | (1U << 8), list.toLocalBitmask());
310 TEST_ASSERT_EQUAL((1U << 0) | (1U << 3), list.toRemoteBitmask());
316 constexpr uint32_t bitmask = 0b10100100;
318 TEST_ASSERT_EQUAL(3, list.count);
319 TEST_ASSERT_EQUAL(0b10100100, list.toLocalBitmask());
320 TEST_ASSERT_EQUAL(0, list.toRemoteBitmask());
326 constexpr uint32_t bitmask = (1UL << 16) | (1UL << 18) | (1UL << 20);
328 TEST_ASSERT_EQUAL(3, list.count);
329 TEST_ASSERT_EQUAL(0, list.toLocalBitmask());
330 TEST_ASSERT_EQUAL((1U << 0) | (1U << 2) | (1U << 4), list.toRemoteBitmask());
336 constexpr uint32_t bitmask = (1UL << 4) | (1UL << 6) | (1UL << 17) | (1UL << 19);
338 TEST_ASSERT_EQUAL(4, list.count);
339 TEST_ASSERT_EQUAL((1U << 4) | (1U << 6), list.toLocalBitmask());
340 TEST_ASSERT_EQUAL((1U << 1) | (1U << 3), list.toRemoteBitmask());
351 TEST_ASSERT_EQUAL(0, pair.getRemoteBitmask());
358 TEST_ASSERT_EQUAL(0, pair.getLocalBitmask());
359 TEST_ASSERT_EQUAL((1U << 0) | (1U << 2), pair.getRemoteBitmask());
366 TEST_ASSERT_EQUAL((1U << 4) | (1U << 5), pair.getLocalBitmask());
367 TEST_ASSERT_EQUAL((1U << 1) | (1U << 3), pair.getRemoteBitmask());
379 TEST_ASSERT_EQUAL(0, pins.getRemoteBitmask(0));
387 TEST_ASSERT_EQUAL(0, pins.getLocalBitmask(0));
388 TEST_ASSERT_EQUAL((1U << 0) | (1U << 2), pins.getRemoteBitmask(0));
396 TEST_ASSERT_EQUAL((1U << 4) | (1U << 5), pins.getLocalBitmask(0));
397 TEST_ASSERT_EQUAL((1U << 1) | (1U << 3), pins.getRemoteBitmask(0));
405 TEST_ASSERT_EQUAL(0, pins.getRemoteBitmask(1));
406 TEST_ASSERT_EQUAL(0, pins.getRemoteBitmask(99));
416 TEST_ASSERT_EQUAL((1U << 0) | (1U << 1), pins.findRemoteBitmask(10));
417 TEST_ASSERT_EQUAL((1U << 2) | (1U << 3), pins.findRemoteBitmask(11));
418 TEST_ASSERT_EQUAL((1U << 4) | (1U << 5), pins.findRemoteBitmask(12));
426 TEST_ASSERT_EQUAL(0, pins.findRemoteBitmask(99));
427 TEST_ASSERT_EQUAL(0, pins.findRemoteBitmask(0));
439 TEST_ASSERT_EQUAL(3, pins.size());
442 TEST_ASSERT_EQUAL((1U << 4) | (1U << 5), pins.getLocalBitmask(0));
443 TEST_ASSERT_EQUAL(0, pins.getRemoteBitmask(0));
446 TEST_ASSERT_EQUAL(0, pins.getLocalBitmask(1));
447 TEST_ASSERT_EQUAL((1U << 0) | (1U << 1), pins.getRemoteBitmask(1));
450 TEST_ASSERT_EQUAL((1U << 6) | (1U << 7), pins.getLocalBitmask(2));
451 TEST_ASSERT_EQUAL(1U << 2, pins.getRemoteBitmask(2));
454 TEST_ASSERT_EQUAL((1U << 4) | (1U << 5), pins.findLocalBitmask(2));
455 TEST_ASSERT_EQUAL(0, pins.findRemoteBitmask(2));
456 TEST_ASSERT_EQUAL(0, pins.findLocalBitmask(3));
457 TEST_ASSERT_EQUAL((1U << 0) | (1U << 1), pins.findRemoteBitmask(3));
472constexpr RelaySetting relaySettings[]{ { 8 }, { 9, 500, 100, 5, 5 } };
480 TEST_ASSERT_EQUAL(5, withRelays.pinOf(
LOAD(0)));
482 TEST_ASSERT_EQUAL(6, withRelays.pinOf(
LOAD(2)));
484 TEST_ASSERT_EQUAL(6, withRelays.pinOf(
LOCAL_LOAD(2)));
490 TEST_ASSERT_EQUAL(0, withRelays.pinOf(
LOAD(4)));
491 TEST_ASSERT_EQUAL(0, withRelays.pinOf(
LOAD(32)));
492 TEST_ASSERT_EQUAL(0, withRelays.pinOf(
LOCAL_LOAD(4)));
493 TEST_ASSERT_EQUAL(0, withRelays.pinOf(
RELAY(2)));
498 TEST_ASSERT_EQUAL(8, withRelays.pinOf(
RELAY(0)));
499 TEST_ASSERT_EQUAL(9, withRelays.pinOf(
RELAY(1)));
500 TEST_ASSERT_EQUAL(0, withoutRelays.pinOf(
RELAY(0)));
505 TEST_ASSERT_EQUAL(7, withRelays.pinOf(7));
511 TEST_ASSERT_EQUAL_HEX16((1U << 5) | (1U << 6), withRelays.localBitmask(
PinList< 1 >{ ALL_LOCAL_LOADS() }));
512 TEST_ASSERT_EQUAL_HEX8(0, withRelays.remoteBitmask(
PinList< 1 >{ ALL_LOCAL_LOADS() }));
514 TEST_ASSERT_EQUAL_HEX16(0, withRelays.localBitmask(
PinList< 1 >{ ALL_REMOTE_LOADS() }));
515 TEST_ASSERT_EQUAL_HEX8(0b11, withRelays.remoteBitmask(
PinList< 1 >{ ALL_REMOTE_LOADS() }));
517 TEST_ASSERT_EQUAL_HEX16((1U << 5) | (1U << 6), withRelays.localBitmask(
PinList< 1 >{ ALL_LOADS() }));
518 TEST_ASSERT_EQUAL_HEX8(0b11, withRelays.remoteBitmask(
PinList< 1 >{ ALL_LOADS() }));
520 TEST_ASSERT_EQUAL_HEX16((1U << 8) | (1U << 9), withRelays.localBitmask(
PinList< 1 >{ ALL_RELAYS() }));
521 TEST_ASSERT_EQUAL_HEX16(0, withoutRelays.localBitmask(
PinList< 1 >{ ALL_RELAYS() }));
523 TEST_ASSERT_EQUAL_HEX16((1U << 5) | (1U << 6) | (1U << 8) | (1U << 9), withRelays.localBitmask(
PinList< 1 >{ ALL_LOADS_AND_RELAYS() }));
524 TEST_ASSERT_EQUAL_HEX8(0b11, withRelays.remoteBitmask(
PinList< 1 >{ ALL_LOADS_AND_RELAYS() }));
525 TEST_ASSERT_EQUAL_HEX16((1U << 5) | (1U << 6), withoutRelays.localBitmask(
PinList< 1 >{ ALL_LOADS_AND_RELAYS() }));
531 TEST_ASSERT_EQUAL_HEX16((1U << 5) | (1U << 6) | (1U << 9), withRelays.localBitmask(targets));
532 TEST_ASSERT_EQUAL_HEX8(0b10, withRelays.remoteBitmask(targets));
539 constexpr OverrideTable fromSettings{ settings, withRelays };
543 for (uint8_t
i = 0;
i != 2; ++
i)
545 TEST_ASSERT_EQUAL(fromPins.getPin(
i), fromSettings.getPin(
i));
546 TEST_ASSERT_EQUAL_HEX16(fromPins.getLocalBitmask(
i), fromSettings.getLocalBitmask(
i));
547 TEST_ASSERT_EQUAL_HEX8(fromPins.getRemoteBitmask(
i), fromSettings.getRemoteBitmask(
i));
The override pins, as in config.h: each pin with the targets it forces.
Manages override pins and their associated bitmasks for forced operation.
The relays, as in config.h: the sliding average and the settings of each relay.
What the target codes of config.h stand for, once the load map and the relays are known.
constexpr RelayEngine relays
constexpr uint8_t REMOTE_PIN_BASE
Base value for virtual pins representing remote loads.
constexpr uint8_t LOCAL_LOAD(const uint8_t loadNum)
Same as LOAD(), for a load known to be local.
constexpr uint8_t ALL_LOCAL_LOADS()
Every local load.
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 ALL_LOADS()
Every load, local and remote.
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_are_pins_valid_rejects_pin_14_and_above(void)
void test_PinList_default_constructor(void)
void test_OverrideTable_findRemoteBitmask_found(void)
void test_TargetMap_LOAD_gives_the_pin_or_the_remote_rank(void)
void test_OverrideTable_multiple_entries_mixed(void)
void test_OverrideTable_multiple_entries(void)
void test_PinList_from_uint32_bitmask_remote_only(void)
void test_PinList_single_pin(void)
void test_PinList_toLocalBitmask(void)
void test_are_pins_valid_all_valid(void)
void test_OverrideTable_findRemoteBitmask_not_found(void)
void test_OverrideTable_many_entries(void)
void test_PinList_from_bitmask(void)
void test_OverrideTable_getRemoteBitmask_mixed(void)
void test_KeyIndexPair_from_bitmask(void)
void test_indicesToBitmask_consecutive(void)
void test_PinList_toRemoteBitmask_local_only(void)
void test_TargetMap_groups(void)
void test_PinList_variadic_constructor(void)
void test_PinList_from_bitmask_full(void)
void test_PinList_from_bitmask_empty(void)
void test_indicesToBitmask_single_index(void)
void test_KeyIndexPair_construction(void)
void test_PinList_toRemoteBitmask_empty(void)
void test_PinList_toRemoteBitmask_multiple_remote(void)
void test_KeyIndexPair_single_pin(void)
void test_OverrideTable_findLocalBitmask_found(void)
void test_OverrideTable_getRemoteBitmask_local_only(void)
void test_OverrideTable_getRemoteBitmask_out_of_bounds(void)
void test_OverrideTable_from_the_settings_matches_plain_pins(void)
void test_OverrideTable_getRemoteBitmask_remote_only(void)
void test_TargetMap_a_group_and_single_targets_in_one_list(void)
void test_OverrideTable_getPin_out_of_bounds(void)
void test_are_pins_valid_rejects_pin_0(void)
void test_PinList_max_pins(void)
void test_TargetMap_RELAY_needs_relay_diversion(void)
void test_KeyIndexPair_getLocalBitmask(void)
void test_KeyIndexPair_getRemoteBitmask_mixed(void)
void test_are_pins_valid_rejects_pin_1(void)
void test_OverrideTable_single_entry(void)
void test_indicesToBitmask_multiple_indices(void)
void test_KeyIndexPair_getRemoteBitmask_empty(void)
void test_OverrideTable_findLocalBitmask_not_found(void)
void test_PinList_toRemoteBitmask_mixed(void)
void test_OverrideTable_getLocalBitmask_out_of_bounds(void)
void test_PinList_toRemoteBitmask_single_remote(void)
void test_TargetMap_out_of_range_gives_pin_0(void)
void test_PinList_from_uint32_bitmask_local_only(void)
void test_KeyIndexPair_getRemoteBitmask_remote_only(void)
void test_indicesToBitmask_all_bits(void)
void test_TargetMap_plain_pins_pass_through(void)
void test_OverrideTable_with_bitmask_constructor(void)
void test_PinList_from_uint32_bitmask_mixed(void)
Structure holding a pin and its associated index list.
Wrapper for a list of pins, constructible from variadic arguments.
The settings of one relay, as in config.h: { pin, surplus, import, minON, minOFF }...
Compile-time utilities for managing override pins and index-to-bitmask mapping.
constexpr bool are_pins_valid()
Compile-time validation function for pin values.
constexpr uint16_t indicesToBitmask()
Helper to convert pins to a bitmask at compile-time.