phxa7
This commit is contained in:
@@ -9,10 +9,10 @@
|
||||
|
||||
[platformio]
|
||||
|
||||
default_envs = RPP_Cortex_TCP ; Select here the name of the configuration you want to download
|
||||
default_envs = STU_UMP_STU_2_0_CAH_IDR_60_TCP_PHXA7 ; Select here the name of the configuration you want to download
|
||||
|
||||
[env]
|
||||
upload_port = COM15
|
||||
upload_port = COM4
|
||||
|
||||
[common_env_options]
|
||||
framework = arduino
|
||||
@@ -273,4 +273,17 @@ platform = espressif32
|
||||
board = dfrobot_firebeetle2_esp32e
|
||||
extends = common_env_options
|
||||
build_flags = -D USE_MODBUS_IP
|
||||
build_src_filter = -<*> +<EPMS/RPP/RPP_Cortex_TCP>
|
||||
build_src_filter = -<*> +<EPMS/RPP/RPP_Cortex_TCP>
|
||||
|
||||
[env:CH_York_YVA_RTU_PHXA7]
|
||||
platform = espressif32
|
||||
board = dfrobot_firebeetle2_esp32e
|
||||
extends = common_env_options
|
||||
build_src_filter = -<*> +<BMS/CHILLER/CH_York_YVA_RTU_PHXA7>
|
||||
|
||||
[env:STU_UMP_STU_2_0_CAH_IDR_60_TCP_PHXA7]
|
||||
platform = espressif32
|
||||
board = dfrobot_firebeetle2_esp32e
|
||||
extends = common_env_options
|
||||
build_flags = -D USE_MODBUS_IP
|
||||
build_src_filter = -<*> +<BMS/STU/STU_UMP_STU_2_0_CAH_IDR_60_TCP_PHXA7>
|
||||
35
src/BMS/CHILLER/CH_York_YVA_RTU_PHXA7/README.md
Normal file
35
src/BMS/CHILLER/CH_York_YVA_RTU_PHXA7/README.md
Normal file
@@ -0,0 +1,35 @@
|
||||
# EQUIPMENT_TYPE MANUFACTURER MODEL RTU
|
||||
|
||||
## Brief Introduction
|
||||
Equipment specifc details that make it different from other devices
|
||||
|
||||
## List of Equipmentt
|
||||
This cofiguration has been used for these models:
|
||||
* **Model**: 09-15-22
|
||||
* **Model**: 09-15-23
|
||||
* **Model**: 09-15-25
|
||||
|
||||
## Hardware Prerequisites
|
||||
|
||||
The code is written for an ESP8266/ESP32-style microcontroller with WiFi capabilities and at least one hardware serial port for RS485 communication.
|
||||
|
||||
* **Microcontroller**: [Firebeetle 2 ESP32.](https://www.dfrobot.com/product-2231.html)
|
||||
* **RS485 Transceiver**: [RS485 Shield for Arduino.](https://www.dfrobot.com/product-1024.html)
|
||||
|
||||
---
|
||||
|
||||
## States and Strategies
|
||||
Provide a brief description of what variables and strategies were used in this configuraiton
|
||||
|
||||
### Standby State
|
||||
* **Equipment running**: set to 0
|
||||
* **Common Alarm**: set to 0
|
||||
* **SAT temperature**: set to 85
|
||||
|
||||
### Running State
|
||||
* **Equipment running**: set to 1
|
||||
* **SAT temperature**: **Ramp Strategy** set to 65 deg setpoint
|
||||
|
||||
### Fail State
|
||||
* **Commong Alarm**: set to 1
|
||||
* **SAT temperature**: **Ramp Strategy** set to 105 deg setpointset
|
||||
77
src/BMS/CHILLER/CH_York_YVA_RTU_PHXA7/State_Fail.cpp
Normal file
77
src/BMS/CHILLER/CH_York_YVA_RTU_PHXA7/State_Fail.cpp
Normal file
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* @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...");
|
||||
|
||||
}
|
||||
89
src/BMS/CHILLER/CH_York_YVA_RTU_PHXA7/State_Running.cpp
Normal file
89
src/BMS/CHILLER/CH_York_YVA_RTU_PHXA7/State_Running.cpp
Normal file
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* @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 <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() {
|
||||
//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<ModbusRTU>* RunningState<ModbusRTU>::update(Equipment<ModbusRTU>* 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<ModbusRTU>::enterState(Equipment<ModbusRTU>* 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<ModbusRTU>::exitState(Equipment<ModbusRTU>* equipment) {
|
||||
// Cleanup logic to run when the equipment leaves this state
|
||||
Serial.println("Exit Running State...");
|
||||
}
|
||||
77
src/BMS/CHILLER/CH_York_YVA_RTU_PHXA7/State_Standby.cpp
Normal file
77
src/BMS/CHILLER/CH_York_YVA_RTU_PHXA7/State_Standby.cpp
Normal file
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* @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("Sts_EvapHeater", new SingleValueStrategy(100.0f, 5.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");
|
||||
|
||||
// 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...");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
|
||||
}
|
||||
122
src/BMS/CHILLER/CH_York_YVA_RTU_PHXA7/config.h
Normal file
122
src/BMS/CHILLER/CH_York_YVA_RTU_PHXA7/config.h
Normal file
@@ -0,0 +1,122 @@
|
||||
/**
|
||||
* @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 = "Prime Guest"; /**< @brief The SSID of the WiFi network. */
|
||||
const char *password = "Pr1meguest#"; /**< @brief The password for the WiFi network. */
|
||||
IPAddress local_IP(192, 168, 103, 91); /**< @brief The static IP address for the device. */
|
||||
IPAddress gateway(192, 168, 103, 65); /**< @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, 67, 0, "Sts_EvapHeater"},
|
||||
{HR, 68, 0, "Sts_EvapPump"},
|
||||
{HR, 87, 0, "Sts_FlowSwitch"},
|
||||
{HR, 10, 0, "Sts_AmbientTemp"},
|
||||
{HR, 6, 0, "Sts_EvapTempIN"},
|
||||
{HR, 5, 0, "Sts_EvapTempOUT"},
|
||||
{HR, 127, 0, "Sts_VSD_CmdHz"},
|
||||
{HR, 27, 0, "Sts_VSD_FdbkHz"},
|
||||
{HR, 8, 0, "Sts_Cond1Temp"},
|
||||
{HR, 120, 0, "Sts_Cond1FanSpd"},
|
||||
{HR, 50, 0, "Sts_Cond2Temp"},
|
||||
{HR, 121, 0, "Sts_Cond2FanSpd"},
|
||||
{HR, 69, 0, "Sts_Comp1"},
|
||||
{HR, 14, 0, "Sts_Comp1_DischargePresure"},
|
||||
{HR, 13, 0, "Sts_Comp1_SuctionPresure"},
|
||||
{HR, 15, 0, "Sts_Comp1_FLA"},
|
||||
{HR, 17, 0, "Sts_Comp1Starts"},
|
||||
{HR, 70, 0, "Sts_Comp2"},
|
||||
{HR, 23, 0, "Sts_Comp2_DischargePresure"},
|
||||
{HR, 22, 0, "Sts_Comp2_SuctionPresure"},
|
||||
{HR, 24, 0, "Sts_Comp2_FLA"},
|
||||
{HR, 26, 0, "Sts_Comp2Starts"},
|
||||
{HR, 14, 0, "Sts_Sys1_DischPress"},
|
||||
{HR, 13, 0, "Sts_Sys1_SuctPress"},
|
||||
{HR, 9, 0, "Sts_Sys1_DischTemp"},
|
||||
{HR, 12, 0, "Sts_Sys1_OilPress"},
|
||||
{HR, 42, 0, "Sts_Sys1_EconValvePos"},
|
||||
{HR, 11, 0, "Sts_Sys1_EductorTemp"},
|
||||
{HR, 18, 0, "Sts_Sys1_MotorTemp"},
|
||||
{HR, 30, 0, "Sts_Sys1_OpCode"},
|
||||
{HR, 31, 0, "Sts_Sys1_FaultCode"},
|
||||
{HR, 16, 0, "Sts_Sys1_Runtime"},
|
||||
{HR, 141, 0, "Sts_Sys1_FanKW"},
|
||||
{HR, 142, 0, "Sts_Sys1_CompKW"},
|
||||
{HR, 23, 0, "Sts_Sys2_DischPress"},
|
||||
{HR, 22, 0, "Sts_Sys2_SuctPress"},
|
||||
{HR, 51, 0, "Sts_Sys2_DischTemp"},
|
||||
{HR, 21, 0, "Sts_Sys2_OilPress"},
|
||||
{HR, 43, 0, "Sts_Sys2_EconValvePos"},
|
||||
{HR, 20, 0, "Sts_Sys2_EductorTemp"},
|
||||
{HR, 19, 0, "Sts_Sys2_MotorTemp"},
|
||||
{HR, 32, 0, "Sts_Sys2_OpCode"},
|
||||
{HR, 33, 0, "Sts_Sys2_FaultCode"},
|
||||
{HR, 25, 0, "Sts_Sys2_Runtime"},
|
||||
{HR, 143, 0, "Sts_Sys2_FanKW"},
|
||||
{HR, 144, 0, "Sts_Sys2_CompKW"},
|
||||
{HR, 66, 0, "Alm_Summary"},
|
||||
{HR, 85, 0, "Alm_Sys1_Lockout"},
|
||||
{HR, 86, 0, "Alm_Sys2_Lockout"},
|
||||
{HR, 175, 0, "Alm_Cond1_FanFlt"},
|
||||
{HR, 176, 0, "Alm_Cond2_FanFlt"},
|
||||
};
|
||||
|
||||
//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
|
||||
78
src/BMS/CHILLER/CH_York_YVA_RTU_PHXA7/main.cpp
Normal file
78
src/BMS/CHILLER/CH_York_YVA_RTU_PHXA7/main.cpp
Normal file
@@ -0,0 +1,78 @@
|
||||
/**
|
||||
* @file main.cpp
|
||||
* @brief Main execution program for the Daikin Chiller (RTU) Emulator.
|
||||
* @author Emmanuel Hernandez Cruz
|
||||
* @date 2025-09-02
|
||||
*
|
||||
* @details This file contains the main execution program for an Arduino-based
|
||||
* emulator of a Daikin Chiller unit. The program communicates via the
|
||||
* Modbus RTU protocol over a serial connection.
|
||||
*
|
||||
* The setup() function initializes the following:
|
||||
* - Serial communication for debugging.
|
||||
* - A Modbus RTU server with parameters from config.h.
|
||||
* - Modbus points (Coils, Holding Registers, etc.) based on a predefined map in config.h.
|
||||
*
|
||||
* The loop() function continuously:
|
||||
* - Services the Modbus RTU server to handle incoming requests.
|
||||
* - Periodically calls the main update loop for the emulated equipment, which
|
||||
* manages state transitions and behavior strategies.
|
||||
*
|
||||
* @see config.h for Modbus RTU and register map configuration.
|
||||
* @see Equipment.h for the main equipment logic.
|
||||
* @see State.h for different equipment states.
|
||||
* @see Strategies/Strategy_Behavior.h for value generation strategies.
|
||||
* @see Modbus_Point.h for the base class for all Modbus points.
|
||||
*/
|
||||
//=================================================================================================================================
|
||||
//Libraries and declaration of variables.
|
||||
#include <Arduino.h>
|
||||
#include "config.h"
|
||||
#include "ModbusPoints/Modbus_PointFactory.h"
|
||||
|
||||
//=================================================================================================================================
|
||||
/**
|
||||
* @brief Initializes the application.
|
||||
* @details This function runs once at startup. It configures the serial communication
|
||||
* for debugging and the Modbus RTU server. It then creates and initializes all
|
||||
* the Modbus points based on the `mb_map` array in `config.h`.
|
||||
*/
|
||||
const int rtsPin = 4;
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Serial.println("Setup function started");
|
||||
|
||||
Serial2.begin(BAUDRATE, SERIAL_8N1, RX_PIN, TX_PIN);
|
||||
mb.begin(&Serial2, RST_PIN); // Start the server
|
||||
mb.slave(MODBUS_ID); // Set the slave ID
|
||||
|
||||
for(int i = 0; i < map_size; i++){
|
||||
Modbus_Point<ModbusRTU>* point = createModbus_Point(&mb, mb_map[i].category, mb_map[i].address, mb_map[i].value, mb_map[i].description);
|
||||
if (point) {
|
||||
point->addToModbusServer();
|
||||
EquipmentInstance.addModbus_Point(mb_map[i].description, point);
|
||||
}
|
||||
}
|
||||
Serial.println("Setup function ended");
|
||||
}
|
||||
//=================================================================================================================================
|
||||
/**
|
||||
* @brief The main application loop.
|
||||
* @details This function runs repeatedly after setup() has completed. It performs two main actions:
|
||||
* 1. It continuously services the Modbus server by calling `mb.task()` to handle
|
||||
* incoming requests from a Modbus master.
|
||||
* 2. At a fixed interval (defined in `config.h`), it calls `EquipmentInstance.update()`
|
||||
* to run the emulator's internal state machine and behavior logic.
|
||||
*/
|
||||
void loop() {
|
||||
mb.task();
|
||||
unsigned long currentMillis = millis();
|
||||
if (currentMillis - previousMillis >= interval) {
|
||||
previousMillis = currentMillis;
|
||||
unsigned long startTime = millis();
|
||||
EquipmentInstance.update();
|
||||
unsigned long endTime = millis();
|
||||
unsigned long elapsedTime = endTime - startTime;
|
||||
Serial.printf("Control Execution time: %d ms\n", elapsedTime);
|
||||
}
|
||||
}
|
||||
33
src/BMS/STU/STU_UMP_STU_2_0_CAH_IDR_60_TCP_PHXA7/README.md
Normal file
33
src/BMS/STU/STU_UMP_STU_2_0_CAH_IDR_60_TCP_PHXA7/README.md
Normal file
@@ -0,0 +1,33 @@
|
||||
# EQUIPMENT_TYPE MANUFACTURER MODEL TCP
|
||||
|
||||
## Brief Introduction
|
||||
Equipment specifc details that make it different from other devices
|
||||
|
||||
## List of Equipmentt
|
||||
This cofiguration has been used for these models:
|
||||
* **Model**: 09-15-22
|
||||
* **Model**: 09-15-23
|
||||
* **Model**: 09-15-25
|
||||
|
||||
## Hardware Prerequisites
|
||||
|
||||
The code is written for an ESP8266/ESP32-style microcontroller with WiFi capabilities.
|
||||
* **Microcontroller**: [Firebeetle 2 ESP32.](https://www.dfrobot.com/product-2231.html)
|
||||
|
||||
---
|
||||
|
||||
## States and Strategies
|
||||
Provide a brief description of what variables and strategies were used in this configuraiton
|
||||
|
||||
### Standby State
|
||||
* **Equipment running**: set to 0
|
||||
* **Common Alarm**: set to 0
|
||||
* **SAT temperature**: set to 85
|
||||
|
||||
### Running State
|
||||
* **Equipment running**: set to 1
|
||||
* **SAT temperature**: **Ramp Strategy** set to 65 deg setpoint
|
||||
|
||||
### Fail State
|
||||
* **Commong Alarm**: set to 1
|
||||
* **SAT temperature**: **Ramp Strategy** set to 105 deg setpointset
|
||||
@@ -0,0 +1,81 @@
|
||||
/**
|
||||
* @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 "ModbusPoints/Modbus_Point.h"
|
||||
#include "Equipment/Equipment.h"
|
||||
#include "Strategies/Strategy_Ramp.h"
|
||||
#include "Strategies/Strategy_SingleValue.h"
|
||||
#include "Strategies/Strategy_PID.h"
|
||||
#include "States/State_Standby.h"
|
||||
#include "States/State_Running.h"
|
||||
#include "States/State_Fail.h"
|
||||
#if defined(USE_MODBUS_IP)
|
||||
#include <ModbusIP_ESP8266.h>
|
||||
#else
|
||||
#include <ModbusRTU.h>
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Constructs a new FailState object with a list of active alarms.
|
||||
*
|
||||
* 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 'CW Valve Position'
|
||||
* to maintain its state during the fault.
|
||||
* @param activeAlarms A vector of strings, where each string is the
|
||||
* description of a Modbus point to be set as an active alarm.
|
||||
*/
|
||||
template<>
|
||||
FailState<ModbusIP>::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 "Alarm Reset" 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 (e.g., keeping alarm bits active).
|
||||
*
|
||||
* @param equipment Pointer to the Equipment instance.
|
||||
* @return A pointer to a new State if a transition should occur, otherwise nullptr.
|
||||
*/
|
||||
template<>
|
||||
State<ModbusIP>* FailState<ModbusIP>::update(Equipment<ModbusIP>* 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 "Alarm Common" point to 1 to indicate a general fault condition.
|
||||
* @param equipment Pointer to the Equipment instance.
|
||||
*/
|
||||
template<>
|
||||
void FailState<ModbusIP>::enterState(Equipment<ModbusIP>* 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 "Alarm Common" point to 0 before transitioning to the next state.
|
||||
* @param equipment Pointer to the Equipment instance.
|
||||
*/
|
||||
template<>
|
||||
void FailState<ModbusIP>::exitState(Equipment<ModbusIP>* equipment) {
|
||||
// Cleanup logic to run when the equipment leaves this state
|
||||
Serial.println("Exit Fail State...");
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* @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 "ModbusPoints/Modbus_Point.h"
|
||||
#include "ModbusPoints/Modbus_FloatDecorator.h"
|
||||
#include "Equipment/Equipment.h"
|
||||
#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 "Strategies/Strategy_Totalizer.h"
|
||||
#include "States/State_Standby.h"
|
||||
#include "States/State_Running.h"
|
||||
#include "States/State_Fail.h"
|
||||
#include "States/State.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<ModbusIP>::RunningState() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @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<ModbusIP>* RunningState<ModbusIP>::update(Equipment<ModbusIP>* 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 "Run Status" for all EC fans to 1 to indicate they are active.
|
||||
* @param equipment Pointer to the Equipment instance.
|
||||
*/
|
||||
template<>
|
||||
void RunningState<ModbusIP>::enterState(Equipment<ModbusIP>* 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
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Logic to execute once when exiting the running state.
|
||||
* Sets the "Run Status" for all EC fans to 0 before transitioning to the next state.
|
||||
* @param equipment Pointer to the Equipment instance.
|
||||
*/
|
||||
template<>
|
||||
void RunningState<ModbusIP>::exitState(Equipment<ModbusIP>* equipment) {
|
||||
// Cleanup logic to run when the equipment leaves this state
|
||||
Serial.println("Exit Running State...");
|
||||
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/**
|
||||
* @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 "ModbusPoints/Modbus_Point.h"
|
||||
#include "ModbusPoints/Modbus_FloatDecorator.h"
|
||||
#include "Equipment/Equipment.h"
|
||||
#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 "States/State_Standby.h"
|
||||
#include "States/State_Running.h"
|
||||
#include "States/State_Fail.h"
|
||||
#include "States/State.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 strategies
|
||||
* to bring the system to a safe, idle condition. It sets a stable value for
|
||||
* the SAT reading and creates ramp strategies to bring the CW valve and all
|
||||
* EC fan speeds down to zero.
|
||||
*/
|
||||
template<>
|
||||
StandbyState<ModbusIP>::StandbyState() {
|
||||
// You can add initialization code here if needed
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Executes the standby state's logic for one update cycle.
|
||||
*
|
||||
* This method applies the strategies defined for the standby state (e.g.,
|
||||
* ramping values to zero).
|
||||
*
|
||||
* @warning This method currently does not check for a command to transition to the
|
||||
* Running state. This logic needs to be added to allow the unit to start.
|
||||
* @return A pointer to a new State if a transition should occur, otherwise nullptr.
|
||||
*/
|
||||
template<>
|
||||
State<ModbusIP>* StandbyState<ModbusIP>::update(Equipment<ModbusIP>* equipment) {
|
||||
// STATE control, add conditions if change to a different state is needed
|
||||
Serial.println("Standby update function");
|
||||
|
||||
// Apply any strategies defined for the standby state
|
||||
_applyStrategies(equipment);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Logic to execute once when entering the standby state.
|
||||
* This method performs cleanup by setting all alarm points and all EC fan
|
||||
* run status points to 0.
|
||||
* @param equipment Pointer to the Equipment instance.
|
||||
*/
|
||||
template<>
|
||||
void StandbyState<ModbusIP>::enterState(Equipment<ModbusIP>* equipment) {
|
||||
// Logic to run when the equipment enters this state
|
||||
Serial.println("Enter Standby State...");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Logic to execute once when exiting the standby state.
|
||||
* @param equipment Pointer to the Equipment instance.
|
||||
*/
|
||||
template<>
|
||||
void StandbyState<ModbusIP>::exitState(Equipment<ModbusIP>* equipment) {
|
||||
// Cleanup logic to run when the equipment leaves this state
|
||||
Serial.println("Exit Standby State...");
|
||||
}
|
||||
120
src/BMS/STU/STU_UMP_STU_2_0_CAH_IDR_60_TCP_PHXA7/config.h
Normal file
120
src/BMS/STU/STU_UMP_STU_2_0_CAH_IDR_60_TCP_PHXA7/config.h
Normal file
@@ -0,0 +1,120 @@
|
||||
/**
|
||||
* @file config.h
|
||||
* @brief Main configuration file for the CRAH Unit (TCP) emulator.
|
||||
* @author Emmanuel Hernandez Cruz
|
||||
* @date 2025-09-02
|
||||
*
|
||||
* This file contains two important configurations: WiFi network parameters
|
||||
* and the Modbus register map for the device.
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_H
|
||||
#define CONFIG_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 = "Prime Guest"; /**< @brief The SSID of the WiFi network. */
|
||||
const char *password = "Pr1meguest#"; /**< @brief The password for the WiFi network. */
|
||||
IPAddress local_IP(192, 168, 103, 91); /**< @brief The static IP address for the device. */
|
||||
IPAddress gateway(192, 168, 103, 65); /**< @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
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @defgroup ModbusMapConfig Modbus Map Configuration
|
||||
* @brief Defines the Modbus register map and related parameters for the emulator.
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @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[] =
|
||||
{
|
||||
{COIL, 0, 0, "Fn_Enable"},
|
||||
{COIL, 1, 0, "Fn_Manual"},
|
||||
{COIL, 2, 0, "Reset_Cmd"},
|
||||
{DI, 0, 0, "Sts_Enabled"},
|
||||
{DI, 1, 0, "Sts_MANUAL"},
|
||||
{DI, 2, 0, "Alm_Actuator1"},
|
||||
{DI, 11, 0, "Alm_Actuator2"},
|
||||
{DI, 3, 0, "Alm_Fn_Fault"},
|
||||
{DI, 4, 0, "Alm_Smoke"},
|
||||
{DI, 5, 0, "Alm_Leak"},
|
||||
{DI, 6, 0, "Alm_DA_Sensor_Fault"},
|
||||
{DI, 7, 0, "Alm_CHWS_HiTemp"},
|
||||
{DI, 8, 0, "Alm_CHWR_HiTemp"},
|
||||
{DI, 9, 0, "Alm_CHWS_LoTemp"},
|
||||
{DI, 10, 0, "Alm_CHWR_LoTemp"},
|
||||
{HR, 0, 0, "Cfg_DischargeAir"},
|
||||
{HR, 2, 0, "Cfg_Fn_Speed"},
|
||||
{HR, 4, 0, "Cfg_CHWV_ManualCmd"},
|
||||
{HR, 6, 0, "Cfg_CHWS_HiTemp"},
|
||||
{HR, 8, 0, "Cfg_CHWS_LoTemp"},
|
||||
{HR, 10, 0, "Cfg_CHWR_HiTemp"},
|
||||
{HR, 12, 0, "Cfg_CHWR_LoTemp"},
|
||||
{IR, 0, 0, "Sts_DischargeAir_Avg"},
|
||||
{IR, 2, 0, "Sts_DischargeAir_1"},
|
||||
{IR, 4, 0, "Sts_DischargeAir_2"},
|
||||
{IR, 6, 0, ""},
|
||||
{IR, 8, 0, "Sts_CHWS_Temp"},
|
||||
{IR, 10, 0, "Sts_CHWR_Temp1"},
|
||||
{IR, 12, 0, "Sts_RAT"},
|
||||
{IR, 14, 0, "Sts_CHWV_PositionCmd"},
|
||||
{IR, 15, 0, "Sts_CHWR_Temp2"},
|
||||
{IR, 16, 0, "Sts_CHWV1_PositionFb"},
|
||||
{IR, 17, 0, "Sts_CHWV2_PositionFb"},
|
||||
{IR, 18, 0, "Sts_Fn1"},
|
||||
{IR, 20, 0, "Sts_Fn2"},
|
||||
{IR, 22, 0, "Sts_Fn3"},
|
||||
{IR, 24, 0, "Sts_Fn4"},
|
||||
{IR, 26, 0, "Sts_Fn5"},
|
||||
{IR, 28, 0, "Sts_Fn6"},
|
||||
{IR, 30, 0, "Sts_Fn7"},
|
||||
{IR, 32, 0, "Sts_Fn8"},
|
||||
{IR, 34, 0, "Sts_Fn9"},
|
||||
{IR, 35, 0, "Sts_Runtime_1"},
|
||||
{IR, 36, 0, "Sts_Runtime_2"},
|
||||
};
|
||||
//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;
|
||||
/** @} */ // End of ModbusMapConfig group
|
||||
|
||||
#endif // CONFIG_H
|
||||
86
src/BMS/STU/STU_UMP_STU_2_0_CAH_IDR_60_TCP_PHXA7/main.cpp
Normal file
86
src/BMS/STU/STU_UMP_STU_2_0_CAH_IDR_60_TCP_PHXA7/main.cpp
Normal file
@@ -0,0 +1,86 @@
|
||||
/**
|
||||
* @file main.cpp
|
||||
* @brief Main execution program for the CRAH Unit (TCP) Emulator.
|
||||
* @author Emmanuel Hernandez Cruz
|
||||
* @date 2025-09-02
|
||||
*
|
||||
* @details This file contains the main execution program for an Arduino-based emulator of a CRAH unit.
|
||||
* The program uses a Wi-Fi connection to communicate via the Modbus IP protocol.
|
||||
*
|
||||
* The setup() function initializes the following:
|
||||
* - Serial communication for debugging.
|
||||
* - Wi-Fi connection using credentials from config.h.
|
||||
* - A Modbus TCP server.
|
||||
* - Modbus points (Coils, Holding Registers, etc.) based on a predefined map in config.h.
|
||||
*
|
||||
* The loop() function continuously:
|
||||
* - Services the Modbus TCP server to handle incoming requests.
|
||||
* - Periodically calls the main update loop for the emulated equipment, which
|
||||
* manages state transitions and behavior strategies.
|
||||
*
|
||||
* @see config.h for Wi-Fi and Modbus configuration.
|
||||
* @see Equipment.h for the main equipment logic.
|
||||
* @see State.h for different equipment states.
|
||||
* @see Strategies/Strategy_Behavior.h for value generation strategies.
|
||||
* @see Modbus_Point.h for the base class for all Modbus points.
|
||||
*/
|
||||
//=================================================================================================================================
|
||||
//Libraries and declaration of variables.
|
||||
#include <WiFi.h>
|
||||
#include "config.h"
|
||||
#include "ModbusPoints/Modbus_PointFactory.h"
|
||||
#if defined(USE_MODBUS_IP)
|
||||
#include <ModbusIP_ESP8266.h>
|
||||
#else
|
||||
#include <ModbusRTU.h>
|
||||
#endif
|
||||
//=================================================================================================================================
|
||||
/**
|
||||
* @brief Initializes the application.
|
||||
* @details This function runs once at startup. It configures the serial communication,
|
||||
* Wi-Fi, and the Modbus server. It also creates and initializes all the Modbus points
|
||||
* based on the `mb_map` array in `config.h`.
|
||||
*/
|
||||
void setup() {
|
||||
Serial.begin(115200); //Serial comm start
|
||||
WiFi.config(local_IP, gateway, subnet); // Wifi service start
|
||||
WiFi.begin(ssid, password);
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
delay(1000);
|
||||
Serial.print(".");
|
||||
}
|
||||
Serial.println("Connected!!");
|
||||
mb.server(); //Modbus server start
|
||||
Serial.println("Server Created");
|
||||
Serial.println(map_size);
|
||||
for(int i = 0; i < map_size; i++){
|
||||
Modbus_Point<ModbusIP>* point = createModbus_Point(&mb, mb_map[i].category, mb_map[i].address, mb_map[i].value, mb_map[i].description);
|
||||
if (point) {
|
||||
point->addToModbusServer();
|
||||
EquipmentInstance.addModbus_Point(mb_map[i].description, point);
|
||||
}
|
||||
}
|
||||
Serial.println("All modbus Points created");
|
||||
Serial.println("Setup function ended");
|
||||
}
|
||||
//=================================================================================================================================
|
||||
/**
|
||||
* @brief The main application loop.
|
||||
* @details This function runs repeatedly after setup() has completed. It performs two main actions:
|
||||
* 1. It continuously services the Modbus server by calling `mb.task()` to handle
|
||||
* incoming requests from a Modbus master.
|
||||
* 2. At a fixed interval (defined in `config.h`), it calls `EquipmentInstance.update()`
|
||||
* to run the emulator's internal state machine and behavior logic.
|
||||
*/
|
||||
void loop() {
|
||||
mb.task();
|
||||
unsigned long currentMillis = millis();
|
||||
if (currentMillis - previousMillis >= interval) {
|
||||
previousMillis = currentMillis;
|
||||
unsigned long startTime = millis();
|
||||
EquipmentInstance.update();
|
||||
unsigned long endTime = millis();
|
||||
unsigned long elapsedTime = endTime - startTime;
|
||||
Serial.printf("Control Execution time: %d ms\n", elapsedTime);
|
||||
}
|
||||
}
|
||||
35
src/BMS/VFD/VFD_YASKAWA_HV600_RTU_ESV/README.md
Normal file
35
src/BMS/VFD/VFD_YASKAWA_HV600_RTU_ESV/README.md
Normal file
@@ -0,0 +1,35 @@
|
||||
# EQUIPMENT_TYPE MANUFACTURER MODEL RTU
|
||||
|
||||
## Brief Introduction
|
||||
Equipment specifc details that make it different from other devices
|
||||
|
||||
## List of Equipmentt
|
||||
This cofiguration has been used for these models:
|
||||
* **Model**: 09-15-22
|
||||
* **Model**: 09-15-23
|
||||
* **Model**: 09-15-25
|
||||
|
||||
## Hardware Prerequisites
|
||||
|
||||
The code is written for an ESP8266/ESP32-style microcontroller with WiFi capabilities and at least one hardware serial port for RS485 communication.
|
||||
|
||||
* **Microcontroller**: [Firebeetle 2 ESP32.](https://www.dfrobot.com/product-2231.html)
|
||||
* **RS485 Transceiver**: [RS485 Shield for Arduino.](https://www.dfrobot.com/product-1024.html)
|
||||
|
||||
---
|
||||
|
||||
## States and Strategies
|
||||
Provide a brief description of what variables and strategies were used in this configuraiton
|
||||
|
||||
### Standby State
|
||||
* **Equipment running**: set to 0
|
||||
* **Common Alarm**: set to 0
|
||||
* **SAT temperature**: set to 85
|
||||
|
||||
### Running State
|
||||
* **Equipment running**: set to 1
|
||||
* **SAT temperature**: **Ramp Strategy** set to 65 deg setpoint
|
||||
|
||||
### Fail State
|
||||
* **Commong Alarm**: set to 1
|
||||
* **SAT temperature**: **Ramp Strategy** set to 105 deg setpointset
|
||||
77
src/BMS/VFD/VFD_YASKAWA_HV600_RTU_ESV/State_Fail.cpp
Normal file
77
src/BMS/VFD/VFD_YASKAWA_HV600_RTU_ESV/State_Fail.cpp
Normal file
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* @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...");
|
||||
|
||||
}
|
||||
89
src/BMS/VFD/VFD_YASKAWA_HV600_RTU_ESV/State_Running.cpp
Normal file
89
src/BMS/VFD/VFD_YASKAWA_HV600_RTU_ESV/State_Running.cpp
Normal file
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* @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 <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() {
|
||||
//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<ModbusRTU>* RunningState<ModbusRTU>::update(Equipment<ModbusRTU>* 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<ModbusRTU>::enterState(Equipment<ModbusRTU>* 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<ModbusRTU>::exitState(Equipment<ModbusRTU>* equipment) {
|
||||
// Cleanup logic to run when the equipment leaves this state
|
||||
Serial.println("Exit Running State...");
|
||||
}
|
||||
77
src/BMS/VFD/VFD_YASKAWA_HV600_RTU_ESV/State_Standby.cpp
Normal file
77
src/BMS/VFD/VFD_YASKAWA_HV600_RTU_ESV/State_Standby.cpp
Normal file
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* @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 <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() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @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");
|
||||
|
||||
// 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...");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
|
||||
}
|
||||
81
src/BMS/VFD/VFD_YASKAWA_HV600_RTU_ESV/config.h
Normal file
81
src/BMS/VFD/VFD_YASKAWA_HV600_RTU_ESV/config.h
Normal file
@@ -0,0 +1,81 @@
|
||||
/**
|
||||
* @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, 32, 0, "Sts_Remote"},
|
||||
{HR, 62, 0, "Sts_SpdRPM"},
|
||||
{HR, 39, 0, "Sts_Power"},
|
||||
{HR, 38, 0, "Sts_Current"},
|
||||
{HR, 37, 0, "Sts_Voltage"},
|
||||
{HR_LONG, 92, 0, "Sts_Energy"},
|
||||
{HR, 1, 0, "Cmd_Reset"},
|
||||
{HR, 32, 0, "Alm_NotAuto"},
|
||||
{HR, 77, 0, ""},
|
||||
{HR, 91, 0, ""},
|
||||
};
|
||||
|
||||
//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
|
||||
78
src/BMS/VFD/VFD_YASKAWA_HV600_RTU_ESV/main.cpp
Normal file
78
src/BMS/VFD/VFD_YASKAWA_HV600_RTU_ESV/main.cpp
Normal file
@@ -0,0 +1,78 @@
|
||||
/**
|
||||
* @file main.cpp
|
||||
* @brief Main execution program for the Daikin Chiller (RTU) Emulator.
|
||||
* @author Emmanuel Hernandez Cruz
|
||||
* @date 2025-09-02
|
||||
*
|
||||
* @details This file contains the main execution program for an Arduino-based
|
||||
* emulator of a Daikin Chiller unit. The program communicates via the
|
||||
* Modbus RTU protocol over a serial connection.
|
||||
*
|
||||
* The setup() function initializes the following:
|
||||
* - Serial communication for debugging.
|
||||
* - A Modbus RTU server with parameters from config.h.
|
||||
* - Modbus points (Coils, Holding Registers, etc.) based on a predefined map in config.h.
|
||||
*
|
||||
* The loop() function continuously:
|
||||
* - Services the Modbus RTU server to handle incoming requests.
|
||||
* - Periodically calls the main update loop for the emulated equipment, which
|
||||
* manages state transitions and behavior strategies.
|
||||
*
|
||||
* @see config.h for Modbus RTU and register map configuration.
|
||||
* @see Equipment.h for the main equipment logic.
|
||||
* @see State.h for different equipment states.
|
||||
* @see Strategies/Strategy_Behavior.h for value generation strategies.
|
||||
* @see Modbus_Point.h for the base class for all Modbus points.
|
||||
*/
|
||||
//=================================================================================================================================
|
||||
//Libraries and declaration of variables.
|
||||
#include <Arduino.h>
|
||||
#include "config.h"
|
||||
#include "ModbusPoints/Modbus_PointFactory.h"
|
||||
|
||||
//=================================================================================================================================
|
||||
/**
|
||||
* @brief Initializes the application.
|
||||
* @details This function runs once at startup. It configures the serial communication
|
||||
* for debugging and the Modbus RTU server. It then creates and initializes all
|
||||
* the Modbus points based on the `mb_map` array in `config.h`.
|
||||
*/
|
||||
const int rtsPin = 4;
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Serial.println("Setup function started");
|
||||
|
||||
Serial2.begin(BAUDRATE, SERIAL_8N1, RX_PIN, TX_PIN);
|
||||
mb.begin(&Serial2, RST_PIN); // Start the server
|
||||
mb.slave(MODBUS_ID); // Set the slave ID
|
||||
|
||||
for(int i = 0; i < map_size; i++){
|
||||
Modbus_Point<ModbusRTU>* point = createModbus_Point(&mb, mb_map[i].category, mb_map[i].address, mb_map[i].value, mb_map[i].description);
|
||||
if (point) {
|
||||
point->addToModbusServer();
|
||||
EquipmentInstance.addModbus_Point(mb_map[i].description, point);
|
||||
}
|
||||
}
|
||||
Serial.println("Setup function ended");
|
||||
}
|
||||
//=================================================================================================================================
|
||||
/**
|
||||
* @brief The main application loop.
|
||||
* @details This function runs repeatedly after setup() has completed. It performs two main actions:
|
||||
* 1. It continuously services the Modbus server by calling `mb.task()` to handle
|
||||
* incoming requests from a Modbus master.
|
||||
* 2. At a fixed interval (defined in `config.h`), it calls `EquipmentInstance.update()`
|
||||
* to run the emulator's internal state machine and behavior logic.
|
||||
*/
|
||||
void loop() {
|
||||
mb.task();
|
||||
unsigned long currentMillis = millis();
|
||||
if (currentMillis - previousMillis >= interval) {
|
||||
previousMillis = currentMillis;
|
||||
unsigned long startTime = millis();
|
||||
EquipmentInstance.update();
|
||||
unsigned long endTime = millis();
|
||||
unsigned long elapsedTime = endTime - startTime;
|
||||
Serial.printf("Control Execution time: %d ms\n", elapsedTime);
|
||||
}
|
||||
}
|
||||
35
src/EPMS/GEN/GEN_Kohler_KD2500_RTU_ESV/README.md
Normal file
35
src/EPMS/GEN/GEN_Kohler_KD2500_RTU_ESV/README.md
Normal file
@@ -0,0 +1,35 @@
|
||||
# EQUIPMENT_TYPE MANUFACTURER MODEL RTU
|
||||
|
||||
## Brief Introduction
|
||||
Equipment specifc details that make it different from other devices
|
||||
|
||||
## List of Equipmentt
|
||||
This cofiguration has been used for these models:
|
||||
* **Model**: 09-15-22
|
||||
* **Model**: 09-15-23
|
||||
* **Model**: 09-15-25
|
||||
|
||||
## Hardware Prerequisites
|
||||
|
||||
The code is written for an ESP8266/ESP32-style microcontroller with WiFi capabilities and at least one hardware serial port for RS485 communication.
|
||||
|
||||
* **Microcontroller**: [Firebeetle 2 ESP32.](https://www.dfrobot.com/product-2231.html)
|
||||
* **RS485 Transceiver**: [RS485 Shield for Arduino.](https://www.dfrobot.com/product-1024.html)
|
||||
|
||||
---
|
||||
|
||||
## States and Strategies
|
||||
Provide a brief description of what variables and strategies were used in this configuraiton
|
||||
|
||||
### Standby State
|
||||
* **Equipment running**: set to 0
|
||||
* **Common Alarm**: set to 0
|
||||
* **SAT temperature**: set to 85
|
||||
|
||||
### Running State
|
||||
* **Equipment running**: set to 1
|
||||
* **SAT temperature**: **Ramp Strategy** set to 65 deg setpoint
|
||||
|
||||
### Fail State
|
||||
* **Commong Alarm**: set to 1
|
||||
* **SAT temperature**: **Ramp Strategy** set to 105 deg setpointset
|
||||
77
src/EPMS/GEN/GEN_Kohler_KD2500_RTU_ESV/State_Fail.cpp
Normal file
77
src/EPMS/GEN/GEN_Kohler_KD2500_RTU_ESV/State_Fail.cpp
Normal file
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* @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...");
|
||||
|
||||
}
|
||||
89
src/EPMS/GEN/GEN_Kohler_KD2500_RTU_ESV/State_Running.cpp
Normal file
89
src/EPMS/GEN/GEN_Kohler_KD2500_RTU_ESV/State_Running.cpp
Normal file
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* @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 <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() {
|
||||
//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<ModbusRTU>* RunningState<ModbusRTU>::update(Equipment<ModbusRTU>* 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<ModbusRTU>::enterState(Equipment<ModbusRTU>* 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<ModbusRTU>::exitState(Equipment<ModbusRTU>* equipment) {
|
||||
// Cleanup logic to run when the equipment leaves this state
|
||||
Serial.println("Exit Running State...");
|
||||
}
|
||||
77
src/EPMS/GEN/GEN_Kohler_KD2500_RTU_ESV/State_Standby.cpp
Normal file
77
src/EPMS/GEN/GEN_Kohler_KD2500_RTU_ESV/State_Standby.cpp
Normal file
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* @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 <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() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @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");
|
||||
|
||||
// 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...");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
|
||||
}
|
||||
164
src/EPMS/GEN/GEN_Kohler_KD2500_RTU_ESV/config.h
Normal file
164
src/EPMS/GEN/GEN_Kohler_KD2500_RTU_ESV/config.h
Normal file
@@ -0,0 +1,164 @@
|
||||
/**
|
||||
* @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[] =
|
||||
{
|
||||
{COIL, 24, 0, "Alm_GenFault"},
|
||||
{HR_LONG, 669, 0, "Avg_Current"},
|
||||
{HR_LONG, 673, 0, "Batt_V"},
|
||||
{HR_LONG, 261, 0, "Cooling_Tmp"},
|
||||
{HR_LONG, 257, 0, "Engine_RPM"},
|
||||
{HR_LONG, 21, 0, "Freq"},
|
||||
{HR_LONG, 255, 0, "Fuel_Rate"},
|
||||
{HR_LONG, 657, 0, "kVAR_Total"},
|
||||
{HR_LONG, 655, 0, "kW_Total"},
|
||||
{HR_LONG, 263, 0, "Manifold_Tmp"},
|
||||
{HR_LONG, 279, 0, "Oil_Pres"},
|
||||
{HR_LONG, 259, 0, "Oil_Tmp"},
|
||||
{HR_LONG, 659, 0, "PF_Total"},
|
||||
{HR_LONG, 7, 0, "VoltageA"},
|
||||
{HR_LONG, 9, 0, "VoltageB"},
|
||||
{HR_LONG, 11, 0, "VoltageC"},
|
||||
{COIL, 30, 0, "Breaker_Sts"},
|
||||
{COIL, 31, 0, "Tripped"},
|
||||
{HR_LONG, 285, 0, "Fuel_Percent"},
|
||||
{HR, 0, 0, "Engine_Starts"},
|
||||
{HR_LONG, 267, 0, "Run_Hrs"},
|
||||
{COIL, 219, 0, "Run_Status"},
|
||||
{COIL, 223, 0, "Charger_AC_Failure"},
|
||||
{COIL, 13, 0, "Emergency_Stop"},
|
||||
{COIL, 327, 0, "Failure_to_Close_1"},
|
||||
{COIL, 328, 0, "Failure_to_Close_2"},
|
||||
{COIL, 357, 0, "Fuel_Hi_Lvl"},
|
||||
{COIL, 236, 0, "Fuel_Leak_Detection"},
|
||||
{COIL, 358, 0, "Fuel_Low_Lvl"},
|
||||
{COIL, 6, 0, "Ground_Fault"},
|
||||
{COIL, 227, 0, "Hi_Engine_Tmp"},
|
||||
{COIL, 221, 0, "Low_Batt_V"},
|
||||
{COIL, 740, 0, "Low_Coolant_Lvl"},
|
||||
{COIL, 225, 0, "Low_Oil_Pres"},
|
||||
{COIL, 234, 0, "Not_in_Auto"},
|
||||
{COIL, 276, 0, "Over_Voltage_1"},
|
||||
{COIL, 277, 0, "Over_Voltage_2"},
|
||||
{COIL, 278, 0, "Over_Voltage_3"},
|
||||
{COIL, 279, 0, "Over_Voltage_4"},
|
||||
{COIL, 280, 0, "Over_Voltage_5"},
|
||||
{COIL, 281, 0, "Over_Voltage_6"},
|
||||
{COIL, 285, 0, "Overcurrent_1"},
|
||||
{COIL, 286, 0, "Overcurrent_2"},
|
||||
{COIL, 287, 0, "Overcurrent_3"},
|
||||
{COIL, 235, 0, "Overload"},
|
||||
{COIL, 763, 0, "Overspeed"},
|
||||
{COIL, 226, 0, "Pre_Hi_Engine_Temp_Alm"},
|
||||
{COIL, 224, 0, "Pre_Lo_Oil_Pres_Alm"},
|
||||
{COIL, 24, 0, "Shutdown_Alarm"},
|
||||
{COIL, 202, 0, "Under_Freq"},
|
||||
{COIL, 264, 0, "Under_Voltage_1"},
|
||||
{COIL, 265, 0, "Under_Voltage_2"},
|
||||
{COIL, 266, 0, "Under_Voltage_3"},
|
||||
{COIL, 267, 0, "Under_Voltage_4"},
|
||||
{COIL, 268, 0, "Under_Voltage_5"},
|
||||
{COIL, 269, 0, "Under_Voltage_6"},
|
||||
{COIL, 210, 0, "Low_Cooling_Tmp"},
|
||||
{HR_LONG, 14, 0, "CurrentA"},
|
||||
{HR_LONG, 16, 0, "CurrentB"},
|
||||
{HR_LONG, 18, 0, "CurrentC"},
|
||||
{HR_LONG, 284, 0, "Fuel_Usage"},
|
||||
{HR_LONG, 2, 0, "VoltageAB"},
|
||||
{HR_LONG, 4, 0, "VoltageBC"},
|
||||
{HR_LONG, 6, 0, "VoltageCA"},
|
||||
{COIL, 247, 0, "ECU_CommLoss"},
|
||||
{HR_LONG, 672, 0, "Controller_Hours"},
|
||||
{COIL, 14, 0, "E_Stop"},
|
||||
{COIL, 270, 0, "OV_Warning_1"},
|
||||
{COIL, 271, 0, "OV_Warning_2"},
|
||||
{COIL, 272, 0, "OV_Warning_3"},
|
||||
{COIL, 273, 0, "OV_Warning_4"},
|
||||
{COIL, 274, 0, "OV_Warning_5"},
|
||||
{COIL, 275, 0, "OV_Warning_6"},
|
||||
{COIL, 282, 0, "OC_Warning_1"},
|
||||
{COIL, 283, 0, "OC_Warning_2"},
|
||||
{COIL, 284, 0, "OC_Warning_3"},
|
||||
{COIL, 203, 0, "Ufreq_Shutdown"},
|
||||
{COIL, 258, 0, "UV_Warning_1"},
|
||||
{COIL, 259, 0, "UV_Warning_2"},
|
||||
{COIL, 260, 0, "UV_Warning_3"},
|
||||
{COIL, 261, 0, "UV_Warning_4"},
|
||||
{COIL, 262, 0, "UV_Warning_5"},
|
||||
{COIL, 263, 0, "UV_Warning_6"},
|
||||
{COIL, 201, 0, "Overcrank"},
|
||||
{COIL, 230, 0, "Alt_Thermal_Shutdown_1"},
|
||||
{COIL, 231, 0, "Alt_Thermal_Shutdown_2"},
|
||||
{COIL, 232, 0, "Alt_Thermal_Shutdown_3"},
|
||||
{COIL, 233, 0, "Alt_Thermal_Shutdown_4"},
|
||||
{COIL, 250, 0, "RevPwr_Shutdown"},
|
||||
{COIL, 251, 0, "RevVAR_Shutdown"},
|
||||
{COIL, 318, 0, "Sys_NotReady"},
|
||||
{COIL, 241, 0, "Week_Battery"},
|
||||
|
||||
};
|
||||
|
||||
//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
|
||||
78
src/EPMS/GEN/GEN_Kohler_KD2500_RTU_ESV/main.cpp
Normal file
78
src/EPMS/GEN/GEN_Kohler_KD2500_RTU_ESV/main.cpp
Normal file
@@ -0,0 +1,78 @@
|
||||
/**
|
||||
* @file main.cpp
|
||||
* @brief Main execution program for the Daikin Chiller (RTU) Emulator.
|
||||
* @author Emmanuel Hernandez Cruz
|
||||
* @date 2025-09-02
|
||||
*
|
||||
* @details This file contains the main execution program for an Arduino-based
|
||||
* emulator of a Daikin Chiller unit. The program communicates via the
|
||||
* Modbus RTU protocol over a serial connection.
|
||||
*
|
||||
* The setup() function initializes the following:
|
||||
* - Serial communication for debugging.
|
||||
* - A Modbus RTU server with parameters from config.h.
|
||||
* - Modbus points (Coils, Holding Registers, etc.) based on a predefined map in config.h.
|
||||
*
|
||||
* The loop() function continuously:
|
||||
* - Services the Modbus RTU server to handle incoming requests.
|
||||
* - Periodically calls the main update loop for the emulated equipment, which
|
||||
* manages state transitions and behavior strategies.
|
||||
*
|
||||
* @see config.h for Modbus RTU and register map configuration.
|
||||
* @see Equipment.h for the main equipment logic.
|
||||
* @see State.h for different equipment states.
|
||||
* @see Strategies/Strategy_Behavior.h for value generation strategies.
|
||||
* @see Modbus_Point.h for the base class for all Modbus points.
|
||||
*/
|
||||
//=================================================================================================================================
|
||||
//Libraries and declaration of variables.
|
||||
#include <Arduino.h>
|
||||
#include "config.h"
|
||||
#include "ModbusPoints/Modbus_PointFactory.h"
|
||||
|
||||
//=================================================================================================================================
|
||||
/**
|
||||
* @brief Initializes the application.
|
||||
* @details This function runs once at startup. It configures the serial communication
|
||||
* for debugging and the Modbus RTU server. It then creates and initializes all
|
||||
* the Modbus points based on the `mb_map` array in `config.h`.
|
||||
*/
|
||||
const int rtsPin = 4;
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Serial.println("Setup function started");
|
||||
|
||||
Serial2.begin(BAUDRATE, SERIAL_8N1, RX_PIN, TX_PIN);
|
||||
mb.begin(&Serial2, RST_PIN); // Start the server
|
||||
mb.slave(MODBUS_ID); // Set the slave ID
|
||||
|
||||
for(int i = 0; i < map_size; i++){
|
||||
Modbus_Point<ModbusRTU>* point = createModbus_Point(&mb, mb_map[i].category, mb_map[i].address, mb_map[i].value, mb_map[i].description);
|
||||
if (point) {
|
||||
point->addToModbusServer();
|
||||
EquipmentInstance.addModbus_Point(mb_map[i].description, point);
|
||||
}
|
||||
}
|
||||
Serial.println("Setup function ended");
|
||||
}
|
||||
//=================================================================================================================================
|
||||
/**
|
||||
* @brief The main application loop.
|
||||
* @details This function runs repeatedly after setup() has completed. It performs two main actions:
|
||||
* 1. It continuously services the Modbus server by calling `mb.task()` to handle
|
||||
* incoming requests from a Modbus master.
|
||||
* 2. At a fixed interval (defined in `config.h`), it calls `EquipmentInstance.update()`
|
||||
* to run the emulator's internal state machine and behavior logic.
|
||||
*/
|
||||
void loop() {
|
||||
mb.task();
|
||||
unsigned long currentMillis = millis();
|
||||
if (currentMillis - previousMillis >= interval) {
|
||||
previousMillis = currentMillis;
|
||||
unsigned long startTime = millis();
|
||||
EquipmentInstance.update();
|
||||
unsigned long endTime = millis();
|
||||
unsigned long elapsedTime = endTime - startTime;
|
||||
Serial.printf("Control Execution time: %d ms\n", elapsedTime);
|
||||
}
|
||||
}
|
||||
35
src/EPMS/Harmonic Filter/Harmonic Guard_RTU_ESV/README.md
Normal file
35
src/EPMS/Harmonic Filter/Harmonic Guard_RTU_ESV/README.md
Normal file
@@ -0,0 +1,35 @@
|
||||
# EQUIPMENT_TYPE MANUFACTURER MODEL RTU
|
||||
|
||||
## Brief Introduction
|
||||
Equipment specifc details that make it different from other devices
|
||||
|
||||
## List of Equipmentt
|
||||
This cofiguration has been used for these models:
|
||||
* **Model**: 09-15-22
|
||||
* **Model**: 09-15-23
|
||||
* **Model**: 09-15-25
|
||||
|
||||
## Hardware Prerequisites
|
||||
|
||||
The code is written for an ESP8266/ESP32-style microcontroller with WiFi capabilities and at least one hardware serial port for RS485 communication.
|
||||
|
||||
* **Microcontroller**: [Firebeetle 2 ESP32.](https://www.dfrobot.com/product-2231.html)
|
||||
* **RS485 Transceiver**: [RS485 Shield for Arduino.](https://www.dfrobot.com/product-1024.html)
|
||||
|
||||
---
|
||||
|
||||
## States and Strategies
|
||||
Provide a brief description of what variables and strategies were used in this configuraiton
|
||||
|
||||
### Standby State
|
||||
* **Equipment running**: set to 0
|
||||
* **Common Alarm**: set to 0
|
||||
* **SAT temperature**: set to 85
|
||||
|
||||
### Running State
|
||||
* **Equipment running**: set to 1
|
||||
* **SAT temperature**: **Ramp Strategy** set to 65 deg setpoint
|
||||
|
||||
### Fail State
|
||||
* **Commong Alarm**: set to 1
|
||||
* **SAT temperature**: **Ramp Strategy** set to 105 deg setpointset
|
||||
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* @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...");
|
||||
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* @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 <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() {
|
||||
//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<ModbusRTU>* RunningState<ModbusRTU>::update(Equipment<ModbusRTU>* 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<ModbusRTU>::enterState(Equipment<ModbusRTU>* 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<ModbusRTU>::exitState(Equipment<ModbusRTU>* equipment) {
|
||||
// Cleanup logic to run when the equipment leaves this state
|
||||
Serial.println("Exit Running State...");
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* @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 <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() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @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");
|
||||
|
||||
// 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...");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
|
||||
}
|
||||
169
src/EPMS/Harmonic Filter/Harmonic Guard_RTU_ESV/config.h
Normal file
169
src/EPMS/Harmonic Filter/Harmonic Guard_RTU_ESV/config.h
Normal file
@@ -0,0 +1,169 @@
|
||||
/**
|
||||
* @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, 33, 0, "V_LINE_AB_THD"},
|
||||
{HR, 34, 0, "V_LINE_BC_THD"},
|
||||
{HR, 35, 0, "V_LINE_CA_THD"},
|
||||
{HR, 39, 0, "I_LINE_A_THD"},
|
||||
{HR, 40, 0, "I_LINE_B_THD"},
|
||||
{HR, 41, 0, "I_LINE_C_THD"},
|
||||
{HR, 42, 0, "I_LINE_A_TDD"},
|
||||
{HR, 43, 0, "I_LINE_B_TDD"},
|
||||
{HR, 44, 0, "I_LINE_C_TDD"},
|
||||
{HR, 53, 0, "V_LOAD_AB_THD"},
|
||||
{HR, 54, 0, "V_LOAD_BC_THD"},
|
||||
{HR, 55, 0, "V_LOAD_CA_THD"},
|
||||
{HR, 59, 0, "I_LOAD_A_THD"},
|
||||
{HR, 60, 0, "I_LOAD_B_THD"},
|
||||
{HR, 61, 0, "I_LOAD_C_THD"},
|
||||
{HR, 73, 0, "V_TUNE_AB_THD"},
|
||||
{HR, 74, 0, "V_TUNE_BC_THD"},
|
||||
{HR, 75, 0, "V_TUNE_CA_THD"},
|
||||
{HR, 79, 0, "I_TUNE_A_THD"},
|
||||
{HR, 80, 0, "I_TUNE_B_THD"},
|
||||
{HR, 81, 0, "I_TUNE_C_THD"},
|
||||
{HR, 100, 0, "P_LINE_APPARENT_TOTAL"},
|
||||
{HR, 101, 0, "P_LINE_REAL_TOTAL"},
|
||||
{HR, 102, 0, "P_LINE_REACTIVE_TOTAL"},
|
||||
{HR, 103, 0, "P_LINE_POWER_FACTOR"},
|
||||
{HR, 120, 0, "P_LOAD_APPARENT_TOTAL"},
|
||||
{HR, 121, 0, "P_LOAD_REAL_TOTAL"},
|
||||
{HR, 122, 0, "P_LOAD_REACTIVE_TOTAL"},
|
||||
{HR, 123, 0, "P_LOAD_POWER_FACTOR"},
|
||||
{HR, 124, 0, "P_LOAD_REAL_MEAS"},
|
||||
{HR, 140, 0, "I_LINE_A_HARM_1"},
|
||||
{HR, 141, 0, "I_LINE_A_HARM_3"},
|
||||
{HR, 142, 0, "I_LINE_A_HARM_5"},
|
||||
{HR, 143, 0, "I_LINE_A_HARM_7"},
|
||||
{HR, 144, 0, "I_LINE_A_HARM_11"},
|
||||
{HR, 145, 0, "I_LINE_A_HARM_13"},
|
||||
{HR, 146, 0, "I_LINE_A_HARM_17"},
|
||||
{HR, 147, 0, "I_LINE_A_HARM_19"},
|
||||
{HR, 148, 0, "I_LINE_A_HARM_23"},
|
||||
{HR, 149, 0, "I_LINE_A_HARM_25"},
|
||||
{HR, 160, 0, "I_LINE_B_HARM_1"},
|
||||
{HR, 161, 0, "I_LINE_B_HARM_3"},
|
||||
{HR, 162, 0, "I_LINE_B_HARM_5"},
|
||||
{HR, 163, 0, "I_LINE_B_HARM_7"},
|
||||
{HR, 164, 0, "I_LINE_B_HARM_11"},
|
||||
{HR, 165, 0, "I_LINE_B_HARM_13"},
|
||||
{HR, 166, 0, "I_LINE_B_HARM_17"},
|
||||
{HR, 167, 0, "I_LINE_B_HARM_19"},
|
||||
{HR, 168, 0, "I_LINE_B_HARM_23"},
|
||||
{HR, 169, 0, "I_LINE_B_HARM_25"},
|
||||
{HR, 180, 0, "I_LINE_C_HARM_1"},
|
||||
{HR, 181, 0, "I_LINE_C_HARM_3"},
|
||||
{HR, 182, 0, "I_LINE_C_HARM_5"},
|
||||
{HR, 183, 0, "I_LINE_C_HARM_7"},
|
||||
{HR, 184, 0, "I_LINE_C_HARM_11"},
|
||||
{HR, 185, 0, "I_LINE_C_HARM_13"},
|
||||
{HR, 186, 0, "I_LINE_C_HARM_17"},
|
||||
{HR, 187, 0, "I_LINE_C_HARM_19"},
|
||||
{HR, 188, 0, "I_LINE_C_HARM_23"},
|
||||
{HR, 189, 0, "I_LINE_C_HARM_25"},
|
||||
{HR, 200, 0, "CNT_OPENED"},
|
||||
{HR, 201, 0, "SYS_POWER_ON"},
|
||||
{HR, 202, 0, "SYS_STATUS_OK"},
|
||||
{HR, 203, 0, "SYS_AT_CAPACITY"},
|
||||
{HR, 204, 0, "T_AMBIENT"},
|
||||
{HR, 210, 0, "RECLOSE_LIMIT"},
|
||||
{HR, 210, 0, "NCP_FAULT_A"},
|
||||
{HR, 210, 0, "NCP_FAULT_B"},
|
||||
{HR, 210, 0, "LINE_REACTOR_THERMAL_SW"},
|
||||
{HR, 211, 0, "TUNE_PHASE_LOSS_A"},
|
||||
{HR, 211, 0, "TUNE_PHASE_LOSS_B"},
|
||||
{HR, 211, 0, "TUNE_PHASE_LOSS_C"},
|
||||
{HR, 211, 0, "TUNE_ BALANCE_LOSS_A"},
|
||||
{HR, 211, 0, "TUNE_ BALANCE_LOSS_B"},
|
||||
{HR, 211, 0, "TUNE_ BALANCE_LOSS_C"},
|
||||
{HR, 211, 0, "TUNE_UNDERCURRENT_A"},
|
||||
{HR, 211, 0, "TUNE_UNDERCURRENT_B"},
|
||||
{HR, 211, 0, "TUNE_UNDERCURRENT_C"},
|
||||
{HR, 211, 0, "TUNE_OVERCURRENT_A"},
|
||||
{HR, 211, 0, "TUNE_OVERCURRENT_B"},
|
||||
{HR, 211, 0, "TUNE_OVERCURRENT_C"},
|
||||
{HR, 211, 0, "UNDER_TEMP"},
|
||||
{HR, 211, 0, "OVER_TEMP"},
|
||||
{HR, 211, 0, "CPU_ERROR"},
|
||||
{HR, 211, 0, "TUNE_REACTOR_THERMAL_SW"},
|
||||
{HR, 212, 0, "PHASE_LOSS_A"},
|
||||
{HR, 212, 0, "PHASE_LOSS_B"},
|
||||
{HR, 212, 0, "PHASE_LOSS_C"},
|
||||
{HR, 212, 0, "OVERVOLTAGE_A"},
|
||||
{HR, 212, 0, "OVERVOLTAGE_B"},
|
||||
{HR, 212, 0, "OVERVOLTAGE_C"},
|
||||
{HR, 212, 0, "FILTER_FREQ_MISMATCH"},
|
||||
{HR, 212, 0, "HIGH_VOLTAGE_THD"},
|
||||
{HR, 212, 0, "LINE_PHASE_ROTATION"},
|
||||
{HR, 250, 0, "SYS_CONTROL_MODE_RO"},
|
||||
{HR, 251, 0, "TRACE_GO_DONE_RO"},
|
||||
{HR, 256, 0, "SYS_STATE"},
|
||||
{HR, 12, 0, ""},
|
||||
};
|
||||
|
||||
//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
|
||||
78
src/EPMS/Harmonic Filter/Harmonic Guard_RTU_ESV/main.cpp
Normal file
78
src/EPMS/Harmonic Filter/Harmonic Guard_RTU_ESV/main.cpp
Normal file
@@ -0,0 +1,78 @@
|
||||
/**
|
||||
* @file main.cpp
|
||||
* @brief Main execution program for the Daikin Chiller (RTU) Emulator.
|
||||
* @author Emmanuel Hernandez Cruz
|
||||
* @date 2025-09-02
|
||||
*
|
||||
* @details This file contains the main execution program for an Arduino-based
|
||||
* emulator of a Daikin Chiller unit. The program communicates via the
|
||||
* Modbus RTU protocol over a serial connection.
|
||||
*
|
||||
* The setup() function initializes the following:
|
||||
* - Serial communication for debugging.
|
||||
* - A Modbus RTU server with parameters from config.h.
|
||||
* - Modbus points (Coils, Holding Registers, etc.) based on a predefined map in config.h.
|
||||
*
|
||||
* The loop() function continuously:
|
||||
* - Services the Modbus RTU server to handle incoming requests.
|
||||
* - Periodically calls the main update loop for the emulated equipment, which
|
||||
* manages state transitions and behavior strategies.
|
||||
*
|
||||
* @see config.h for Modbus RTU and register map configuration.
|
||||
* @see Equipment.h for the main equipment logic.
|
||||
* @see State.h for different equipment states.
|
||||
* @see Strategies/Strategy_Behavior.h for value generation strategies.
|
||||
* @see Modbus_Point.h for the base class for all Modbus points.
|
||||
*/
|
||||
//=================================================================================================================================
|
||||
//Libraries and declaration of variables.
|
||||
#include <Arduino.h>
|
||||
#include "config.h"
|
||||
#include "ModbusPoints/Modbus_PointFactory.h"
|
||||
|
||||
//=================================================================================================================================
|
||||
/**
|
||||
* @brief Initializes the application.
|
||||
* @details This function runs once at startup. It configures the serial communication
|
||||
* for debugging and the Modbus RTU server. It then creates and initializes all
|
||||
* the Modbus points based on the `mb_map` array in `config.h`.
|
||||
*/
|
||||
const int rtsPin = 4;
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Serial.println("Setup function started");
|
||||
|
||||
Serial2.begin(BAUDRATE, SERIAL_8N1, RX_PIN, TX_PIN);
|
||||
mb.begin(&Serial2, RST_PIN); // Start the server
|
||||
mb.slave(MODBUS_ID); // Set the slave ID
|
||||
|
||||
for(int i = 0; i < map_size; i++){
|
||||
Modbus_Point<ModbusRTU>* point = createModbus_Point(&mb, mb_map[i].category, mb_map[i].address, mb_map[i].value, mb_map[i].description);
|
||||
if (point) {
|
||||
point->addToModbusServer();
|
||||
EquipmentInstance.addModbus_Point(mb_map[i].description, point);
|
||||
}
|
||||
}
|
||||
Serial.println("Setup function ended");
|
||||
}
|
||||
//=================================================================================================================================
|
||||
/**
|
||||
* @brief The main application loop.
|
||||
* @details This function runs repeatedly after setup() has completed. It performs two main actions:
|
||||
* 1. It continuously services the Modbus server by calling `mb.task()` to handle
|
||||
* incoming requests from a Modbus master.
|
||||
* 2. At a fixed interval (defined in `config.h`), it calls `EquipmentInstance.update()`
|
||||
* to run the emulator's internal state machine and behavior logic.
|
||||
*/
|
||||
void loop() {
|
||||
mb.task();
|
||||
unsigned long currentMillis = millis();
|
||||
if (currentMillis - previousMillis >= interval) {
|
||||
previousMillis = currentMillis;
|
||||
unsigned long startTime = millis();
|
||||
EquipmentInstance.update();
|
||||
unsigned long endTime = millis();
|
||||
unsigned long elapsedTime = endTime - startTime;
|
||||
Serial.printf("Control Execution time: %d ms\n", elapsedTime);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user