/** * @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 "States/State_Standby.h" #include "States/State_Running.h" #include "States/State_Fail.h" #include "Strategies/Strategy_Behavior.h" #include "Strategies/Strategy_PID.h" #include "Strategies/Strategy_Ramp.h" #include "Strategies/Strategy_Totalizer.h" #include "Equipment/Equipment.h" #include "ModbusPoints/Modbus_Point.h" #include "ModbusPoints/Modbus_FloatDecorator.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() { //Add strategies //addStrategy("Actual Capacity", new PIDStrategy("Active SP", 1000, "Supply Temp")); } /** * @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 "Chiller Sts" point to indicate the unit is running. * @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..."); } /** * @brief Logic to execute once when exiting the running state. * Sets the "Chiller Sts" point to indicate the unit is no longer running. * @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..."); }