diff --git a/lib/Core/ModbusPoints/Modbus_PointFactory.h b/lib/Core/ModbusPoints/Modbus_PointFactory.h index 3064421..26c8e3d 100644 --- a/lib/Core/ModbusPoints/Modbus_PointFactory.h +++ b/lib/Core/ModbusPoints/Modbus_PointFactory.h @@ -68,7 +68,7 @@ Modbus_Point* createModbus_Point(T* server, int category, int address, int va Serial.printf("Creating Input Register: %s\n", description); return new Modbus_Ireg(server, address, value, description); - case IR_10X: { + case IR_10x: { Serial.printf("Creating Scaled Input Register (10x): %s\n", description); Modbus_Point* point = new Modbus_Ireg(server, address, value, description); return new Modbus_ScaleDecorator(point); diff --git a/lib/Core/core.h b/lib/Core/core.h index 63bda63..e4703ba 100644 --- a/lib/Core/core.h +++ b/lib/Core/core.h @@ -32,7 +32,7 @@ const int COIL = 0; /**< @brief 0x: R/W Coil */ const int DI = 1; /**< @brief 1x: R Discrete Inputs */ const int IR = 3; /**< @brief 3x: R Input Register - Single word */ -const int IR_10X = 31; /**< @brief 3x: R Input Register - Single word, 10x scaled */ +const int IR_10x = 31; /**< @brief 3x: R Input Register - Single word, 10x scaled */ const int IR_LONG = 32; /**< @brief 3x: R Input Register - Double word, Long type */ const int IR_FLOAT = 33; /**< @brief 3x: R Input Register - Double word, Float encoding */ const int HR = 4; /**< @brief 4x: R/W Holding Register - Single word */ diff --git a/platformio.ini b/platformio.ini index e2130f3..2ab396e 100644 --- a/platformio.ini +++ b/platformio.ini @@ -9,7 +9,7 @@ ; https://docs.platformio.org/page/projectconf.html [platformio] -default_envs = CH_Daikin_AWV026B_RTU ; Select here the name of the configuration you want to download +default_envs = Base_RTU ; Select here the name of the configuration you want to download [env] upload_port = COM100 @@ -19,20 +19,90 @@ framework = arduino monitor_speed = 115200 lib_ldf_mode = chain+ lib_compat_mode = soft - +;--------------------------------------------------------------------------------------------------- +; TEMPLATES ;Base configuration for RTU equipment [env:Base_RTU] platform = espressif32 board = dfrobot_firebeetle2_esp32e extends = common_env_options -build_src_filter = -<*> + ;Add the specific folder path here +build_src_filter = -<*> + ;Add the specific folder path here ;Base configuration for TCP equipment [env:Base_TCP] platform = espressif32 board = dfrobot_firebeetle2_esp32e extends = common_env_options build_flags = -D USE_MODBUS_IP ;Importat configuration, this flags is used to configure the program -build_src_filter = -<*> + ;Add the specific folder path here +build_src_filter = -<*> + ;Add the specific folder path here +;---------------------------------------------------------------------------------------------------- +[env:POD_MBB_Power_Meter_TCP] +platform = espressif32 +board = dfrobot_firebeetle2_esp32e +extends = common_env_options +build_flags = -D USE_MODBUS_IP +build_src_filter = -<*> + + +[env:STS_PowerSmiths_STATYS_UL_600A_TCP] +platform = espressif32 +board = dfrobot_firebeetle2_esp32e +extends = common_env_options +build_flags = -D USE_MODBUS_IP +build_src_filter = -<*> + + +[env:PDU_Maverick_Power_TCP] +platform = espressif32 +board = dfrobot_firebeetle2_esp32e +extends = common_env_options +build_flags = -D USE_MODBUS_IP +build_src_filter = -<*> + + +[env:MVG_SEL2440_TCP] +platform = espressif32 +board = dfrobot_firebeetle2_esp32e +extends = common_env_options +build_flags = -D USE_MODBUS_IP +build_src_filter = -<*> + + +[env:GEN_CAT_EMCP4_TCP] +platform = espressif32 +board = dfrobot_firebeetle2_esp32e +extends = common_env_options +build_flags = -D USE_MODBUS_IP +build_src_filter = -<*> + + +[env:BKR_ABB_EMax2_TCP] +platform = espressif32 +board = dfrobot_firebeetle2_esp32e +extends = common_env_options +build_flags = -D USE_MODBUS_IP +build_src_filter = -<*> + + +[env:CRAC_Munters_SysCooll_TCP] +platform = espressif32 +board = dfrobot_firebeetle2_esp32e +extends = common_env_options +build_flags = -D USE_MODBUS_IP +build_src_filter = -<*> + + +[env:SS_Daiken_TCP] +platform = espressif32 +board = dfrobot_firebeetle2_esp32e +extends = common_env_options +build_flags = -D USE_MODBUS_IP +build_src_filter = -<*> + + +[env:Testing_RTU] +platform = espressif32 +board = dfrobot_firebeetle2_esp32e +extends = common_env_options +build_src_filter = -<*> + + +[env:Testing_TCP] +platform = espressif32 +board = dfrobot_firebeetle2_esp32e +extends = common_env_options +build_flags = -D USE_MODBUS_IP +build_src_filter = -<*> + [env:CH_Daikin_AWV026B_RTU] platform = espressif32 @@ -53,3 +123,10 @@ platform = espressif32 board = dfrobot_firebeetle2_esp32e extends = common_env_options build_src_filter = -<*> + + +[env:CH_York_XXXXX_RTU] +platform = espressif32 +board = dfrobot_firebeetle2_esp32e +extends = common_env_options +build_src_filter = -<*> + + diff --git a/src/BMS/CHILLER/CH_York_XXXXX_RTU/README.md b/src/BMS/CHILLER/CH_York_XXXXX_RTU/README.md new file mode 100644 index 0000000..630cf02 --- /dev/null +++ b/src/BMS/CHILLER/CH_York_XXXXX_RTU/README.md @@ -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 diff --git a/src/BMS/CHILLER/CH_York_XXXXX_RTU/State_Fail.cpp b/src/BMS/CHILLER/CH_York_XXXXX_RTU/State_Fail.cpp new file mode 100644 index 0000000..6d85f9a --- /dev/null +++ b/src/BMS/CHILLER/CH_York_XXXXX_RTU/State_Fail.cpp @@ -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 +#include + +#if defined(USE_MODBUS_IP) + #include +#else + #include +#endif + +/** + * @brief Constructs a new FailState object. + * + * This constructor receives a list of alarm descriptions and creates strategies + * to set the corresponding Modbus points to a value of 1, indicating an + * active alarm. It also initializes a PID strategy for the valve position. + */ +template<> +FailState::FailState(const std::vector& activeAlarms) { + // Simulate a failure: set common alarm and a specific fan alarm. +} + +/** + * @brief Executes the fail state's logic for one update cycle. + * + * This method checks the "Clear Alm" Modbus point for a command to transition + * back to Standby, which would typically happen after a fault is cleared by a + * user. If no transition is requested, it continues to apply the failure strategies. + * + * @param equipment Pointer to the Equipment instance. + * @return A pointer to a new State if a transition should occur, otherwise nullptr. + */ +template<> +State* FailState::update(Equipment* equipment) { + // STATE control, add conditions if change to a different state is needed + Serial.println("Fail update function"); + + _applyStrategies(equipment); + return nullptr; +} + +/** + * @brief Logic to execute once when entering the fail state. Sets the main alarm bit. + * @param equipment Pointer to the Equipment instance. + */ +template<> +void FailState::enterState(Equipment* equipment) { + // Logic to run when the equipment enters this state + Serial.println("Enter Fail State..."); + +} + +/** + * @brief Logic to execute once when exiting the fail state. Clears the main alarm bit. + * @param equipment Pointer to the Equipment instance. + */ +template<> +void FailState::exitState(Equipment* equipment) { + // Cleanup logic to run when the equipment leaves this state + Serial.println("Exit Fail State..."); + +} \ No newline at end of file diff --git a/src/BMS/CHILLER/CH_York_XXXXX_RTU/State_Running.cpp b/src/BMS/CHILLER/CH_York_XXXXX_RTU/State_Running.cpp new file mode 100644 index 0000000..4299d0b --- /dev/null +++ b/src/BMS/CHILLER/CH_York_XXXXX_RTU/State_Running.cpp @@ -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 +#include + +#if defined(USE_MODBUS_IP) + #include +#else + #include +#endif + +/** + * @brief Constructs a new RunningState object. + * + * This constructor initializes behavior strategies active during the running + * state, such as a PID controller for the 'CW Valve Position' and totalizers + * for the run-hours of each EC fan. + */ +template<> +RunningState::RunningState() { + //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* RunningState::update(Equipment* 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::enterState(Equipment* 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::exitState(Equipment* equipment) { + // Cleanup logic to run when the equipment leaves this state + Serial.println("Exit Running State..."); +} \ No newline at end of file diff --git a/src/BMS/CHILLER/CH_York_XXXXX_RTU/State_Standby.cpp b/src/BMS/CHILLER/CH_York_XXXXX_RTU/State_Standby.cpp new file mode 100644 index 0000000..4d6de94 --- /dev/null +++ b/src/BMS/CHILLER/CH_York_XXXXX_RTU/State_Standby.cpp @@ -0,0 +1,79 @@ +/** + * @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 +#include +#if defined(USE_MODBUS_IP) + #include +#else + #include +#endif + +/** + * @brief Constructs a new StandbyState object. + * + * In this state, the equipment is idle. This constructor initializes several + * strategies to generate random values for various status points, simulating + * a live but non-operational unit. + */ +template<> +StandbyState::StandbyState() { + + addStrategy("HR1", new RampStrategy(200.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* StandbyState::update(Equipment* 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::enterState(Equipment* 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::exitState(Equipment* equipment) { + // Cleanup logic to run when the equipment leaves this state + +} \ No newline at end of file diff --git a/src/BMS/CHILLER/CH_York_XXXXX_RTU/config.h b/src/BMS/CHILLER/CH_York_XXXXX_RTU/config.h new file mode 100644 index 0000000..2af3d03 --- /dev/null +++ b/src/BMS/CHILLER/CH_York_XXXXX_RTU/config.h @@ -0,0 +1,74 @@ +/** + * @file config.h + * @brief Main configuration file for the Daikin Chiller (RTU) emulator. + * @author Emmanuel Hernandez Cruz + * @date 2025-09-02 + * + * This file contains important configurations for the Modbus RTU communication + * and the specific register map for the emulated device. + */ + +#ifndef CONFIG_H +#define CONFIG_H +#include +#include "core.h" +#include "Equipment/Equipment.h" + + +#if defined(USE_MODBUS_IP) +/** + * @defgroup ModbusTCPConfig Modbus IP Configuration + * @brief Parameters for Modbus TCP communication. + * @{ + */ + #include + const char *ssid = "wifi_name"; /**< @brief The SSID of the WiFi network. */ + const char *password = "wifi_password"; /**< @brief The password for the WiFi network. */ + IPAddress local_IP(192, 168, 1, 234); /**< @brief The static IP address for the device. */ + IPAddress gateway(192, 168, 1, 1); /**< @brief The gateway IP address. */ + IPAddress subnet(255, 255, 255, 0); /**< @brief The subnet mask. */ + + ModbusIP mb; +#else + /** + * @defgroup ModbusRTUConfig Modbus RTU Configuration + * @brief Parameters for serial Modbus RTU communication. + * @{ + */ + #include + const int BAUDRATE = 19200; /**< @brief The serial communication speed in bits per second. */ + const int RX_PIN = 17; /**< @brief The GPIO pin used for receiving data (RX). */ + const int TX_PIN = 16; /**< @brief The GPIO pin used for transmitting data (TX). */ + const int RST_PIN = 4; /**< @brief The GPIO pin connected to the RS485 driver's DE/RE pins for direction control. */ + const int MODBUS_ID = 1; /**< @brief The unique slave ID for this device on the Modbus bus. */ + /** @} */ + + /** @brief Global instance of the Modbus RTU server. */ + ModbusRTU mb; +#endif + +/** + * @brief The Modbus map for the Equipment device. + * This array defines all the Modbus points available on the emulated device. + * The `description` field is crucial as it's used to look up points within the application logic. + */ +modbusMap mb_map[] = +{ + {HR, 0, 0, "HR1"}, //Internal to control from Modscan + {HR_10x, 1, 0, "HR2"}, //Internal to control from Modscan + {HR_FLOAT, 2, 0, "HR3"}, //Internal to control from Modscan + {HR_LONG, 4, 0, "HR4"}, //Internal to control from Modscan +}; +//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 diff --git a/src/BMS/CHILLER/CH_York_XXXXX_RTU/main.cpp b/src/BMS/CHILLER/CH_York_XXXXX_RTU/main.cpp new file mode 100644 index 0000000..5dbc9f1 --- /dev/null +++ b/src/BMS/CHILLER/CH_York_XXXXX_RTU/main.cpp @@ -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 +#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* 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); + } +} diff --git a/src/EPMS/Breaker/BKR_Manufacturer_Model_TCP/README.md b/src/BMS/CRAC/CRAC_Munters_SysCooll_TCP/README.md similarity index 100% rename from src/EPMS/Breaker/BKR_Manufacturer_Model_TCP/README.md rename to src/BMS/CRAC/CRAC_Munters_SysCooll_TCP/README.md diff --git a/src/EPMS/Breaker/BKR_Manufacturer_Model_TCP/State_Fail.cpp b/src/BMS/CRAC/CRAC_Munters_SysCooll_TCP/State_Fail.cpp similarity index 100% rename from src/EPMS/Breaker/BKR_Manufacturer_Model_TCP/State_Fail.cpp rename to src/BMS/CRAC/CRAC_Munters_SysCooll_TCP/State_Fail.cpp diff --git a/src/EPMS/Breaker/BKR_Manufacturer_Model_TCP/State_Running.cpp b/src/BMS/CRAC/CRAC_Munters_SysCooll_TCP/State_Running.cpp similarity index 100% rename from src/EPMS/Breaker/BKR_Manufacturer_Model_TCP/State_Running.cpp rename to src/BMS/CRAC/CRAC_Munters_SysCooll_TCP/State_Running.cpp diff --git a/src/EPMS/Breaker/BKR_Manufacturer_Model_TCP/State_Standby.cpp b/src/BMS/CRAC/CRAC_Munters_SysCooll_TCP/State_Standby.cpp similarity index 100% rename from src/EPMS/Breaker/BKR_Manufacturer_Model_TCP/State_Standby.cpp rename to src/BMS/CRAC/CRAC_Munters_SysCooll_TCP/State_Standby.cpp diff --git a/src/BMS/CRAC/CRAC_Munters_SysCooll_TCP/config.h b/src/BMS/CRAC/CRAC_Munters_SysCooll_TCP/config.h new file mode 100644 index 0000000..ce882e2 --- /dev/null +++ b/src/BMS/CRAC/CRAC_Munters_SysCooll_TCP/config.h @@ -0,0 +1,262 @@ +/** + * @file config.h + * @brief Main configuration file for the CRAC Munters SysCooll + * @author Zach Gutierrez + * @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 + const char *ssid = "Wifi1"; /**< @brief The SSID of the WiFi network. */ + const char *password = "123abc456"; /**< @brief The password for the WiFi network. */ + IPAddress local_IP(172, 17, 22, 130); /**< @brief The static IP address for the device. */ + IPAddress gateway(172, 17, 22, 254); /**< @brief The gateway IP address. */ + IPAddress subnet(255, 255, 255, 0); /**< @brief The subnet mask. */ + + ModbusIP mb; +#else + /** + * @defgroup ModbusRTUConfig Modbus RTU Configuration + * @brief Parameters for serial Modbus RTU communication. + * @{ + */ + #include + const int BAUDRATE = 19200; /**< @brief The serial communication speed in bits per second. */ + const int RX_PIN = 17; /**< @brief The GPIO pin used for receiving data (RX). */ + const int TX_PIN = 16; /**< @brief The GPIO pin used for transmitting data (TX). */ + const int RST_PIN = 4; /**< @brief The GPIO pin connected to the RS485 driver's DE/RE pins for direction control. */ + const int MODBUS_ID = 1; /**< @brief The unique slave ID for this device on the Modbus bus. */ + /** @} */ + + /** @brief Global instance of the Modbus RTU server. */ + ModbusRTU mb; +#endif + + + +/** + * @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, "Start_CMD" }, + {COIL, 1, 0, "Reset_CMD" }, + {COIL, 2, 0, "Start_CMD" }, + {COIL, 3, 0, "Reset_CMD" }, + {DI, 2, 0, "BldgSafety" }, + {DI, 31, 0, "SystemOnSts" }, + {DI, 35, 0, "CoolingStatus" }, + {DI, 42, 0, "ComAlm" }, + {DI, 43, 0, "TSAlerts" }, + {DI, 44, 0, "DXAlerts" }, + {DI, 45, 0, "PwrMonAlm" }, + {DI, 101, 0, "RAFilterAlm" }, + {DI, 126, 0, "SmokeAlm" }, + {DI, 171, 0, "SACmnAlm" }, + {DI, 112, 0, "FanDPASnsr" }, + {DI, 113, 0, "FanDPBSnsr" }, + {DI, 66, 0, "CondComsLost" }, + {DI, 4, 0, "HPSwitchCkt1" }, + {DI, 5, 0, "HPSwitchCkt2" }, + {DI, 6, 0, "HPSwitchCkt3" }, + {DI, 7, 0, "HPSwitchCkt4" }, + {DI, 19, 0, "Comp1AEnable" }, + {DI, 8, 0, "Comp1Status" }, + {DI, 160, 0, "Comp1A Alm" }, + {DI, 21, 0, "Comp1BEnable" }, + {DI, 9, 0, "Comp1BStatus" }, + {DI, 161, 0, "Comp1BAlm" }, + {DI, 22, 0, "Comp2AEnable" }, + {DI, 13, 0, "Comp2AStatus" }, + {DI, 162, 0, "Comp2AAlm" }, + {DI, 23, 0, "Comp2BEnable" }, + {DI, 14, 0, "Comp2BStatus" }, + {DI, 163, 0, "Comp2BAlm" }, + {DI, 24, 0, "Comp3AEnable" }, + {DI, 15, 0, "Comp3AStatus" }, + {DI, 164, 0, "Comp3AAlm" }, + {DI, 25, 0, "Comp3BEnable" }, + {DI, 16, 0, "Comp3BStatus" }, + {DI, 165, 0, "Comp3BAlm" }, + {DI, 26, 0, "Comp4AEnable" }, + {DI, 17, 0, "Comp4AStatus" }, + {DI, 166, 0, "Comp4AAlm" }, + {DI, 28, 0, "Comp4BEnable" }, + {DI, 18, 0, "Comp4BStatus" }, + {DI, 167, 0, "Comp4BAlm" }, + {DI, 47, 0, "Fan1AAlm" }, + {DI, 48, 0, "Fan1BAlm" }, + {DI, 49, 0, "Fan1CAlm" }, + {DI, 50, 0, "Fan1DAlm" }, + {DI, 51, 0, "Fan1EAlm" }, + {DI, 52, 0, "Fan1FAlm" }, + {DI, 53, 0, "Fan1GAlm" }, + {DI, 54, 0, "Fan1HAlm" }, + {DI, 57, 0, "Fan2AAlm" }, + {DI, 58, 0, "Fan2BAlm" }, + {DI, 59, 0, "Fan2CAlm" }, + {DI, 60, 0, "Fan2DAlm" }, + {DI, 61, 0, "Fan2EAlm" }, + {DI, 62, 0, "Fan2FAlm" }, + {DI, 63, 0, "Fan2GAlm" }, + {DI, 64, 0, "Fan2HAlm" }, + {DI, 55, 0, "SAFlowAlm" }, + {DI, 56, 0, "SAFansAlm" }, + {DI, 75, 0, "Ckt1LoWrn" }, + {DI, 83, 0, "Ckt2LoWrn" }, + {DI, 90, 0, "Ckt3LoWrn" }, + {DI, 97, 0, "Ckt4LoWrn" }, + {DI, 104, 0, "RA_FAULT_1" }, + {DI, 105, 0, "RA_FAULT_2" }, + {DI, 246, 0, "Cond2AStatus" }, + {DI, 249, 0, "Cond2BStatus" }, + {DI, 252, 0, "Cond2CStatus" }, + {DI, 255, 0, "Cond2DStatus" }, + {DI, 258, 0, "Cond2EStatus" }, + {DI, 261, 0, "Cond2FStatus" }, + {DI, 264, 0, "Cond2GStatus" }, + {DI, 267, 0, "Cond2Status" }, + {DI, 65, 0, "CondFansAlm" }, + {DI, 123, 0, "CondPot" }, + {DI, 243, 0, "SupFan1ASts" }, + {DI, 180, 0, "SupFan1BSts" }, + {DI, 189, 0, "SupFan1CSts" }, + {DI, 198, 0, "SupFan1DSts" }, + {DI, 207, 0, "SupFan1ESts" }, + {DI, 216, 0, "SupFan1FSts" }, + {DI, 225, 0, "SupFan1GSts" }, + {DI, 234, 0, "SupFan1HSts" }, + {IR, 1, 0, "OA Temp" }, + {IR, 2, 0, "OA Temp" }, + {IR, 3, 0, "Ckt1 DisPrs" }, + {IR, 4, 0, "Ckt1 DisPrs" }, + {IR, 7, 0, "Ckt2 DisPrs" }, + {IR, 8, 0, "Ckt2 DisPrs" }, + {IR, 9, 0, "Ckt3 DisPrs" }, + {IR, 10, 0, "Ckt3 DisPrs" }, + {IR, 11, 0, "Ckt4 DisPrs" }, + {IR, 12, 0, "Ckt4 DisPrs" }, + {IR, 19, 0, "RA Hum" }, + {IR, 20, 0, "RA Hum" }, + {IR, 25, 0, "RA Temp1" }, + {IR, 26, 0, "RA Temp1" }, + {IR, 27, 0, "RA Temp2" }, + {IR, 28, 0, "RA Temp2" }, + {IR, 33, 0, "RF Diff" }, + {IR, 34, 0, "RF Diff" }, + {IR, 37, 0, "SF Diff" }, + {IR, 38, 0, "SF Diff" }, + {IR, 37, 0, "RA FilterDP" }, + {IR, 38, 0, "RA FilterDP" }, + {IR, 105, 0, "RA Temp Avg" }, + {IR, 106, 0, "RA Temp Avg" }, + {IR, 107, 0, "SA Temp Avg" }, + {IR, 108, 0, "SA Temp Avg" }, + {IR, 113, 0, "SA Flow Total MSB" }, + {IR, 114, 0, "SA Flow Total LSB" }, + {IR, 133, 0, "RA Dew Calc" }, + {IR, 134, 0, "RA Dew Calc" }, + {IR, 143, 0, "Clg Pcnt" }, + {IR, 144, 0, "Clg Pcnt" }, + {IR, 147, 0, "TS1 Low" }, + {IR, 148, 0, "TS1 Low" }, + {IR, 149, 0, "TS1 Up" }, + {IR, 150, 0, "TS1 Up" }, + {IR, 151, 0, "TS2 Low" }, + {IR, 152, 0, "TS2 Low" }, + {IR, 153, 0, "TS2 Up" }, + {IR, 154, 0, "TS2 Up" }, + {IR, 155, 0, "Sys Stat" }, + {IR, 156, 0, "" }, + {IR, 185, 0, "Fan1B Spd MSB" }, + {IR, 186, 0, "Fan1B Spd LSB" }, + {IR, 197, 0, "Fan1C Spd MSB" }, + {IR, 198, 0, "Fan1C Spd LSB" }, + {IR, 205, 0, "Fan1D Spd MSB" }, + {IR, 206, 0, "Fan1D Spd LSB" }, + {IR, 221, 0, "Fan1E Spd MSB" }, + {IR, 222, 0, "Fan1E Spd LSB" }, + {IR, 233, 0, "Fan1F Spd MSB" }, + {IR, 234, 0, "Fan1F Spd LSB" }, + {IR, 245, 0, "Fan1G Spd MSB" }, + {IR, 246, 0, "Fan1G Spd LSB" }, + {IR, 257, 0, "Fan1H Spd MSB" }, + {IR, 258, 0, "Fan1H Spd LSB" }, + {IR, 269, 0, "Fan1A Spd MSB" }, + {IR, 270, 0, "Fan1A Spd LSB" }, + {IR, 426, 0, "EVM1SuctPrsA" }, + {IR, 427, 0, "EVM1SuctPrsA" }, + {IR, 428, 0, "EVM1SuctPrsB" }, + {IR, 429, 0, "EVM1SuctPrsB" }, + {IR, 430, 0, "EVM1SuctTmpA" }, + {IR, 431, 0, "EVM1SuctTmpA" }, + {IR, 432, 0, "EVM1SuctTmpB" }, + {IR, 433, 0, "EVM1SuctTmpB" }, + {IR, 438, 0, "EVM1ValveA" }, + {IR, 439, 0, "EVM1ValveA" }, + {IR, 440, 0, "EVM1ValveB" }, + {IR, 441, 0, "EVM1ValveB" }, + {IR, 462, 0, "EVM3SuctPrsA" }, + {IR, 463, 0, "EVM3SuctPrsA" }, + {IR, 464, 0, "EVM3SuctPrsB" }, + {IR, 465, 0, "EVM3SuctPrsB" }, + {IR, 466, 0, "EVM3SuctTmpA" }, + {IR, 467, 0, "EVM3SuctTmpA" }, + {IR, 468, 0, "EVM3SuctTmpB" }, + {IR, 469, 0, "EVM3SuctTmpB" }, + {IR, 474, 0, "EVM3Valve A" }, + {IR, 475, 0, "EVM3Valve A" }, + {IR, 476, 0, "EVM3Valve B" }, + {IR, 477, 0, "EVM3Valve B" }, + {IR, 526, 0, "EVM1ErrCode" }, + {IR, 527, 0, "EVM2ErrCode" }, + {IR, 528, 0, "EVM3ErrCode" }, + {IR, 529, 0, "EVM4ErrCode" }, + {HR, 1, 0, "RATemp SP" }, + {HR, 2, 0, "RATemp SP" }, + {HR, 3, 0, "SATemp SP" }, + {HR, 4, 0, "SATemp SP" }, + {HR, 5, 0, "SATemp DF" }, + {HR, 6, 0, "SATemp DF" }, + {HR, 7, 0, "SAFSpdSP" }, + {HR, 8, 0, "SAFSpdSP" }, + {HR, 9, 0, "SAFlMaxSpdSP" }, + {HR, 10, 0, "SAFlMaxSpdSP" }, + {HR, 11, 0, "SAFlMinSpdSP" }, + {HR, 12, 0, "SAFlMinSpdSP" }, + {HR, 13, 0, "RAFltrDPSP" }, + {HR, 14, 0, "RAFltrDPSP" }, +}; +//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 diff --git a/src/EPMS/Breaker/BKR_Manufacturer_Model_TCP/main.cpp b/src/BMS/CRAC/CRAC_Munters_SysCooll_TCP/main.cpp similarity index 100% rename from src/EPMS/Breaker/BKR_Manufacturer_Model_TCP/main.cpp rename to src/BMS/CRAC/CRAC_Munters_SysCooll_TCP/main.cpp diff --git a/src/BMS/CRAH/CRAH_LIEBERT_80_125_SLAB_TCP/README.md b/src/BMS/CRAH/CRAH_LIEBERT_80_125_SLAB_TCP/README.md index 355156f..c863c27 100644 --- a/src/BMS/CRAH/CRAH_LIEBERT_80_125_SLAB_TCP/README.md +++ b/src/BMS/CRAH/CRAH_LIEBERT_80_125_SLAB_TCP/README.md @@ -1,13 +1,11 @@ -# EQUIPMENT_TYPE MANUFACTURER MODEL TCP +# CRAH Liebert 80 125 SLAB 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 +* **Libert 80_125 SLAB**: 09-15-25 ## Hardware Prerequisites diff --git a/src/EPMS/GEN/GEN_Manufacturer_Model_TCP/README.md b/src/BMS/HUM/HUM_Munters_HM3_TCP/README.md similarity index 100% rename from src/EPMS/GEN/GEN_Manufacturer_Model_TCP/README.md rename to src/BMS/HUM/HUM_Munters_HM3_TCP/README.md diff --git a/src/EPMS/GEN/GEN_Manufacturer_Model_TCP/State_Fail.cpp b/src/BMS/HUM/HUM_Munters_HM3_TCP/State_Fail.cpp similarity index 100% rename from src/EPMS/GEN/GEN_Manufacturer_Model_TCP/State_Fail.cpp rename to src/BMS/HUM/HUM_Munters_HM3_TCP/State_Fail.cpp diff --git a/src/EPMS/GEN/GEN_Manufacturer_Model_TCP/State_Running.cpp b/src/BMS/HUM/HUM_Munters_HM3_TCP/State_Running.cpp similarity index 100% rename from src/EPMS/GEN/GEN_Manufacturer_Model_TCP/State_Running.cpp rename to src/BMS/HUM/HUM_Munters_HM3_TCP/State_Running.cpp diff --git a/src/EPMS/GEN/GEN_Manufacturer_Model_TCP/State_Standby.cpp b/src/BMS/HUM/HUM_Munters_HM3_TCP/State_Standby.cpp similarity index 100% rename from src/EPMS/GEN/GEN_Manufacturer_Model_TCP/State_Standby.cpp rename to src/BMS/HUM/HUM_Munters_HM3_TCP/State_Standby.cpp diff --git a/src/BMS/HUM/HUM_Munters_HM3_TCP/config.h b/src/BMS/HUM/HUM_Munters_HM3_TCP/config.h new file mode 100644 index 0000000..cf47221 --- /dev/null +++ b/src/BMS/HUM/HUM_Munters_HM3_TCP/config.h @@ -0,0 +1,84 @@ +/** + * @file config.h + * @brief Main configuration file for the Humidifier Munters HM3 + * @author Zach Gutierrez + * @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 + 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(172, 17, 22, 172); /**< @brief The static IP address for the device. */ + IPAddress gateway(172, 17, 22, 1); /**< @brief The gateway IP address. */ + IPAddress subnet(255, 255, 255, 0); /**< @brief The subnet mask. */ + + ModbusIP mb; +#else + /** + * @defgroup ModbusRTUConfig Modbus RTU Configuration + * @brief Parameters for serial Modbus RTU communication. + * @{ + */ + #include + const int BAUDRATE = 19200; /**< @brief The serial communication speed in bits per second. */ + const int RX_PIN = 17; /**< @brief The GPIO pin used for receiving data (RX). */ + const int TX_PIN = 16; /**< @brief The GPIO pin used for transmitting data (TX). */ + const int RST_PIN = 4; /**< @brief The GPIO pin connected to the RS485 driver's DE/RE pins for direction control. */ + const int MODBUS_ID = 1; /**< @brief The unique slave ID for this device on the Modbus bus. */ + /** @} */ + + /** @brief Global instance of the Modbus RTU server. */ + ModbusRTU mb; +#endif + + + +/** + * @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[] = { + + // DISCRETE ALARMS (COILS - 1x) + // 00000 + {HR, 0, 0, "Unit Status" }, + {HR, 1, 0, "Air Temp SP" }, + {HR, 2, 0, "Space Temp" }, + {HR, 3, 0, "System Mode" }, + {HR, 4, 0, "Fan Speed" }, + +}; +//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 diff --git a/src/EPMS/GEN/GEN_Manufacturer_Model_TCP/main.cpp b/src/BMS/HUM/HUM_Munters_HM3_TCP/main.cpp similarity index 100% rename from src/EPMS/GEN/GEN_Manufacturer_Model_TCP/main.cpp rename to src/BMS/HUM/HUM_Munters_HM3_TCP/main.cpp diff --git a/src/EPMS/MVG/MVG_Manufacturer_Model_TCP/README.md b/src/BMS/Split_System/SS_Daiken_TCP/README.md similarity index 100% rename from src/EPMS/MVG/MVG_Manufacturer_Model_TCP/README.md rename to src/BMS/Split_System/SS_Daiken_TCP/README.md diff --git a/src/EPMS/MVG/MVG_Manufacturer_Model_TCP/State_Fail.cpp b/src/BMS/Split_System/SS_Daiken_TCP/State_Fail.cpp similarity index 100% rename from src/EPMS/MVG/MVG_Manufacturer_Model_TCP/State_Fail.cpp rename to src/BMS/Split_System/SS_Daiken_TCP/State_Fail.cpp diff --git a/src/EPMS/MVG/MVG_Manufacturer_Model_TCP/State_Running.cpp b/src/BMS/Split_System/SS_Daiken_TCP/State_Running.cpp similarity index 100% rename from src/EPMS/MVG/MVG_Manufacturer_Model_TCP/State_Running.cpp rename to src/BMS/Split_System/SS_Daiken_TCP/State_Running.cpp diff --git a/src/EPMS/MVG/MVG_Manufacturer_Model_TCP/State_Standby.cpp b/src/BMS/Split_System/SS_Daiken_TCP/State_Standby.cpp similarity index 100% rename from src/EPMS/MVG/MVG_Manufacturer_Model_TCP/State_Standby.cpp rename to src/BMS/Split_System/SS_Daiken_TCP/State_Standby.cpp diff --git a/src/EPMS/Breaker/BKR_Manufacturer_Model_TCP/config.h b/src/BMS/Split_System/SS_Daiken_TCP/config.h similarity index 98% rename from src/EPMS/Breaker/BKR_Manufacturer_Model_TCP/config.h rename to src/BMS/Split_System/SS_Daiken_TCP/config.h index bd4ad09..8f822e8 100644 --- a/src/EPMS/Breaker/BKR_Manufacturer_Model_TCP/config.h +++ b/src/BMS/Split_System/SS_Daiken_TCP/config.h @@ -1,7 +1,7 @@ /** * @file config.h - * @brief Main configuration file for the CRAH Unit (TCP) emulator. - * @author Emmanuel Hernandez Cruz + * @brief Main configuration file for the Split Sytstem Daiken + * @author Zach Gutierrez * @date 2025-09-02 * * This file contains two important configurations: WiFi network parameters diff --git a/src/EPMS/MVG/MVG_Manufacturer_Model_TCP/main.cpp b/src/BMS/Split_System/SS_Daiken_TCP/main.cpp similarity index 100% rename from src/EPMS/MVG/MVG_Manufacturer_Model_TCP/main.cpp rename to src/BMS/Split_System/SS_Daiken_TCP/main.cpp diff --git a/src/BMS/VFD/VFD_ABB_ACH580_RTU/State_Running.cpp b/src/BMS/VFD/VFD_ABB_ACH580_RTU/State_Running.cpp index 3e083ed..8dd88b8 100644 --- a/src/BMS/VFD/VFD_ABB_ACH580_RTU/State_Running.cpp +++ b/src/BMS/VFD/VFD_ABB_ACH580_RTU/State_Running.cpp @@ -17,6 +17,8 @@ #include "Strategies/Strategy_Totalizer.h" #include "Strategies/Strategy_Random.h" #include "Strategies/Strategy_SingleValue.h" +#include "Strategies/Strategy_Saw.h" +#include "Strategies/Strategy_Square.h" #include "Equipment/Equipment.h" #include "ModbusPoints/Modbus_Point.h" #include "ModbusPoints/Modbus_FloatDecorator.h" @@ -39,16 +41,8 @@ */ template<> RunningState::RunningState() { - //Add strategies - //addStrategy("Actual Capacity", new PIDStrategy("Active SP", 1000, "Supply Temp")); - addStrategy("Output Frequency", new SingleValueStrategy(60.0f, 0.2, 1000 )); - addStrategy("Output Voltage", new SingleValueStrategy(600.0f, 10, 1000 )); - addStrategy("Motor Speed Used", new RampStrategy(0.0f, 5.0f, 1000 )); - addStrategy("Motor Speed estimated", new RampStrategy(0.0f, 100.0f, 1000 )); - addStrategy("Motor Current", new RampStrategy(0.0f, 9.0f, 1000 )); - addStrategy("Motor Torque", new RampStrategy(0.0f, 10.0f, 1000 )); - addStrategy("Hours Run", new TotalizerStrategy(1000)); - addStrategy("Inverter Temperature", new RampStrategy(120.0f, 0.5f, 1000 )); + + addStrategy("Inverter Temperature", new SquareStrategy(40.0f, 80.0f,1000)); } /** diff --git a/src/Base_RTU/config.h b/src/Base_RTU/config.h index 54a889b..3791cd7 100644 --- a/src/Base_RTU/config.h +++ b/src/Base_RTU/config.h @@ -54,67 +54,18 @@ */ modbusMap mb_map[] = { - {HR, 100, 0, "State Control"}, //Internal to control from Modscan - {HR, 101, 0, "Fault Code"}, - {HR_FLOAT, 102, 0, "Supply Temp"}, - {HR, 0, 0, "Chiller Local-Network"}, - {HR, 1, 0, "Chiller Enable Output"}, - {HR, 2, 0, "Run Enabled"}, - {HR, 3, 0, "Chiller Capacity Limited"}, - {HR, 4, 0, "Alm Digital Output"}, - {HR, 6, 0, "Evap Flow Switch Sts"}, - {HR, 7, 0, "Cond Flow Switch Sts"}, - {HR, 8, 0, "Chiller On-Off"}, - {HR, 9, 0, "Chiller Enable SP"}, - {HR, 10, 0, "Clear Alm"}, - {HR, 11, 0, "Chiller Mode Output"}, - {HR_10x, 12, 0, "Active SP"}, - {HR_10x, 13, 0, "Actual Capacity"}, - {HR_10x, 14, 0, "Active Capacity Limit"}, - {HR, 15, 0, "Chiller Sts"}, - {HR_10x, 16, 0, "Evap Entering Fluid Temp"}, - {HR_10x, 17, 0, "Evap Leaving Fluid Temp"}, - {HR, 18, 0, "Evap Fluid Flow Rate"}, - {HR_10x, 19, 0, "Cond Entering Fluid Temp"}, - {HR_10x, 20, 0, "Cond Leaving Fluid Temp"}, - {HR, 21, 0, "Cond Fluid Flow Rate"}, - {HR_10x, 24, 0, "Outdoor Air Temp"}, - {HR, 25, 0, "Chiller Current"}, - {HR, 27, 0, "Total Kw"}, - {HR, 28, 0, "Warning Alm Idx"}, - {HR, 29, 0, "Problem Alm Idx"}, - {HR, 30, 0, "Fault Alm Idx"}, - {HR, 31, 0, "Warning Alm Code"}, - {HR, 32, 0, "Problem Alm Code"}, - {HR, 33, 0, "Fault Alm Code"}, - {HR, 34, 0, "Chiller Mode SP"}, - {HR_10x, 35, 0, "Cool SP"}, - {HR_10x, 36, 0, "Ice SP"}, - {HR_10x, 38, 0, "Capacity Limit SP"}, - {HR_10x, 39, 0, "Cond Refrig Pressure"}, - {HR_10x, 40, 0, "Cond Saturated Refrig Temp"}, - {HR_10x, 41, 0, "Evap Refrig Pressure"}, - {HR_10x, 42, 0, "Evap Saturated Refrig Temp"}, - {HR, 65, 0, "Comp Suction Refrig Temp"}, - {HR_10x, 68, 0, "Comp Discharge Refrig Temp"}, - {HR, 69, 0, "Comp1 Percent RLA"}, - {HR, 70, 0, "Comp1 Current"}, - {HR, 71, 0, "Comp Voltage"}, - {HR, 72, 0, "Comp Power"}, - {HR, 73, 0, "Comp Starts"}, - {HR, 74, 0, "Comp Run Hours"}, - {HR, 75, 0, "Comp Run Hours"}, - {HR, 82, 0, "Comp2 Percent RLA"}, - {HR, 303, 0, "Evap Pump Run Hours"}, - {HR, 304, 0, "Evap Pump Run Hours"}, - {HR, 305, 0, "Evap Pump Sts"}, - {HR, 316, 0, "Units"}, - {HR, 317, 0, "Chiller Model"}, - {HR, 1849, 0, "Oil Feed Pessure"}, - {HR, 1854, 0, "Wtrside Econo State"}, - {HR, 1855, 0, "Wtrside Econo En SP"}, - -}; + {COIL, 0, 0, "Coil"}, + {DI, 1, 0, "Discrete input"}, + {IR, 2, 0, "Input Register 1 word"}, + {IR_10x, 3, 0, "Input Register scaled by 10"}, + {IR_FLOAT, 4, 0, "Input Register float"}, + {IR_LONG, 6, 0, "Input Register 2 word"}, + {HR, 8, 0, "Holding Register 1 word"}, + {HR_10x, 8, 0, "Holding Register scaled by 10"}, + {HR_FLOAT, 10, 0, "Holding Register float"}, + {HR_LONG, 12, 0, "Holding Register 2 word"}, +}; + //Size of modbus map used in FOR cycles, automatically calculated. /** * @brief The total number of entries in the `mb_map` array. diff --git a/src/Base_TCP/config.h b/src/Base_TCP/config.h index bd4ad09..09bf37f 100644 --- a/src/Base_TCP/config.h +++ b/src/Base_TCP/config.h @@ -60,83 +60,17 @@ */ modbusMap mb_map[] = { - {HR, 15, 0, "State Control"}, //Internal to control from Modscan - {HR, 16, 0, "Fault Code"}, - {HR_FLOAT, 18, 0, "RAT"}, //Internal Fault code from Modscan - {HR_FLOAT, 1, 0, "SAT Setpoint"}, - {HR_FLOAT, 681, 0, "RAT Setpoint"}, - {HR_FLOAT, 111, 0, "High RAT Limit"}, - {HR_FLOAT, 114, 0, "Low RAT Limit"}, - {HR_FLOAT, 118, 0, "High SAT Limit"}, - {HR_FLOAT, 122, 0, "Low SAT Limit"}, - {HR_FLOAT, 685, 0, "High RAH Limit"}, - {HR_FLOAT, 689, 0, "Low RAH Limit"}, - {HR, 5, 0, "Setting the EC Fan Max Speed"}, - {HR, 695, 0, "Setting the EC Fan Min Speed"}, - {HR_FLOAT, 693, 0, "Setting Room Temp"}, - {HR, 691, 0, "Setting EC Fan Speed "}, - {DI, 146, 0, "Alarm SAT Sensor Fault"}, - {DI, 1246, 0, "Alarm RAH Sensor Fault"}, - {DI, 1245, 0, "Alarm RAT Sensor Fault"}, - {DI, 1250, 0, "Alarm Filter DP Sensor Fault"}, - {DI, 51, 0, "Alarm Flooding"}, - {DI, 1096, 0, "Alarm Dirty Filter"}, - {DI, 1367, 0, "Alarm High RAT"}, - {DI, 1099, 0, "Alarm Low RAT"}, - {DI, 118, 0, "Alarm High SAT"}, - {DI, 122, 0, "Alarm Low SAT"}, - {DI, 1307, 0, "Alarm High RAH"}, - {DI, 1308, 0, "Alarm Low RAH"}, - {DI, 1342, 0, "Alarm Common"}, - {DI, 148, 0, "Alarm Phase Failure"}, - {DI, 1370, 0, "Alarm Condensate Pump"}, - {DI, 1368, 0, "Alarm Smoke"}, - {DI, 1369, 0, "Alarm Fire"}, - {DI, 131, 0, "Alarm EC Fan #1"}, - {DI, 132, 0, "Alarm EC Fan #2"}, - {DI, 133, 0, "Alarm EC Fan #3"}, - {DI, 134, 0, "Alarm EC Fan #4"}, - {DI, 135, 0, "Alarm EC Fan #5"}, - {DI, 136, 0, "Alarm EC Fan #6"}, - {DI, 1360, 0, "Alarm EC Fan #7"}, - {DI, 1361, 0, "Alarm EC Fan #8"}, - {DI, 1362, 0, "Alarm EC Fan #9"}, - {DI, 138, 0, "Run Status EC Fan #1"}, - {DI, 139, 0, "Run Status EC Fan #2"}, - {DI, 140, 0, "Run Status EC Fan #3"}, - {DI, 141, 0, "Run Status EC Fan #4"}, - {DI, 142, 0, "Run Status EC Fan #5"}, - {DI, 143, 0, "Run Status EC Fan #6"}, - {DI, 1363, 0, "Run Status EC Fan #7"}, - {DI, 1364, 0, "Run Status EC Fan #8"}, - {DI, 1365, 0, "Run Status EC Fan #9"}, - {IR_FLOAT, 99, 0, "SAT Reading"}, - {IR_FLOAT, 70, 0, "RAH Reading"}, - {IR_FLOAT, 101, 0, "RAT Reading"}, - {IR_FLOAT, 106, 0, "Filter DP Reading"}, - {IR_FLOAT, 496, 0, "CW Valve Position"}, - {IR, 53, 0, "Speed EC Fan #1"}, - {IR, 228, 0, "Speed EC Fan #2"}, - {IR, 229, 0, "Speed EC Fan #3"}, - {IR, 230, 0, "Speed EC Fan #4"}, - {IR, 231, 0, "Speed EC Fan #5"}, - {IR, 232, 0, "Speed EC Fan #6"}, - {IR, 678, 0, "Speed EC Fan #7"}, - {IR, 679, 0, "Speed EC Fan #8"}, - {IR, 680, 0, "Speed EC Fan #9"}, - {IR, 274, 0, "Operating Hours EC Fan #1"}, - {IR, 233, 0, "Operating Hours EC Fan #2"}, - {IR, 244, 0, "Operating Hours EC Fan #3"}, - {IR, 235, 0, "Operating Hours EC Fan #4"}, - {IR, 236, 0, "Operating Hours EC Fan #5"}, - {IR, 245, 0, "Operating Hours EC Fan #6"}, - {IR, 486, 0, "Operating Hours EC Fan #7"}, - {IR, 487, 0, "Operating Hours EC Fan #8"}, - {IR, 488, 0, "Operating Hours EC Fan #9"}, - {COIL, 301, 0, "ON/OFF Command By BMS"}, - {COIL, 302, 0, "Enable Off By Supervisory"}, - {COIL, 264, 0, "Alarm Reset"} -}; + {COIL, 0, 0, "Coil"}, + {DI, 1, 0, "Discrete input"}, + {IR, 2, 0, "Input Register 1 word"}, + {IR_10x, 3, 0, "Input Register scaled by 10"}, + {IR_FLOAT, 4, 0, "Input Register float"}, + {IR_LONG, 6, 0, "Input Register 2 word"}, + {HR, 8, 0, "Holding Register 1 word"}, + {HR_10x, 8, 0, "Holding Register scaled by 10"}, + {HR_FLOAT, 10, 0, "Holding Register float"}, + {HR_LONG, 12, 0, "Holding Register 2 word"}, +}; //Size of modbus map used in FOR cycles, automatically calculated. /** diff --git a/src/EPMS/PDU/PDU_Manufacturer_Model_TCP/README.md b/src/EPMS/Breaker/BKR_ABB_EMax2_TCP/README.md similarity index 100% rename from src/EPMS/PDU/PDU_Manufacturer_Model_TCP/README.md rename to src/EPMS/Breaker/BKR_ABB_EMax2_TCP/README.md diff --git a/src/EPMS/PDU/PDU_Manufacturer_Model_TCP/State_Fail.cpp b/src/EPMS/Breaker/BKR_ABB_EMax2_TCP/State_Fail.cpp similarity index 100% rename from src/EPMS/PDU/PDU_Manufacturer_Model_TCP/State_Fail.cpp rename to src/EPMS/Breaker/BKR_ABB_EMax2_TCP/State_Fail.cpp diff --git a/src/EPMS/PDU/PDU_Manufacturer_Model_TCP/State_Running.cpp b/src/EPMS/Breaker/BKR_ABB_EMax2_TCP/State_Running.cpp similarity index 100% rename from src/EPMS/PDU/PDU_Manufacturer_Model_TCP/State_Running.cpp rename to src/EPMS/Breaker/BKR_ABB_EMax2_TCP/State_Running.cpp diff --git a/src/EPMS/PDU/PDU_Manufacturer_Model_TCP/State_Standby.cpp b/src/EPMS/Breaker/BKR_ABB_EMax2_TCP/State_Standby.cpp similarity index 100% rename from src/EPMS/PDU/PDU_Manufacturer_Model_TCP/State_Standby.cpp rename to src/EPMS/Breaker/BKR_ABB_EMax2_TCP/State_Standby.cpp diff --git a/src/EPMS/Breaker/BKR_ABB_EMax2_TCP/config.h b/src/EPMS/Breaker/BKR_ABB_EMax2_TCP/config.h new file mode 100644 index 0000000..3887572 --- /dev/null +++ b/src/EPMS/Breaker/BKR_ABB_EMax2_TCP/config.h @@ -0,0 +1,96 @@ +/** + * @file config.h + * @brief Main configuration file for the Breaker ABB EMax2 + * @author Zach Gutierrez + * @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 + 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(172, 17, 22, 152); /**< @brief The static IP address for the device. */ + IPAddress gateway(172, 17, 22, 254); /**< @brief The gateway IP address. */ + IPAddress subnet(255, 255, 255, 0); /**< @brief The subnet mask. */ + + ModbusIP mb; +#else + /** + * @defgroup ModbusRTUConfig Modbus RTU Configuration + * @brief Parameters for serial Modbus RTU communication. + * @{ + */ + #include + const int BAUDRATE = 19200; /**< @brief The serial communication speed in bits per second. */ + const int RX_PIN = 17; /**< @brief The GPIO pin used for receiving data (RX). */ + const int TX_PIN = 16; /**< @brief The GPIO pin used for transmitting data (TX). */ + const int RST_PIN = 4; /**< @brief The GPIO pin connected to the RS485 driver's DE/RE pins for direction control. */ + const int MODBUS_ID = 1; /**< @brief The unique slave ID for this device on the Modbus bus. */ + /** @} */ + + /** @brief Global instance of the Modbus RTU server. */ + ModbusRTU mb; +#endif + + + +/** + * @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[] = { + // ESP8266 Modbus server uses 0-based addressing, while Modbus Poll uses 1-based addressing. + // Convert from ESP8266 to traditional Modbus addressing: subtract 30001/40001. + + // Input Registers (3x) - Floating Point (MSB & LSB) + {IR, 40, 0, "CB_Position" }, // 300041.0 - Circuit Breaker Position + {IR, 40, 0, "CB_Trip" }, // 300041.12 - Circuit Breaker Tripped + {IR_LONG, 100, 0, "Amps_A" }, //DWORD + {IR_LONG, 102, 0, "Amps_B" }, //DWORD + {IR_LONG, 104, 0, "Amps_C" }, //DWORD + {IR_LONG, 106, 0, "Amps_N" }, //DWORD + {IR_LONG, 108, 0, "Amps_G" }, //DWORD + {IR, 150, 0, "V_AN" }, //WORD + {IR, 151, 0, "V_BN" }, //WORD + {IR, 152, 0, "V_CN" }, //WORD + {IR, 154, 0, "V_AB" }, //WORD + {IR, 155, 0, "V_BC" }, //WORD + {IR, 156, 0, "V_CA" }, //WORD + {IR_LONG, 222, 0, "k_VA" }, //LONG + {IR_LONG, 206, 0, "kW" }, //LONG + {IR_LONG, 304, 0, "kWh" }, //LONG + {IR, 253, 0, "k_VA" }, //SHORT +}; +//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 diff --git a/src/EPMS/PDU/PDU_Manufacturer_Model_TCP/main.cpp b/src/EPMS/Breaker/BKR_ABB_EMax2_TCP/main.cpp similarity index 100% rename from src/EPMS/PDU/PDU_Manufacturer_Model_TCP/main.cpp rename to src/EPMS/Breaker/BKR_ABB_EMax2_TCP/main.cpp diff --git a/src/EPMS/STS/STS_Manufacturer_Model_TCP/README.md b/src/EPMS/Breaker/BKR_ABB_XT_TCP/README.md similarity index 100% rename from src/EPMS/STS/STS_Manufacturer_Model_TCP/README.md rename to src/EPMS/Breaker/BKR_ABB_XT_TCP/README.md diff --git a/src/EPMS/STS/STS_Manufacturer_Model_TCP/State_Fail.cpp b/src/EPMS/Breaker/BKR_ABB_XT_TCP/State_Fail.cpp similarity index 100% rename from src/EPMS/STS/STS_Manufacturer_Model_TCP/State_Fail.cpp rename to src/EPMS/Breaker/BKR_ABB_XT_TCP/State_Fail.cpp diff --git a/src/EPMS/STS/STS_Manufacturer_Model_TCP/State_Running.cpp b/src/EPMS/Breaker/BKR_ABB_XT_TCP/State_Running.cpp similarity index 100% rename from src/EPMS/STS/STS_Manufacturer_Model_TCP/State_Running.cpp rename to src/EPMS/Breaker/BKR_ABB_XT_TCP/State_Running.cpp diff --git a/src/EPMS/STS/STS_Manufacturer_Model_TCP/State_Standby.cpp b/src/EPMS/Breaker/BKR_ABB_XT_TCP/State_Standby.cpp similarity index 100% rename from src/EPMS/STS/STS_Manufacturer_Model_TCP/State_Standby.cpp rename to src/EPMS/Breaker/BKR_ABB_XT_TCP/State_Standby.cpp diff --git a/src/EPMS/Breaker/BKR_ABB_XT_TCP/config.h b/src/EPMS/Breaker/BKR_ABB_XT_TCP/config.h new file mode 100644 index 0000000..0dadeb5 --- /dev/null +++ b/src/EPMS/Breaker/BKR_ABB_XT_TCP/config.h @@ -0,0 +1,93 @@ +/** + * @file config.h + * @brief Main configuration file for the Braker ABB XT + * @author Zach Gutierrez + * @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 + 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(172, 17, 22, 175); /**< @brief The static IP address for the device. */ + IPAddress gateway(172, 17, 22, 254); /**< @brief The gateway IP address. */ + IPAddress subnet(255, 255, 255, 0); /**< @brief The subnet mask. */ + + ModbusIP mb; +#else + /** + * @defgroup ModbusRTUConfig Modbus RTU Configuration + * @brief Parameters for serial Modbus RTU communication. + * @{ + */ + #include + const int BAUDRATE = 19200; /**< @brief The serial communication speed in bits per second. */ + const int RX_PIN = 17; /**< @brief The GPIO pin used for receiving data (RX). */ + const int TX_PIN = 16; /**< @brief The GPIO pin used for transmitting data (TX). */ + const int RST_PIN = 4; /**< @brief The GPIO pin connected to the RS485 driver's DE/RE pins for direction control. */ + const int MODBUS_ID = 1; /**< @brief The unique slave ID for this device on the Modbus bus. */ + /** @} */ + + /** @brief Global instance of the Modbus RTU server. */ + ModbusRTU mb; +#endif + + + +/** + * @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[] = { + // ESP8266 Modbus server uses 0-based addressing, while Modbus Poll uses 1-based addressing. + // Convert from ESP8266 to traditional Modbus addressing: subtract 30001/40001. + + {HR, 350, 0, "Amps_A" }, // 40351 Amps_A + {HR, 354, 0, "Amps_C" }, // 40355 Amps_C + {HR, 352, 0, "Amps_B" }, // 40353 Amps_B + {HR, 372, 0, "kVA" }, // 40373 kVA + {HR, 358, 0, "Volts_AN" }, // 40359 Volts_AN + {HR, 366, 0, "Volts_BC" }, // 40367 Volts_BC + {HR, 362, 0, "Volts_CN" }, // 40363 Volts_CN + {HR, 910, 0, "PF" }, // 40911 PF + {HR, 900, 0, "Freq" }, // 40901 Freq + {HR, 600, 0, "kWh" }, // 40601 kWh + {HR, 364, 0, "Volts_AB" }, // 40365 Volts_AB + {HR, 360, 0, "Volts_BN" }, // 40361 Volts_BN + {HR, 356, 0, "Amps_N" }, // 40357 Amps_N + {HR, 368, 0, "Volts_CA" }, // 40369 Volts_CA + {HR, 370, 0, "kW" } // 40371 kW +}; +//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 diff --git a/src/EPMS/STS/STS_Manufacturer_Model_TCP/main.cpp b/src/EPMS/Breaker/BKR_ABB_XT_TCP/main.cpp similarity index 100% rename from src/EPMS/STS/STS_Manufacturer_Model_TCP/main.cpp rename to src/EPMS/Breaker/BKR_ABB_XT_TCP/main.cpp diff --git a/src/EPMS/GEN/GEN_CAT_EMCP4_TCP/README.md b/src/EPMS/GEN/GEN_CAT_EMCP4_TCP/README.md new file mode 100644 index 0000000..355156f --- /dev/null +++ b/src/EPMS/GEN/GEN_CAT_EMCP4_TCP/README.md @@ -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 diff --git a/src/EPMS/GEN/GEN_CAT_EMCP4_TCP/State_Fail.cpp b/src/EPMS/GEN/GEN_CAT_EMCP4_TCP/State_Fail.cpp new file mode 100644 index 0000000..8bc0385 --- /dev/null +++ b/src/EPMS/GEN/GEN_CAT_EMCP4_TCP/State_Fail.cpp @@ -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 +#else + #include +#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::FailState(const std::vector& 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* FailState::update(Equipment* 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::enterState(Equipment* 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::exitState(Equipment* equipment) { + // Cleanup logic to run when the equipment leaves this state + Serial.println("Exit Fail State..."); +} \ No newline at end of file diff --git a/src/EPMS/GEN/GEN_CAT_EMCP4_TCP/State_Running.cpp b/src/EPMS/GEN/GEN_CAT_EMCP4_TCP/State_Running.cpp new file mode 100644 index 0000000..b9e4a99 --- /dev/null +++ b/src/EPMS/GEN/GEN_CAT_EMCP4_TCP/State_Running.cpp @@ -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 +#include +#if defined(USE_MODBUS_IP) + #include +#else + #include +#endif + +/** + * @brief Constructs a new RunningState object. + * + * This constructor initializes behavior strategies active during the running + * state, such as a PID controller for the 'CW Valve Position' and totalizers + * for the run-hours of each EC fan. + */ +template<> +RunningState::RunningState() { +} + +/** + * @brief Executes the running state's logic for one update cycle. + * + * This method first checks for state transition commands: + * 1. It reads the "ON/OFF Command By BMS" point. If it's 0, it transitions to StandbyState. + * 2. It reads the "Fault Code" point. If it's non-zero, it transitions to FailState, + * passing the corresponding alarm description. + * + * If no transition occurs, it applies the strategies defined for the running state. + * + * @param equipment Pointer to the Equipment instance. + * @return A pointer to a new State if a transition should occur, otherwise nullptr. + */ +template<> +State* RunningState::update(Equipment* equipment) { + // STATE control, add conditions if change to a different state is needed + Serial.println("Running update function"); + + // 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::enterState(Equipment* equipment) { + // Logic to run when the equipment enters this state + Serial.println("Enter Running State..."); + // You could also update a Modbus register to show the "standby" state + +} + +/** + * @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::exitState(Equipment* equipment) { + // Cleanup logic to run when the equipment leaves this state + Serial.println("Exit Running State..."); + +} \ No newline at end of file diff --git a/src/EPMS/GEN/GEN_CAT_EMCP4_TCP/State_Standby.cpp b/src/EPMS/GEN/GEN_CAT_EMCP4_TCP/State_Standby.cpp new file mode 100644 index 0000000..20029d1 --- /dev/null +++ b/src/EPMS/GEN/GEN_CAT_EMCP4_TCP/State_Standby.cpp @@ -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 +#include +#if defined(USE_MODBUS_IP) + #include +#else + #include +#endif +/** + * @brief Constructs a new StandbyState object. + * + * In this state, the equipment is idle. This constructor initializes 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::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* StandbyState::update(Equipment* 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::enterState(Equipment* 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::exitState(Equipment* equipment) { + // Cleanup logic to run when the equipment leaves this state + Serial.println("Exit Standby State..."); +} \ No newline at end of file diff --git a/src/EPMS/GEN/GEN_CAT_EMCP4_TCP/config.h b/src/EPMS/GEN/GEN_CAT_EMCP4_TCP/config.h new file mode 100644 index 0000000..b45aea7 --- /dev/null +++ b/src/EPMS/GEN/GEN_CAT_EMCP4_TCP/config.h @@ -0,0 +1,124 @@ +/** + * @file config.h + * @brief Main configuration file for the GEN CAT EMCP4 + * @author Zach Gutierrez + * @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 + const char *ssid = "wifi_name"; /**< @brief The SSID of the WiFi network. */ + const char *password = "wifi_password"; /**< @brief The password for the WiFi network. */ + IPAddress local_IP(192, 168, 1, 234); /**< @brief The static IP address for the device. */ + IPAddress gateway(192, 168, 1, 1); /**< @brief The gateway IP address. */ + IPAddress subnet(255, 255, 255, 0); /**< @brief The subnet mask. */ + + ModbusIP mb; +#else + /** + * @defgroup ModbusRTUConfig Modbus RTU Configuration + * @brief Parameters for serial Modbus RTU communication. + * @{ + */ + #include + const int BAUDRATE = 19200; /**< @brief The serial communication speed in bits per second. */ + const int RX_PIN = 17; /**< @brief The GPIO pin used for receiving data (RX). */ + const int TX_PIN = 16; /**< @brief The GPIO pin used for transmitting data (TX). */ + const int RST_PIN = 4; /**< @brief The GPIO pin connected to the RS485 driver's DE/RE pins for direction control. */ + const int MODBUS_ID = 1; /**< @brief The unique slave ID for this device on the Modbus bus. */ + /** @} */ + + /** @brief Global instance of the Modbus RTU server. */ + ModbusRTU mb; +#endif + + + +/** + * @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[] = { + // ESP8266 Modbus server uses 0-based addressing, while Modbus Poll uses 1-based addressing. + {HR, 48899, 0, "Alm01" }, // 448900 + {HR, 48898, 0, "Alm02" }, // 448899 + {HR, 48905, 0, "Alm03" }, // 448906 + {HR, 48896, 0, "Alm04" }, // 448897 + {HR, 48900, 0, "Alm05" }, // 448901 + {HR, 48903, 0, "Alm06" }, // 448904 + {HR, 48901, 0, "Alm07" }, // 448902 + {HR, 48902, 0, "Alm08" }, // 448903 + {HR, 48907, 0, "Fuel_LoLo" }, // 448908 + {HR, 48912, 0, "Alm10" }, // 448913 + {HR, 48897, 0, "Alm11" }, // 448898 + {HR, 48914, 0, "Fuel_Hi" }, // 448915 + {HR, 48906, 0, "Fuel_Lo" }, // 448907 + {HR, 48911, 0, "Alm14" }, // 448912 + {HR, 48904, 0, "Common_Alarm" }, // 448905 + {HR, 8654, 0, "Bkr_State" }, //48655 + {HR, 1024, 0, "Oil Pressure" }, // 41025 Engine_Oil_Pressure + {HR, 1025, 0, "Coolant Temp" }, // 41026 Coolant_Temperature_degC + {HR, 1026, 0, "Oil_Temp_degC" }, // 41027 Oil_Temperature_degC + {HR, 1029, 0, "Battery_Voltage" }, // 41030 Battery_Voltage + {HR, 1030, 0, "Engine_Speed" }, // 41031 Engine_Speed + {HR, 1031, 0, "Freq" }, // 41032 Freq + {HR, 1032, 0, "Volts_AN" }, // 41033 Volts_AN + {HR, 1034, 0, "Volts_BN" }, // 41035 Volts_BN + {HR, 1036, 0, "Volts_CN" }, // 41037 Volts_CN + {HR, 1038, 0, "Volts_AB" }, // 41039 Volts_AB + {HR, 1040, 0, "Volts_BC" }, // 41041 Volts_BC + {HR, 1042, 0, "Volts_CA" }, // 41043 Volts_CA + {HR, 1044, 0, "Amps_A" }, // 41045 Amps_A + {HR, 1046, 0, "Amps_B" }, // 41047 Amps_B + {HR, 1048, 0, "Amps_C" }, // 41049 Amps_C + {HR, 1052, 0, "kW_A" }, // 41053 kW_A + {HR, 1054, 0, "kW_B" }, // 41055 kW_B + {HR, 1056, 0, "kW_C" }, // 41057 kW_C + {HR, 1288, 0, "L_Exhaust_degC" }, // 41289 Left_Exhaust_Temp_degC + {HR, 1289, 0, "R_Exhaust_degC" }, // 41290 Right_Exhaust_Temp_degC + {HR, 1354, 0, "Percent_Load" }, // 41355 Percent_Load + {HR, 1536, 0, "kW_Tot" }, // 41537 kW + {HR, 1538, 0, "kVA_A" }, // 41539 kVA_A + {HR, 1540, 0, "kVA_B" }, // 41541 kVA_B + {HR, 1542, 0, "kVA_C" }, // 41543 kVA_C + {HR, 1544, 0, "kVA_Tot" }, // 41545 kVA + {HR, 1552, 0, "kVAR_Tot" }, // 41553 kVAR + {HR, 1557, 0, "PF_Tot" }, // 41558 PF + {HR, 1798, 0, "TTL_Run_Hours" }, // 41799 TTL_Run_Hours + {HR, 1800, 0, "kWh_Tot" }, // 41801 kWh + {HR, 1808, 0, "TTL_Starts" }, // 41809 TTL_Engine_Starts + {HR, 48908, 0, "Auto_Mode" } // 448909 Auto_Mode +}; +//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 diff --git a/src/EPMS/GEN/GEN_CAT_EMCP4_TCP/main.cpp b/src/EPMS/GEN/GEN_CAT_EMCP4_TCP/main.cpp new file mode 100644 index 0000000..286a98c --- /dev/null +++ b/src/EPMS/GEN/GEN_CAT_EMCP4_TCP/main.cpp @@ -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 +#include "config.h" +#include "ModbusPoints/Modbus_PointFactory.h" +#if defined(USE_MODBUS_IP) + #include +#else + #include +#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* 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); + } +} diff --git a/src/EPMS/GEN/GEN_Manufacturer_Model_TCP/config.h b/src/EPMS/GEN/GEN_Manufacturer_Model_TCP/config.h deleted file mode 100644 index bd4ad09..0000000 --- a/src/EPMS/GEN/GEN_Manufacturer_Model_TCP/config.h +++ /dev/null @@ -1,152 +0,0 @@ -/** - * @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 - const char *ssid = "wifi_name"; /**< @brief The SSID of the WiFi network. */ - const char *password = "wifi_password"; /**< @brief The password for the WiFi network. */ - IPAddress local_IP(192, 168, 1, 234); /**< @brief The static IP address for the device. */ - IPAddress gateway(192, 168, 1, 1); /**< @brief The gateway IP address. */ - IPAddress subnet(255, 255, 255, 0); /**< @brief The subnet mask. */ - - ModbusIP mb; -#else - /** - * @defgroup ModbusRTUConfig Modbus RTU Configuration - * @brief Parameters for serial Modbus RTU communication. - * @{ - */ - #include - const int BAUDRATE = 19200; /**< @brief The serial communication speed in bits per second. */ - const int RX_PIN = 17; /**< @brief The GPIO pin used for receiving data (RX). */ - const int TX_PIN = 16; /**< @brief The GPIO pin used for transmitting data (TX). */ - const int RST_PIN = 4; /**< @brief The GPIO pin connected to the RS485 driver's DE/RE pins for direction control. */ - const int MODBUS_ID = 1; /**< @brief The unique slave ID for this device on the Modbus bus. */ - /** @} */ - - /** @brief Global instance of the Modbus RTU server. */ - ModbusRTU mb; -#endif - - - -/** - * @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, 15, 0, "State Control"}, //Internal to control from Modscan - {HR, 16, 0, "Fault Code"}, - {HR_FLOAT, 18, 0, "RAT"}, //Internal Fault code from Modscan - {HR_FLOAT, 1, 0, "SAT Setpoint"}, - {HR_FLOAT, 681, 0, "RAT Setpoint"}, - {HR_FLOAT, 111, 0, "High RAT Limit"}, - {HR_FLOAT, 114, 0, "Low RAT Limit"}, - {HR_FLOAT, 118, 0, "High SAT Limit"}, - {HR_FLOAT, 122, 0, "Low SAT Limit"}, - {HR_FLOAT, 685, 0, "High RAH Limit"}, - {HR_FLOAT, 689, 0, "Low RAH Limit"}, - {HR, 5, 0, "Setting the EC Fan Max Speed"}, - {HR, 695, 0, "Setting the EC Fan Min Speed"}, - {HR_FLOAT, 693, 0, "Setting Room Temp"}, - {HR, 691, 0, "Setting EC Fan Speed "}, - {DI, 146, 0, "Alarm SAT Sensor Fault"}, - {DI, 1246, 0, "Alarm RAH Sensor Fault"}, - {DI, 1245, 0, "Alarm RAT Sensor Fault"}, - {DI, 1250, 0, "Alarm Filter DP Sensor Fault"}, - {DI, 51, 0, "Alarm Flooding"}, - {DI, 1096, 0, "Alarm Dirty Filter"}, - {DI, 1367, 0, "Alarm High RAT"}, - {DI, 1099, 0, "Alarm Low RAT"}, - {DI, 118, 0, "Alarm High SAT"}, - {DI, 122, 0, "Alarm Low SAT"}, - {DI, 1307, 0, "Alarm High RAH"}, - {DI, 1308, 0, "Alarm Low RAH"}, - {DI, 1342, 0, "Alarm Common"}, - {DI, 148, 0, "Alarm Phase Failure"}, - {DI, 1370, 0, "Alarm Condensate Pump"}, - {DI, 1368, 0, "Alarm Smoke"}, - {DI, 1369, 0, "Alarm Fire"}, - {DI, 131, 0, "Alarm EC Fan #1"}, - {DI, 132, 0, "Alarm EC Fan #2"}, - {DI, 133, 0, "Alarm EC Fan #3"}, - {DI, 134, 0, "Alarm EC Fan #4"}, - {DI, 135, 0, "Alarm EC Fan #5"}, - {DI, 136, 0, "Alarm EC Fan #6"}, - {DI, 1360, 0, "Alarm EC Fan #7"}, - {DI, 1361, 0, "Alarm EC Fan #8"}, - {DI, 1362, 0, "Alarm EC Fan #9"}, - {DI, 138, 0, "Run Status EC Fan #1"}, - {DI, 139, 0, "Run Status EC Fan #2"}, - {DI, 140, 0, "Run Status EC Fan #3"}, - {DI, 141, 0, "Run Status EC Fan #4"}, - {DI, 142, 0, "Run Status EC Fan #5"}, - {DI, 143, 0, "Run Status EC Fan #6"}, - {DI, 1363, 0, "Run Status EC Fan #7"}, - {DI, 1364, 0, "Run Status EC Fan #8"}, - {DI, 1365, 0, "Run Status EC Fan #9"}, - {IR_FLOAT, 99, 0, "SAT Reading"}, - {IR_FLOAT, 70, 0, "RAH Reading"}, - {IR_FLOAT, 101, 0, "RAT Reading"}, - {IR_FLOAT, 106, 0, "Filter DP Reading"}, - {IR_FLOAT, 496, 0, "CW Valve Position"}, - {IR, 53, 0, "Speed EC Fan #1"}, - {IR, 228, 0, "Speed EC Fan #2"}, - {IR, 229, 0, "Speed EC Fan #3"}, - {IR, 230, 0, "Speed EC Fan #4"}, - {IR, 231, 0, "Speed EC Fan #5"}, - {IR, 232, 0, "Speed EC Fan #6"}, - {IR, 678, 0, "Speed EC Fan #7"}, - {IR, 679, 0, "Speed EC Fan #8"}, - {IR, 680, 0, "Speed EC Fan #9"}, - {IR, 274, 0, "Operating Hours EC Fan #1"}, - {IR, 233, 0, "Operating Hours EC Fan #2"}, - {IR, 244, 0, "Operating Hours EC Fan #3"}, - {IR, 235, 0, "Operating Hours EC Fan #4"}, - {IR, 236, 0, "Operating Hours EC Fan #5"}, - {IR, 245, 0, "Operating Hours EC Fan #6"}, - {IR, 486, 0, "Operating Hours EC Fan #7"}, - {IR, 487, 0, "Operating Hours EC Fan #8"}, - {IR, 488, 0, "Operating Hours EC Fan #9"}, - {COIL, 301, 0, "ON/OFF Command By BMS"}, - {COIL, 302, 0, "Enable Off By Supervisory"}, - {COIL, 264, 0, "Alarm Reset"} -}; -//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 diff --git a/src/EPMS/MVG/MVG_Manufacturer_Model_TCP/config.h b/src/EPMS/MVG/MVG_Manufacturer_Model_TCP/config.h deleted file mode 100644 index bd4ad09..0000000 --- a/src/EPMS/MVG/MVG_Manufacturer_Model_TCP/config.h +++ /dev/null @@ -1,152 +0,0 @@ -/** - * @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 - const char *ssid = "wifi_name"; /**< @brief The SSID of the WiFi network. */ - const char *password = "wifi_password"; /**< @brief The password for the WiFi network. */ - IPAddress local_IP(192, 168, 1, 234); /**< @brief The static IP address for the device. */ - IPAddress gateway(192, 168, 1, 1); /**< @brief The gateway IP address. */ - IPAddress subnet(255, 255, 255, 0); /**< @brief The subnet mask. */ - - ModbusIP mb; -#else - /** - * @defgroup ModbusRTUConfig Modbus RTU Configuration - * @brief Parameters for serial Modbus RTU communication. - * @{ - */ - #include - const int BAUDRATE = 19200; /**< @brief The serial communication speed in bits per second. */ - const int RX_PIN = 17; /**< @brief The GPIO pin used for receiving data (RX). */ - const int TX_PIN = 16; /**< @brief The GPIO pin used for transmitting data (TX). */ - const int RST_PIN = 4; /**< @brief The GPIO pin connected to the RS485 driver's DE/RE pins for direction control. */ - const int MODBUS_ID = 1; /**< @brief The unique slave ID for this device on the Modbus bus. */ - /** @} */ - - /** @brief Global instance of the Modbus RTU server. */ - ModbusRTU mb; -#endif - - - -/** - * @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, 15, 0, "State Control"}, //Internal to control from Modscan - {HR, 16, 0, "Fault Code"}, - {HR_FLOAT, 18, 0, "RAT"}, //Internal Fault code from Modscan - {HR_FLOAT, 1, 0, "SAT Setpoint"}, - {HR_FLOAT, 681, 0, "RAT Setpoint"}, - {HR_FLOAT, 111, 0, "High RAT Limit"}, - {HR_FLOAT, 114, 0, "Low RAT Limit"}, - {HR_FLOAT, 118, 0, "High SAT Limit"}, - {HR_FLOAT, 122, 0, "Low SAT Limit"}, - {HR_FLOAT, 685, 0, "High RAH Limit"}, - {HR_FLOAT, 689, 0, "Low RAH Limit"}, - {HR, 5, 0, "Setting the EC Fan Max Speed"}, - {HR, 695, 0, "Setting the EC Fan Min Speed"}, - {HR_FLOAT, 693, 0, "Setting Room Temp"}, - {HR, 691, 0, "Setting EC Fan Speed "}, - {DI, 146, 0, "Alarm SAT Sensor Fault"}, - {DI, 1246, 0, "Alarm RAH Sensor Fault"}, - {DI, 1245, 0, "Alarm RAT Sensor Fault"}, - {DI, 1250, 0, "Alarm Filter DP Sensor Fault"}, - {DI, 51, 0, "Alarm Flooding"}, - {DI, 1096, 0, "Alarm Dirty Filter"}, - {DI, 1367, 0, "Alarm High RAT"}, - {DI, 1099, 0, "Alarm Low RAT"}, - {DI, 118, 0, "Alarm High SAT"}, - {DI, 122, 0, "Alarm Low SAT"}, - {DI, 1307, 0, "Alarm High RAH"}, - {DI, 1308, 0, "Alarm Low RAH"}, - {DI, 1342, 0, "Alarm Common"}, - {DI, 148, 0, "Alarm Phase Failure"}, - {DI, 1370, 0, "Alarm Condensate Pump"}, - {DI, 1368, 0, "Alarm Smoke"}, - {DI, 1369, 0, "Alarm Fire"}, - {DI, 131, 0, "Alarm EC Fan #1"}, - {DI, 132, 0, "Alarm EC Fan #2"}, - {DI, 133, 0, "Alarm EC Fan #3"}, - {DI, 134, 0, "Alarm EC Fan #4"}, - {DI, 135, 0, "Alarm EC Fan #5"}, - {DI, 136, 0, "Alarm EC Fan #6"}, - {DI, 1360, 0, "Alarm EC Fan #7"}, - {DI, 1361, 0, "Alarm EC Fan #8"}, - {DI, 1362, 0, "Alarm EC Fan #9"}, - {DI, 138, 0, "Run Status EC Fan #1"}, - {DI, 139, 0, "Run Status EC Fan #2"}, - {DI, 140, 0, "Run Status EC Fan #3"}, - {DI, 141, 0, "Run Status EC Fan #4"}, - {DI, 142, 0, "Run Status EC Fan #5"}, - {DI, 143, 0, "Run Status EC Fan #6"}, - {DI, 1363, 0, "Run Status EC Fan #7"}, - {DI, 1364, 0, "Run Status EC Fan #8"}, - {DI, 1365, 0, "Run Status EC Fan #9"}, - {IR_FLOAT, 99, 0, "SAT Reading"}, - {IR_FLOAT, 70, 0, "RAH Reading"}, - {IR_FLOAT, 101, 0, "RAT Reading"}, - {IR_FLOAT, 106, 0, "Filter DP Reading"}, - {IR_FLOAT, 496, 0, "CW Valve Position"}, - {IR, 53, 0, "Speed EC Fan #1"}, - {IR, 228, 0, "Speed EC Fan #2"}, - {IR, 229, 0, "Speed EC Fan #3"}, - {IR, 230, 0, "Speed EC Fan #4"}, - {IR, 231, 0, "Speed EC Fan #5"}, - {IR, 232, 0, "Speed EC Fan #6"}, - {IR, 678, 0, "Speed EC Fan #7"}, - {IR, 679, 0, "Speed EC Fan #8"}, - {IR, 680, 0, "Speed EC Fan #9"}, - {IR, 274, 0, "Operating Hours EC Fan #1"}, - {IR, 233, 0, "Operating Hours EC Fan #2"}, - {IR, 244, 0, "Operating Hours EC Fan #3"}, - {IR, 235, 0, "Operating Hours EC Fan #4"}, - {IR, 236, 0, "Operating Hours EC Fan #5"}, - {IR, 245, 0, "Operating Hours EC Fan #6"}, - {IR, 486, 0, "Operating Hours EC Fan #7"}, - {IR, 487, 0, "Operating Hours EC Fan #8"}, - {IR, 488, 0, "Operating Hours EC Fan #9"}, - {COIL, 301, 0, "ON/OFF Command By BMS"}, - {COIL, 302, 0, "Enable Off By Supervisory"}, - {COIL, 264, 0, "Alarm Reset"} -}; -//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 diff --git a/src/EPMS/MVG/MVG_SEL2440_TCP/README.md b/src/EPMS/MVG/MVG_SEL2440_TCP/README.md new file mode 100644 index 0000000..355156f --- /dev/null +++ b/src/EPMS/MVG/MVG_SEL2440_TCP/README.md @@ -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 diff --git a/src/EPMS/MVG/MVG_SEL2440_TCP/State_Fail.cpp b/src/EPMS/MVG/MVG_SEL2440_TCP/State_Fail.cpp new file mode 100644 index 0000000..8bc0385 --- /dev/null +++ b/src/EPMS/MVG/MVG_SEL2440_TCP/State_Fail.cpp @@ -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 +#else + #include +#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::FailState(const std::vector& 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* FailState::update(Equipment* 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::enterState(Equipment* 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::exitState(Equipment* equipment) { + // Cleanup logic to run when the equipment leaves this state + Serial.println("Exit Fail State..."); +} \ No newline at end of file diff --git a/src/EPMS/MVG/MVG_SEL2440_TCP/State_Running.cpp b/src/EPMS/MVG/MVG_SEL2440_TCP/State_Running.cpp new file mode 100644 index 0000000..b9e4a99 --- /dev/null +++ b/src/EPMS/MVG/MVG_SEL2440_TCP/State_Running.cpp @@ -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 +#include +#if defined(USE_MODBUS_IP) + #include +#else + #include +#endif + +/** + * @brief Constructs a new RunningState object. + * + * This constructor initializes behavior strategies active during the running + * state, such as a PID controller for the 'CW Valve Position' and totalizers + * for the run-hours of each EC fan. + */ +template<> +RunningState::RunningState() { +} + +/** + * @brief Executes the running state's logic for one update cycle. + * + * This method first checks for state transition commands: + * 1. It reads the "ON/OFF Command By BMS" point. If it's 0, it transitions to StandbyState. + * 2. It reads the "Fault Code" point. If it's non-zero, it transitions to FailState, + * passing the corresponding alarm description. + * + * If no transition occurs, it applies the strategies defined for the running state. + * + * @param equipment Pointer to the Equipment instance. + * @return A pointer to a new State if a transition should occur, otherwise nullptr. + */ +template<> +State* RunningState::update(Equipment* equipment) { + // STATE control, add conditions if change to a different state is needed + Serial.println("Running update function"); + + // 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::enterState(Equipment* equipment) { + // Logic to run when the equipment enters this state + Serial.println("Enter Running State..."); + // You could also update a Modbus register to show the "standby" state + +} + +/** + * @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::exitState(Equipment* equipment) { + // Cleanup logic to run when the equipment leaves this state + Serial.println("Exit Running State..."); + +} \ No newline at end of file diff --git a/src/EPMS/MVG/MVG_SEL2440_TCP/State_Standby.cpp b/src/EPMS/MVG/MVG_SEL2440_TCP/State_Standby.cpp new file mode 100644 index 0000000..20029d1 --- /dev/null +++ b/src/EPMS/MVG/MVG_SEL2440_TCP/State_Standby.cpp @@ -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 +#include +#if defined(USE_MODBUS_IP) + #include +#else + #include +#endif +/** + * @brief Constructs a new StandbyState object. + * + * In this state, the equipment is idle. This constructor initializes 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::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* StandbyState::update(Equipment* 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::enterState(Equipment* 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::exitState(Equipment* equipment) { + // Cleanup logic to run when the equipment leaves this state + Serial.println("Exit Standby State..."); +} \ No newline at end of file diff --git a/src/EPMS/MVG/MVG_SEL2440_TCP/config.h b/src/EPMS/MVG/MVG_SEL2440_TCP/config.h new file mode 100644 index 0000000..461d904 --- /dev/null +++ b/src/EPMS/MVG/MVG_SEL2440_TCP/config.h @@ -0,0 +1,112 @@ +/** + * @file config.h + * @brief Main configuration file for the MVG SEL 2440 + * @author Zach Gutierrez + * @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 + const char *ssid = "wifi_name"; /**< @brief The SSID of the WiFi network. */ + const char *password = "wifi_password"; /**< @brief The password for the WiFi network. */ + IPAddress local_IP(192, 168, 1, 234); /**< @brief The static IP address for the device. */ + IPAddress gateway(192, 168, 1, 1); /**< @brief The gateway IP address. */ + IPAddress subnet(255, 255, 255, 0); /**< @brief The subnet mask. */ + + ModbusIP mb; +#else + /** + * @defgroup ModbusRTUConfig Modbus RTU Configuration + * @brief Parameters for serial Modbus RTU communication. + * @{ + */ + #include + const int BAUDRATE = 19200; /**< @brief The serial communication speed in bits per second. */ + const int RX_PIN = 17; /**< @brief The GPIO pin used for receiving data (RX). */ + const int TX_PIN = 16; /**< @brief The GPIO pin used for transmitting data (TX). */ + const int RST_PIN = 4; /**< @brief The GPIO pin connected to the RS485 driver's DE/RE pins for direction control. */ + const int MODBUS_ID = 1; /**< @brief The unique slave ID for this device on the Modbus bus. */ + /** @} */ + + /** @brief Global instance of the Modbus RTU server. */ + ModbusRTU mb; +#endif + + + +/** + * @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[] = { + // ESP8266 Modbus server uses 0-based addressing, while Modbus Poll uses 1-based addressing. + // Convert from ESP8266 to traditional Modbus addressing: subtract 30001/40001. + {IR, 548, 0, "Way2_Grounded" }, // 300549.0 Way2_Grounded + {IR, 548, 0, "Way2_Open" }, // 300549.1 Way2_Open + {IR, 548, 0, "Way2_Closed" }, // 300549.2 Way2_Closed + {IR, 548, 0, "Way1_Tripped" }, // 300549.3 Way1_Tripped + {IR, 548, 0, "Way1_Grounded" }, // 300549.4 Way1_Grounded + {IR, 548, 0, "Way1_Open" }, // 300549.5 Way1_Open + {IR, 548, 0, "Way1_Closed" }, // 300549.6 Way1_Closed + {IR, 548, 0, "Tank_Pressure" }, // 300549.7 Tank_Pressure + {IR, 549, 0, "Way2_Tripped" }, // 300550.0 Way2_Tripped + {IR, 549, 0, "Way4_Open" }, // 300550.1 Way4_Open + {IR, 549, 0, "Way4_Closed" }, // 300550.2 Way4_Closed + {IR, 549, 0, "Way3_Tripped" }, // 300550.4 Way3_Tripped + {IR, 549, 0, "Way3_Open" }, // 300550.5 Way3_Open + {IR, 549, 0, "Way3_Closed" }, // 300550.6 Way3_Closed + {IR, 550, 0, "Way5_Tripped" }, // 300551.3 Way5_Tripped + {IR, 550, 0, "Way5_Grounded" }, // 300551.4 Way5_Grounded + {IR, 550, 0, "Way5_Open" }, // 300551.5 Way5_Open + {IR, 550, 0, "Way5_Closed" }, // 300551.6 Way5_Closed + {IR, 550, 0, "Way4_Tripped" }, // 300551.7 Way4_Tripped + {HR, 350, 0, "Amps_A" }, // 40351 Amps_A + {HR, 354, 0, "Amps_C" }, // 40355 Amps_C + {HR, 352, 0, "Amps_B" }, // 40353 Amps_B + {HR, 372, 0, "kVA" }, // 40373 kVA + {HR, 358, 0, "Volts_AN" }, // 40359 Volts_AN + {HR, 366, 0, "Volts_BC" }, // 40367 Volts_BC + {HR, 362, 0, "Volts_CN" }, // 40363 Volts_CN + {HR, 910, 0, "PF" }, // 40911 PF + {HR, 900, 0, "Freq" }, // 40901 Freq + {HR, 600, 0, "kWh" }, // 40601 kWh + {HR, 364, 0, "Volts_AB" }, // 40365 Volts_AB + {HR, 360, 0, "Volts_BN" }, // 40361 Volts_BN + {HR, 356, 0, "Amps_N" }, // 40357 Amps_N + {HR, 368, 0, "Volts_CA" }, // 40369 Volts_CA + {HR, 370, 0, "kW" } // 40371 kW + +}; +//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 diff --git a/src/EPMS/MVG/MVG_SEL2440_TCP/main.cpp b/src/EPMS/MVG/MVG_SEL2440_TCP/main.cpp new file mode 100644 index 0000000..286a98c --- /dev/null +++ b/src/EPMS/MVG/MVG_SEL2440_TCP/main.cpp @@ -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 +#include "config.h" +#include "ModbusPoints/Modbus_PointFactory.h" +#if defined(USE_MODBUS_IP) + #include +#else + #include +#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* 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); + } +} diff --git a/src/EPMS/PDU/PDU_Manufacturer_Model_TCP/config.h b/src/EPMS/PDU/PDU_Manufacturer_Model_TCP/config.h deleted file mode 100644 index bd4ad09..0000000 --- a/src/EPMS/PDU/PDU_Manufacturer_Model_TCP/config.h +++ /dev/null @@ -1,152 +0,0 @@ -/** - * @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 - const char *ssid = "wifi_name"; /**< @brief The SSID of the WiFi network. */ - const char *password = "wifi_password"; /**< @brief The password for the WiFi network. */ - IPAddress local_IP(192, 168, 1, 234); /**< @brief The static IP address for the device. */ - IPAddress gateway(192, 168, 1, 1); /**< @brief The gateway IP address. */ - IPAddress subnet(255, 255, 255, 0); /**< @brief The subnet mask. */ - - ModbusIP mb; -#else - /** - * @defgroup ModbusRTUConfig Modbus RTU Configuration - * @brief Parameters for serial Modbus RTU communication. - * @{ - */ - #include - const int BAUDRATE = 19200; /**< @brief The serial communication speed in bits per second. */ - const int RX_PIN = 17; /**< @brief The GPIO pin used for receiving data (RX). */ - const int TX_PIN = 16; /**< @brief The GPIO pin used for transmitting data (TX). */ - const int RST_PIN = 4; /**< @brief The GPIO pin connected to the RS485 driver's DE/RE pins for direction control. */ - const int MODBUS_ID = 1; /**< @brief The unique slave ID for this device on the Modbus bus. */ - /** @} */ - - /** @brief Global instance of the Modbus RTU server. */ - ModbusRTU mb; -#endif - - - -/** - * @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, 15, 0, "State Control"}, //Internal to control from Modscan - {HR, 16, 0, "Fault Code"}, - {HR_FLOAT, 18, 0, "RAT"}, //Internal Fault code from Modscan - {HR_FLOAT, 1, 0, "SAT Setpoint"}, - {HR_FLOAT, 681, 0, "RAT Setpoint"}, - {HR_FLOAT, 111, 0, "High RAT Limit"}, - {HR_FLOAT, 114, 0, "Low RAT Limit"}, - {HR_FLOAT, 118, 0, "High SAT Limit"}, - {HR_FLOAT, 122, 0, "Low SAT Limit"}, - {HR_FLOAT, 685, 0, "High RAH Limit"}, - {HR_FLOAT, 689, 0, "Low RAH Limit"}, - {HR, 5, 0, "Setting the EC Fan Max Speed"}, - {HR, 695, 0, "Setting the EC Fan Min Speed"}, - {HR_FLOAT, 693, 0, "Setting Room Temp"}, - {HR, 691, 0, "Setting EC Fan Speed "}, - {DI, 146, 0, "Alarm SAT Sensor Fault"}, - {DI, 1246, 0, "Alarm RAH Sensor Fault"}, - {DI, 1245, 0, "Alarm RAT Sensor Fault"}, - {DI, 1250, 0, "Alarm Filter DP Sensor Fault"}, - {DI, 51, 0, "Alarm Flooding"}, - {DI, 1096, 0, "Alarm Dirty Filter"}, - {DI, 1367, 0, "Alarm High RAT"}, - {DI, 1099, 0, "Alarm Low RAT"}, - {DI, 118, 0, "Alarm High SAT"}, - {DI, 122, 0, "Alarm Low SAT"}, - {DI, 1307, 0, "Alarm High RAH"}, - {DI, 1308, 0, "Alarm Low RAH"}, - {DI, 1342, 0, "Alarm Common"}, - {DI, 148, 0, "Alarm Phase Failure"}, - {DI, 1370, 0, "Alarm Condensate Pump"}, - {DI, 1368, 0, "Alarm Smoke"}, - {DI, 1369, 0, "Alarm Fire"}, - {DI, 131, 0, "Alarm EC Fan #1"}, - {DI, 132, 0, "Alarm EC Fan #2"}, - {DI, 133, 0, "Alarm EC Fan #3"}, - {DI, 134, 0, "Alarm EC Fan #4"}, - {DI, 135, 0, "Alarm EC Fan #5"}, - {DI, 136, 0, "Alarm EC Fan #6"}, - {DI, 1360, 0, "Alarm EC Fan #7"}, - {DI, 1361, 0, "Alarm EC Fan #8"}, - {DI, 1362, 0, "Alarm EC Fan #9"}, - {DI, 138, 0, "Run Status EC Fan #1"}, - {DI, 139, 0, "Run Status EC Fan #2"}, - {DI, 140, 0, "Run Status EC Fan #3"}, - {DI, 141, 0, "Run Status EC Fan #4"}, - {DI, 142, 0, "Run Status EC Fan #5"}, - {DI, 143, 0, "Run Status EC Fan #6"}, - {DI, 1363, 0, "Run Status EC Fan #7"}, - {DI, 1364, 0, "Run Status EC Fan #8"}, - {DI, 1365, 0, "Run Status EC Fan #9"}, - {IR_FLOAT, 99, 0, "SAT Reading"}, - {IR_FLOAT, 70, 0, "RAH Reading"}, - {IR_FLOAT, 101, 0, "RAT Reading"}, - {IR_FLOAT, 106, 0, "Filter DP Reading"}, - {IR_FLOAT, 496, 0, "CW Valve Position"}, - {IR, 53, 0, "Speed EC Fan #1"}, - {IR, 228, 0, "Speed EC Fan #2"}, - {IR, 229, 0, "Speed EC Fan #3"}, - {IR, 230, 0, "Speed EC Fan #4"}, - {IR, 231, 0, "Speed EC Fan #5"}, - {IR, 232, 0, "Speed EC Fan #6"}, - {IR, 678, 0, "Speed EC Fan #7"}, - {IR, 679, 0, "Speed EC Fan #8"}, - {IR, 680, 0, "Speed EC Fan #9"}, - {IR, 274, 0, "Operating Hours EC Fan #1"}, - {IR, 233, 0, "Operating Hours EC Fan #2"}, - {IR, 244, 0, "Operating Hours EC Fan #3"}, - {IR, 235, 0, "Operating Hours EC Fan #4"}, - {IR, 236, 0, "Operating Hours EC Fan #5"}, - {IR, 245, 0, "Operating Hours EC Fan #6"}, - {IR, 486, 0, "Operating Hours EC Fan #7"}, - {IR, 487, 0, "Operating Hours EC Fan #8"}, - {IR, 488, 0, "Operating Hours EC Fan #9"}, - {COIL, 301, 0, "ON/OFF Command By BMS"}, - {COIL, 302, 0, "Enable Off By Supervisory"}, - {COIL, 264, 0, "Alarm Reset"} -}; -//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 diff --git a/src/EPMS/PDU/PDU_Maverick_Power_TCP/README.md b/src/EPMS/PDU/PDU_Maverick_Power_TCP/README.md new file mode 100644 index 0000000..355156f --- /dev/null +++ b/src/EPMS/PDU/PDU_Maverick_Power_TCP/README.md @@ -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 diff --git a/src/EPMS/PDU/PDU_Maverick_Power_TCP/State_Fail.cpp b/src/EPMS/PDU/PDU_Maverick_Power_TCP/State_Fail.cpp new file mode 100644 index 0000000..8bc0385 --- /dev/null +++ b/src/EPMS/PDU/PDU_Maverick_Power_TCP/State_Fail.cpp @@ -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 +#else + #include +#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::FailState(const std::vector& 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* FailState::update(Equipment* 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::enterState(Equipment* 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::exitState(Equipment* equipment) { + // Cleanup logic to run when the equipment leaves this state + Serial.println("Exit Fail State..."); +} \ No newline at end of file diff --git a/src/EPMS/PDU/PDU_Maverick_Power_TCP/State_Running.cpp b/src/EPMS/PDU/PDU_Maverick_Power_TCP/State_Running.cpp new file mode 100644 index 0000000..b9e4a99 --- /dev/null +++ b/src/EPMS/PDU/PDU_Maverick_Power_TCP/State_Running.cpp @@ -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 +#include +#if defined(USE_MODBUS_IP) + #include +#else + #include +#endif + +/** + * @brief Constructs a new RunningState object. + * + * This constructor initializes behavior strategies active during the running + * state, such as a PID controller for the 'CW Valve Position' and totalizers + * for the run-hours of each EC fan. + */ +template<> +RunningState::RunningState() { +} + +/** + * @brief Executes the running state's logic for one update cycle. + * + * This method first checks for state transition commands: + * 1. It reads the "ON/OFF Command By BMS" point. If it's 0, it transitions to StandbyState. + * 2. It reads the "Fault Code" point. If it's non-zero, it transitions to FailState, + * passing the corresponding alarm description. + * + * If no transition occurs, it applies the strategies defined for the running state. + * + * @param equipment Pointer to the Equipment instance. + * @return A pointer to a new State if a transition should occur, otherwise nullptr. + */ +template<> +State* RunningState::update(Equipment* equipment) { + // STATE control, add conditions if change to a different state is needed + Serial.println("Running update function"); + + // 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::enterState(Equipment* equipment) { + // Logic to run when the equipment enters this state + Serial.println("Enter Running State..."); + // You could also update a Modbus register to show the "standby" state + +} + +/** + * @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::exitState(Equipment* equipment) { + // Cleanup logic to run when the equipment leaves this state + Serial.println("Exit Running State..."); + +} \ No newline at end of file diff --git a/src/EPMS/PDU/PDU_Maverick_Power_TCP/State_Standby.cpp b/src/EPMS/PDU/PDU_Maverick_Power_TCP/State_Standby.cpp new file mode 100644 index 0000000..20029d1 --- /dev/null +++ b/src/EPMS/PDU/PDU_Maverick_Power_TCP/State_Standby.cpp @@ -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 +#include +#if defined(USE_MODBUS_IP) + #include +#else + #include +#endif +/** + * @brief Constructs a new StandbyState object. + * + * In this state, the equipment is idle. This constructor initializes 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::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* StandbyState::update(Equipment* 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::enterState(Equipment* 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::exitState(Equipment* equipment) { + // Cleanup logic to run when the equipment leaves this state + Serial.println("Exit Standby State..."); +} \ No newline at end of file diff --git a/src/EPMS/PDU/PDU_Maverick_Power_TCP/config.h b/src/EPMS/PDU/PDU_Maverick_Power_TCP/config.h new file mode 100644 index 0000000..b4e5999 --- /dev/null +++ b/src/EPMS/PDU/PDU_Maverick_Power_TCP/config.h @@ -0,0 +1,502 @@ +/** + * @file config.h + * @brief Main configuration file for the PDU Maverick Power + * @author Zach Gutierrez + * @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 + const char *ssid = "wifi_name"; /**< @brief The SSID of the WiFi network. */ + const char *password = "wifi_password"; /**< @brief The password for the WiFi network. */ + IPAddress local_IP(192, 168, 1, 234); /**< @brief The static IP address for the device. */ + IPAddress gateway(192, 168, 1, 1); /**< @brief The gateway IP address. */ + IPAddress subnet(255, 255, 255, 0); /**< @brief The subnet mask. */ + + ModbusIP mb; +#else + /** + * @defgroup ModbusRTUConfig Modbus RTU Configuration + * @brief Parameters for serial Modbus RTU communication. + * @{ + */ + #include + const int BAUDRATE = 19200; /**< @brief The serial communication speed in bits per second. */ + const int RX_PIN = 17; /**< @brief The GPIO pin used for receiving data (RX). */ + const int TX_PIN = 16; /**< @brief The GPIO pin used for transmitting data (TX). */ + const int RST_PIN = 4; /**< @brief The GPIO pin connected to the RS485 driver's DE/RE pins for direction control. */ + const int MODBUS_ID = 1; /**< @brief The unique slave ID for this device on the Modbus bus. */ + /** @} */ + + /** @brief Global instance of the Modbus RTU server. */ + ModbusRTU mb; +#endif + + + +/** + * @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[] = { + + //*************************************** + // Write Registers (as Input Registers - 3X) + //*************************************** + + // System Status + {IR_FLOAT, 1, 0, "CB0_V1N" }, + {IR_FLOAT, 3, 0, "CB0_V2N" }, + {IR_FLOAT, 5, 0, "CB0_V3N" }, + {IR_FLOAT, 7, 0, "CB0_I1" }, + {IR_FLOAT, 9, 0, "CB0_I2" }, + {IR_FLOAT, 11, 0, "CB0_I3" }, + {IR_FLOAT, 13, 0, "CB0_L1KW" }, + {IR_FLOAT, 15, 0, "CB0_L2KW" }, + {IR_FLOAT, 17, 0, "CB0_L3KW" }, + {IR_FLOAT, 19, 0, "CB0_L1KVar" }, + {IR_FLOAT, 21, 0, "CB0_L2KVar" }, + {IR_FLOAT, 23, 0, "CB0_L3KVar" }, + {IR_FLOAT, 25, 0, "CB0_L1KVA" }, + {IR_FLOAT, 27, 0, "CB0_L2KVA" }, + {IR_FLOAT, 29, 0, "CB0_L3KVA" }, + {IR_FLOAT, 31, 0, "CB0_L1PF" }, + {IR_FLOAT, 33, 0, "CB0_L2PF" }, + {IR_FLOAT, 35, 0, "CB0_L3PF" }, + {IR_FLOAT, 37, 0, "CB0_V1THD" }, + {IR_FLOAT, 39, 0, "CB0_V2THD" }, + {IR_FLOAT, 41, 0, "CB0_V3THD" }, + {IR_FLOAT, 43, 0, "CB0_I1THD" }, + {IR_FLOAT, 45, 0, "CB0_I2THD" }, + {IR_FLOAT, 47, 0, "CB0_I3THD" }, + {IR_FLOAT, 49, 0, "CB0_I1Kfactor" }, + {IR_FLOAT, 51, 0, "CB0_I2Kfactor" }, + {IR_FLOAT, 53, 0, "CB0_I3Kfactor" }, + {IR_FLOAT, 55, 0, "CB0_I1TDD" }, + {IR_FLOAT, 57, 0, "CB0_I2TDD" }, + {IR_FLOAT, 59, 0, "CB0_I3TDD" }, + {IR_FLOAT, 61, 0, "CB0_V12" }, + {IR_FLOAT, 63, 0, "CB0_V23" }, + {IR_FLOAT, 65, 0, "CB0_V31" }, + {IR_FLOAT, 67, 0, "CB0_TotalKW" }, + {IR_FLOAT, 69, 0, "CB0_TotalKVar" }, + {IR_FLOAT, 71, 0, "CB0_TotalKVA" }, + {IR_FLOAT, 73, 0, "CB0_TotalPF" }, + {IR_FLOAT, 75, 0, "CB0_TotalPFLag" }, + {IR_FLOAT, 77, 0, "CB0_TotalPFLead" }, + {IR_FLOAT, 79, 0, "CB0_TotalKWImport" }, + {IR_FLOAT, 81, 0, "CB0_TotalKWExport" }, + {IR_FLOAT, 83, 0, "CB0_TotalKVarImport" }, + {IR_FLOAT, 85, 0, "CB0_TotalKVarExport" }, + {IR_FLOAT, 87, 0, "CB0_LN_Avg" }, + {IR_FLOAT, 89, 0, "CB0_LL_Avg" }, + + // Circuit Breaker 1 (OB01) + {IR_FLOAT, 101, 0, "CB1_V1N" }, + {IR_FLOAT, 103, 0, "CB1_V2N" }, + {IR_FLOAT, 105, 0, "CB1_V3N" }, + {IR_FLOAT, 107, 0, "CB1_I1" }, + {IR_FLOAT, 109, 0, "CB1_I2" }, + {IR_FLOAT, 111, 0, "CB1_I3" }, + {IR_FLOAT, 113, 0, "CB1_L1KW" }, + {IR_FLOAT, 115, 0, "CB1_L2KW" }, + {IR_FLOAT, 117, 0, "CB1_L3KW" }, + {IR_FLOAT, 119, 0, "CB1_L1KVar" }, + {IR_FLOAT, 121, 0, "CB1_L2KVar" }, + {IR_FLOAT, 123, 0, "CB1_L3KVar" }, + {IR_FLOAT, 125, 0, "CB1_L1KVA" }, + {IR_FLOAT, 127, 0, "CB1_L2KVA" }, + {IR_FLOAT, 129, 0, "CB1_L3KVA" }, + {IR_FLOAT, 131, 0, "CB1_L1PF" }, + {IR_FLOAT, 133, 0, "CB1_L2PF" }, + {IR_FLOAT, 135, 0, "CB1_L3PF" }, + {IR_FLOAT, 137, 0, "CB1_V1THD" }, + {IR_FLOAT, 139, 0, "CB1_V2THD" }, + {IR_FLOAT, 141, 0, "CB1_V3THD" }, + {IR_FLOAT, 143, 0, "CB1_I1THD" }, + {IR_FLOAT, 145, 0, "CB1_I2THD" }, + {IR_FLOAT, 147, 0, "CB1_I3THD" }, + {IR_FLOAT, 149, 0, "CB1_I1Kfactor" }, + {IR_FLOAT, 151, 0, "CB1_I2Kfactor" }, + {IR_FLOAT, 153, 0, "CB1_I3Kfactor" }, + {IR_FLOAT, 155, 0, "CB1_I1TDD" }, + {IR_FLOAT, 157, 0, "CB1_I2TDD" }, + {IR_FLOAT, 159, 0, "CB1_I3TDD" }, + {IR_FLOAT, 161, 0, "CB1_V12" }, + {IR_FLOAT, 163, 0, "CB1_V23" }, + {IR_FLOAT, 165, 0, "CB1_V31" }, + {IR_FLOAT, 167, 0, "CB1_TotalKW" }, + {IR_FLOAT, 169, 0, "CB1_TotalKVar" }, + {IR_FLOAT, 171, 0, "CB1_TotalKVA" }, + {IR_FLOAT, 173, 0, "CB1_TotalPF" }, + {IR_FLOAT, 175, 0, "CB1_TotalPFLag" }, + {IR_FLOAT, 177, 0, "CB1_TotalPFLead" }, + {IR_FLOAT, 179, 0, "CB1_TotalKWImport" }, + {IR_FLOAT, 181, 0, "CB1_TotalKWExport" }, + {IR_FLOAT, 183, 0, "CB1_TotalKVarImport" }, + {IR_FLOAT, 185, 0, "CB1_TotalKVarExport" }, + {IR_FLOAT, 187, 0, "CB1_LN_Avg" }, + {IR_FLOAT, 189, 0, "CB1_LL_Avg" }, + + // Circuit Breaker 1 (OB01) + {IR_FLOAT, 201, 0, "CB2_V1N" }, + {IR_FLOAT, 203, 0, "CB2_V2N" }, + {IR_FLOAT, 205, 0, "CB2_V3N" }, + {IR_FLOAT, 207, 0, "CB2_I1" }, + {IR_FLOAT, 209, 0, "CB2_I2" }, + {IR_FLOAT, 211, 0, "CB2_I3" }, + {IR_FLOAT, 213, 0, "CB2_L1KW" }, + {IR_FLOAT, 215, 0, "CB2_L2KW" }, + {IR_FLOAT, 217, 0, "CB2_L3KW" }, + {IR_FLOAT, 219, 0, "CB2_L1KVar" }, + {IR_FLOAT, 221, 0, "CB2_L2KVar" }, + {IR_FLOAT, 223, 0, "CB2_L3KVar" }, + {IR_FLOAT, 225, 0, "CB2_L1KVA" }, + {IR_FLOAT, 227, 0, "CB2_L2KVA" }, + {IR_FLOAT, 229, 0, "CB2_L3KVA" }, + {IR_FLOAT, 231, 0, "CB2_L1PF" }, + {IR_FLOAT, 233, 0, "CB2_L2PF" }, + {IR_FLOAT, 235, 0, "CB2_L3PF" }, + {IR_FLOAT, 237, 0, "CB2_V1THD" }, + {IR_FLOAT, 239, 0, "CB2_V2THD" }, + {IR_FLOAT, 241, 0, "CB2_V3THD" }, + {IR_FLOAT, 243, 0, "CB2_I1THD" }, + {IR_FLOAT, 245, 0, "CB2_I2THD" }, + {IR_FLOAT, 247, 0, "CB2_I3THD" }, + {IR_FLOAT, 249, 0, "CB2_I1Kfactor" }, + {IR_FLOAT, 251, 0, "CB2_I2Kfactor" }, + {IR_FLOAT, 253, 0, "CB2_I3Kfactor" }, + {IR_FLOAT, 255, 0, "CB2_I1TDD" }, + {IR_FLOAT, 257, 0, "CB2_I2TDD" }, + {IR_FLOAT, 259, 0, "CB2_I3TDD" }, + {IR_FLOAT, 261, 0, "CB2_V12" }, + {IR_FLOAT, 263, 0, "CB2_V23" }, + {IR_FLOAT, 265, 0, "CB2_V31" }, + {IR_FLOAT, 267, 0, "CB2_TotalKW" }, + {IR_FLOAT, 269, 0, "CB2_TotalKVar" }, + {IR_FLOAT, 271, 0, "CB2_TotalKVA" }, + {IR_FLOAT, 273, 0, "CB2_TotalPF" }, + {IR_FLOAT, 275, 0, "CB2_TotalPFLag" }, + {IR_FLOAT, 277, 0, "CB2_TotalPFLead" }, + {IR_FLOAT, 279, 0, "CB2_TotalKWImport" }, + {IR_FLOAT, 281, 0, "CB2_TotalKWExport" }, + {IR_FLOAT, 283, 0, "CB2_TotalKVarImport" }, + {IR_FLOAT, 285, 0, "CB2_TotalKVarExport" }, + {IR_FLOAT, 287, 0, "CB2_LN_Avg" }, + {IR_FLOAT, 289, 0, "CB2_LL_Avg" }, + + // Circuit Breaker 1 (OB01) + {IR_FLOAT, 301, 0, "CB3_V1N" }, + {IR_FLOAT, 303, 0, "CB3_V2N" }, + {IR_FLOAT, 305, 0, "CB3_V3N" }, + {IR_FLOAT, 307, 0, "CB3_I1" }, + {IR_FLOAT, 309, 0, "CB3_I2" }, + {IR_FLOAT, 311, 0, "CB3_I3" }, + {IR_FLOAT, 313, 0, "CB3_L1KW" }, + {IR_FLOAT, 315, 0, "CB3_L2KW" }, + {IR_FLOAT, 317, 0, "CB3_L3KW" }, + {IR_FLOAT, 319, 0, "CB3_L1KVar" }, + {IR_FLOAT, 321, 0, "CB3_L2KVar" }, + {IR_FLOAT, 323, 0, "CB3_L3KVar" }, + {IR_FLOAT, 325, 0, "CB3_L1KVA" }, + {IR_FLOAT, 327, 0, "CB3_L2KVA" }, + {IR_FLOAT, 329, 0, "CB3_L3KVA" }, + {IR_FLOAT, 331, 0, "CB3_L1PF" }, + {IR_FLOAT, 333, 0, "CB3_L2PF" }, + {IR_FLOAT, 335, 0, "CB3_L3PF" }, + {IR_FLOAT, 337, 0, "CB3_V1THD" }, + {IR_FLOAT, 339, 0, "CB3_V2THD" }, + {IR_FLOAT, 341, 0, "CB3_V3THD" }, + {IR_FLOAT, 343, 0, "CB3_I1THD" }, + {IR_FLOAT, 345, 0, "CB3_I2THD" }, + {IR_FLOAT, 347, 0, "CB3_I3THD" }, + {IR_FLOAT, 349, 0, "CB3_I1Kfactor" }, + {IR_FLOAT, 351, 0, "CB3_I2Kfactor" }, + {IR_FLOAT, 353, 0, "CB3_I3Kfactor" }, + {IR_FLOAT, 355, 0, "CB3_I1TDD" }, + {IR_FLOAT, 357, 0, "CB3_I2TDD" }, + {IR_FLOAT, 359, 0, "CB3_I3TDD" }, + {IR_FLOAT, 361, 0, "CB3_V12" }, + {IR_FLOAT, 363, 0, "CB3_V23" }, + {IR_FLOAT, 365, 0, "CB3_V31" }, + {IR_FLOAT, 367, 0, "CB3_TotalKW" }, + {IR_FLOAT, 369, 0, "CB3_TotalKVar" }, + {IR_FLOAT, 371, 0, "CB3_TotalKVA" }, + {IR_FLOAT, 373, 0, "CB3_TotalPF" }, + {IR_FLOAT, 375, 0, "CB3_TotalPFLag" }, + {IR_FLOAT, 377, 0, "CB3_TotalPFLead" }, + {IR_FLOAT, 379, 0, "CB3_TotalKWImport" }, + {IR_FLOAT, 381, 0, "CB3_TotalKWExport" }, + {IR_FLOAT, 383, 0, "CB3_TotalKVarImport" }, + {IR_FLOAT, 385, 0, "CB3_TotalKVarExport" }, + {IR_FLOAT, 387, 0, "CB3_LN_Avg" }, + {IR_FLOAT, 389, 0, "CB3_LL_Avg" }, + + // Circuit Breaker 1 (OB01) + {IR_FLOAT, 401, 0, "CB4_V1N" }, + {IR_FLOAT, 403, 0, "CB4_V2N" }, + {IR_FLOAT, 405, 0, "CB4_V3N" }, + {IR_FLOAT, 407, 0, "CB4_I1" }, + {IR_FLOAT, 409, 0, "CB4_I2" }, + {IR_FLOAT, 411, 0, "CB4_I3" }, + {IR_FLOAT, 413, 0, "CB4_L1KW" }, + {IR_FLOAT, 415, 0, "CB4_L2KW" }, + {IR_FLOAT, 417, 0, "CB4_L3KW" }, + {IR_FLOAT, 419, 0, "CB4_L1KVar" }, + {IR_FLOAT, 421, 0, "CB4_L2KVar" }, + {IR_FLOAT, 423, 0, "CB4_L3KVar" }, + {IR_FLOAT, 425, 0, "CB4_L1KVA" }, + {IR_FLOAT, 427, 0, "CB4_L2KVA" }, + {IR_FLOAT, 429, 0, "CB4_L3KVA" }, + {IR_FLOAT, 431, 0, "CB4_L1PF" }, + {IR_FLOAT, 433, 0, "CB4_L2PF" }, + {IR_FLOAT, 435, 0, "CB4_L3PF" }, + {IR_FLOAT, 437, 0, "CB4_V1THD" }, + {IR_FLOAT, 439, 0, "CB4_V2THD" }, + {IR_FLOAT, 441, 0, "CB4_V3THD" }, + {IR_FLOAT, 443, 0, "CB4_I1THD" }, + {IR_FLOAT, 445, 0, "CB4_I2THD" }, + {IR_FLOAT, 447, 0, "CB4_I3THD" }, + {IR_FLOAT, 449, 0, "CB4_I1Kfactor" }, + {IR_FLOAT, 451, 0, "CB4_I2Kfactor" }, + {IR_FLOAT, 453, 0, "CB4_I3Kfactor" }, + {IR_FLOAT, 455, 0, "CB4_I1TDD" }, + {IR_FLOAT, 457, 0, "CB4_I2TDD" }, + {IR_FLOAT, 459, 0, "CB4_I3TDD" }, + {IR_FLOAT, 461, 0, "CB4_V12" }, + {IR_FLOAT, 463, 0, "CB4_V23" }, + {IR_FLOAT, 465, 0, "CB4_V31" }, + {IR_FLOAT, 467, 0, "CB4_TotalKW" }, + {IR_FLOAT, 469, 0, "CB4_TotalKVar" }, + {IR_FLOAT, 471, 0, "CB4_TotalKVA" }, + {IR_FLOAT, 473, 0, "CB4_TotalPF" }, + {IR_FLOAT, 475, 0, "CB4_TotalPFLag" }, + {IR_FLOAT, 477, 0, "CB4_TotalPFLead" }, + {IR_FLOAT, 479, 0, "CB4_TotalKWImport" }, + {IR_FLOAT, 481, 0, "CB4_TotalKWExport" }, + {IR_FLOAT, 483, 0, "CB4_TotalKVarImport" }, + {IR_FLOAT, 485, 0, "CB4_TotalKVarExport" }, + {IR_FLOAT, 487, 0, "CB4_LN_Avg" }, + {IR_FLOAT, 489, 0, "CB4_LL_Avg" }, + + // Circuit Breaker 1 (OB01) + {IR_FLOAT, 501, 0, "CB5_V1N" }, + {IR_FLOAT, 503, 0, "CB5_V2N" }, + {IR_FLOAT, 505, 0, "CB5_V3N" }, + {IR_FLOAT, 507, 0, "CB5_I1" }, + {IR_FLOAT, 509, 0, "CB5_I2" }, + {IR_FLOAT, 511, 0, "CB5_I3" }, + {IR_FLOAT, 513, 0, "CB5_L1KW" }, + {IR_FLOAT, 515, 0, "CB5_L2KW" }, + {IR_FLOAT, 517, 0, "CB5_L3KW" }, + {IR_FLOAT, 519, 0, "CB5_L1KVar" }, + {IR_FLOAT, 521, 0, "CB5_L2KVar" }, + {IR_FLOAT, 523, 0, "CB5_L3KVar" }, + {IR_FLOAT, 525, 0, "CB5_L1KVA" }, + {IR_FLOAT, 527, 0, "CB5_L2KVA" }, + {IR_FLOAT, 529, 0, "CB5_L3KVA" }, + {IR_FLOAT, 531, 0, "CB5_L1PF" }, + {IR_FLOAT, 533, 0, "CB5_L2PF" }, + {IR_FLOAT, 535, 0, "CB5_L3PF" }, + {IR_FLOAT, 537, 0, "CB5_V1THD" }, + {IR_FLOAT, 539, 0, "CB5_V2THD" }, + {IR_FLOAT, 541, 0, "CB5_V3THD" }, + {IR_FLOAT, 543, 0, "CB5_I1THD" }, + {IR_FLOAT, 545, 0, "CB5_I2THD" }, + {IR_FLOAT, 547, 0, "CB5_I3THD" }, + {IR_FLOAT, 549, 0, "CB5_I1Kfactor" }, + {IR_FLOAT, 551, 0, "CB5_I2Kfactor" }, + {IR_FLOAT, 553, 0, "CB5_I3Kfactor" }, + {IR_FLOAT, 555, 0, "CB5_I1TDD" }, + {IR_FLOAT, 557, 0, "CB5_I2TDD" }, + {IR_FLOAT, 559, 0, "CB5_I3TDD" }, + {IR_FLOAT, 561, 0, "CB5_V12" }, + {IR_FLOAT, 563, 0, "CB5_V23" }, + {IR_FLOAT, 565, 0, "CB5_V31" }, + {IR_FLOAT, 567, 0, "CB5_TotalKW" }, + {IR_FLOAT, 569, 0, "CB5_TotalKVar" }, + {IR_FLOAT, 571, 0, "CB5_TotalKVA" }, + {IR_FLOAT, 573, 0, "CB5_TotalPF" }, + {IR_FLOAT, 575, 0, "CB5_TotalPFLag" }, + {IR_FLOAT, 577, 0, "CB5_TotalPFLead" }, + {IR_FLOAT, 579, 0, "CB5_TotalKWImport" }, + {IR_FLOAT, 581, 0, "CB5_TotalKWExport" }, + {IR_FLOAT, 583, 0, "CB5_TotalKVarImport" }, + {IR_FLOAT, 585, 0, "CB5_TotalKVarExport" }, + {IR_FLOAT, 587, 0, "CB5_LN_Avg" }, + {IR_FLOAT, 589, 0, "CB5_LL_Avg" }, + + // Circuit Breaker 1 (OB01) + {IR_FLOAT, 601, 0, "CB6_V1N" }, + {IR_FLOAT, 603, 0, "CB6_V2N" }, + {IR_FLOAT, 605, 0, "CB6_V3N" }, + {IR_FLOAT, 607, 0, "CB6_I1" }, + {IR_FLOAT, 609, 0, "CB6_I2" }, + {IR_FLOAT, 611, 0, "CB6_I3" }, + {IR_FLOAT, 613, 0, "CB6_L1KW" }, + {IR_FLOAT, 615, 0, "CB6_L2KW" }, + {IR_FLOAT, 617, 0, "CB6_L3KW" }, + {IR_FLOAT, 619, 0, "CB6_L1KVar" }, + {IR_FLOAT, 621, 0, "CB6_L2KVar" }, + {IR_FLOAT, 623, 0, "CB6_L3KVar" }, + {IR_FLOAT, 625, 0, "CB6_L1KVA" }, + {IR_FLOAT, 627, 0, "CB6_L2KVA" }, + {IR_FLOAT, 629, 0, "CB6_L3KVA" }, + {IR_FLOAT, 631, 0, "CB6_L1PF" }, + {IR_FLOAT, 633, 0, "CB6_L2PF" }, + {IR_FLOAT, 635, 0, "CB6_L3PF" }, + {IR_FLOAT, 637, 0, "CB6_V1THD" }, + {IR_FLOAT, 639, 0, "CB6_V2THD" }, + {IR_FLOAT, 641, 0, "CB6_V3THD" }, + {IR_FLOAT, 643, 0, "CB6_I1THD" }, + {IR_FLOAT, 645, 0, "CB6_I2THD" }, + {IR_FLOAT, 647, 0, "CB6_I3THD" }, + {IR_FLOAT, 649, 0, "CB6_I1Kfactor" }, + {IR_FLOAT, 651, 0, "CB6_I2Kfactor" }, + {IR_FLOAT, 653, 0, "CB6_I3Kfactor" }, + {IR_FLOAT, 655, 0, "CB6_I1TDD" }, + {IR_FLOAT, 657, 0, "CB6_I2TDD" }, + {IR_FLOAT, 659, 0, "CB6_I3TDD" }, + {IR_FLOAT, 661, 0, "CB6_V12" }, + {IR_FLOAT, 663, 0, "CB6_V23" }, + {IR_FLOAT, 665, 0, "CB6_V31" }, + {IR_FLOAT, 667, 0, "CB6_TotalKW" }, + {IR_FLOAT, 669, 0, "CB6_TotalKVar" }, + {IR_FLOAT, 671, 0, "CB6_TotalKVA" }, + {IR_FLOAT, 673, 0, "CB6_TotalPF" }, + {IR_FLOAT, 675, 0, "CB6_TotalPFLag" }, + {IR_FLOAT, 677, 0, "CB6_TotalPFLead" }, + {IR_FLOAT, 679, 0, "CB6_TotalKWImport" }, + {IR_FLOAT, 681, 0, "CB6_TotalKWExport" }, + {IR_FLOAT, 683, 0, "CB6_TotalKVarImport" }, + {IR_FLOAT, 685, 0, "CB6_TotalKVarExport" }, + {IR_FLOAT, 687, 0, "CB6_LN_Avg" }, + {IR_FLOAT, 689, 0, "CB6_LL_Avg" }, + + // Circuit Breaker 1 (OB01) + {IR_FLOAT, 701, 0, "CB7_V1N" }, + {IR_FLOAT, 703, 0, "CB7_V2N" }, + {IR_FLOAT, 705, 0, "CB7_V3N" }, + {IR_FLOAT, 707, 0, "CB7_I1" }, + {IR_FLOAT, 709, 0, "CB7_I2" }, + {IR_FLOAT, 711, 0, "CB7_I3" }, + {IR_FLOAT, 713, 0, "CB7_L1KW" }, + {IR_FLOAT, 715, 0, "CB7_L2KW" }, + {IR_FLOAT, 717, 0, "CB7_L3KW" }, + {IR_FLOAT, 719, 0, "CB7_L1KVar" }, + {IR_FLOAT, 721, 0, "CB7_L2KVar" }, + {IR_FLOAT, 723, 0, "CB7_L3KVar" }, + {IR_FLOAT, 725, 0, "CB7_L1KVA" }, + {IR_FLOAT, 727, 0, "CB7_L2KVA" }, + {IR_FLOAT, 729, 0, "CB7_L3KVA" }, + {IR_FLOAT, 731, 0, "CB7_L1PF" }, + {IR_FLOAT, 733, 0, "CB7_L2PF" }, + {IR_FLOAT, 735, 0, "CB7_L3PF" }, + {IR_FLOAT, 737, 0, "CB7_V1THD" }, + {IR_FLOAT, 739, 0, "CB7_V2THD" }, + {IR_FLOAT, 741, 0, "CB7_V3THD" }, + {IR_FLOAT, 743, 0, "CB7_I1THD" }, + {IR_FLOAT, 745, 0, "CB7_I2THD" }, + {IR_FLOAT, 747, 0, "CB7_I3THD" }, + {IR_FLOAT, 749, 0, "CB7_I1Kfactor" }, + {IR_FLOAT, 751, 0, "CB7_I2Kfactor" }, + {IR_FLOAT, 753, 0, "CB7_I3Kfactor" }, + {IR_FLOAT, 755, 0, "CB7_I1TDD" }, + {IR_FLOAT, 757, 0, "CB7_I2TDD" }, + {IR_FLOAT, 759, 0, "CB7_I3TDD" }, + {IR_FLOAT, 761, 0, "CB7_V12" }, + {IR_FLOAT, 763, 0, "CB7_V23" }, + {IR_FLOAT, 765, 0, "CB7_V31" }, + {IR_FLOAT, 767, 0, "CB7_TotalKW" }, + {IR_FLOAT, 769, 0, "CB7_TotalKVar" }, + {IR_FLOAT, 771, 0, "CB7_TotalKVA" }, + {IR_FLOAT, 773, 0, "CB7_TotalPF" }, + {IR_FLOAT, 775, 0, "CB7_TotalPFLag" }, + {IR_FLOAT, 777, 0, "CB7_TotalPFLead" }, + {IR_FLOAT, 779, 0, "CB7_TotalKWImport" }, + {IR_FLOAT, 781, 0, "CB7_TotalKWExport" }, + {IR_FLOAT, 783, 0, "CB7_TotalKVarImport" }, + {IR_FLOAT, 785, 0, "CB7_TotalKVarExport" }, + {IR_FLOAT, 787, 0, "CB7_LN_Avg" }, + {IR_FLOAT, 789, 0, "CB7_LL_Avg" }, + + // Circuit Breaker 1 (OB01) + {IR_FLOAT, 801, 0, "CB8_V1N" }, + {IR_FLOAT, 803, 0, "CB8_V2N" }, + {IR_FLOAT, 805, 0, "CB8_V3N" }, + {IR_FLOAT, 807, 0, "CB8_I1" }, + {IR_FLOAT, 809, 0, "CB8_I2" }, + {IR_FLOAT, 811, 0, "CB8_I3" }, + {IR_FLOAT, 813, 0, "CB8_L1KW" }, + {IR_FLOAT, 815, 0, "CB8_L2KW" }, + {IR_FLOAT, 817, 0, "CB8_L3KW" }, + {IR_FLOAT, 819, 0, "CB8_L1KVar" }, + {IR_FLOAT, 821, 0, "CB8_L2KVar" }, + {IR_FLOAT, 823, 0, "CB8_L3KVar" }, + {IR_FLOAT, 825, 0, "CB8_L1KVA" }, + {IR_FLOAT, 827, 0, "CB8_L2KVA" }, + {IR_FLOAT, 829, 0, "CB8_L3KVA" }, + {IR_FLOAT, 831, 0, "CB8_L1PF" }, + {IR_FLOAT, 833, 0, "CB8_L2PF" }, + {IR_FLOAT, 835, 0, "CB8_L3PF" }, + {IR_FLOAT, 837, 0, "CB8_V1THD" }, + {IR_FLOAT, 839, 0, "CB8_V2THD" }, + {IR_FLOAT, 841, 0, "CB8_V3THD" }, + {IR_FLOAT, 843, 0, "CB8_I1THD" }, + {IR_FLOAT, 845, 0, "CB8_I2THD" }, + {IR_FLOAT, 847, 0, "CB8_I3THD" }, + {IR_FLOAT, 849, 0, "CB8_I1Kfactor" }, + {IR_FLOAT, 851, 0, "CB8_I2Kfactor" }, + {IR_FLOAT, 853, 0, "CB8_I3Kfactor" }, + {IR_FLOAT, 855, 0, "CB8_I1TDD" }, + {IR_FLOAT, 857, 0, "CB8_I2TDD" }, + {IR_FLOAT, 859, 0, "CB8_I3TDD" }, + {IR_FLOAT, 861, 0, "CB8_V12" }, + {IR_FLOAT, 863, 0, "CB8_V23" }, + {IR_FLOAT, 865, 0, "CB8_V31" }, + {IR_FLOAT, 867, 0, "CB8_TotalKW" }, + {IR_FLOAT, 869, 0, "CB8_TotalKVar" }, + {IR_FLOAT, 871, 0, "CB8_TotalKVA" }, + {IR_FLOAT, 873, 0, "CB8_TotalPF" }, + {IR_FLOAT, 875, 0, "CB8_TotalPFLag" }, + {IR_FLOAT, 877, 0, "CB8_TotalPFLead" }, + {IR_FLOAT, 879, 0, "CB8_TotalKWImport" }, + {IR_FLOAT, 881, 0, "CB8_TotalKWExport" }, + {IR_FLOAT, 883, 0, "CB8_TotalKVarImport" }, + {IR_FLOAT, 885, 0, "CB8_TotalKVarExport" }, + {IR_FLOAT, 887, 0, "CB8_LN_Avg" }, + {IR_FLOAT, 889, 0, "CB8_LL_Avg" }, +}; +//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 diff --git a/src/EPMS/PDU/PDU_Maverick_Power_TCP/main.cpp b/src/EPMS/PDU/PDU_Maverick_Power_TCP/main.cpp new file mode 100644 index 0000000..286a98c --- /dev/null +++ b/src/EPMS/PDU/PDU_Maverick_Power_TCP/main.cpp @@ -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 +#include "config.h" +#include "ModbusPoints/Modbus_PointFactory.h" +#if defined(USE_MODBUS_IP) + #include +#else + #include +#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* 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); + } +} diff --git a/src/EPMS/POD/POD_MBB_Power_Meter_TCP/README.md b/src/EPMS/POD/POD_MBB_Power_Meter_TCP/README.md new file mode 100644 index 0000000..355156f --- /dev/null +++ b/src/EPMS/POD/POD_MBB_Power_Meter_TCP/README.md @@ -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 diff --git a/src/EPMS/POD/POD_MBB_Power_Meter_TCP/State_Fail.cpp b/src/EPMS/POD/POD_MBB_Power_Meter_TCP/State_Fail.cpp new file mode 100644 index 0000000..8bc0385 --- /dev/null +++ b/src/EPMS/POD/POD_MBB_Power_Meter_TCP/State_Fail.cpp @@ -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 +#else + #include +#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::FailState(const std::vector& 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* FailState::update(Equipment* 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::enterState(Equipment* 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::exitState(Equipment* equipment) { + // Cleanup logic to run when the equipment leaves this state + Serial.println("Exit Fail State..."); +} \ No newline at end of file diff --git a/src/EPMS/POD/POD_MBB_Power_Meter_TCP/State_Running.cpp b/src/EPMS/POD/POD_MBB_Power_Meter_TCP/State_Running.cpp new file mode 100644 index 0000000..b9e4a99 --- /dev/null +++ b/src/EPMS/POD/POD_MBB_Power_Meter_TCP/State_Running.cpp @@ -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 +#include +#if defined(USE_MODBUS_IP) + #include +#else + #include +#endif + +/** + * @brief Constructs a new RunningState object. + * + * This constructor initializes behavior strategies active during the running + * state, such as a PID controller for the 'CW Valve Position' and totalizers + * for the run-hours of each EC fan. + */ +template<> +RunningState::RunningState() { +} + +/** + * @brief Executes the running state's logic for one update cycle. + * + * This method first checks for state transition commands: + * 1. It reads the "ON/OFF Command By BMS" point. If it's 0, it transitions to StandbyState. + * 2. It reads the "Fault Code" point. If it's non-zero, it transitions to FailState, + * passing the corresponding alarm description. + * + * If no transition occurs, it applies the strategies defined for the running state. + * + * @param equipment Pointer to the Equipment instance. + * @return A pointer to a new State if a transition should occur, otherwise nullptr. + */ +template<> +State* RunningState::update(Equipment* equipment) { + // STATE control, add conditions if change to a different state is needed + Serial.println("Running update function"); + + // 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::enterState(Equipment* equipment) { + // Logic to run when the equipment enters this state + Serial.println("Enter Running State..."); + // You could also update a Modbus register to show the "standby" state + +} + +/** + * @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::exitState(Equipment* equipment) { + // Cleanup logic to run when the equipment leaves this state + Serial.println("Exit Running State..."); + +} \ No newline at end of file diff --git a/src/EPMS/POD/POD_MBB_Power_Meter_TCP/State_Standby.cpp b/src/EPMS/POD/POD_MBB_Power_Meter_TCP/State_Standby.cpp new file mode 100644 index 0000000..20029d1 --- /dev/null +++ b/src/EPMS/POD/POD_MBB_Power_Meter_TCP/State_Standby.cpp @@ -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 +#include +#if defined(USE_MODBUS_IP) + #include +#else + #include +#endif +/** + * @brief Constructs a new StandbyState object. + * + * In this state, the equipment is idle. This constructor initializes 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::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* StandbyState::update(Equipment* 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::enterState(Equipment* 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::exitState(Equipment* equipment) { + // Cleanup logic to run when the equipment leaves this state + Serial.println("Exit Standby State..."); +} \ No newline at end of file diff --git a/src/EPMS/POD/POD_MBB_Power_Meter_TCP/config.h b/src/EPMS/POD/POD_MBB_Power_Meter_TCP/config.h new file mode 100644 index 0000000..2eb6175 --- /dev/null +++ b/src/EPMS/POD/POD_MBB_Power_Meter_TCP/config.h @@ -0,0 +1,93 @@ +/** + * @file config.h + * @brief Main configuration file for the POD MBB Power Meter + * @author Zach Gutierrez + * @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 + const char *ssid = "wifi_name"; /**< @brief The SSID of the WiFi network. */ + const char *password = "wifi_password"; /**< @brief The password for the WiFi network. */ + IPAddress local_IP(192, 168, 1, 234); /**< @brief The static IP address for the device. */ + IPAddress gateway(192, 168, 1, 1); /**< @brief The gateway IP address. */ + IPAddress subnet(255, 255, 255, 0); /**< @brief The subnet mask. */ + + ModbusIP mb; +#else + /** + * @defgroup ModbusRTUConfig Modbus RTU Configuration + * @brief Parameters for serial Modbus RTU communication. + * @{ + */ + #include + const int BAUDRATE = 19200; /**< @brief The serial communication speed in bits per second. */ + const int RX_PIN = 17; /**< @brief The GPIO pin used for receiving data (RX). */ + const int TX_PIN = 16; /**< @brief The GPIO pin used for transmitting data (TX). */ + const int RST_PIN = 4; /**< @brief The GPIO pin connected to the RS485 driver's DE/RE pins for direction control. */ + const int MODBUS_ID = 1; /**< @brief The unique slave ID for this device on the Modbus bus. */ + /** @} */ + + /** @brief Global instance of the Modbus RTU server. */ + ModbusRTU mb; +#endif + + + +/** + * @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[] = { + // ESP8266 Modbus server uses 0-based addressing, while Modbus Poll uses 1-based addressing. + + // ANALOG VALUES (HOLDING REGISTERS - 4X) & 32-BIT (FLOATING POINT SPLIT INTO MOST SIGNIFICANT BIT + LEAST SIGNIFICANT BIT) + // HOLDING REGISTERS (4X) - FLOAT VALUES SPLIT INTO MSB & LSB + {HR_FLOAT, 99, 0, "Base Sts" }, + {HR_FLOAT, 899, 0, "Freq" }, + {HR_FLOAT, 910, 0, "PWR F" }, + {HR_FLOAT, 199, 0, "Dev Tm" }, + {HR_FLOAT, 350, 0, "Amp_A" }, + {HR_FLOAT, 352, 0, "Arr_B" }, + {HR_FLOAT, 354, 0, "Arr_C" }, + {HR_FLOAT, 356, 0, "Amps_N" }, + {HR_FLOAT, 364, 0, "Volts_AB" }, + {HR_FLOAT, 366, 0, "Volts_BC" }, + {HR_FLOAT, 368, 0, "Volts_CA" }, + {HR_FLOAT, 370, 0, "kW" }, + {HR_FLOAT, 372, 0, "kVA" }, + {HR_FLOAT, 600, 0, "kWH" }, +}; +//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 diff --git a/src/EPMS/POD/POD_MBB_Power_Meter_TCP/main.cpp b/src/EPMS/POD/POD_MBB_Power_Meter_TCP/main.cpp new file mode 100644 index 0000000..286a98c --- /dev/null +++ b/src/EPMS/POD/POD_MBB_Power_Meter_TCP/main.cpp @@ -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 +#include "config.h" +#include "ModbusPoints/Modbus_PointFactory.h" +#if defined(USE_MODBUS_IP) + #include +#else + #include +#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* 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); + } +} diff --git a/src/EPMS/STS/STS_Manufacturer_Model_TCP/config.h b/src/EPMS/STS/STS_Manufacturer_Model_TCP/config.h deleted file mode 100644 index bd4ad09..0000000 --- a/src/EPMS/STS/STS_Manufacturer_Model_TCP/config.h +++ /dev/null @@ -1,152 +0,0 @@ -/** - * @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 - const char *ssid = "wifi_name"; /**< @brief The SSID of the WiFi network. */ - const char *password = "wifi_password"; /**< @brief The password for the WiFi network. */ - IPAddress local_IP(192, 168, 1, 234); /**< @brief The static IP address for the device. */ - IPAddress gateway(192, 168, 1, 1); /**< @brief The gateway IP address. */ - IPAddress subnet(255, 255, 255, 0); /**< @brief The subnet mask. */ - - ModbusIP mb; -#else - /** - * @defgroup ModbusRTUConfig Modbus RTU Configuration - * @brief Parameters for serial Modbus RTU communication. - * @{ - */ - #include - const int BAUDRATE = 19200; /**< @brief The serial communication speed in bits per second. */ - const int RX_PIN = 17; /**< @brief The GPIO pin used for receiving data (RX). */ - const int TX_PIN = 16; /**< @brief The GPIO pin used for transmitting data (TX). */ - const int RST_PIN = 4; /**< @brief The GPIO pin connected to the RS485 driver's DE/RE pins for direction control. */ - const int MODBUS_ID = 1; /**< @brief The unique slave ID for this device on the Modbus bus. */ - /** @} */ - - /** @brief Global instance of the Modbus RTU server. */ - ModbusRTU mb; -#endif - - - -/** - * @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, 15, 0, "State Control"}, //Internal to control from Modscan - {HR, 16, 0, "Fault Code"}, - {HR_FLOAT, 18, 0, "RAT"}, //Internal Fault code from Modscan - {HR_FLOAT, 1, 0, "SAT Setpoint"}, - {HR_FLOAT, 681, 0, "RAT Setpoint"}, - {HR_FLOAT, 111, 0, "High RAT Limit"}, - {HR_FLOAT, 114, 0, "Low RAT Limit"}, - {HR_FLOAT, 118, 0, "High SAT Limit"}, - {HR_FLOAT, 122, 0, "Low SAT Limit"}, - {HR_FLOAT, 685, 0, "High RAH Limit"}, - {HR_FLOAT, 689, 0, "Low RAH Limit"}, - {HR, 5, 0, "Setting the EC Fan Max Speed"}, - {HR, 695, 0, "Setting the EC Fan Min Speed"}, - {HR_FLOAT, 693, 0, "Setting Room Temp"}, - {HR, 691, 0, "Setting EC Fan Speed "}, - {DI, 146, 0, "Alarm SAT Sensor Fault"}, - {DI, 1246, 0, "Alarm RAH Sensor Fault"}, - {DI, 1245, 0, "Alarm RAT Sensor Fault"}, - {DI, 1250, 0, "Alarm Filter DP Sensor Fault"}, - {DI, 51, 0, "Alarm Flooding"}, - {DI, 1096, 0, "Alarm Dirty Filter"}, - {DI, 1367, 0, "Alarm High RAT"}, - {DI, 1099, 0, "Alarm Low RAT"}, - {DI, 118, 0, "Alarm High SAT"}, - {DI, 122, 0, "Alarm Low SAT"}, - {DI, 1307, 0, "Alarm High RAH"}, - {DI, 1308, 0, "Alarm Low RAH"}, - {DI, 1342, 0, "Alarm Common"}, - {DI, 148, 0, "Alarm Phase Failure"}, - {DI, 1370, 0, "Alarm Condensate Pump"}, - {DI, 1368, 0, "Alarm Smoke"}, - {DI, 1369, 0, "Alarm Fire"}, - {DI, 131, 0, "Alarm EC Fan #1"}, - {DI, 132, 0, "Alarm EC Fan #2"}, - {DI, 133, 0, "Alarm EC Fan #3"}, - {DI, 134, 0, "Alarm EC Fan #4"}, - {DI, 135, 0, "Alarm EC Fan #5"}, - {DI, 136, 0, "Alarm EC Fan #6"}, - {DI, 1360, 0, "Alarm EC Fan #7"}, - {DI, 1361, 0, "Alarm EC Fan #8"}, - {DI, 1362, 0, "Alarm EC Fan #9"}, - {DI, 138, 0, "Run Status EC Fan #1"}, - {DI, 139, 0, "Run Status EC Fan #2"}, - {DI, 140, 0, "Run Status EC Fan #3"}, - {DI, 141, 0, "Run Status EC Fan #4"}, - {DI, 142, 0, "Run Status EC Fan #5"}, - {DI, 143, 0, "Run Status EC Fan #6"}, - {DI, 1363, 0, "Run Status EC Fan #7"}, - {DI, 1364, 0, "Run Status EC Fan #8"}, - {DI, 1365, 0, "Run Status EC Fan #9"}, - {IR_FLOAT, 99, 0, "SAT Reading"}, - {IR_FLOAT, 70, 0, "RAH Reading"}, - {IR_FLOAT, 101, 0, "RAT Reading"}, - {IR_FLOAT, 106, 0, "Filter DP Reading"}, - {IR_FLOAT, 496, 0, "CW Valve Position"}, - {IR, 53, 0, "Speed EC Fan #1"}, - {IR, 228, 0, "Speed EC Fan #2"}, - {IR, 229, 0, "Speed EC Fan #3"}, - {IR, 230, 0, "Speed EC Fan #4"}, - {IR, 231, 0, "Speed EC Fan #5"}, - {IR, 232, 0, "Speed EC Fan #6"}, - {IR, 678, 0, "Speed EC Fan #7"}, - {IR, 679, 0, "Speed EC Fan #8"}, - {IR, 680, 0, "Speed EC Fan #9"}, - {IR, 274, 0, "Operating Hours EC Fan #1"}, - {IR, 233, 0, "Operating Hours EC Fan #2"}, - {IR, 244, 0, "Operating Hours EC Fan #3"}, - {IR, 235, 0, "Operating Hours EC Fan #4"}, - {IR, 236, 0, "Operating Hours EC Fan #5"}, - {IR, 245, 0, "Operating Hours EC Fan #6"}, - {IR, 486, 0, "Operating Hours EC Fan #7"}, - {IR, 487, 0, "Operating Hours EC Fan #8"}, - {IR, 488, 0, "Operating Hours EC Fan #9"}, - {COIL, 301, 0, "ON/OFF Command By BMS"}, - {COIL, 302, 0, "Enable Off By Supervisory"}, - {COIL, 264, 0, "Alarm Reset"} -}; -//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 diff --git a/src/EPMS/STS/STS_PowerSmiths_STATYS_UL_600A_TCP/README.md b/src/EPMS/STS/STS_PowerSmiths_STATYS_UL_600A_TCP/README.md new file mode 100644 index 0000000..355156f --- /dev/null +++ b/src/EPMS/STS/STS_PowerSmiths_STATYS_UL_600A_TCP/README.md @@ -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 diff --git a/src/EPMS/STS/STS_PowerSmiths_STATYS_UL_600A_TCP/State_Fail.cpp b/src/EPMS/STS/STS_PowerSmiths_STATYS_UL_600A_TCP/State_Fail.cpp new file mode 100644 index 0000000..8bc0385 --- /dev/null +++ b/src/EPMS/STS/STS_PowerSmiths_STATYS_UL_600A_TCP/State_Fail.cpp @@ -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 +#else + #include +#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::FailState(const std::vector& 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* FailState::update(Equipment* 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::enterState(Equipment* 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::exitState(Equipment* equipment) { + // Cleanup logic to run when the equipment leaves this state + Serial.println("Exit Fail State..."); +} \ No newline at end of file diff --git a/src/EPMS/STS/STS_PowerSmiths_STATYS_UL_600A_TCP/State_Running.cpp b/src/EPMS/STS/STS_PowerSmiths_STATYS_UL_600A_TCP/State_Running.cpp new file mode 100644 index 0000000..b9e4a99 --- /dev/null +++ b/src/EPMS/STS/STS_PowerSmiths_STATYS_UL_600A_TCP/State_Running.cpp @@ -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 +#include +#if defined(USE_MODBUS_IP) + #include +#else + #include +#endif + +/** + * @brief Constructs a new RunningState object. + * + * This constructor initializes behavior strategies active during the running + * state, such as a PID controller for the 'CW Valve Position' and totalizers + * for the run-hours of each EC fan. + */ +template<> +RunningState::RunningState() { +} + +/** + * @brief Executes the running state's logic for one update cycle. + * + * This method first checks for state transition commands: + * 1. It reads the "ON/OFF Command By BMS" point. If it's 0, it transitions to StandbyState. + * 2. It reads the "Fault Code" point. If it's non-zero, it transitions to FailState, + * passing the corresponding alarm description. + * + * If no transition occurs, it applies the strategies defined for the running state. + * + * @param equipment Pointer to the Equipment instance. + * @return A pointer to a new State if a transition should occur, otherwise nullptr. + */ +template<> +State* RunningState::update(Equipment* equipment) { + // STATE control, add conditions if change to a different state is needed + Serial.println("Running update function"); + + // 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::enterState(Equipment* equipment) { + // Logic to run when the equipment enters this state + Serial.println("Enter Running State..."); + // You could also update a Modbus register to show the "standby" state + +} + +/** + * @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::exitState(Equipment* equipment) { + // Cleanup logic to run when the equipment leaves this state + Serial.println("Exit Running State..."); + +} \ No newline at end of file diff --git a/src/EPMS/STS/STS_PowerSmiths_STATYS_UL_600A_TCP/State_Standby.cpp b/src/EPMS/STS/STS_PowerSmiths_STATYS_UL_600A_TCP/State_Standby.cpp new file mode 100644 index 0000000..20029d1 --- /dev/null +++ b/src/EPMS/STS/STS_PowerSmiths_STATYS_UL_600A_TCP/State_Standby.cpp @@ -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 +#include +#if defined(USE_MODBUS_IP) + #include +#else + #include +#endif +/** + * @brief Constructs a new StandbyState object. + * + * In this state, the equipment is idle. This constructor initializes 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::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* StandbyState::update(Equipment* 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::enterState(Equipment* 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::exitState(Equipment* equipment) { + // Cleanup logic to run when the equipment leaves this state + Serial.println("Exit Standby State..."); +} \ No newline at end of file diff --git a/src/EPMS/STS/STS_PowerSmiths_STATYS_UL_600A_TCP/config.h b/src/EPMS/STS/STS_PowerSmiths_STATYS_UL_600A_TCP/config.h new file mode 100644 index 0000000..6a061ba --- /dev/null +++ b/src/EPMS/STS/STS_PowerSmiths_STATYS_UL_600A_TCP/config.h @@ -0,0 +1,162 @@ +/** + * @file config.h + * @brief Main configuration file for the STS Powersmiths STATYS UL 600A + * @author Zach Gutierrez + * @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 + const char *ssid = "wifi_name"; /**< @brief The SSID of the WiFi network. */ + const char *password = "wifi_password"; /**< @brief The password for the WiFi network. */ + IPAddress local_IP(192, 168, 1, 234); /**< @brief The static IP address for the device. */ + IPAddress gateway(192, 168, 1, 1); /**< @brief The gateway IP address. */ + IPAddress subnet(255, 255, 255, 0); /**< @brief The subnet mask. */ + + ModbusIP mb; +#else + /** + * @defgroup ModbusRTUConfig Modbus RTU Configuration + * @brief Parameters for serial Modbus RTU communication. + * @{ + */ + #include + const int BAUDRATE = 19200; /**< @brief The serial communication speed in bits per second. */ + const int RX_PIN = 17; /**< @brief The GPIO pin used for receiving data (RX). */ + const int TX_PIN = 16; /**< @brief The GPIO pin used for transmitting data (TX). */ + const int RST_PIN = 4; /**< @brief The GPIO pin connected to the RS485 driver's DE/RE pins for direction control. */ + const int MODBUS_ID = 1; /**< @brief The unique slave ID for this device on the Modbus bus. */ + /** @} */ + + /** @brief Global instance of the Modbus RTU server. */ + ModbusRTU mb; +#endif + + + +/** + * @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, 56, 0, "Amb_Temp_Alm" }, + {HR, 70, 0, "Amps_A" }, + {HR, 71, 0, "Amps_B" }, + {HR, 72, 0, "Amps_C" }, + {HR, 73, 0, "Amps_N" }, + {HR, 49, 0, "CB1_Status" }, + {HR, 49, 0, "CB2_Status" }, + {HR, 49, 0, "CB3_Status" }, + {HR, 49, 0, "CB3A_Status" }, + {HR, 49, 0, "CB4_Status" }, + {HR, 49, 0, "CB5_Status" }, + {HR, 59, 0, "Comm_Fail" }, + {HR, 56, 0, "Cons_Volt" }, + {HR, 77, 0, "FREQ" }, + {HR, 56, 0, "Gen_Alm" }, + {HR, 56, 0, "Imm_Stop" }, + {HR, 48, 0, "In_Ser_Mode" }, + {HR, 68, 0, "kVA" }, + {HR, 112, 0, "kVA_A" }, + {HR, 113, 0, "kVA_B" }, + {HR, 114, 0, "kVA_C" }, + {HR, 69, 0, "kW" }, + {HR, 115, 0, "kW_A" }, + {HR, 116, 0, "kW_B" }, + {HR, 117, 0, "kW_C" }, + {HR, 56, 12, "Maint_Alm" }, + {HR, 48, 15, "Maint_Alt" }, + {HR, 56, 8, "Out_Of_Tol" }, + {HR, 56, 7, "Out_Sht_Ckt_Det" }, + {HR, 56, 1, "Ovrld" }, + {HR, 1007, 0, "Ovrd" }, + {HR, 41, 0, "Perc_Load" }, + {HR, 65, 0, "Perc_Load_A" }, + {HR, 66, 0, "Perc_Load_B" }, + {HR, 67, 0, "Perc_Load_C" }, + {HR, 121, 0, "PF_A" }, + {HR, 122, 0, "PF_B" }, + {HR, 123, 0, "PF_C" }, + {HR, 51, 0, "S1_Active" }, + {HR, 128, 0, "S1_Amps_A" }, + {HR, 129, 0, "S1_Amps_B" }, + {HR, 130, 0, "S1_Amps_C" }, + {HR, 99, 0, "S1_FREQ" }, + {HR, 92, 0, "S1_kVA" }, + {HR, 80, 0, "S1_kVA_A" }, + {HR, 81, 0, "S1_kVA_B" }, + {HR, 82, 0, "S1_kVA_C" }, + {HR, 93, 0, "S1_kW" }, + {HR, 131, 0, "S1_kW_A" }, + {HR, 132, 0, "S1_kW_B" }, + {HR, 133, 0, "S1_kW_C" }, + {HR, 2050, 0, "S1_Not_Avail" }, + {HR, 51, 0, "S1_OK" }, + {HR, 48, 0, "S1_Pref" }, + {HR, 100, 0, "S1_Volts_AB" }, + {HR, 101, 0, "S1_Volts_BC" }, + {HR, 102, 0, "S1_Volts_CA" }, + {HR, 51, 0, "S2_Active" }, + {HR, 134, 0, "S2_Amps_A" }, + {HR, 135, 0, "S2_Amps_B" }, + {HR, 136, 0, "S2_Amps_C" }, + {HR, 106, 0, "S2_FREQ" }, + {HR, 94, 0, "S2_kVA" }, + {HR, 83, 0, "S2_kVA_A" }, + {HR, 84, 0, "S2_kVA_B" }, + {HR, 85, 0, "S2_kVA_C" }, + {HR, 95, 0, "S2_kW" }, + {HR, 137, 0, "S2_kW_A" }, + {HR, 138, 0, "S2_kW_B" }, + {HR, 139, 0, "S2_kW_C" }, + {HR, 2052, 0,"S2_Not_Avail" }, + {HR, 51, 56, "S2_OK" }, + {HR, 48, 7, "S2_Pref" }, + {HR, 107, 0, "S2_Volts_AB" }, + {HR, 108, 0, "S2_Volts_BC" }, + {HR, 109, 0, "S2_Volts_CA" }, + {HR, 51, 0, "SS1_Closed" }, + {HR, 51, 0, "SS2_Closed" }, + {HR, 59, 0, "STS_Power_Off" }, + {HR, 56, 0, "SWBK_Imposs" }, + {HR, 79, 0, "Temp" }, + {HR, 42, 0, "Ttl_Trsfer_Cnt" }, + {HR, 56, 0, "Trsfer_Impo" }, + {HR, 48, 0, "Trsfer_Lock" }, + {HR, 118, 0, "Volts_AB" }, + {HR, 119, 0, "Volts_BC" }, + {HR, 120, 0, "Volts_CA" } +}; +//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 diff --git a/src/EPMS/STS/STS_PowerSmiths_STATYS_UL_600A_TCP/main.cpp b/src/EPMS/STS/STS_PowerSmiths_STATYS_UL_600A_TCP/main.cpp new file mode 100644 index 0000000..286a98c --- /dev/null +++ b/src/EPMS/STS/STS_PowerSmiths_STATYS_UL_600A_TCP/main.cpp @@ -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 +#include "config.h" +#include "ModbusPoints/Modbus_PointFactory.h" +#if defined(USE_MODBUS_IP) + #include +#else + #include +#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* 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); + } +}