122 lines
5.4 KiB
C++
122 lines
5.4 KiB
C++
/**
|
|
* @file StateUtils.cpp
|
|
* @brief Implementation of the StateUtils class.
|
|
* @author Robert J. Davis
|
|
* @date 2025-10-03
|
|
*
|
|
* This file contains implementation of utility functions that are used in multiple States.
|
|
*/
|
|
#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 "ModbusPoints/Modbus_Point.h"
|
|
#include "ModbusPoints/Modbus_FloatDecorator.h"
|
|
#include "Equipment/Equipment.h"
|
|
#include "States/State_Standby.h"
|
|
#include "States/State_Running.h"
|
|
#include "States/State_Fail.h"
|
|
#include "States/State.h"
|
|
#include "StateUtils.h"
|
|
#include <vector>
|
|
#include <string>
|
|
#if defined(USE_MODBUS_IP)
|
|
#include <ModbusIP_ESP8266.h>
|
|
#else
|
|
#include <ModbusRTU.h>
|
|
#endif
|
|
|
|
/**
|
|
* @brief This function is used to update the Control Mode (feedback),
|
|
* based on the selected BMS Control Source and BMS Enable Source.
|
|
*
|
|
* This is a function used in the update() of the Standby, Running, and Fail States.
|
|
*
|
|
*/
|
|
void updateControlMode(Equipment<ModbusIP>* equipment){
|
|
Modbus_Point<ModbusIP>* BMS_Control_Source_Pt = equipment -> getModbus_Point ("BMS Control Source");
|
|
Modbus_Point<ModbusIP>* BMS_Enable_Source_Pt = equipment -> getModbus_Point ("BMS Enable Source");
|
|
Modbus_Point<ModbusIP>* Control_Mode_Pt = equipment -> getModbus_Point ("Control Mode Selected");
|
|
int BMS_Control_Source = BMS_Control_Source_Pt ? BMS_Control_Source_Pt->getValue() : 0;
|
|
int BMS_Enable_Source = BMS_Enable_Source_Pt ? BMS_Enable_Source_Pt->getValue() : 0;
|
|
int Control_Mode_Selected = Control_Mode_Pt ? Control_Mode_Pt->getValue() : -1;
|
|
|
|
if (BMS_Control_Source == 0 && BMS_Enable_Source == 2) {
|
|
Control_Mode_Selected = 0;
|
|
} else if (BMS_Control_Source == 1 && BMS_Enable_Source == 2) {
|
|
Control_Mode_Selected = 1;
|
|
} else if (BMS_Enable_Source == 0) {
|
|
Control_Mode_Selected = 2;
|
|
}
|
|
equipment->setModbus_Point("Control Mode Selected", Control_Mode_Selected);
|
|
}
|
|
|
|
/**
|
|
* @brief This function will update the Alarm status DI bits according to the Alarm Commands from Coils (Modscan)
|
|
* It will also update the Common Alarm: if any alarm is active, the Common alarm will also be active.
|
|
*
|
|
* This is a function used in the update() of the Standby, Running, and Fail States.
|
|
*
|
|
*/
|
|
void updateAlarms(Equipment<ModbusIP>* equipment){
|
|
const std::vector<std::string> alarmDescriptions = {
|
|
"Alarm Fan 1", "Alarm Fan 2", "Alarm Fan 3", "Alarm Fan 4",
|
|
"Alarm Fan 5", "Alarm Fan 6", "Alarm Fan 7", "Alarm Fan 8",
|
|
"Alarm Fan 9", "Alarm Dirty Filter", "Alarm Leak Detect",
|
|
"Alarm Condensate Pump", "Alarm Fire", "Alarm Smoke"
|
|
};
|
|
|
|
const std::vector<std::string> alarmCommands = {
|
|
"Alarm Fan 1 ON", "Alarm Fan 2 ON", "Alarm Fan 3 ON", "Alarm Fan 4 ON",
|
|
"Alarm Fan 5 ON", "Alarm Fan 6 ON", "Alarm Fan 7 ON", "Alarm Fan 8 ON",
|
|
"Alarm Fan 9 ON", "Alarm Dirty Filter ON", "Alarm Leak Detect ON",
|
|
"Alarm Condensate Pump ON", "Alarm Fire ON", "Alarm Smoke ON"
|
|
};
|
|
|
|
int numAlarms = 0;
|
|
for (int i =0; i< alarmCommands.size() && i < alarmDescriptions.size(); ++i) {
|
|
Modbus_Point<ModbusIP>* commandPoint = equipment->getModbus_Point(alarmCommands[i]);
|
|
Modbus_Point<ModbusIP>* alarmPoint = equipment->getModbus_Point(alarmDescriptions[i]);
|
|
if (commandPoint) {
|
|
alarmPoint->setValue(commandPoint->getValue());
|
|
if (alarmPoint->getValue() == 1) numAlarms++;
|
|
}
|
|
}
|
|
if (numAlarms >= 1) equipment->setModbus_Point("Common Alarm", 1);
|
|
else equipment->setModbus_Point("Common Alarm", 0);
|
|
}
|
|
|
|
/**
|
|
* @brief The purpose of this function is for testing the RA Temp and RA Humidity alarms (Ignition HMI display)
|
|
* User will manually set Alarms through Modscan coils, which will change RA Temp or RA Humidity accordingly.
|
|
* The RA Temp alarm limits (reference Ignition UDT) are 72, 100.
|
|
* The SA Temp alarm limits (reference Ignition UDT) are 72, 78.
|
|
* The RA Humidity alarm limits (reference Ignition UDT) are 20, 60.
|
|
* If an associated alarm coil is not active, the analog values are set to a safe, un-alarmed value.
|
|
*
|
|
* NOTE: These analog alarms will not activate the Common Alarm in the Arduino test.
|
|
* Since these alarms will be set in Ignition, will not be sent over Modbus from CRAH to Ignition.
|
|
*
|
|
* This is a function used in the update() of the Running State.
|
|
*
|
|
*/
|
|
// Note: The Common Alarm is not configured to annunciate with these analog low/high alarms.
|
|
void updateAnalogs(Equipment<ModbusIP>* equipment){
|
|
if (equipment->getModbus_Point("RA Temp Low Alarm ON")->getValue() ==1){
|
|
equipment->setModbus_Point("Return Air Temp", 68.0f);
|
|
}
|
|
else if (equipment->getModbus_Point("RA Temp High Alarm ON")->getValue()==1){
|
|
equipment->setModbus_Point("Return Air Temp", 104.0f);
|
|
}
|
|
else equipment->setModbus_Point("Return Air Temp", 74.0f);
|
|
|
|
if (equipment->getModbus_Point("RA Humidity Low Alarm ON")->getValue()==1){
|
|
equipment->setModbus_Point("Return Air Humidity", 15.0f);
|
|
}
|
|
else if (equipment->getModbus_Point("RA Humidity High Alarm ON")->getValue()==1){
|
|
equipment->setModbus_Point("Return Air Humidity", 65.0f);
|
|
}
|
|
else equipment->setModbus_Point("Return Air Humidity", 35.0f);
|
|
} |