RPP program added
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
|
||||
[platformio]
|
||||
|
||||
default_envs = CDU_CoolIT_Oracle_TCP ; Select here the name of the configuration you want to download
|
||||
default_envs = RPP_Cortex_TCP ; Select here the name of the configuration you want to download
|
||||
|
||||
[env]
|
||||
upload_port = COM19
|
||||
@@ -267,3 +267,10 @@ board = dfrobot_firebeetle2_esp32e
|
||||
extends = common_env_options
|
||||
build_flags = -D USE_MODBUS_IP
|
||||
build_src_filter = -<*> +<BMS/CDU/CDU_CoolIT_Oracle_TCP>
|
||||
|
||||
[env:RPP_Cortex_TCP]
|
||||
platform = espressif32
|
||||
board = dfrobot_firebeetle2_esp32e
|
||||
extends = common_env_options
|
||||
build_flags = -D USE_MODBUS_IP
|
||||
build_src_filter = -<*> +<EPMS/RPP/RPP_Cortex_TCP>
|
||||
@@ -23,8 +23,8 @@
|
||||
#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 local_IP(172, 17, 38, 22); /**< @brief The static IP address for the device. */
|
||||
IPAddress gateway(172, 17, 38, 1); /**< @brief The gateway IP address. */
|
||||
IPAddress subnet(255, 255, 255, 0); /**< @brief The subnet mask. */
|
||||
|
||||
ModbusIP mb;
|
||||
|
||||
33
src/EPMS/RPP/RPP_Cortex_TCP/README.md
Normal file
33
src/EPMS/RPP/RPP_Cortex_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/EPMS/RPP/RPP_Cortex_TCP/State_Fail.cpp
Normal file
81
src/EPMS/RPP/RPP_Cortex_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...");
|
||||
}
|
||||
99
src/EPMS/RPP/RPP_Cortex_TCP/State_Running.cpp
Normal file
99
src/EPMS/RPP/RPP_Cortex_TCP/State_Running.cpp
Normal file
@@ -0,0 +1,99 @@
|
||||
/**
|
||||
* @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));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @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");
|
||||
setPointValue(equipment, "TT01_TT02", (TT01 + TT02)/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...");
|
||||
|
||||
}
|
||||
224
src/EPMS/RPP/RPP_Cortex_TCP/State_Standby.cpp
Normal file
224
src/EPMS/RPP/RPP_Cortex_TCP/State_Standby.cpp
Normal file
@@ -0,0 +1,224 @@
|
||||
/**
|
||||
* @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("In_freq", new SingleValueStrategy(60.0F, 1.0f, 1000));
|
||||
addStrategy("InV_L1N", new SingleValueStrategy(220.0F, 1.0f, 1000));
|
||||
addStrategy("InV_L2N", new SingleValueStrategy(220.0F, 1.0f, 1000));
|
||||
addStrategy("InV_L3N", new SingleValueStrategy(220.0F, 1.0f, 1000));
|
||||
addStrategy("InV_L12", new SingleValueStrategy(480.0F, 1.0f, 1000));
|
||||
addStrategy("InV_L23", new SingleValueStrategy(480.0F, 1.0f, 1000));
|
||||
addStrategy("InV_L31", new SingleValueStrategy(480.0F, 1.0f, 1000));
|
||||
addStrategy("InTHD_L1N", new SingleValueStrategy(2.5F, 0.5f, 1000));
|
||||
addStrategy("InTHD_L2N", new SingleValueStrategy(3.1F, 0.5f, 1000));
|
||||
addStrategy("InTHD_L3N", new SingleValueStrategy(2.4F, 0.5f, 1000));
|
||||
addStrategy("InTHD_L1_1st", new SingleValueStrategy(2.4F, 0.2f, 1000));
|
||||
addStrategy("InTHD_L1_3rd", new SingleValueStrategy(2.1F, 0.2f, 1000));
|
||||
addStrategy("InTHD_L1_5th", new SingleValueStrategy(1.9F, 0.2f, 1000));
|
||||
addStrategy("InTHD_L1_7th", new SingleValueStrategy(2.1F, 0.2f, 1000));
|
||||
addStrategy("InTHD_L1_9th", new SingleValueStrategy(1.8F, 0.2f, 1000));
|
||||
addStrategy("InTHD_L2_1st", new SingleValueStrategy(2.3F, 0.2f, 1000));
|
||||
addStrategy("InTHD_L2_3rd", new SingleValueStrategy(2.2F, 0.2f, 1000));
|
||||
addStrategy("InTHD_L2_5th", new SingleValueStrategy(2.4F, 0.2f, 1000));
|
||||
addStrategy("InTHD_L2_7th", new SingleValueStrategy(2.5F, 0.2f, 1000));
|
||||
addStrategy("InTHD_L2_9th", new SingleValueStrategy(2.6F, 0.2f, 1000));
|
||||
addStrategy("InTHD_L3_1st", new SingleValueStrategy(2.2F, 0.2f, 1000));
|
||||
addStrategy("InTHD_L3_3rd", new SingleValueStrategy(2.3F, 0.2f, 1000));
|
||||
addStrategy("InTHD_L3_5th", new SingleValueStrategy(2.1F, 0.2f, 1000));
|
||||
addStrategy("InTHD_L3_7th", new SingleValueStrategy(2.4F, 0.2f, 1000));
|
||||
addStrategy("InTHD_L3_9th", new SingleValueStrategy(2.5F, 0.2f, 1000));
|
||||
addStrategy("InTHD_L12", new SingleValueStrategy(3.1F, 0.2f, 1000));
|
||||
addStrategy("InTHD_L23", new SingleValueStrategy(2.1F, 0.2f, 1000));
|
||||
addStrategy("InTHD_L31", new SingleValueStrategy(1.8F, 0.2f, 1000));
|
||||
|
||||
addStrategy("CB1_kW", new SingleValueStrategy(3.1F, 3.0f, 1000));
|
||||
addStrategy("CB2_kW", new SingleValueStrategy(3.1F, 3.0f, 1000));
|
||||
addStrategy("CB3_kW", new SingleValueStrategy(3.1F, 3.0f, 1000));
|
||||
addStrategy("CB4_kW", new SingleValueStrategy(3.1F, 3.0f, 1000));
|
||||
addStrategy("CB5_kW", new SingleValueStrategy(3.1F, 3.0f, 1000));
|
||||
addStrategy("CB6_kW", new SingleValueStrategy(3.1F, 3.0f, 1000));
|
||||
addStrategy("CB7_kW", new SingleValueStrategy(3.1F, 3.0f, 1000));
|
||||
addStrategy("CB8_kW", new SingleValueStrategy(3.1F, 3.0f, 1000));
|
||||
addStrategy("CB9_kW", new SingleValueStrategy(3.1F, 3.0f, 1000));
|
||||
addStrategy("CB10_kW", new SingleValueStrategy(3.1F, 3.0f, 1000));
|
||||
addStrategy("CB11_kW", new SingleValueStrategy(3.1F, 3.0f, 1000));
|
||||
addStrategy("CB12_kW", new SingleValueStrategy(3.1F, 3.0f, 1000));
|
||||
addStrategy("CB13_kW", new SingleValueStrategy(3.1F, 3.0f, 1000));
|
||||
addStrategy("CB14_kW", new SingleValueStrategy(3.1F, 3.0f, 1000));
|
||||
addStrategy("CB15_kW", new SingleValueStrategy(3.1F, 3.0f, 1000));
|
||||
addStrategy("CB16_kW", new SingleValueStrategy(3.1F, 3.0f, 1000));
|
||||
|
||||
addStrategy("MainCB_PF", new SingleValueStrategy(0.9F, 0.05f, 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");
|
||||
|
||||
// Calculate Avergae for voltage LN points
|
||||
float InV_L1N = getPointValue(equipment, "InV_L1N");
|
||||
float InV_L2N = getPointValue(equipment, "InV_L2N");
|
||||
float InV_L3N = getPointValue(equipment, "InV_L3N");
|
||||
setPointValue(equipment, "InV_LN_avg", (InV_L1N + InV_L2N + InV_L3N)/3.0f);
|
||||
// Calculate Avergae for voltage LL points
|
||||
float InV_L12 = getPointValue(equipment, "InV_L12");
|
||||
float InV_L23 = getPointValue(equipment, "InV_L23");
|
||||
float InV_L31 = getPointValue(equipment, "InV_L31");
|
||||
setPointValue(equipment, "InV_LL_avg", (InV_L12 + InV_L23 + InV_L31)/3.0f);
|
||||
|
||||
|
||||
for (int i = 1; i <= 16; i++) {
|
||||
std::string cb_name = "CB" + std::to_string(i);
|
||||
std::string kw_name = cb_name + "_kW";
|
||||
std::string max_kw_name = cb_name + "_max_kW";
|
||||
std::string max_current_name = cb_name + "_maxCurrent";
|
||||
|
||||
float cb_value = getPointValue(equipment, cb_name.c_str());
|
||||
if (cb_value == 1.0f){
|
||||
float kw = 350.0f;
|
||||
Strategy_Behavior* svs_cb_kW = getStrategy(kw_name.c_str());
|
||||
static_cast<SingleValueStrategy*>(svs_cb_kW)->setSetpoint(kw);
|
||||
|
||||
float in_v_ll_avg = getPointValue(equipment, "InV_LL_avg");
|
||||
float current = (kw*1000.0f)/(in_v_ll_avg*1.73f);
|
||||
setPointValue(equipment, max_current_name.c_str(), current);
|
||||
|
||||
float max_kw = getPointValue(equipment, max_kw_name.c_str());
|
||||
if (kw > max_kw){
|
||||
setPointValue(equipment, max_kw_name.c_str(), kw);
|
||||
}
|
||||
|
||||
float max_current = getPointValue(equipment, max_current_name.c_str());
|
||||
if (current > max_current){
|
||||
setPointValue(equipment, max_current_name.c_str(), current);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
float mainCB_total_kW = 0.0f;
|
||||
float mainCB_maxCurrent = 0.0f;
|
||||
float mainCB_neutralCurrent = 0.0f;
|
||||
float mainCB_maxTotalKw = 0.0f;
|
||||
float mainCB_maxTotalCurrent = 0.0f;
|
||||
for (int i = 1; i <= 16; i++) {
|
||||
std::string kw_name = "CB" + std::to_string(i) + "_kW";
|
||||
std::string max_current_name = "CB" + std::to_string(i) + "_maxCurrent";
|
||||
mainCB_total_kW += getPointValue(equipment, kw_name.c_str());
|
||||
mainCB_maxCurrent += getPointValue(equipment, max_current_name.c_str());
|
||||
float max_kw = getPointValue(equipment, ("CB" + std::to_string(i) + "_max_kW").c_str());
|
||||
if (max_kw > mainCB_maxTotalKw) {
|
||||
mainCB_maxTotalKw = max_kw;
|
||||
}
|
||||
float max_current = getPointValue(equipment, max_current_name.c_str());
|
||||
if (max_current > mainCB_maxTotalCurrent) {
|
||||
mainCB_maxTotalCurrent = max_current;
|
||||
}
|
||||
}
|
||||
|
||||
float mainCB_PF = getPointValue(equipment, "MainCB_PF");
|
||||
setPointValue(equipment, "MainCB_Total_kW", mainCB_total_kW);
|
||||
setPointValue(equipment, "MainCB_maxCurrent", mainCB_maxCurrent);
|
||||
setPointValue(equipment, "MainCB_neutralCurrent", mainCB_neutralCurrent);
|
||||
setPointValue(equipment, "MainCB_maxTotalkW", mainCB_maxTotalKw);
|
||||
setPointValue(equipment, "MainCB_maxTotalCurrent", mainCB_maxTotalCurrent);
|
||||
|
||||
setPointValue(equipment, "MainCB_L1_kW", mainCB_total_kW);
|
||||
setPointValue(equipment, "MainCB_L1_kVA", mainCB_total_kW*1.3f);
|
||||
setPointValue(equipment, "MainCB_L1_Current", mainCB_maxCurrent);
|
||||
setPointValue(equipment, "MainCB_L1_PF", mainCB_PF);
|
||||
setPointValue(equipment, "MainCB_L1_max_kW", mainCB_maxTotalKw);
|
||||
setPointValue(equipment, "MainCB_L1_max_current", mainCB_maxTotalCurrent);
|
||||
|
||||
setPointValue(equipment, "MainCB_L2_kW", mainCB_total_kW);
|
||||
setPointValue(equipment, "MainCB_L2_kVA", mainCB_total_kW*1.3f);
|
||||
setPointValue(equipment, "MainCB_L2_Current", mainCB_maxCurrent);
|
||||
setPointValue(equipment, "MainCB_L2_PF", mainCB_PF);
|
||||
setPointValue(equipment, "MainCB_L2_max_kW", mainCB_maxTotalKw);
|
||||
setPointValue(equipment, "MainCB_L2_max_current", mainCB_maxTotalCurrent);
|
||||
|
||||
setPointValue(equipment, "MainCB_L3_kW", mainCB_total_kW);
|
||||
setPointValue(equipment, "MainCB_L3_kVA", mainCB_total_kW*1.3f);
|
||||
setPointValue(equipment, "MainCB_L3_Current", mainCB_maxCurrent);
|
||||
setPointValue(equipment, "MainCB_L3_PF", mainCB_PF);
|
||||
setPointValue(equipment, "MainCB_L3_max_kW", mainCB_maxTotalKw);
|
||||
setPointValue(equipment, "MainCB_L3_max_current", mainCB_maxTotalCurrent);
|
||||
|
||||
|
||||
// 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...");
|
||||
}
|
||||
|
||||
219
src/EPMS/RPP/RPP_Cortex_TCP/config.h
Normal file
219
src/EPMS/RPP/RPP_Cortex_TCP/config.h
Normal file
@@ -0,0 +1,219 @@
|
||||
/**
|
||||
* @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(172, 17, 38, 72); /**< @brief The static IP address for the device. */
|
||||
IPAddress gateway(172, 17, 38, 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, 2046, 0, "CB1"},
|
||||
{HR, 2047, 0, "CB2"},
|
||||
{HR, 2048, 0, "CB3"},
|
||||
{HR, 2049, 0, "CB4"},
|
||||
{HR, 2050, 0, "CB5"},
|
||||
{HR, 2051, 0, "CB6"},
|
||||
{HR, 2052, 0, "CB7"},
|
||||
{HR, 2053, 0, "CB8"},
|
||||
{HR, 2054, 0, "CB9"},
|
||||
{HR, 2055, 0, "CB10"},
|
||||
{HR, 2056, 0, "CB11"},
|
||||
{HR, 2057, 0, "CB12"},
|
||||
{HR, 2058, 0, "CB13"},
|
||||
{HR, 2059, 0, "CB14"},
|
||||
{HR, 2060, 0, "CB15"},
|
||||
{HR, 2061, 0, "CB16"},
|
||||
{HR_FLOAT, 9000, 0, "In_freq"},
|
||||
{HR_FLOAT, 9002, 0, "InV_L1N"},
|
||||
{HR_FLOAT, 9004, 0, "InV_L2N"},
|
||||
{HR_FLOAT, 9006, 0, "InV_L3N"},
|
||||
{HR_FLOAT, 9008, 0, "InV_LN_avg"},
|
||||
{HR_FLOAT, 9010, 0, "InV_L12"},
|
||||
{HR_FLOAT, 9012, 0, "InV_L23"},
|
||||
{HR_FLOAT, 9014, 0, "InV_L31"},
|
||||
{HR_FLOAT, 9016, 0, "InV_LL_avg"},
|
||||
{HR_FLOAT, 9018, 0, "InTHD_L1N"},
|
||||
{HR_FLOAT, 9020, 0, "InTHD_L2N"},
|
||||
{HR_FLOAT, 9022, 0, "InTHD_L3N"},
|
||||
{HR_FLOAT, 9036, 0, "InTHD_L1_1st"},
|
||||
{HR_FLOAT, 9040, 0, "InTHD_L1_3rd"},
|
||||
{HR_FLOAT, 9044, 0, "InTHD_L1_5th"},
|
||||
{HR_FLOAT, 9048, 0, "InTHD_L1_7th"},
|
||||
{HR_FLOAT, 9052, 0, "InTHD_L1_9th"},
|
||||
{HR_FLOAT, 9162, 0, "InTHD_L2_1st"},
|
||||
{HR_FLOAT, 9166, 0, "InTHD_L2_3rd"},
|
||||
{HR_FLOAT, 9170, 0, "InTHD_L2_5th"},
|
||||
{HR_FLOAT, 9174, 0, "InTHD_L2_7th"},
|
||||
{HR_FLOAT, 9178, 0, "InTHD_L2_9th"},
|
||||
{HR_FLOAT, 9288, 0, "InTHD_L3_1st"},
|
||||
{HR_FLOAT, 9292, 0, "InTHD_L3_3rd"},
|
||||
{HR_FLOAT, 9296, 0, "InTHD_L3_5th"},
|
||||
{HR_FLOAT, 9300, 0, "InTHD_L3_7th"},
|
||||
{HR_FLOAT, 9304, 0, "InTHD_L3_9th"},
|
||||
{HR_FLOAT, 9018, 0, "InTHD_L12"},
|
||||
{HR_FLOAT, 9020, 0, "InTHD_L23"},
|
||||
{HR_FLOAT, 9022, 0, "InTHD_L31"},
|
||||
|
||||
{HR_FLOAT, 13456, 0, "CB1_kW"},
|
||||
{HR_FLOAT, 13460, 0, "CB2_kW"},
|
||||
{HR_FLOAT, 13464, 0, "CB3_kW"},
|
||||
{HR_FLOAT, 13468, 0, "CB4_kW"},
|
||||
{HR_FLOAT, 13472, 0, "CB5_kW"},
|
||||
{HR_FLOAT, 13476, 0, "CB6_kW"},
|
||||
{HR_FLOAT, 13480, 0, "CB7_kW"},
|
||||
{HR_FLOAT, 13484, 0, "CB8_kW"},
|
||||
{HR_FLOAT, 13488, 0, "CB9_kW"},
|
||||
{HR_FLOAT, 13492, 0, "CB10_kW"},
|
||||
{HR_FLOAT, 13496, 0, "CB11_kW"},
|
||||
{HR_FLOAT, 13500, 0, "CB12_kW"},
|
||||
{HR_FLOAT, 13504, 0, "CB13_kW"},
|
||||
{HR_FLOAT, 13508, 0, "CB14_kW"},
|
||||
{HR_FLOAT, 13512, 0, "CB15_kW"},
|
||||
{HR_FLOAT, 13516, 0, "CB16_kW"},
|
||||
|
||||
{HR_FLOAT, 14608, 0, "CB1_Current"},
|
||||
{HR_FLOAT, 14612, 0, "CB2_Current"},
|
||||
{HR_FLOAT, 14616, 0, "CB3_Current"},
|
||||
{HR_FLOAT, 14620, 0, "CB4_Current"},
|
||||
{HR_FLOAT, 14624, 0, "CB5_Current"},
|
||||
{HR_FLOAT, 14628, 0, "CB6_Current"},
|
||||
{HR_FLOAT, 14632, 0, "CB7_Current"},
|
||||
{HR_FLOAT, 14636, 0, "CB8_Current"},
|
||||
{HR_FLOAT, 14640, 0, "CB9_Current"},
|
||||
{HR_FLOAT, 14644, 0, "CB10_Current"},
|
||||
{HR_FLOAT, 14648, 0, "CB11_Current"},
|
||||
{HR_FLOAT, 14652, 0, "CB12_Current"},
|
||||
{HR_FLOAT, 14656, 0, "CB13_Current"},
|
||||
{HR_FLOAT, 14660, 0, "CB14_Current"},
|
||||
{HR_FLOAT, 14664, 0, "CB15_Current"},
|
||||
{HR_FLOAT, 14668, 0, "CB16_Current"},
|
||||
|
||||
{HR_FLOAT, 16912, 0, "CB1_max_kW"},
|
||||
{HR_FLOAT, 16916, 0, "CB2_max_kW"},
|
||||
{HR_FLOAT, 16920, 0, "CB3_max_kW"},
|
||||
{HR_FLOAT, 16924, 0, "CB4_max_kW"},
|
||||
{HR_FLOAT, 16928, 0, "CB5_max_kW"},
|
||||
{HR_FLOAT, 16932, 0, "CB6_max_kW"},
|
||||
{HR_FLOAT, 16936, 0, "CB7_max_kW"},
|
||||
{HR_FLOAT, 16940, 0, "CB8_max_kW"},
|
||||
{HR_FLOAT, 16944, 0, "CB9_max_kW"},
|
||||
{HR_FLOAT, 16948, 0, "CB10_max_kW"},
|
||||
{HR_FLOAT, 16952, 0, "CB11_max_kW"},
|
||||
{HR_FLOAT, 16956, 0, "CB12_max_kW"},
|
||||
{HR_FLOAT, 16960, 0, "CB13_max_kW"},
|
||||
{HR_FLOAT, 16964, 0, "CB14_max_kW"},
|
||||
{HR_FLOAT, 16968, 0, "CB15_max_kW"},
|
||||
{HR_FLOAT, 16972, 0, "CB16_max_kW"},
|
||||
|
||||
{HR_FLOAT, 17296, 0, "CB1_maxCurrent"},
|
||||
{HR_FLOAT, 17300, 0, "CB2_maxCurrent"},
|
||||
{HR_FLOAT, 17304, 0, "CB3_maxCurrent"},
|
||||
{HR_FLOAT, 17308, 0, "CB4_maxCurrent"},
|
||||
{HR_FLOAT, 17312, 0, "CB5_maxCurrent"},
|
||||
{HR_FLOAT, 17316, 0, "CB6_maxCurrent"},
|
||||
{HR_FLOAT, 17320, 0, "CB7_maxCurrent"},
|
||||
{HR_FLOAT, 17324, 0, "CB8_maxCurrent"},
|
||||
{HR_FLOAT, 17328, 0, "CB9_maxCurrent"},
|
||||
{HR_FLOAT, 17332, 0, "CB10_maxCurrent"},
|
||||
{HR_FLOAT, 17336, 0, "CB11_maxCurrent"},
|
||||
{HR_FLOAT, 17340, 0, "CB12_maxCurrent"},
|
||||
{HR_FLOAT, 17344, 0, "CB13_maxCurrent"},
|
||||
{HR_FLOAT, 17348, 0, "CB14_maxCurrent"},
|
||||
{HR_FLOAT, 17352, 0, "CB15_maxCurrent"},
|
||||
{HR_FLOAT, 17356, 0, "CB16_maxCurrent"},
|
||||
|
||||
{HR_FLOAT, 40058, 0, "MainCB_Total_kW"},
|
||||
{HR_FLOAT, 40064, 0, "MainCB_maxCurrent"},
|
||||
{HR_FLOAT, 40068, 0, "MainCB_neutralCurrent"},
|
||||
{HR_FLOAT, 40070, 0, "MainCB_PF"},
|
||||
{HR_FLOAT, 40074, 0, "MainCB_maxTotalkW"},
|
||||
{HR_FLOAT, 40076, 0, "MainCB_maxTotalCurrent"},
|
||||
|
||||
{HR_FLOAT, 40108, 0, "MainCB_L1_kW"},
|
||||
{HR_FLOAT, 40112, 0, "MainCB_L1_kVA"},
|
||||
{HR_FLOAT, 40114, 0, "MainCB_L1_Current"},
|
||||
{HR_FLOAT, 40116, 0, "MainCB_L1_PF"},
|
||||
{HR_FLOAT, 40126, 0, "MainCB_L1_max_kW"},
|
||||
{HR_FLOAT, 40128, 0, "MainCB_L1_max_current"},
|
||||
|
||||
{HR_FLOAT, 40158, 0, "MainCB_L2_kW"},
|
||||
{HR_FLOAT, 40162, 0, "MainCB_L2_kVA"},
|
||||
{HR_FLOAT, 40164, 0, "MainCB_L2_Current"},
|
||||
{HR_FLOAT, 40166, 0, "MainCB_L2_PF"},
|
||||
{HR_FLOAT, 40176, 0, "MainCB_L2_max_kW"},
|
||||
{HR_FLOAT, 40178, 0, "MainCB_L2_max_current"},
|
||||
|
||||
{HR_FLOAT, 40208, 0, "MainCB_L3_kW"},
|
||||
{HR_FLOAT, 40212, 0, "MainCB_L3_kVA"},
|
||||
{HR_FLOAT, 40214, 0, "MainCB_L3_Current"},
|
||||
{HR_FLOAT, 40216, 0, "MainCB_L3_PF"},
|
||||
{HR_FLOAT, 40226, 0, "MainCB_L3_max_kW"},
|
||||
{HR_FLOAT, 40228, 0, "MainCB_L3_max_current"},
|
||||
|
||||
};
|
||||
//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/EPMS/RPP/RPP_Cortex_TCP/main.cpp
Normal file
86
src/EPMS/RPP/RPP_Cortex_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