CoolIT CDU equipment added to library
This commit is contained in:
33
src/BMS/CDU/CDU_CoolIT_Oracle_TCP/README.md
Normal file
33
src/BMS/CDU/CDU_CoolIT_Oracle_TCP/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
|
||||
81
src/BMS/CDU/CDU_CoolIT_Oracle_TCP/State_Fail.cpp
Normal file
81
src/BMS/CDU/CDU_CoolIT_Oracle_TCP/State_Fail.cpp
Normal file
@@ -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...");
|
||||
}
|
||||
136
src/BMS/CDU/CDU_CoolIT_Oracle_TCP/State_Running.cpp
Normal file
136
src/BMS/CDU/CDU_CoolIT_Oracle_TCP/State_Running.cpp
Normal file
@@ -0,0 +1,136 @@
|
||||
/**
|
||||
* @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() {
|
||||
addStrategy("TT01", new SingleValueStrategy(870.0F, 10.0f, 1000));
|
||||
addStrategy("TT02", new SingleValueStrategy(880.0F, 10.0f, 1000));
|
||||
addStrategy("TT31", new SingleValueStrategy(670.0F, 10.0f, 1000));
|
||||
addStrategy("TT41", new SingleValueStrategy(660.0F, 10.0f, 1000));
|
||||
addStrategy("PT01", new SingleValueStrategy(350.0F, 10.0f, 1000));
|
||||
addStrategy("PT02", new SingleValueStrategy(380.0F, 10.0f, 1000));
|
||||
addStrategy("PT31", new SingleValueStrategy(340.0F, 10.0f, 1000));
|
||||
addStrategy("PT41", new SingleValueStrategy(370.0F, 10.0f, 1000));
|
||||
addStrategy("PT32", new SingleValueStrategy(380.0F, 10.0f, 1000));
|
||||
addStrategy("PT42", new SingleValueStrategy(350.0F, 10.0f, 1000));
|
||||
addStrategy("PT21", new SingleValueStrategy(370.0F, 10.0f, 1000));
|
||||
addStrategy("PT11", new SingleValueStrategy(390.0F, 10.0f, 1000));
|
||||
addStrategy("AirTemp", new SingleValueStrategy(660.0F, 1.0f, 1000));
|
||||
addStrategy("DP31", new SingleValueStrategy(150.0F, 10.0f, 1000));
|
||||
addStrategy("DP41", new SingleValueStrategy(180.0F, 10.0f, 1000));
|
||||
addStrategy("DP", new SingleValueStrategy(160.0F, 10.0f, 1000));
|
||||
addStrategy("FL01", new SingleValueStrategy(7420.0F, 10.0f, 1000));
|
||||
addStrategy("P31_Speed", new SingleValueStrategy(300.0F, 10.0f, 1000));
|
||||
addStrategy("P41_Speed", new SingleValueStrategy(410.0F, 10.0f, 1000));
|
||||
addStrategy("F1_Speed", new SingleValueStrategy(180.0F, 10.0f, 1000));
|
||||
addStrategy("F2_Speed", new SingleValueStrategy(190.0F, 10.0f, 1000));
|
||||
addStrategy("F3_Speed", new SingleValueStrategy(170.0F, 10.0f, 1000));
|
||||
addStrategy("F4_Speed", new SingleValueStrategy(200.0F, 10.0f, 1000));
|
||||
addStrategy("F5_Speed", new SingleValueStrategy(250.0F, 10.0f, 1000));
|
||||
addStrategy("F6_Speed", new SingleValueStrategy(210.0F, 10.0f, 1000));
|
||||
addStrategy("F7_Speed", new SingleValueStrategy(200.0F, 10.0f, 1000));
|
||||
addStrategy("F8_Speed", new SingleValueStrategy(180.0F, 10.0f, 1000));
|
||||
addStrategy("AirTemp", new SingleValueStrategy(680.0f, 100.0f, 5000));
|
||||
addStrategy("Group_Flow", new SingleValueStrategy(7510.0F, 10.0f, 1000));
|
||||
addStrategy("Group_DP", new SingleValueStrategy(200.0F, 10.0f, 1000));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Executes the running state's logic for one update cycle.
|
||||
*
|
||||
* This method first checks for state transition commands:
|
||||
* 1. It reads the "ON/OFF Command By BMS" point. If it's 0, it transitions to StandbyState.
|
||||
* 2. It reads the "Fault Code" point. If it's non-zero, it transitions to FailState,
|
||||
* passing the corresponding alarm description.
|
||||
*
|
||||
* If no transition occurs, it applies the strategies defined for the running state.
|
||||
*
|
||||
* @param equipment Pointer to the Equipment instance.
|
||||
* @return A pointer to a new State if a transition should occur, otherwise nullptr.
|
||||
*/
|
||||
template<>
|
||||
State<ModbusIP>* RunningState<ModbusIP>::update(Equipment<ModbusIP>* equipment) {
|
||||
// STATE control, add conditions if change to a different state is needed
|
||||
Serial.println("Running update function");
|
||||
float State_Ctrl = getPointValue(equipment, "Remote_Start");
|
||||
if (State_Ctrl == 0){
|
||||
return new StandbyState<ModbusIP>();
|
||||
}
|
||||
|
||||
float TT01 = getPointValue(equipment, "TT01");
|
||||
float TT02 = getPointValue(equipment, "TT02");
|
||||
float TT31 = getPointValue(equipment, "TT31");
|
||||
float TT41 = getPointValue(equipment, "TT41");
|
||||
float PT01 = getPointValue(equipment, "PT01");
|
||||
float PT02 = getPointValue(equipment, "PT02");
|
||||
float PT31 = getPointValue(equipment, "PT31");
|
||||
float PT41 = getPointValue(equipment, "PT41");
|
||||
setPointValue(equipment, "TT01_TT02", (TT01 + TT02)/2.0f);
|
||||
setPointValue(equipment, "TT31_TT41", (TT31 + TT41)/2.0f);
|
||||
setPointValue(equipment, "PT01_PT02", (PT01 + PT02)/2.0f);
|
||||
setPointValue(equipment, "PT31_PT41", (PT31 + PT41)/2.0f);
|
||||
|
||||
// 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
|
||||
setPointValue(equipment, "Status", 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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...");
|
||||
|
||||
}
|
||||
130
src/BMS/CDU/CDU_CoolIT_Oracle_TCP/State_Standby.cpp
Normal file
130
src/BMS/CDU/CDU_CoolIT_Oracle_TCP/State_Standby.cpp
Normal file
@@ -0,0 +1,130 @@
|
||||
/**
|
||||
* @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
|
||||
addStrategy("TT01", new SingleValueStrategy(870.0F, 10.0f, 1000));
|
||||
addStrategy("TT02", new SingleValueStrategy(870.0F, 10.0f, 1000));
|
||||
addStrategy("TT31", new SingleValueStrategy(870.0F, 10.0f, 1000));
|
||||
addStrategy("TT41", new SingleValueStrategy(870.0F, 10.0f, 1000));
|
||||
addStrategy("PT01", new SingleValueStrategy(1.0F, 1.0f, 1000));
|
||||
addStrategy("PT02", new SingleValueStrategy(1.0F, 1.0f, 1000));
|
||||
addStrategy("PT31", new SingleValueStrategy(1.0F, 1.0f, 1000));
|
||||
addStrategy("PT41", new SingleValueStrategy(1.0F, 1.0f, 1000));
|
||||
addStrategy("PT32", new SingleValueStrategy(1.0F, 1.0f, 1000));
|
||||
addStrategy("PT42", new SingleValueStrategy(1.0F, 1.0f, 1000));
|
||||
addStrategy("PT21", new SingleValueStrategy(1.0F, 1.0f, 1000));
|
||||
addStrategy("PT11", new SingleValueStrategy(1.0F, 1.0f, 1000));
|
||||
addStrategy("DP31", new SingleValueStrategy(1.0F, 1.0f, 1000));
|
||||
addStrategy("DP41", new SingleValueStrategy(1.0F, 1.0f, 1000));
|
||||
addStrategy("DP", new SingleValueStrategy(1.0F, 1.0f, 1000));
|
||||
addStrategy("FL01", new SingleValueStrategy(1.0F, 1.0f, 1000));
|
||||
addStrategy("AirTemp", new SingleValueStrategy(870.0F, 10.0f, 1000));
|
||||
addStrategy("P31_Speed", new SingleValueStrategy(1.0F, 1.0f, 1000));
|
||||
addStrategy("P41_Speed", new SingleValueStrategy(1.0F, 1.0f, 1000));
|
||||
addStrategy("F1_Speed", new SingleValueStrategy(1.0F, 1.0f, 1000));
|
||||
addStrategy("F2_Speed", new SingleValueStrategy(1.0F, 1.0f, 1000));
|
||||
addStrategy("F3_Speed", new SingleValueStrategy(1.0F, 1.0f, 1000));
|
||||
addStrategy("F4_Speed", new SingleValueStrategy(1.0F, 1.0f, 1000));
|
||||
addStrategy("F5_Speed", new SingleValueStrategy(1.0F, 1.0f, 1000));
|
||||
addStrategy("F6_Speed", new SingleValueStrategy(1.0F, 1.0f, 1000));
|
||||
addStrategy("F7_Speed", new SingleValueStrategy(1.0F, 1.0f, 1000));
|
||||
addStrategy("F8_Speed", new SingleValueStrategy(1.0F, 1.0f, 1000));
|
||||
addStrategy("Group_Flow", new SingleValueStrategy(1.0F, 1.0f, 1000));
|
||||
addStrategy("Group_DP", new SingleValueStrategy(1.0F, 1.0f, 1000));
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @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");
|
||||
float State_Ctrl = getPointValue(equipment, "Remote_Start");
|
||||
if (State_Ctrl == 1){
|
||||
return new RunningState<ModbusIP>();
|
||||
}
|
||||
float TT01 = getPointValue(equipment, "TT01");
|
||||
float TT02 = getPointValue(equipment, "TT02");
|
||||
float TT31 = getPointValue(equipment, "TT31");
|
||||
float TT41 = getPointValue(equipment, "TT41");
|
||||
float PT01 = getPointValue(equipment, "PT01");
|
||||
float PT02 = getPointValue(equipment, "PT02");
|
||||
float PT31 = getPointValue(equipment, "PT31");
|
||||
float PT41 = getPointValue(equipment, "PT41");
|
||||
setPointValue(equipment, "TT01_TT02", (TT01 + TT02)/2.0f);
|
||||
setPointValue(equipment, "TT31_TT41", (TT31 + TT41)/2.0f);
|
||||
setPointValue(equipment, "PT01_PT02", (PT01 + PT02)/2.0f);
|
||||
setPointValue(equipment, "PT31_PT41", (PT31 + PT41)/2.0f);
|
||||
// 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...");
|
||||
setPointValue(equipment, "Status", 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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...");
|
||||
}
|
||||
129
src/BMS/CDU/CDU_CoolIT_Oracle_TCP/config.h
Normal file
129
src/BMS/CDU/CDU_CoolIT_Oracle_TCP/config.h
Normal file
@@ -0,0 +1,129 @@
|
||||
/**
|
||||
* @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 = "Oracle_SA"; /**< @brief The SSID of the WiFi network. */
|
||||
const char *password = "Prime!123"; /**< @brief The password for the WiFi network. */
|
||||
IPAddress local_IP(192, 168, 1, 110); /**< @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
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @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[] =
|
||||
{
|
||||
{HR, 0, 0, "Status"},
|
||||
{HR, 1, 0, "Group"},
|
||||
{HR, 2, 0, "TT01"},
|
||||
{HR, 3, 0, "TT02"},
|
||||
{HR, 4, 0, "TT31"},
|
||||
{HR, 5, 0, "TT41"},
|
||||
{HR, 6, 0, "PT01"},
|
||||
{HR, 7, 0, "PT02"},
|
||||
{HR, 8, 0, "PT31"},
|
||||
{HR, 9, 0, "PT41"},
|
||||
{HR, 10, 0, "PT32"},
|
||||
{HR, 11, 0, "PT42"},
|
||||
{HR, 12, 0, "PT21"},
|
||||
{HR, 13, 0, "PT11"},
|
||||
{HR, 14, 0, "TT01_TT02"},
|
||||
{HR, 15, 0, "TT31_TT41"},
|
||||
{HR, 16, 0, "PT01_PT02"},
|
||||
{HR, 17, 0, "PT31_PT41"},
|
||||
{HR, 18, 0, "DP31"},
|
||||
{HR, 19, 0, "DP41"},
|
||||
{HR, 20, 0, "DP"},
|
||||
{HR, 21, 0, "FL01"},
|
||||
{HR, 22, 0, "P31_Speed"},
|
||||
{HR, 23, 0, "P41_Speed"},
|
||||
{HR, 24, 0, "F1_Speed"},
|
||||
{HR, 25, 0, "F2_Speed"},
|
||||
{HR, 26, 0, "F3_Speed"},
|
||||
{HR, 27, 0, "F4_Speed"},
|
||||
{HR, 28, 0, "F5_Speed"},
|
||||
{HR, 29, 0, "F6_Speed"},
|
||||
{HR, 30, 0, "F7_Speed"},
|
||||
{HR, 31, 0, "F8_Speed"},
|
||||
{HR, 33, 0, "AirTemp"},
|
||||
{HR_FLOAT, 40, 0, "Group_Flow"},
|
||||
{HR_FLOAT, 42, 0, "Group_DP"},
|
||||
{HR, 44, 0, "Version"},
|
||||
{HR, 200, 0, "Temp_SP"},
|
||||
{HR, 201, 0, "DP_SP"},
|
||||
{HR, 202, 0, "Flow_SP"},
|
||||
|
||||
{COIL, 0, 0, "Alarm"},
|
||||
{COIL, 1, 0, "Alarm_Ack"},
|
||||
{COIL, 5, 0, "OvrPressure"},
|
||||
{COIL, 14, 0, "Ntwk_Fault"},
|
||||
{COIL, 15, 0, "Unit_Available"},
|
||||
{COIL, 33, 0, "OvrTemp"},
|
||||
{COIL, 86, 0, "LD01"},
|
||||
{COIL, 87, 0, "StpBtn"},
|
||||
{COIL, 131, 0, "Critical_Fault"},
|
||||
{COIL, 132, 0, "Power_Fault"},
|
||||
{COIL, 133, 0, "PLC_Fault"},
|
||||
{COIL, 200, 0, "Remote_Start"},
|
||||
|
||||
};
|
||||
//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/CDU/CDU_CoolIT_Oracle_TCP/main.cpp
Normal file
86
src/BMS/CDU/CDU_CoolIT_Oracle_TCP/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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user