25static_assert(__cplusplus >= 201703L,
"**** Please define 'gnu++17' in 'platform.txt' ! ****");
26static_assert(__cplusplus >= 201703L,
"See also : https://github.com/FredM67/PVRouter-3-phase/blob/main/Mk2_3phase_RFdatalog_temp/Readme.md");
141template< u
int8_t pin >
163 statusln(pin.active ? F(
"Trigger diversion OFF!") : F(
"End diversion OFF!"));
194 statusln(pin.active ? F(
"Router OFF!") : F(
"Router ON!"));
256 statusln(F(
"Change to off-peak period!"));
269 statusln(F(
"Change to peak period!"));
364 debug(F(
">>free RAM = "));
536 relayDiverter.proceed_relays(privateOverrideMasks.local, bDiversionEnabled);
566 static uint8_t perSecondTimer{ 0 };
567 static bool bOffPeak{
false };
568 static int16_t iTemperature_x100{ 0 };
576 [[maybe_unused]] uint32_t cycleSeen_us{ 0 };
577 [[maybe_unused]]
bool bCycleOnTime{
false };
583 constexpr uint32_t ON_TIME_US{ 1000 };
584 static uint32_t passStart_us{ 0 };
585 const uint32_t now_us{ micros() };
586 const bool bOnTime{ (now_us - passStart_us) < ON_TIME_US };
587 passStart_us = now_us;
591 cycleSeen_us = now_us;
592 bCycleOnTime = bOnTime;
643 constexpr uint32_t PERIOD_END_ON_TIME_US{ 3000 };
The round of the sensors, one transaction per mains cycle.
constexpr bool ROUTER_OFF_PIN_PRESENT
constexpr bool RELAY_DIVERSION
constexpr bool OVERRIDE_PIN_PRESENT
constexpr uint32_t ROTATION_AFTER_SECONDS
constexpr bool DUAL_TARIFF
constexpr bool CALIBRATION_MODE
constexpr bool TEMP_SENSOR_PRESENT
constexpr int16_t iTemperatureThreshold
constexpr bool WATCHDOG_PIN_PRESENT
constexpr uint8_t BOOST_TEMP_SENSOR
constexpr bool DIVERSION_PIN_PRESENT
constexpr uint8_t watchDogPin
The configuration as the firmware uses it: the settings, and what is built from them.
constexpr float f_voltageCal[NO_OF_PHASES]
constexpr bool REMOTE_LOADS_PRESENT
constexpr RelayDiverter relayDiverter
constexpr float f_powerCal[NO_OF_PHASES]
constexpr TempSensors tempSensors
constexpr OverrideTable overrideTable
constexpr uint8_t DATALOG_PERIOD_IN_SECONDS
constexpr uint8_t NO_OF_PHASES
constexpr uint8_t SUPPLY_FREQUENCY
Integer arithmetic of the datalog: power and RMS voltage per phase.
void infoln(const Args &... args)
Print an informational message and a line end, as Serial.println() does.
void statusln(const Args &... args)
Print a status message and a line end, as Serial.println() does (human-readable output only).
void debugln(const Args &... args)
Print a debug message and a line end, as Serial.println() does (only with ENABLE_DEBUG).
void debug(const Args &... args)
Print a debug message, as Serial.print() does (only with ENABLE_DEBUG).
constexpr int16_t DEVICE_DISCONNECTED_RAW
constexpr BoostTable boostTable PROGMEM
constexpr uint8_t NO_OF_BOOSTS
static volatile float powerCal[]
static volatile float voltageCal[]
DualTariff::Boost readBoost(const uint8_t i)
Reads scheduled boost i from flash.
OverrideMasks getDualTariffForcingBitmask(const bool bOffPeak, const int16_t currentTemperature_x100)
Calculates the dual tariff forcing bitmasks based on current conditions.
void updatePowerAndVoltageData()
Updates power and voltage data for all phases.
bool isRouterOff()
Tells whether the router is OFF.
OverrideMasks getOverrideBitmask(const bool bOffPeak, const int16_t currentTemperature_x100)
Gets the combined bitmasks 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.
bool isDiversionEnabled()
Reads the diversion pin.
bool proceedDualTariffLogic()
Handles dual tariff state transitions and priority rotation during off-peak periods.
void proceedLoadPriorities(const bool bOverridden)
Handles load priority rotation.
void proceedRotation()
Proceeds with load priority rotation.
PinEdges readPinEdges()
Reads an active-LOW input pin, and tells how it changed since the previous reading.
void sendResults(bool bOffPeak)
Prints or sends telemetry data logs based on the selected output format.
void logLoadPriorities()
Prints the load priorities to the Serial output.
void loop()
Main processor loop.
void setup()
Called once during startup.
void printConfiguration()
Print the configuration during startup.
int freeRam()
Get the available RAM during setup.
void initializeProcessing()
Initializes the processing engine, including ports, load states, and ADC setup.
void runTemperatureTransaction(const bool onTime)
Runs the 1-Wire transaction of this mains cycle, if any.
void processTemperatureData(const bool bStartNow)
Processes temperature data from DS18B20 sensors.
TempSchedule::Scheduler< tempSensors.size(), TempSchedule::conversionCycles(SUPPLY_FREQUENCY) > tempSchedule
The round of the temperature sensors: one 1-Wire transaction per mains cycle (temp_schedule....
int16_t temperatureReadings[tempSensors.size()]
The last reading of each sensor, in hundredths of °C, as endRead() returned it (none yet: setup()).
Header file for the main application.
constexpr uint16_t vrmsFactor(const uint8_t datalogPeriodInSeconds)
Scaling of the datalog voltage, Vrms_L_x100.
constexpr FixedCalibration< N > voltageCalibration(const uint16_t factor, const float(&cal)[N])
The voltage calibration in fixed point, for vrms(), built at compile time.
int16_t watts(const int32_t averagePower, const uint16_t calFixed, const uint8_t shift)
The average power of a phase, in watts.
constexpr FixedCalibration< N > powerCalibration(const float(&cal)[N])
The power calibration in fixed point, for watts(), built at compile time.
int32_t averagePower(const int32_t sum, const Count sampleSets)
The average power of a datalog period, back at the x1 scale of V_ADC x I_ADC.
uint16_t vrms(const uint32_t meanSquare, const uint16_t calFixed, const uint8_t shift)
The RMS voltage of a phase.
OverrideMasks boostForcing(const bool bOffPeak, const uint32_t elapsed, const int16_t temperature_x100, const int16_t threshold_x100, const uint8_t count, ReadBoost readBoost)
The targets of the scheduled boosts whose window is open.
OverrideMasks pinForcing(const Pins &pins, IsActive isActive)
The targets of the override pins that are active (held LOW).
void beginStartupText()
Serial settings for the startup text: 9600 baud 8N1, the default of serial monitors.
void endStartupText()
Serial settings after the startup text: 7E1 for the IoT telemetry frames, as the mk2Wifi module expec...
void poll(Print &out=Serial)
Write as many steps as the transmit buffer can take, without waiting.
volatile uint16_t overrideBitmask
volatile bool b_datalogEventPending
volatile bool b_reOrderLoads
volatile uint16_t copyOf_sampleSetsDuringThisDatalogPeriod
volatile int32_t copyOf_sumP_atSupplyPoint[NO_OF_PHASES]
volatile uint8_t remoteOverrideBitmask
volatile uint16_t absenceOfDivertedEnergyCountInSeconds
volatile uint32_t copyOf_sum_Vsquared[NO_OF_PHASES]
volatile bool b_newMainsCycle
volatile bool b_diversionEnabled
constexpr uint16_t conversionCycles(const uint8_t supplyFrequency)
The mains cycles from the conversion to the first read.
The forced outputs: the override pins, and the scheduled boosts of the dual tariff.
The edges of the active-LOW input pins: pressed, released, or no change.
constexpr bool isRotationRequested(const PinEdges &pin, const bool bOverridden)
Tells whether the rotation pin asks for a rotation now.
PinEdges trackPinEdges(const bool active)
Gives the edges of a pin from its current level, and keeps that level for the next call.
Public functions/variables of processing engine.
PayloadTx_struct< NO_OF_PHASES, TEMP_SENSOR_PRESENT ? tempSensors.size() :0 > tx_data
constexpr uint16_t initialDelay
void processRemoteLoadTransmissions()
Process pending RF transmissions.
The readings of one sensor, the power-on value skipped.
Holds both local and remote override bitmasks.
State of an active-LOW input pin, and how it changed since the previous reading.
The transaction to run, and the sensor it reads (ADDRESS, READ, CLOSE).
Which 1-Wire transaction of the temperature sensors runs on which mains cycle.
Some basics classes/types.
constexpr bool getPinState(uint8_t pin)
Get the Pin State.
constexpr void togglePin(uint8_t pin)
Toggle the specified pin.
Some utility functions for the relay output feature.
Compile-time validations.