77 lines
2.5 KiB
C++
77 lines
2.5 KiB
C++
/**
|
|
* @file State_Fail.cpp
|
|
* @brief Implementation of the FailState class.
|
|
* @author Emmanuel Hernandez Cruz
|
|
* @date 2025-09-05
|
|
*
|
|
* This file contains the implementation for the FailState, which defines
|
|
* the behavior of the equipment when it has entered a fault condition.
|
|
*/
|
|
#include "States/State_Standby.h"
|
|
#include "States/State_Fail.h"
|
|
#include "ModbusPoints/Modbus_Point.h"
|
|
#include "Equipment/Equipment.h"
|
|
#include "Strategies/Strategy_SingleValue.h"
|
|
#include "Strategies/Strategy_PID.h"
|
|
|
|
#include <vector>
|
|
#include <string>
|
|
|
|
#if defined(USE_MODBUS_IP)
|
|
#include <ModbusIP_ESP8266.h>
|
|
#else
|
|
#include <ModbusRTU.h>
|
|
#endif
|
|
|
|
/**
|
|
* @brief Constructs a new FailState object.
|
|
*
|
|
* This constructor receives a list of alarm descriptions and creates strategies
|
|
* to set the corresponding Modbus points to a value of 1, indicating an
|
|
* active alarm. It also initializes a PID strategy for the valve position.
|
|
*/
|
|
template<>
|
|
FailState<ModbusRTU>::FailState(const std::vector<std::string>& activeAlarms) {
|
|
// Simulate a failure: set common alarm and a specific fan alarm.
|
|
}
|
|
|
|
/**
|
|
* @brief Executes the fail state's logic for one update cycle.
|
|
*
|
|
* This method checks the "Clear Alm" Modbus point for a command to transition
|
|
* back to Standby, which would typically happen after a fault is cleared by a
|
|
* user. If no transition is requested, it continues to apply the failure strategies.
|
|
*
|
|
* @param equipment Pointer to the Equipment instance.
|
|
* @return A pointer to a new State if a transition should occur, otherwise nullptr.
|
|
*/
|
|
template<>
|
|
State<ModbusRTU>* FailState<ModbusRTU>::update(Equipment<ModbusRTU>* equipment) {
|
|
// STATE control, add conditions if change to a different state is needed
|
|
Serial.println("Fail update function");
|
|
|
|
_applyStrategies(equipment);
|
|
return nullptr;
|
|
}
|
|
|
|
/**
|
|
* @brief Logic to execute once when entering the fail state. Sets the main alarm bit.
|
|
* @param equipment Pointer to the Equipment instance.
|
|
*/
|
|
template<>
|
|
void FailState<ModbusRTU>::enterState(Equipment<ModbusRTU>* equipment) {
|
|
// Logic to run when the equipment enters this state
|
|
Serial.println("Enter Fail State...");
|
|
|
|
}
|
|
|
|
/**
|
|
* @brief Logic to execute once when exiting the fail state. Clears the main alarm bit.
|
|
* @param equipment Pointer to the Equipment instance.
|
|
*/
|
|
template<>
|
|
void FailState<ModbusRTU>::exitState(Equipment<ModbusRTU>* equipment) {
|
|
// Cleanup logic to run when the equipment leaves this state
|
|
Serial.println("Exit Fail State...");
|
|
|
|
} |