diff --git a/platformio.ini b/platformio.ini index b198ccc..9deb29a 100644 --- a/platformio.ini +++ b/platformio.ini @@ -9,7 +9,7 @@ ; https://docs.platformio.org/page/projectconf.html [platformio] -default_envs = UPS_Vertiv_APM2_TCP ; Select here the name of the configuration you want to download +default_envs = CH_Daikin_AWV026B_RTU ; Select here the name of the configuration you want to download [env] upload_port = COM15 diff --git a/src/BMS/CHILLER/CH_Daikin_AWV026B_RTU/State_Fail_old.cpp b/src/BMS/CHILLER/CH_Daikin_AWV026B_RTU/State_Fail_old.cpp deleted file mode 100644 index 70da82d..0000000 --- a/src/BMS/CHILLER/CH_Daikin_AWV026B_RTU/State_Fail_old.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/** - * @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 -#include - -#if defined(USE_MODBUS_IP) - #include -#else - #include -#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::FailState(const std::vector& 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* FailState::update(Equipment* equipment) { - // STATE control, add conditions if change to a different state is needed - Serial.println("Fail update function"); - Modbus_Point* clearAlm = equipment->getModbus_Point("Clear Alm"); - int nextStateId = clearAlm ? clearAlm->getValue() : 0; - if (nextStateId == 1){ - return new StandbyState(); - } - _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::enterState(Equipment* equipment) { - // Logic to run when the equipment enters this state - Serial.println("Enter Fail State..."); - Modbus_Point* 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::exitState(Equipment* equipment) { - // Cleanup logic to run when the equipment leaves this state - Serial.println("Exit Fail State..."); - Modbus_Point* alarm_common = equipment->getModbus_Point("Alarm Common"); - alarm_common->setValue(0); -} \ No newline at end of file diff --git a/src/BMS/CHILLER/CH_Daikin_AWV026B_RTU/State_Running_old.cpp b/src/BMS/CHILLER/CH_Daikin_AWV026B_RTU/State_Running_old.cpp deleted file mode 100644 index 6b6b207..0000000 --- a/src/BMS/CHILLER/CH_Daikin_AWV026B_RTU/State_Running_old.cpp +++ /dev/null @@ -1,156 +0,0 @@ -/** - * @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 -#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() { - 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* RunningState::update(Equipment* 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(); - } - - // 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(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(ramp_strategy1)->setTarget(actualCapacity); - static_cast(ramp_strategy2)->setTarget(0); - } else { - if (actualCapacity > 100) actualCapacity = 100; - static_cast(ramp_strategy1)->setTarget(actualCapacity); - int actualCapacity2 = (actualCapacity - 50)*4; - if (actualCapacity2 > 100) actualCapacity2 = 100; - static_cast(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(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::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 - 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::exitState(Equipment* equipment) { - // Cleanup logic to run when the equipment leaves this state - Serial.println("Exit Running State..."); -} \ No newline at end of file diff --git a/src/BMS/CHILLER/CH_Daikin_AWV026B_RTU/State_Standby_old.cpp b/src/BMS/CHILLER/CH_Daikin_AWV026B_RTU/State_Standby_old.cpp deleted file mode 100644 index d6e8c75..0000000 --- a/src/BMS/CHILLER/CH_Daikin_AWV026B_RTU/State_Standby_old.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/** - * @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 -#include -#if defined(USE_MODBUS_IP) - #include -#else - #include -#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::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* StandbyState::update(Equipment* 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(); - } - 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::enterState(Equipment* 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::exitState(Equipment* equipment) { - // Cleanup logic to run when the equipment leaves this state - Serial.println("Exit Standby State..."); -} \ No newline at end of file diff --git a/src/BMS/CHILLER/CH_Daikin_AWV026B_RTU/config_old.h b/src/BMS/CHILLER/CH_Daikin_AWV026B_RTU/config_old.h deleted file mode 100644 index 3b31f9c..0000000 --- a/src/BMS/CHILLER/CH_Daikin_AWV026B_RTU/config_old.h +++ /dev/null @@ -1,132 +0,0 @@ -/** - * @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 -#include "core.h" -#include "Equipment/Equipment.h" - - -#if defined(USE_MODBUS_IP) -/** - * @defgroup ModbusTCPConfig Modbus IP Configuration - * @brief Parameters for Modbus TCP communication. - * @{ - */ - #include - 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 - 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