3-phase PV router
Loading...
Searching...
No Matches
General Processing

Functions and routines that handle general system processing tasks. More...

Classes

class  EWMA_average< A >
 Implements an Exponentially Weighted Moving Average (EWMA). More...
 

Functions

void checkDiversionOnOff ()
 Checks and updates the diversion state based on the diversion pin.
 
uint16_t getOverrideBitmask (const int16_t currentTemperature_x100)
 Gets the combined bitmask of all active override pins and dual tariff forcing.
 
void handlePerSecondTasks (bool &bOffPeak, int16_t &iTemperature_x100)
 Handles tasks that need to be executed every second.
 
void logLoadPriorities ()
 Prints the load priorities to the Serial output.
 
void loop ()
 Main processor loop.
 
bool proceedDualTariffLogic ()
 Handles dual tariff state transitions and priority rotation during off-peak periods.
 
bool proceedLoadPriorities (const int16_t &currentTemperature_x100)
 Handles load priority rotation and dual tariff state transitions.
 
void proceedRotation ()
 Proceeds with load priority rotation.
 
void sendResults (bool bOffPeak)
 Prints or sends telemetry data logs based on the selected output format.
 
void updatePowerAndVoltageData ()
 Updates power and voltage data for all phases.
 

Detailed Description

Functions and routines that handle general system processing tasks.

This group includes functions that are not time-critical but are essential for the overall operation of the system. These tasks include monitoring system states, managing load priorities, and handling diversion logic.

Function Documentation

◆ checkDiversionOnOff()

void checkDiversionOnOff ( )

Checks and updates the diversion state based on the diversion pin.

This function monitors the state of the diversion pin and updates the global b_diversionOff flag accordingly. It also logs changes in the diversion state for debugging purposes if enabled.

  • If the diversion pin is LOW, the diversion is considered OFF.
  • If the diversion pin is HIGH, the diversion is considered ON.
  • Debug messages are printed when the diversion state changes (if debugging is enabled).

Definition at line 169 of file main.cpp.

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

◆ getOverrideBitmask()

uint16_t getOverrideBitmask ( const int16_t currentTemperature_x100)

Gets the combined bitmask of all active override pins and dual tariff forcing.

This function calculates the complete override bitmask by combining external override pins with dual tariff automatic forcing. The bitwise OR operation automatically handles precedence where external overrides take priority over dual tariff forcing for the same pins.

Parameters
currentTemperature_x100Current temperature multiplied by 100 (used for dual tariff logic).
Returns
Combined bitmask of all active overrides (external pins + dual tariff), 0 if no overrides are active.
  • First checks all configured external override pins and sets corresponding bits.
  • Then applies dual tariff forcing using bitwise OR operation.
  • OR operation ensures external overrides take precedence (1|x = 1).
  • For pins without external overrides (0|x = x), dual tariff forcing is applied.
  • Function is called atomically to prevent race conditions with ISR.

Definition at line 125 of file main.cpp.

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

◆ handlePerSecondTasks()

void handlePerSecondTasks ( bool & bOffPeak,
int16_t & iTemperature_x100 )

Handles tasks that need to be executed every second.

This function performs various tasks that are triggered once per second, ensuring proper system operation and load management.

  • Increments the absence of diverted energy count if no energy is being diverted.
  • Toggles the watchdog pin if the feature is enabled.
  • Checks and updates the diversion state.
  • Manages load priorities and overriding based on the current temperature.
  • Updates relay durations and proceeds with relay state transitions if relay diversion is enabled.
Parameters
bOffPeakReference to the off-peak state flag.
iTemperature_x100Current temperature multiplied by 100 (default to 0 if temperature sensing is disabled).

Definition at line 448 of file main.cpp.

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

◆ logLoadPriorities()

void logLoadPriorities ( )
inline

Prints the load priorities to the Serial output.

This function logs the current load priorities and states to the Serial output for debugging purposes. It provides a detailed view of the load configuration and their respective priorities.

  • Each load's priority and state are printed in a human-readable format.
  • This function is only active when debugging is enabled (ENABLE_DEBUG).

Definition at line 491 of file utils.h.

Here is the caller graph for this function:

◆ loop()

void loop ( )

Main processor loop.

This function handles non-time-critical tasks such as load management, telemetry updates, and temperature sensing. It processes ADC data through flags set by the ISR and ensures proper system operation.

  • Executes tasks triggered by the b_newMainsCycle flag, which is set after every pair of ADC conversions.
  • Handles per-second tasks such as load priority management and diversion state updates.
  • Processes data logging events and updates power, voltage, and temperature data.
  • Sends telemetry results and updates relay states if relay diversion is enabled.

Definition at line 492 of file main.cpp.

Here is the call graph for this function:

◆ proceedDualTariffLogic()

bool proceedDualTariffLogic ( )

Handles dual tariff state transitions and priority rotation during off-peak periods.

This function manages dual tariff state detection and triggers priority rotation when transitioning to off-peak periods. The actual load forcing is handled in getOverrideBitmask().

Returns
true if the system is in a high tariff (on-peak) period.
false if the system is in a low tariff (off-peak) period.
  • Detects transitions between off-peak and on-peak periods using the dual tariff pin.
  • Triggers automatic priority rotation when entering off-peak period.
  • Logs transitions between tariff periods for debugging purposes.
  • Load forcing logic (including temperature conditions) is handled atomically in getOverrideBitmask().

Definition at line 233 of file main.cpp.

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

◆ proceedLoadPriorities()

bool proceedLoadPriorities ( const int16_t & currentTemperature_x100)

Handles load priority rotation and dual tariff state transitions.

This function manages load priority rotation behavior and dual tariff state detection based on the system configuration. It supports priority rotation via pin control, EmonESP control, or automatic rotation. Override logic is handled in getOverrideBitmask().

Parameters
currentTemperature_x100Current temperature multiplied by 100 (default to 0 if deactivated).
Returns
true if the system is in a high tariff (on-peak) period (only for dual tariff mode).
false if the system is in a low tariff (off-peak) period or not in dual tariff mode.
  • If dual tariff is enabled, it delegates to proceedDualTariffLogic for state transitions.
  • If EmonESP control is enabled, it handles load rotation based on the rotation pin state.
  • If priority rotation is set to auto, it rotates priorities after a defined period of inactivity.
  • Override logic (external pins + dual tariff forcing) is handled atomically in getOverrideBitmask().

Definition at line 281 of file main.cpp.

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

◆ proceedRotation()

void proceedRotation ( )

Proceeds with load priority rotation.

This function triggers the rotation of load priorities and waits until the rotation is completed. It ensures that the new load priorities are logged after the rotation.

  • Sets the b_reOrderLoads flag to initiate the rotation process.
  • Waits in a loop until the rotation is completed by the ISR.
  • Logs the updated load priorities after the rotation.

Definition at line 202 of file main.cpp.

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

◆ sendResults()

void sendResults ( bool bOffPeak)
inline

Prints or sends telemetry data logs based on the selected output format.

This function handles the transmission of telemetry data in various formats, such as human-readable text, IoT telemetry, or JSON format. It also ensures that the first incomplete datalogging event is skipped during startup.

Parameters
bOffPeakIndicates whether the system is in an off-peak tariff period.
  • If RF communication is enabled, it sends RF data.
  • Depending on the SERIAL_OUTPUT_TYPE, it prints data in text format, sends telemetry data, or outputs data in JSON format.
  • Skips the first datalogging event during startup to avoid incomplete data.

Definition at line 450 of file utils.h.

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

◆ updatePowerAndVoltageData()

void updatePowerAndVoltageData ( )

Updates power and voltage data for all phases.

This function calculates the power and voltage for each phase based on the accumulated data during the datalogging period. It also updates the total power.

  • Computes the power for each phase using the accumulated power data and calibration factors.
  • Calculates the RMS voltage for each phase using the accumulated voltage squared data.
  • Updates the total power by summing the power of all phases.

Definition at line 372 of file main.cpp.

Here is the caller graph for this function: