chiller updates

This commit is contained in:
Emmanuel HC
2025-10-20 09:42:10 -05:00
parent 1f61631f35
commit 7d7c81385c
14 changed files with 1010 additions and 524 deletions

View File

@@ -54,7 +54,7 @@ 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");
Modbus_Point<ModbusRTU>* clearAlm = equipment->getModbus_Point("Clear Alm");
Modbus_Point<ModbusRTU>* clearAlm = equipment->getModbus_Point("Clear Alarms");
int nextStateId = clearAlm ? clearAlm->getValue() : 0;
if (nextStateId == 1){
return new StandbyState<ModbusRTU>();

View File

@@ -0,0 +1,88 @@
/**
* @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.
for (const auto& alarmName : activeAlarms){
addStrategy(alarmName, new SingleValueStrategy(1.0f, 0.0f, 1000));
}
addStrategy("CW Valve Position", new PIDStrategy("RAT Setpoint", 1000, "RAT"));
}
/**
* @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");
Modbus_Point<ModbusRTU>* clearAlm = equipment->getModbus_Point("Clear Alm");
int nextStateId = clearAlm ? clearAlm->getValue() : 0;
if (nextStateId == 1){
return new StandbyState<ModbusRTU>();
}
_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...");
Modbus_Point<ModbusRTU>* alarm_common = equipment->getModbus_Point("Alarm Common");
alarm_common->setValue(1);
}
/**
* @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...");
Modbus_Point<ModbusRTU>* alarm_common = equipment->getModbus_Point("Alarm Common");
alarm_common->setValue(0);
}

View File

@@ -38,10 +38,11 @@
*/
template<>
RunningState<ModbusRTU>::RunningState() {
addStrategy("Actual Capacity", new PIDStrategy("Active SP", 1000, "Supply Temp"));
addStrategy("Comp1 Percent RLA", new RampStrategy(0.0f, 5.0f, 1000));
addStrategy("Comp2 Percent RLA", new RampStrategy(0.0f, 5.0f, 1000));
addStrategy("Return Temp", new SingleValueStrategy(85,3.0f, 1000));
addStrategy("Actual Capacity", new PIDStrategy("Chiller Local Setpoint", 1000, "PICs Supply Temp"));
addStrategy("C1 Comp 1 Motor Percent (RLA)", new RampStrategy(0.0f, 5.0f, 1000));
addStrategy("C2 Comp 1 Motor Percent (RLA)", new RampStrategy(0.0f, 5.0f, 1000));
addStrategy("C3 Comp 1 Motor Percent (RLA)", new RampStrategy(0.0f, 5.0f, 1000));
addStrategy("PICs Return Temp", new SingleValueStrategy(85,3.0f, 1000));
}
/**
@@ -75,25 +76,27 @@ State<ModbusRTU>* RunningState<ModbusRTU>::update(Equipment<ModbusRTU>* equipmen
// Determine the correct setpoint based on the current operating mode.
switch(currentMode){
case 1:
currentSP = getPointValue(equipment, "Ice SP");
currentSP = getPointValue(equipment, "Ice Setpoint");
currentSP = currentSP - 20;
break; // Added break to prevent fall-through
case 2:
currentSP = getPointValue(equipment, "Cool SP");
currentSP = getPointValue(equipment, "Cooling Active Setpoint");
currentSP = currentSP + 20;
break; // Added break
default:
// The default value is already set.
break;
}
Strategy_Behavior* ramp_strategy1 = getStrategy("Comp1 Percent RLA");
Strategy_Behavior* ramp_strategy2 = getStrategy("Comp2 Percent RLA");
Strategy_Behavior* ramp_strategy1 = getStrategy("C1 Comp 1 Motor Percent (RLA)");
Strategy_Behavior* ramp_strategy2 = getStrategy("C2 Comp 1 Motor Percent (RLA)");
Strategy_Behavior* ramp_strategy3 = getStrategy("C3 Comp 1 Motor Percent (RLA)");
int actualCapacity = getPointValue(equipment, "Actual Capacity");
if (actualCapacity < 50){
actualCapacity = actualCapacity * 2;
if (actualCapacity > 100) actualCapacity = 100;
static_cast<RampStrategy*>(ramp_strategy1)->setTarget(actualCapacity);
static_cast<RampStrategy*>(ramp_strategy2)->setTarget(0);
static_cast<RampStrategy*>(ramp_strategy3)->setTarget(0);
} else {
if (actualCapacity > 100) actualCapacity = 100;
static_cast<RampStrategy*>(ramp_strategy1)->setTarget(actualCapacity);
@@ -110,7 +113,7 @@ State<ModbusRTU>* RunningState<ModbusRTU>::update(Equipment<ModbusRTU>* equipmen
static_cast<PIDStrategy*>(strategy)->setSetpoint(currentSP);
}
float OutdoorTemp = getPointValue(equipment, "Outdoor Air Temp");
float OutdoorTemp = getPointValue(equipment, "Ambient Temperature");
Serial.printf("Outdoor Temp: %f\n", OutdoorTemp);
if (OutdoorTemp >50.0f) {
setPointValue(equipment, "Chiller Mode SP", 1.0f);
@@ -120,10 +123,10 @@ State<ModbusRTU>* RunningState<ModbusRTU>::update(Equipment<ModbusRTU>* equipmen
setPointValue(equipment, "Chiller Mode Output", 2.0f);
}
float SupplyTemp = getPointValue(equipment, "Supply Temp");
setPointValue(equipment, "Return Temp", SupplyTemp + 14.0f);
float SupplyTemp = getPointValue(equipment, "PICs Supply Temp");
setPointValue(equipment, "PICs Return Temp", SupplyTemp + 14.0f);
setPointValue(equipment, "Active SP", currentSP);
setPointValue(equipment, "Chiller Local Setpoint", currentSP);
// Apply any strategies defined for the standby state
_applyStrategies(equipment);
return nullptr;
@@ -139,7 +142,7 @@ void RunningState<ModbusRTU>::enterState(Equipment<ModbusRTU>* 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
setPointValue(equipment, "Run Enabled", 1);
setPointValue(equipment, "Run Enable", 1);
setPointValue(equipment, "Flow Switch", 1);
}

View File

@@ -0,0 +1,156 @@
/**
* @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 "Strategies/Strategy_SingleValue.h"
#include "Equipment/Equipment.h"
#include "ModbusPoints/Modbus_Point.h"
#include "ModbusPoints/Modbus_FloatDecorator.h"
#include <vector>
#include <string>
#if defined(USE_MODBUS_IP)
#include <ModbusIP_ESP8266.h>
#else
#include <ModbusRTU.h>
#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<ModbusRTU>::RunningState() {
addStrategy("Actual Capacity", new PIDStrategy("Active SP", 1000, "Supply Temp"));
addStrategy("Comp1 Percent RLA", new RampStrategy(0.0f, 5.0f, 1000));
addStrategy("Comp2 Percent RLA", new RampStrategy(0.0f, 5.0f, 1000));
addStrategy("Return Temp", new SingleValueStrategy(85,3.0f, 1000));
}
/**
* @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<ModbusRTU>* RunningState<ModbusRTU>::update(Equipment<ModbusRTU>* equipment) {
// STATE control, add conditions if change to a different state is needed
Serial.println("Running update function");
int CH_Enable_SP = getPointValue(equipment, "Chiller Enable SP");
if (CH_Enable_SP == 0){
return new StandbyState<ModbusRTU>();
}
// Declare currentSP outside the switch so it's accessible later.
float highCapacityLimit = getPointValue(equipment, "Active Capacity Limit");
Strategy_Behavior* PID_Strat = getStrategy("Actual Capacity");
static_cast<PIDStrategy*>(PID_Strat)->setLimits(0.0f, highCapacityLimit);
float currentSP = 50.0f; // Default value
int currentMode = getPointValue(equipment, "Chiller Mode Output");
// Determine the correct setpoint based on the current operating mode.
switch(currentMode){
case 1:
currentSP = getPointValue(equipment, "Ice SP");
currentSP = currentSP - 20;
break; // Added break to prevent fall-through
case 2:
currentSP = getPointValue(equipment, "Cool SP");
currentSP = currentSP + 20;
break; // Added break
default:
// The default value is already set.
break;
}
Strategy_Behavior* ramp_strategy1 = getStrategy("Comp1 Percent RLA");
Strategy_Behavior* ramp_strategy2 = getStrategy("Comp2 Percent RLA");
int actualCapacity = getPointValue(equipment, "Actual Capacity");
if (actualCapacity < 50){
actualCapacity = actualCapacity * 2;
if (actualCapacity > 100) actualCapacity = 100;
static_cast<RampStrategy*>(ramp_strategy1)->setTarget(actualCapacity);
static_cast<RampStrategy*>(ramp_strategy2)->setTarget(0);
} else {
if (actualCapacity > 100) actualCapacity = 100;
static_cast<RampStrategy*>(ramp_strategy1)->setTarget(actualCapacity);
int actualCapacity2 = (actualCapacity - 50)*4;
if (actualCapacity2 > 100) actualCapacity2 = 100;
static_cast<RampStrategy*>(ramp_strategy2)->setTarget(actualCapacity2);
}
// 1. Get the strategy by its name.
Strategy_Behavior* strategy = getStrategy("Actual Capacity");
// 2. Check if the strategy exists and is a PID type.
if (strategy && strategy->isPID()) {
// 3. Cast it to a PIDStrategy pointer and call setSetpoint.
static_cast<PIDStrategy*>(strategy)->setSetpoint(currentSP);
}
float OutdoorTemp = getPointValue(equipment, "Outdoor Air Temp");
Serial.printf("Outdoor Temp: %f\n", OutdoorTemp);
if (OutdoorTemp >50.0f) {
setPointValue(equipment, "Chiller Mode SP", 1.0f);
setPointValue(equipment, "Chiller Mode Output", 1.0f);
}else {
setPointValue(equipment, "Chiller Mode SP", 2.0f);
setPointValue(equipment, "Chiller Mode Output", 2.0f);
}
float SupplyTemp = getPointValue(equipment, "Supply Temp");
setPointValue(equipment, "Return Temp", SupplyTemp + 14.0f);
setPointValue(equipment, "Active SP", currentSP);
// 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<ModbusRTU>::enterState(Equipment<ModbusRTU>* 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
setPointValue(equipment, "Run Enabled", 1);
setPointValue(equipment, "Flow Switch", 1);
}
/**
* @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<ModbusRTU>::exitState(Equipment<ModbusRTU>* equipment) {
// Cleanup logic to run when the equipment leaves this state
Serial.println("Exit Running State...");
}

View File

@@ -32,9 +32,10 @@
*/
template<>
StandbyState<ModbusRTU>::StandbyState() {
addStrategy("Comp1 Percent RLA", new RampStrategy(0,5,1000));
addStrategy("Comp2 Percent RLA", new RampStrategy(0,5,1000));
addStrategy("Return Temp", new SingleValueStrategy(85,3.0f, 1000));
addStrategy("C1 Comp 1 Motor Percent (RLA)", new RampStrategy(0,5,1000));
addStrategy("C2 Comp 1 Motor Percent (RLA)", new RampStrategy(0,5,1000));
addStrategy("C3 Comp 1 Motor Percent (RLA)", new RampStrategy(0,5,1000));
addStrategy("PICs Return Temp", new SingleValueStrategy(85,3.0f, 1000));
}
/**
@@ -55,7 +56,7 @@ State<ModbusRTU>* StandbyState<ModbusRTU>::update(Equipment<ModbusRTU>* equipmen
if (CH_Enable_SP == 1){
return new RunningState<ModbusRTU>();
}
float OutdoorTemp = getPointValue(equipment, "Outdoor Air Temp");
float OutdoorTemp = getPointValue(equipment, "Ambient Temperature");
Serial.printf("Outdoor Temp: %f\n", OutdoorTemp);
if (OutdoorTemp >50.0f) {
setPointValue(equipment, "Chiller Mode SP", 1);
@@ -76,7 +77,7 @@ template<>
void StandbyState<ModbusRTU>::enterState(Equipment<ModbusRTU>* equipment) {
// Logic to run when the equipment enters this state
Serial.println("Enter Standby State...");
setPointValue(equipment, "Run Enabled", 0);
setPointValue(equipment, "Run Enable", 0);
setPointValue(equipment, "Flow Switch", 0);
}

View File

@@ -0,0 +1,91 @@
/**
* @file State_Standby.cpp
* @brief Implementation of the StandbyState class.
* @author Emmanuel Hernandez Cruz
* @date 2025-09-05
*
* This file contains the implementation for the StandbyState, which defines
* the behavior of the equipment when it is in an idle or standby mode.
*/
#include "States/State_Running.h"
#include "States/State_Fail.h"
#include "ModbusPoints/Modbus_Point.h"
#include "ModbusPoints/Modbus_FloatDecorator.h"
#include "Equipment/Equipment.h"
#include "Strategies/Strategy_Ramp.h"
#include "Strategies/Strategy_SingleValue.h"
#include <vector>
#include <string>
#if defined(USE_MODBUS_IP)
#include <ModbusIP_ESP8266.h>
#else
#include <ModbusRTU.h>
#endif
/**
* @brief Constructs a new StandbyState object.
*
* In this state, the equipment is idle. This constructor initializes several
* strategies to generate random values for various status points, simulating
* a live but non-operational unit.
*/
template<>
StandbyState<ModbusRTU>::StandbyState() {
addStrategy("Comp1 Percent RLA", new RampStrategy(0,5,1000));
addStrategy("Comp2 Percent RLA", new RampStrategy(0,5,1000));
addStrategy("Return Temp", new SingleValueStrategy(85,3.0f, 1000));
}
/**
* @brief Executes the standby state's logic for one update cycle.
*
* This method checks the "Chiller On-Off" Modbus point for a command to
* transition to the Running state. If no transition is requested, it applies
* the strategies defined for the standby state.
*
* @param equipment Pointer to the Equipment instance.
* @return A pointer to a new State if a transition should occur, otherwise nullptr.
*/
template<>
State<ModbusRTU>* StandbyState<ModbusRTU>::update(Equipment<ModbusRTU>* equipment) {
// STATE control, add conditions if change to a different state is needed
Serial.println("Standby update function");
int CH_Enable_SP = getPointValue(equipment, "Chiller Enable SP");
if (CH_Enable_SP == 1){
return new RunningState<ModbusRTU>();
}
float OutdoorTemp = getPointValue(equipment, "Outdoor Air Temp");
Serial.printf("Outdoor Temp: %f\n", OutdoorTemp);
if (OutdoorTemp >50.0f) {
setPointValue(equipment, "Chiller Mode SP", 1);
}else {
setPointValue(equipment, "Chiller Mode SP", 2);
}
// Apply any strategies defined for the standby state
_applyStrategies(equipment);
return nullptr;
}
/**
* @brief Logic to execute once when entering the standby state.
* Sets the "Chiller Sts" point to indicate the unit is not running.
* @param equipment Pointer to the Equipment instance.
*/
template<>
void StandbyState<ModbusRTU>::enterState(Equipment<ModbusRTU>* equipment) {
// Logic to run when the equipment enters this state
Serial.println("Enter Standby State...");
setPointValue(equipment, "Run Enabled", 0);
setPointValue(equipment, "Flow Switch", 0);
}
/**
* @brief Logic to execute once when exiting the standby state.
* @param equipment Pointer to the Equipment instance.
*/
template<>
void StandbyState<ModbusRTU>::exitState(Equipment<ModbusRTU>* equipment) {
// Cleanup logic to run when the equipment leaves this state
Serial.println("Exit Standby State...");
}

View File

@@ -22,10 +22,10 @@
* @{
*/
#include <ModbusIP_ESP8266.h>
const char *ssid = "wifi_name"; /**< @brief The SSID of the WiFi network. */
const char *password = "wifi_password"; /**< @brief The password for the WiFi network. */
IPAddress local_IP(192, 168, 1, 234); /**< @brief The static IP address for the device. */
IPAddress gateway(192, 168, 1, 1); /**< @brief The gateway IP address. */
const char *ssid = "QTS_CDR_Arduino"; /**< @brief The SSID of the WiFi network. */
const char *password = "123abc456"; /**< @brief The password for the WiFi network. */
IPAddress local_IP(172, 17, 33, 78); /**< @brief The static IP address for the device. */
IPAddress gateway(192, 17, 33, 1); /**< @brief The gateway IP address. */
IPAddress subnet(255, 255, 255, 0); /**< @brief The subnet mask. */
ModbusIP mb;
@@ -54,67 +54,51 @@
*/
modbusMap mb_map[] =
{
{HR, 100, 0, "State Control"}, //Internal to control from Modscan
{HR, 101, 0, "Fault Code"},
{HR_FLOAT, 102, 0, "Supply Temp"},
{HR_FLOAT, 103, 0, "Return Temp"}, //+14
{HR_FLOAT, 104, 0, "Flow Switch"},
{HR, 0, 0, "Chiller Local-Network"},
{HR, 1, 0, "Chiller Enable Output"},
{HR, 2, 0, "Run Enabled"},
{HR, 3, 0, "Chiller Capacity Limited"},
{HR, 4, 0, "Alm Digital Output"},
{HR, 6, 0, "Evap Flow Switch Sts"},
{HR, 7, 0, "Cond Flow Switch Sts"},
{HR, 8, 0, "Chiller On-Off"},
{HR, 9, 0, "Chiller Enable SP"},
{HR, 10, 0, "Clear Alm"},
{HR, 11, 0, "Chiller Mode Output"},
{HR_10x, 12, 0, "Active SP"},
{HR_10x, 13, 0, "Actual Capacity"},
{HR_10x, 14, 0, "Active Capacity Limit"},
{HR, 15, 0, "Chiller Sts"},
{HR_10x, 16, 0, "Evap Entering Fluid Temp"},
{HR_10x, 17, 0, "Evap Leaving Fluid Temp"},
{HR, 18, 0, "Evap Fluid Flow Rate"},
{HR_10x, 19, 0, "Cond Entering Fluid Temp"},
{HR_10x, 20, 0, "Cond Leaving Fluid Temp"},
{HR, 21, 0, "Cond Fluid Flow Rate"},
{HR_10x, 24, 0, "Outdoor Air Temp"},
{HR, 25, 0, "Chiller Current"},
{HR, 27, 0, "Total Kw"},
{HR, 28, 0, "Warning Alm Idx"},
{HR, 29, 0, "Problem Alm Idx"},
{HR, 30, 0, "Fault Alm Idx"},
{HR, 31, 0, "Warning Alm Code"},
{HR, 32, 0, "Problem Alm Code"},
{HR, 33, 0, "Fault Alm Code"},
{HR, 34, 0, "Chiller Mode SP"},
{HR_10x, 35, 0, "Cool SP"},
{HR_10x, 36, 0, "Ice SP"},
{HR_10x, 38, 0, "Capacity Limit SP"},
{HR_10x, 39, 0, "Cond Refrig Pressure"},
{HR_10x, 40, 0, "Cond Saturated Refrig Temp"},
{HR_10x, 41, 0, "Evap Refrig Pressure"},
{HR_10x, 42, 0, "Evap Saturated Refrig Temp"},
{HR, 65, 0, "Comp Suction Refrig Temp"},
{HR_10x, 68, 0, "Comp Discharge Refrig Temp"},
{HR, 69, 0, "Comp1 Percent RLA"},
{HR, 70, 0, "Comp1 Current"},
{HR, 71, 0, "Comp Voltage"},
{HR, 72, 0, "Comp Power"},
{HR, 73, 0, "Comp Starts"},
{HR, 74, 0, "Comp Run Hours"},
{HR, 75, 0, "Comp Run Hours"},
{HR, 82, 0, "Comp2 Percent RLA"},
{HR, 303, 0, "Evap Pump Run Hours"},
{HR, 304, 0, "Evap Pump Run Hours"},
{HR, 305, 0, "Evap Pump Sts"},
{HR, 316, 0, "Units"},
{HR, 317, 0, "Chiller Model"},
{HR, 1849, 0, "Oil Feed Pessure"},
{HR, 1854, 0, "Wtrside Econo State"},
{HR, 1855, 0, "Wtrside Econo En SP"},
{HR_FLOAT, 8100, 0, "PICs Supply Temp"}, //Internal to control from Modscan
{COIL, 8102, 0, "PICs Chiller Enable"},
{HR_FLOAT, 8104, 0, "PICs Chiller Flow"},
{HR_FLOAT, 8106, 0, "PICs Return Temp"},
{HR, 3, 0, "Run Enable"},
{HR, 9, 0, "Chiller Enable SP"},
{HR, 10, 0, "Clear Alarms"},
{HR, 11, 0, "Chiller Mode Output"},
{HR_10x, 12, 0, "Chiller Local Setpoint"},
{HR_10x, 13, 0, "Actual Capacity"},
{HR_10x, 14, 0, "Active Capacity Limit"},
{HR_10x, 16, 0, "System Chill Water In Temp"},
{HR_10x, 17, 0, "System Chill Water Out Temp"},
{HR_10x, 24, 0, "Ambient Temperature"},
{HR, 27, 0, "Chiller Total Power"},
{HR, 34, 0, "Chiller Mode SP"},
{HR_10x, 35, 0, "Cooling Active Setpoint"},
{HR_10x, 36, 0, "Ice Setpoint"},
{HR_10x, 39, 0, "C1 Cond Refrig Pres"},
{HR_10x, 41, 0, "C1 Evap Refrig Pres"},
{HR_10x, 43, 0, "C2 Cond Refrig Pres"},
{HR_10x, 45, 0, "C2 Evap Refrig Pres"},
{HR_10x, 47, 0, "C3 Cond Refrig Pres"},
{HR_10x, 49, 0, "C3 Evap Refrig Pres"},
{HR_10x, 51, 0, "C4 Cond Refrig Pres"},
{HR_10x, 53, 0, "C4 Evap Refrig Pres"},
{HR_10x, 63, 0, "C1 Comp Suction Refrig Pres"},
{HR_10x, 66, 0, "C1 Comp 1 Discharge Refrig Pres"},
{HR, 69, 0, "C1 Comp 1 Motor Percent (RLA)"},
{HR, 70, 0, "C1 Comp Current"},
{HR, 72, 0, "C1 Comp 1 Power"},
{HR_10x, 76, 0, "C1 Comp 2 Suction Refrig Pres"},
{HR_10x, 79, 0, "C1 Comp 2 Discharge Refrig Pres"},
{HR, 108, 0, "C2 Comp 1 Current"},
{HR, 109, 0, "C2 Comp 1 Current"},
{HR, 111, 0, "C2 Comp 1 Power"},
{HR, 147, 0, "C3 Comp 1 Motor Percent (RLA)"},
{HR, 148, 0, "C3 Comp 1 Current"},
{HR, 150, 0, "C3 Comp 1 Power"},
{HR, 592, 0, "Alarm Freeze Protection Evap 1"},
{HR, 593, 0, "Alarm Freeze Protection Evap 2"},
{HR_10x, 1731, 0, "C4 Comp 1 Oil Pres"},
{HR_10x, 1770, 0, "C3 Comp 1 Oil Pres"},
{HR_10x, 1809, 0, "C2 Comp 1 Oil Pres"},
{HR_10x, 1849, 0, "C1 Comp 1 Oil Pres"},
};
//Size of modbus map used in FOR cycles, automatically calculated.

View File

@@ -0,0 +1,132 @@
/**
* @file config.h
* @brief Main configuration file for the Daikin Chiller (RTU) emulator.
* @author Emmanuel Hernandez Cruz
* @date 2025-09-02
*
* This file contains important configurations for the Modbus RTU communication
* and the specific register map for the emulated device.
*/
#ifndef CONFIG_H
#define CONFIG_H
#include <ModbusRTU.h>
#include "core.h"
#include "Equipment/Equipment.h"
#if defined(USE_MODBUS_IP)
/**
* @defgroup ModbusTCPConfig Modbus IP Configuration
* @brief Parameters for Modbus TCP communication.
* @{
*/
#include <ModbusIP_ESP8266.h>
const char *ssid = "wifi_name"; /**< @brief The SSID of the WiFi network. */
const char *password = "wifi_password"; /**< @brief The password for the WiFi network. */
IPAddress local_IP(192, 168, 1, 234); /**< @brief The static IP address for the device. */
IPAddress gateway(192, 168, 1, 1); /**< @brief The gateway IP address. */
IPAddress subnet(255, 255, 255, 0); /**< @brief The subnet mask. */
ModbusIP mb;
#else
/**
* @defgroup ModbusRTUConfig Modbus RTU Configuration
* @brief Parameters for serial Modbus RTU communication.
* @{
*/
#include <ModbusRTU.h>
const int BAUDRATE = 19200; /**< @brief The serial communication speed in bits per second. */
const int RX_PIN = 17; /**< @brief The GPIO pin used for receiving data (RX). */
const int TX_PIN = 16; /**< @brief The GPIO pin used for transmitting data (TX). */
const int RST_PIN = 4; /**< @brief The GPIO pin connected to the RS485 driver's DE/RE pins for direction control. */
const int MODBUS_ID = 1; /**< @brief The unique slave ID for this device on the Modbus bus. */
/** @} */
/** @brief Global instance of the Modbus RTU server. */
ModbusRTU mb;
#endif
/**
* @brief The Modbus map for the Equipment device.
* This array defines all the Modbus points available on the emulated device.
* The `description` field is crucial as it's used to look up points within the application logic.
*/
modbusMap mb_map[] =
{
{HR, 100, 0, "State Control"}, //Internal to control from Modscan
{HR, 101, 0, "Fault Code"},
{HR_FLOAT, 102, 0, "Supply Temp"},
{HR_FLOAT, 103, 0, "Return Temp"}, //+14
{HR_FLOAT, 104, 0, "Flow Switch"},
{HR, 0, 0, "Chiller Local-Network"},
{HR, 1, 0, "Chiller Enable Output"},
{HR, 2, 0, "Run Enabled"},
{HR, 3, 0, "Chiller Capacity Limited"},
{HR, 4, 0, "Alm Digital Output"},
{HR, 6, 0, "Evap Flow Switch Sts"},
{HR, 7, 0, "Cond Flow Switch Sts"},
{HR, 8, 0, "Chiller On-Off"},
{HR, 9, 0, "Chiller Enable SP"},
{HR, 10, 0, "Clear Alm"},
{HR, 11, 0, "Chiller Mode Output"},
{HR_10x, 12, 0, "Active SP"},
{HR_10x, 13, 0, "Actual Capacity"},
{HR_10x, 14, 0, "Active Capacity Limit"},
{HR, 15, 0, "Chiller Sts"},
{HR_10x, 16, 0, "Evap Entering Fluid Temp"},
{HR_10x, 17, 0, "Evap Leaving Fluid Temp"},
{HR, 18, 0, "Evap Fluid Flow Rate"},
{HR_10x, 19, 0, "Cond Entering Fluid Temp"},
{HR_10x, 20, 0, "Cond Leaving Fluid Temp"},
{HR, 21, 0, "Cond Fluid Flow Rate"},
{HR_10x, 24, 0, "Outdoor Air Temp"},
{HR, 25, 0, "Chiller Current"},
{HR, 27, 0, "Total Kw"},
{HR, 28, 0, "Warning Alm Idx"},
{HR, 29, 0, "Problem Alm Idx"},
{HR, 30, 0, "Fault Alm Idx"},
{HR, 31, 0, "Warning Alm Code"},
{HR, 32, 0, "Problem Alm Code"},
{HR, 33, 0, "Fault Alm Code"},
{HR, 34, 0, "Chiller Mode SP"},
{HR_10x, 35, 0, "Cool SP"},
{HR_10x, 36, 0, "Ice SP"},
{HR_10x, 38, 0, "Capacity Limit SP"},
{HR_10x, 39, 0, "Cond Refrig Pressure"},
{HR_10x, 40, 0, "Cond Saturated Refrig Temp"},
{HR_10x, 41, 0, "Evap Refrig Pressure"},
{HR_10x, 42, 0, "Evap Saturated Refrig Temp"},
{HR, 65, 0, "Comp Suction Refrig Temp"},
{HR_10x, 68, 0, "Comp Discharge Refrig Temp"},
{HR, 69, 0, "Comp1 Percent RLA"},
{HR, 70, 0, "Comp1 Current"},
{HR, 71, 0, "Comp Voltage"},
{HR, 72, 0, "Comp Power"},
{HR, 73, 0, "Comp Starts"},
{HR, 74, 0, "Comp Run Hours"},
{HR, 75, 0, "Comp Run Hours"},
{HR, 82, 0, "Comp2 Percent RLA"},
{HR, 303, 0, "Evap Pump Run Hours"},
{HR, 304, 0, "Evap Pump Run Hours"},
{HR, 305, 0, "Evap Pump Sts"},
{HR, 316, 0, "Units"},
{HR, 317, 0, "Chiller Model"},
{HR, 1849, 0, "Oil Feed Pessure"},
{HR, 1854, 0, "Wtrside Econo State"},
{HR, 1855, 0, "Wtrside Econo En SP"},
};
//Size of modbus map used in FOR cycles, automatically calculated.
/**
* @brief The total number of entries in the `mb_map` array.
* This is calculated at compile time and used for iterating over the map.
*/
const int map_size = sizeof(mb_map) / sizeof(mb_map[0]);
/**
* @brief The main loop update interval in milliseconds.
*/
int interval = 250;
#endif // CONFIG_H