/** * @file State_Running.cpp * @brief Implementation of the RunningState class. * @author Emmanuel Hernandez Cruz * @date 2025-09-05 * * This file contains the implementation for the RunningState, which defines * the behavior of the equipment when it is actively running. */ #include "ModbusPoints/Modbus_Point.h" #include "ModbusPoints/Modbus_FloatDecorator.h" #include "Equipment/Equipment.h" #include "Strategies/Strategy_Ramp.h" #include "Strategies/Strategy_Random.h" #include "Strategies/Strategy_Saw.h" #include "Strategies/Strategy_SingleValue.h" #include "Strategies/Strategy_Square.h" #include "Strategies/Strategy_PID.h" #include "Strategies/Strategy_Totalizer.h" #include "States/State_Standby.h" #include "States/State_Running.h" #include "States/State_Fail.h" #include "States/State.h" #include #include #if defined(USE_MODBUS_IP) #include #else #include #endif /** * @brief Constructs a new RunningState object. * * This constructor initializes behavior strategies active during the running * state, such as a PID controller for the 'CW Valve Position' and totalizers * for the run-hours of each EC fan. */ template<> RunningState::RunningState() { } /** * @brief Executes the running state's logic for one update cycle. * * This method first checks for state transition commands: * 1. It reads the "ON/OFF Command By BMS" point. If it's 0, it transitions to StandbyState. * 2. It reads the "Fault Code" point. If it's non-zero, it transitions to FailState, * passing the corresponding alarm description. * * If no transition occurs, it applies the strategies defined for the running state. * * @param equipment Pointer to the Equipment instance. * @return A pointer to a new State if a transition should occur, otherwise nullptr. */ template<> State* RunningState::update(Equipment* equipment) { // STATE control, add conditions if change to a different state is needed Serial.println("Running update function"); // Apply any strategies defined for the standby state _applyStrategies(equipment); return nullptr; } /** * @brief Logic to execute once when entering the running state. * Sets the "Run Status" for all EC fans to 1 to indicate they are active. * @param equipment Pointer to the Equipment instance. */ template<> void RunningState::enterState(Equipment* equipment) { // Logic to run when the equipment enters this state Serial.println("Enter Running State..."); // You could also update a Modbus register to show the "standby" state } /** * @brief Logic to execute once when exiting the running state. * Sets the "Run Status" for all EC fans to 0 before transitioning to the next state. * @param equipment Pointer to the Equipment instance. */ template<> void RunningState::exitState(Equipment* equipment) { // Cleanup logic to run when the equipment leaves this state Serial.println("Exit Running State..."); }