3-phase PV router
Loading...
Searching...
No Matches
RemoteLoadCore< NumUnits > Class Template Reference

Builds and schedules the RF payloads of every remote unit. More...

#include <remote_loads_core.h>

Collaboration diagram for RemoteLoadCore< NumUnits >:

Public Member Functions

constexpr RemoteLoadCore ()=default
 
constexpr bool isPending (uint8_t unitIdx) const
 True if a transmission is due for that unit.
 
constexpr uint8_t payloadOf (uint8_t unitIdx) const
 Current payload of a unit, whether or not it has been sent.
 
void reset ()
 Return every unit to its power-on state.
 
template<uint8_t NumIds, typename Send>
void sendPending (const uint8_t(&nodeIds)[NumIds], Send &&send)
 Hand every pending payload to send, addressed to its unit's node ID.
 
bool takePending (uint8_t unitIdx, uint8_t &payload)
 Claim a pending transmission for one unit.
 
template<const auto & Map, uint8_t NumLoads>
void updateLoads (const LoadStates(&loadStates)[NumLoads])
 Rebuild every unit's payload from the current load states.
 

Static Public Member Functions

static constexpr uint8_t size ()
 Number of remote units handled.
 

Private Member Functions

void schedule (uint8_t unitIdx, uint8_t bitmask)
 Record a unit's freshly computed payload and decide whether to send it.
 
template<const auto & Map, uint8_t Unit, uint8_t NumLoads>
void updateUnit (const LoadStates(&loadStates)[NumLoads])
 Build and schedule the payload of Unit, then of every unit after it.
 

Static Private Member Functions

template<const auto & Map, uint8_t Unit, uint8_t I, uint8_t NumLoads>
static uint8_t bitmaskOf (const LoadStates(&loadStates)[NumLoads])
 Payload of Unit, from map entry I onwards.
 

Private Attributes

RemoteUnitState unitStates [NumUnits ? NumUnits :1] {}
 

Detailed Description

template<uint8_t NumUnits>
class RemoteLoadCore< NumUnits >

Builds and schedules the RF payloads of every remote unit.

Template Parameters
NumUnitsNumber of remote units, 0 to MAX_REMOTE_UNITS.

The load map is a template argument of updateLoads() rather than read from the physicalLoadPin[] global: the tests pass maps of their own, and the compiler resolves every load's unit and payload bit, so the ISR only tests states and ORs bits.

The default constructor is constexpr and every member carries a brace-or-equal initialiser, so an instance at namespace scope is constant-initialized: it lands in .bss with no .init_array entry, and is dropped altogether by --gc-sections when unused.

Definition at line 100 of file remote_loads_core.h.

Constructor & Destructor Documentation

◆ RemoteLoadCore()

template<uint8_t NumUnits>
RemoteLoadCore< NumUnits >::RemoteLoadCore ( )
constexprdefault

Member Function Documentation

◆ bitmaskOf()

template<uint8_t NumUnits>
template<const auto & Map, uint8_t Unit, uint8_t I, uint8_t NumLoads>
static uint8_t RemoteLoadCore< NumUnits >::bitmaskOf ( const LoadStates(&) loadStates[NumLoads])
inlinestaticprivate

Payload of Unit, from map entry I onwards.

Definition at line 228 of file remote_loads_core.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isPending()

template<uint8_t NumUnits>
bool RemoteLoadCore< NumUnits >::isPending ( uint8_t unitIdx) const
inlineconstexpr

True if a transmission is due for that unit.

Definition at line 195 of file remote_loads_core.h.

Here is the caller graph for this function:

◆ payloadOf()

template<uint8_t NumUnits>
uint8_t RemoteLoadCore< NumUnits >::payloadOf ( uint8_t unitIdx) const
inlineconstexpr

Current payload of a unit, whether or not it has been sent.

Definition at line 189 of file remote_loads_core.h.

Here is the caller graph for this function:

◆ reset()

template<uint8_t NumUnits>
void RemoteLoadCore< NumUnits >::reset ( )
inline

Return every unit to its power-on state.

Definition at line 201 of file remote_loads_core.h.

Here is the caller graph for this function:

◆ schedule()

template<uint8_t NumUnits>
void RemoteLoadCore< NumUnits >::schedule ( uint8_t unitIdx,
uint8_t bitmask )
inlineprivate

Record a unit's freshly computed payload and decide whether to send it.

Definition at line 255 of file remote_loads_core.h.

Here is the caller graph for this function:

◆ sendPending()

template<uint8_t NumUnits>
template<uint8_t NumIds, typename Send>
void RemoteLoadCore< NumUnits >::sendPending ( const uint8_t(&) nodeIds[NumIds],
Send && send )
inline

Hand every pending payload to send, addressed to its unit's node ID.

Unit n (index n-1) goes to nodeIds[n-1]. The radio stays out of this class: the firmware passes a lambda around RFM69::send(), the native tests one that records what would have been sent.

Parameters
nodeIdsNode ID table, unit 1 first; at least NumUnits entries.
sendCallable as send(uint8_t nodeId, uint8_t payload).

Definition at line 173 of file remote_loads_core.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ size()

template<uint8_t NumUnits>
static constexpr uint8_t RemoteLoadCore< NumUnits >::size ( )
inlinestaticconstexpr

Number of remote units handled.

Definition at line 106 of file remote_loads_core.h.

Here is the caller graph for this function:

◆ takePending()

template<uint8_t NumUnits>
bool RemoteLoadCore< NumUnits >::takePending ( uint8_t unitIdx,
uint8_t & payload )
inline

Claim a pending transmission for one unit.

Clears the pending flag, so a second call returns false until the state changes again or the refresh period elapses. Safe to call from loop() without disabling interrupts: flag and payload are single bytes, and if the ISR updates them in between, the newer payload is sent and the flag stays set, so at worst the same byte goes out twice.

Parameters
unitIdxZero-based unit index (unit number - 1).
payloadReceives the bitmask to transmit.
Returns
true if a transmission is due.

Definition at line 149 of file remote_loads_core.h.

Here is the caller graph for this function:

◆ updateLoads()

template<uint8_t NumUnits>
template<const auto & Map, uint8_t NumLoads>
void RemoteLoadCore< NumUnits >::updateLoads ( const LoadStates(&) loadStates[NumLoads])
inline

Rebuild every unit's payload from the current load states.

Called once per mains cycle, from the ADC ISR. Local entries of the map are skipped, as is any entry naming a unit beyond NumUnits.

The map is a template argument, so the unit and the payload bit of every load are resolved at compile time: what is left at run time is, per remote load, one state test and one OR into a register.

Template Parameters
MapThe packed load map; must have static storage (a namespace-scope or static constexpr array).
Parameters
loadStatesThe current state of each load, in the same index space.

Definition at line 126 of file remote_loads_core.h.

Here is the call graph for this function:

◆ updateUnit()

template<uint8_t NumUnits>
template<const auto & Map, uint8_t Unit, uint8_t NumLoads>
void RemoteLoadCore< NumUnits >::updateUnit ( const LoadStates(&) loadStates[NumLoads])
inlineprivate

Build and schedule the payload of Unit, then of every unit after it.

Definition at line 214 of file remote_loads_core.h.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ unitStates

template<uint8_t NumUnits>
RemoteUnitState RemoteLoadCore< NumUnits >::unitStates[NumUnits ? NumUnits :1] {}
private

Definition at line 279 of file remote_loads_core.h.


The documentation for this class was generated from the following file: