From 14cf23281dec00cfc940c4d68ee95706b849f9ca Mon Sep 17 00:00:00 2001 From: Emmanuel Hernandez Cruz Date: Mon, 15 Sep 2025 12:51:34 -0500 Subject: [PATCH] Name updated, Categories folder to ModbuPoints, less generic to be self documented --- README.md | 18 ++-- lib/Core/Equipment/Equipment.h | 26 +++--- .../Modbus_Coil.h} | 34 ++++---- .../Modbus_FloatDecorator.h} | 28 +++---- .../Modbus_Hreg.h} | 34 ++++---- .../Modbus_Ireg.h} | 34 ++++---- .../Modbus_Ists.h} | 34 ++++---- .../Modbus_LongDecorator.h} | 28 +++---- .../Modbus_Point.h} | 22 ++--- .../Modbus_PointDecorator.h} | 38 ++++----- .../Modbus_PointFactory.h} | 82 +++++++++---------- .../Modbus_ScaleDecorator.h} | 22 ++--- lib/Core/States/State.h | 24 +++--- lib/Core/core.h | 2 +- lib/README | 46 ----------- lib/README.md | 23 ++++++ src/CH_Daikin_AWV026B_RTU/State_Fail.cpp | 11 ++- src/CH_Daikin_AWV026B_RTU/State_Running.cpp | 13 +-- src/CH_Daikin_AWV026B_RTU/State_Standby.cpp | 8 +- src/CH_Daikin_AWV026B_RTU/main.cpp | 8 +- src/CRAH_PAHHC_600_C6_TCP/State_Fail.cpp | 8 +- src/CRAH_PAHHC_600_C6_TCP/State_Running.cpp | 12 +-- src/CRAH_PAHHC_600_C6_TCP/State_Standby.cpp | 8 +- src/CRAH_PAHHC_600_C6_TCP/main.cpp | 8 +- 24 files changed, 274 insertions(+), 297 deletions(-) rename lib/Core/{Categories/ModbusCoil.h => ModbusPoints/Modbus_Coil.h} (69%) rename lib/Core/{Categories/ModbusFloatDecorator.h => ModbusPoints/Modbus_FloatDecorator.h} (79%) rename lib/Core/{Categories/ModbusHreg.h => ModbusPoints/Modbus_Hreg.h} (71%) rename lib/Core/{Categories/ModbusIreg.h => ModbusPoints/Modbus_Ireg.h} (72%) rename lib/Core/{Categories/ModbusIsts.h => ModbusPoints/Modbus_Ists.h} (71%) rename lib/Core/{Categories/ModbusLongDecorator.h => ModbusPoints/Modbus_LongDecorator.h} (74%) rename lib/Core/{Categories/ModbusPoint.h => ModbusPoints/Modbus_Point.h} (87%) rename lib/Core/{Categories/ModbusPointDecorator.h => ModbusPoints/Modbus_PointDecorator.h} (61%) rename lib/Core/{Categories/ModbusPointFactory.h => ModbusPoints/Modbus_PointFactory.h} (52%) rename lib/Core/{Categories/ModbusScaleDecorator.h => ModbusPoints/Modbus_ScaleDecorator.h} (73%) delete mode 100644 lib/README create mode 100644 lib/README.md diff --git a/README.md b/README.md index 9e6463e..7f3fafe 100644 --- a/README.md +++ b/README.md @@ -72,24 +72,24 @@ The **Decorator Pattern** lets us "wrap" a basic Modbus point to add this extra * **Analogy:** Think of a basic 4-20mA analog input card. That's your base object. Now, you add a "scaling block" in your PLC to convert the raw 4-20mA signal into a temperature in Celsius. That scaling block is a "Decorator". It doesn't change the input card, it just wraps its output to make it more useful. * **How it works here:** - * We start with a basic `ModbusPoint` (like `ModbusHreg` for a Holding Register). - * If a point needs to be treated as a float, we "decorate" or "wrap" it with a `ModbusFloatDecorator`. This decorator knows how to take two 16-bit registers and combine them into a single 32-bit float value, and vice-versa. - * If a point needs to be scaled, we can wrap it with a `ModbusScaleDecorator`. + * We start with a basic `Modbus_Point` (like `Modbus_Hreg` for a Holding Register). + * If a point needs to be treated as a float, we "decorate" or "wrap" it with a `Modbus_FloatDecorator`. This decorator knows how to take two 16-bit registers and combine them into a single 32-bit float value, and vice-versa. + * If a point needs to be scaled, we can wrap it with a `Modbus_ScaleDecorator`. -* **Key Benefit:** This keeps our code clean and avoids an explosion of classes. We don't need `ModbusFloatHoldingRegister`, `ModbusScaledHoldingRegister`, `ModbusLongInputRegister`, etc. We have our basic point types (`Coil`, `Hreg`, `Ireg`) and we simply "decorate" them with the data handling logic they need. This is all handled automatically by the `ModbusPointFactory`. +* **Key Benefit:** This keeps our code clean and avoids an explosion of classes. We don't need `ModbusFloatHoldingRegister`, `ModbusScaledHoldingRegister`, `ModbusLongInputRegister`, etc. We have our basic point types (`Coil`, `Hreg`, `Ireg`) and we simply "decorate" them with the data handling logic they need. This is all handled automatically by the `Modbus_PointFactory`. * **Files to see:** - * `Categories/ModbusPoint.h`: The base for all points. - * `Categories/ModbusPointDecorator.h`: The base "wrapper" class. - * `Categories/ModbusFloatDecorator.h`: A specific wrapper that adds floating-point logic. - * `Categories/ModbusPointFactory.cpp`: The factory that automatically creates and decorates points based on the `config.h` map. + * `Modbus_Points/Modbus_Point.h`: The base for all points. + * `Modbus_Points/Modbus_PointDecorator.h`: The base "wrapper" class. + * `Modbus_Points/Modbus_FloatDecorator.h`: A specific wrapper that adds floating-point logic. + * `Modbus_Points/Modbus_PointFactory.cpp`: The factory that automatically creates and decorates points based on the `config.h` map. ## Project Structure * `BaseEmulator.ino`: The main entry point of the Arduino program. It handles Wi-Fi setup, initializes the Modbus server, and runs the main loop. * `config.h`: The central configuration file. **This is where you define all the Modbus points for the device.** You set the register type, address, and description here. * `/Equipment`: Contains the `Equipment` class, which represents the overall state machine. -* `/Categories`: Contains the classes for different types of Modbus points (`ModbusCoil`, `ModbusHreg`) and the Decorators (`ModbusFloatDecorator`). +* `/Modbus_Points`: Contains the classes for different types of Modbus points (`Modbus_Coil`, `Modbus_Hreg`) and the Decorators (`Modbus_FloatDecorator`). * `/States`: Contains the different operating modes for the `Equipment` (e.g., `State_Running`). * `/Strategies`: Contains the reusable behavior algorithms for Modbus points (e.g., `Strategy_Ramp`). diff --git a/lib/Core/Equipment/Equipment.h b/lib/Core/Equipment/Equipment.h index 13db705..b2cdecc 100644 --- a/lib/Core/Equipment/Equipment.h +++ b/lib/Core/Equipment/Equipment.h @@ -18,7 +18,7 @@ // Forward Declarations template class State; -template class ModbusPoint; +template class Modbus_Point; /** * @class Equipment @@ -63,26 +63,26 @@ public: /** * @brief Adds a Modbus point to the equipment's internal map. * @param description The unique string description used as a key. - * @param point A pointer to the ModbusPoint object. + * @param point A pointer to the Modbus_Point object. */ - void addModbusPoint(const std::string& description, ModbusPoint* point); + void addModbus_Point(const std::string& description, Modbus_Point* point); /** * @brief Retrieves a Modbus point by its description. * @param description The string key for the Modbus point. - * @return A pointer to the ModbusPoint object, or nullptr if not found. + * @return A pointer to the Modbus_Point object, or nullptr if not found. */ - ModbusPoint* getModbusPoint(const std::string& description); + Modbus_Point* getModbus_Point(const std::string& description); /** * @brief Sets the value of a specific Modbus point. * @param description The string key for the Modbus point. * @param value The value to set. Note: This float may be truncated or cast * depending on the underlying point's `setValue` implementation. */ - void setModbusPoint(const std::string& description, float value); + void setModbus_Point(const std::string& description, float value); private: State* _state; /**< @brief Pointer to the current state object. */ - std::map*> _points;/**< @brief Map of all Modbus points, keyed by description. */ + std::map*> _points;/**< @brief Map of all Modbus points, keyed by description. */ int _stateId; /**< @brief A simple integer identifier for the current state. */ T* _server; }; @@ -141,20 +141,20 @@ void Equipment::exitState() { * The point is added to a map for quick lookup by description and to a * vector for simple iteration. * @param description The unique string description used as a key. - * @param point A pointer to the ModbusPoint object. + * @param point A pointer to the Modbus_Point object. */ template -void Equipment::addModbusPoint(const std::string& description, ModbusPoint* point) { +void Equipment::addModbus_Point(const std::string& description, Modbus_Point* point) { this->_points[description] = point; } /** * @brief Retrieves a Modbus point by its description. * @param description The string key for the Modbus point. - * @return A pointer to the ModbusPoint object, or nullptr if not found. + * @return A pointer to the Modbus_Point object, or nullptr if not found. */ template -ModbusPoint* Equipment::getModbusPoint(const std::string& description) { +Modbus_Point* Equipment::getModbus_Point(const std::string& description) { auto it = this->_points.find(description); if (it != this->_points.end()) { return it->second; @@ -169,8 +169,8 @@ ModbusPoint* Equipment::getModbusPoint(const std::string& description) { * @param value The value to set. This float is cast to an int before being passed. */ template -void Equipment::setModbusPoint(const std::string& description, float value) { - ModbusPoint* point = getModbusPoint(description); +void Equipment::setModbus_Point(const std::string& description, float value) { + Modbus_Point* point = getModbus_Point(description); if (point != nullptr) { point->setValue(value); } diff --git a/lib/Core/Categories/ModbusCoil.h b/lib/Core/ModbusPoints/Modbus_Coil.h similarity index 69% rename from lib/Core/Categories/ModbusCoil.h rename to lib/Core/ModbusPoints/Modbus_Coil.h index bcef6e1..6873530 100644 --- a/lib/Core/Categories/ModbusCoil.h +++ b/lib/Core/ModbusPoints/Modbus_Coil.h @@ -1,35 +1,35 @@ /** - * @file ModbusCoil.h - * @brief Defines the ModbusCoil class for handling Modbus coils. + * @file Modbus_Coil.h + * @brief Defines the Modbus_Coil class for handling Modbus coils. * @author Emmanuel Hernandez Cruz * @date 2025-09-04 * - * This file contains the definition of the ModbusCoil class, which is a specific - * implementation of the ModbusPoint for handling coils (digital outputs). + * This file contains the definition of the Modbus_Coil class, which is a specific + * implementation of the Modbus_Point for handling coils (digital outputs). */ -#ifndef ModbusCoil_h -#define ModbusCoil_h -#include "ModbusPoint.h" +#ifndef Modbus_Coil_h +#define Modbus_Coil_h +#include "Modbus_Point.h" /** - * @class ModbusCoil + * @class Modbus_Coil * @brief Represents a Modbus coil point. * * This class provides a concrete implementation for a Modbus coil, - * which is a single bit digital output. It inherits from ModbusPoint + * which is a single bit digital output. It inherits from Modbus_Point * and implements its virtual functions for coil-specific operations. */ template -class ModbusCoil : public ModbusPoint{ +class Modbus_Coil : public Modbus_Point{ public: /** - * @brief Constructor for the ModbusCoil class. + * @brief Constructor for the Modbus_Coil class. * @param server Pointer to the ModbusIP server instance. * @param address The Modbus address of the coil. * @param value The initial value of the coil. * @param description A description of the coil. */ - ModbusCoil(T* server, int address, int value, const char* description); + Modbus_Coil(T* server, int address, int value, const char* description); /** * @brief Adds the coil to the Modbus server. @@ -50,8 +50,8 @@ public: }; template -ModbusCoil::ModbusCoil(T* server, int address, int value, const char* description) - : ModbusPoint(server, address, value, description) {} +Modbus_Coil::Modbus_Coil(T* server, int address, int value, const char* description) + : Modbus_Point(server, address, value, description) {} /** * @brief Adds the coil to the Modbus server's register map. @@ -59,7 +59,7 @@ ModbusCoil::ModbusCoil(T* server, int address, int value, const char* descrip * at the specified address with its initial value. */ template -void ModbusCoil::addToModbusServer(){ +void Modbus_Coil::addToModbusServer(){ this->_server->addCoil(this->_address, this->_value); } @@ -70,7 +70,7 @@ void ModbusCoil::addToModbusServer(){ * @param value The new value for the coil. */ template -void ModbusCoil::setValue(int value){ +void Modbus_Coil::setValue(int value){ this->_server->Coil(this->_address, value); } @@ -79,7 +79,7 @@ void ModbusCoil::setValue(int value){ * @return The current value. */ template -int ModbusCoil::getValue() const{ +int Modbus_Coil::getValue() const{ return this->_server->Coil(this->_address); } diff --git a/lib/Core/Categories/ModbusFloatDecorator.h b/lib/Core/ModbusPoints/Modbus_FloatDecorator.h similarity index 79% rename from lib/Core/Categories/ModbusFloatDecorator.h rename to lib/Core/ModbusPoints/Modbus_FloatDecorator.h index e96ac11..8338290 100644 --- a/lib/Core/Categories/ModbusFloatDecorator.h +++ b/lib/Core/ModbusPoints/Modbus_FloatDecorator.h @@ -1,16 +1,16 @@ /** - * @file ModbusFloatDecorator.h - * @brief Defines the ModbusFloatDecorator class for handling 32-bit float values. + * @file Modbus_FloatDecorator.h + * @brief Defines the Modbus_FloatDecorator class for handling 32-bit float values. * @author Emmanuel Hernandez Cruz * @date 2025-09-05 * * This file contains the definition for a decorator that combines two 16-bit * Modbus registers to represent a single 32-bit floating-point value. */ -#ifndef ModbusFloatDecorator_h -#define ModbusFloatDecorator_h +#ifndef Modbus_FloatDecorator_h +#define Modbus_FloatDecorator_h #include -#include "ModbusPointDecorator.h" +#include "Modbus_PointDecorator.h" /** * @union cracked_float_t @@ -26,24 +26,24 @@ typedef union{ } cracked_float_t; /** - * @class ModbusFloatDecorator + * @class Modbus_FloatDecorator * @brief A decorator that combines two 16-bit registers into a 32-bit float. * - * This class wraps two consecutive ModbusPoint objects (a low-word and a + * This class wraps two consecutive Modbus_Point objects (a low-word and a * high-word point) and treats them as a single 32-bit float value. It * overrides the necessary methods to handle reading, writing, and value * conversion across both underlying registers. */ template -class ModbusFloatDecorator : public ModbusPointDecorator { +class Modbus_FloatDecorator : public Modbus_PointDecorator { public: /** - * @brief Constructs a new ModbusFloatDecorator object. - * @param point A pointer to the ModbusPoint for the low-order word (LSW). - * @param highOrderPoint A pointer to the ModbusPoint for the high-order word. + * @brief Constructs a new Modbus_FloatDecorator object. + * @param point A pointer to the Modbus_Point for the low-order word (LSW). + * @param highOrderPoint A pointer to the Modbus_Point for the high-order word. */ - ModbusFloatDecorator(ModbusPoint* point, ModbusPoint* highOrderPoint) - : ModbusPointDecorator(point), _highOrderPoint(highOrderPoint) {} + Modbus_FloatDecorator(Modbus_Point* point, Modbus_Point* highOrderPoint) + : Modbus_PointDecorator(point), _highOrderPoint(highOrderPoint) {} /** * @brief Returns the logical type of the point. @@ -109,7 +109,7 @@ public: } private: - ModbusPoint* _highOrderPoint; /**< @brief Pointer to the ModbusPoint for the high-order word. */ + Modbus_Point* _highOrderPoint; /**< @brief Pointer to the Modbus_Point for the high-order word. */ }; #endif \ No newline at end of file diff --git a/lib/Core/Categories/ModbusHreg.h b/lib/Core/ModbusPoints/Modbus_Hreg.h similarity index 71% rename from lib/Core/Categories/ModbusHreg.h rename to lib/Core/ModbusPoints/Modbus_Hreg.h index 1fff5e0..cf63acd 100644 --- a/lib/Core/Categories/ModbusHreg.h +++ b/lib/Core/ModbusPoints/Modbus_Hreg.h @@ -1,36 +1,36 @@ /** - * @file ModbusHreg.h - * @brief Defines the ModbusHreg class for handling Modbus holding registers. + * @file Modbus_Hreg.h + * @brief Defines the Modbus_Hreg class for handling Modbus holding registers. * @author Emmanuel Hernandez Cruz * @date 2025-09-04 * - * This file contains the definition of the ModbusHreg class, which is a specific - * implementation of the ModbusPoint for handling holding registers (16-bit). + * This file contains the definition of the Modbus_Hreg class, which is a specific + * implementation of the Modbus_Point for handling holding registers (16-bit). */ -#ifndef ModbusHreg_h -#define ModbusHreg_h +#ifndef Modbus_Hreg_h +#define Modbus_Hreg_h -#include "ModbusPoint.h" +#include "Modbus_Point.h" /** - * @class ModbusHreg + * @class Modbus_Hreg * @brief Represents a Modbus holding register point. * * This class provides a concrete implementation for a Modbus holding register, - * which is a 16-bit read/write register. It inherits from ModbusPoint + * which is a 16-bit read/write register. It inherits from Modbus_Point * and implements its virtual functions for holding register-specific operations. */ template -class ModbusHreg : public ModbusPoint{ +class Modbus_Hreg : public Modbus_Point{ public: /** - * @brief Constructor for the ModbusHreg class. + * @brief Constructor for the Modbus_Hreg class. * @param server Pointer to the ModbusIP server instance. * @param address The Modbus address of the holding register. * @param value The initial value of the holding register. * @param description A description of the holding register. */ - ModbusHreg(T* server, int address, int value, const char* description); + Modbus_Hreg(T* server, int address, int value, const char* description); /** * @brief Adds the holding register to the Modbus server. @@ -55,8 +55,8 @@ public: }; template -ModbusHreg::ModbusHreg(T* server, int address, int value, const char* description) - : ModbusPoint(server, address, value, description) {} +Modbus_Hreg::Modbus_Hreg(T* server, int address, int value, const char* description) + : Modbus_Point(server, address, value, description) {} /** * @brief Adds the holding register to the Modbus server's register map. @@ -64,7 +64,7 @@ ModbusHreg::ModbusHreg(T* server, int address, int value, const char* descrip * register at the specified address with its initial value. */ template -void ModbusHreg::addToModbusServer() { +void Modbus_Hreg::addToModbusServer() { this->_server->addHreg(this->_address, this->_value); } @@ -75,7 +75,7 @@ void ModbusHreg::addToModbusServer() { * @param value The new 16-bit value for the register. */ template -void ModbusHreg::setValue(int value) { +void Modbus_Hreg::setValue(int value) { this->_server->Hreg(this->_address, value); } @@ -84,7 +84,7 @@ void ModbusHreg::setValue(int value) { * @return The current 16-bit value from the register. */ template -int ModbusHreg::getValue() const { +int Modbus_Hreg::getValue() const { return this->_server->Hreg(this->_address); } #endif \ No newline at end of file diff --git a/lib/Core/Categories/ModbusIreg.h b/lib/Core/ModbusPoints/Modbus_Ireg.h similarity index 72% rename from lib/Core/Categories/ModbusIreg.h rename to lib/Core/ModbusPoints/Modbus_Ireg.h index 53578ac..32d5c30 100644 --- a/lib/Core/Categories/ModbusIreg.h +++ b/lib/Core/ModbusPoints/Modbus_Ireg.h @@ -1,36 +1,36 @@ /** - * @file ModbusIreg.h - * @brief Defines the ModbusIreg class for handling Modbus Input Registers. + * @file Modbus_Ireg.h + * @brief Defines the Modbus_Ireg class for handling Modbus Input Registers. * @author Emmanuel Hernandez Cruz * @date 2025-09-04 * - * This file contains the definition of the ModbusIreg class, which is a specific - * implementation of the ModbusPoint for handling input registers (16-bit read-only). + * This file contains the definition of the Modbus_Ireg class, which is a specific + * implementation of the Modbus_Point for handling input registers (16-bit read-only). */ -#ifndef ModbusIreg_h -#define ModbusIreg_h +#ifndef Modbus_Ireg_h +#define Modbus_Ireg_h -#include "ModbusPoint.h" +#include "Modbus_Point.h" /** - * @class ModbusIreg + * @class Modbus_Ireg * @brief Represents a Modbus Input Register point. * * This class provides a concrete implementation for a Modbus input register, - * which is a 16-bit read-only register. It inherits from ModbusPoint + * which is a 16-bit read-only register. It inherits from Modbus_Point * and implements its virtual functions for input register-specific operations. */ template -class ModbusIreg : public ModbusPoint{ +class Modbus_Ireg : public Modbus_Point{ public: /** - * @brief Constructor for the ModbusIreg class. + * @brief Constructor for the Modbus_Ireg class. * @param server Pointer to the ModbusIP server instance. * @param address The Modbus address of the input register. * @param value The initial value of the input register. * @param description A description of the input register. */ - ModbusIreg(T* server, int address, int value, const char* description); + Modbus_Ireg(T* server, int address, int value, const char* description); /** * @brief Adds the input register to the Modbus server. @@ -50,8 +50,8 @@ public: }; template -ModbusIreg::ModbusIreg(T* server, int address, int value, const char* description) - : ModbusPoint(server, address, value, description){} +Modbus_Ireg::Modbus_Ireg(T* server, int address, int value, const char* description) + : Modbus_Point(server, address, value, description){} /** * @brief Sets the value of the input register on the Modbus server. @@ -61,7 +61,7 @@ ModbusIreg::ModbusIreg(T* server, int address, int value, const char* descrip * @param value The new 16-bit value for the register. */ template -void ModbusIreg::setValue(int value){ +void Modbus_Ireg::setValue(int value){ this->_server->Ireg(this->_address, value); } /** @@ -69,7 +69,7 @@ void ModbusIreg::setValue(int value){ * @return The current 16-bit value from the register. */ template -int ModbusIreg::getValue() const { +int Modbus_Ireg::getValue() const { return this->_server->Ireg(this->_address); } @@ -79,7 +79,7 @@ int ModbusIreg::getValue() const { * register at the specified address with its initial value. */ template -void ModbusIreg::addToModbusServer(){ +void Modbus_Ireg::addToModbusServer(){ this->_server->addIreg(this->_address, this->_value); } diff --git a/lib/Core/Categories/ModbusIsts.h b/lib/Core/ModbusPoints/Modbus_Ists.h similarity index 71% rename from lib/Core/Categories/ModbusIsts.h rename to lib/Core/ModbusPoints/Modbus_Ists.h index 13d2b5e..705178d 100644 --- a/lib/Core/Categories/ModbusIsts.h +++ b/lib/Core/ModbusPoints/Modbus_Ists.h @@ -1,36 +1,36 @@ /** - * @file ModbusIsts.h - * @brief Defines the ModbusIsts class for handling Modbus Input Status (Discrete Inputs). + * @file Modbus_Ists.h + * @brief Defines the Modbus_Ists class for handling Modbus Input Status (Discrete Inputs). * @author Emmanuel Hernandez Cruz * @date 2025-09-04 * - * This file contains the definition of the ModbusIsts class, which is a specific - * implementation of the ModbusPoint for handling discrete inputs (read-only coils). + * This file contains the definition of the Modbus_Ists class, which is a specific + * implementation of the Modbus_Point for handling discrete inputs (read-only coils). */ -#ifndef ModbusIsts_h -#define ModbusIsts_h +#ifndef Modbus_Ists_h +#define Modbus_Ists_h -#include "ModbusPoint.h" +#include "Modbus_Point.h" /** - * @class ModbusIsts + * @class Modbus_Ists * @brief Represents a Modbus Input Status (Discrete Input) point. * * This class provides a concrete implementation for a Modbus discrete input, - * which is a single bit read-only value. It inherits from ModbusPoint + * which is a single bit read-only value. It inherits from Modbus_Point * and implements its virtual functions for discrete input-specific operations. */ template -class ModbusIsts : public ModbusPoint{ +class Modbus_Ists : public Modbus_Point{ public: /** - * @brief Constructor for the ModbusIsts class. + * @brief Constructor for the Modbus_Ists class. * @param server Pointer to the ModbusIP server instance. * @param address The Modbus address of the discrete input. * @param value The initial value of the discrete input. * @param description A description of the discrete input. */ - ModbusIsts(T* server, int address, int value, const char* description); + Modbus_Ists(T* server, int address, int value, const char* description); /** * @brief Adds the discrete input to the Modbus server. @@ -51,8 +51,8 @@ public: }; template -ModbusIsts::ModbusIsts(T* server, int address, int value, const char* description) - : ModbusPoint(server, address, value, description) {} +Modbus_Ists::Modbus_Ists(T* server, int address, int value, const char* description) + : Modbus_Point(server, address, value, description) {} /** * @brief Sets the value of the discrete input on the Modbus server. @@ -62,7 +62,7 @@ ModbusIsts::ModbusIsts(T* server, int address, int value, const char* descrip * @param value The new value for the discrete input. */ template -void ModbusIsts::setValue(int value){ +void Modbus_Ists::setValue(int value){ this->_server->Ists(this->_address, value); } /** @@ -70,7 +70,7 @@ void ModbusIsts::setValue(int value){ * @return The current value. */ template -int ModbusIsts::getValue() const{ +int Modbus_Ists::getValue() const{ return this->_server->Ists(this->_address); } /** @@ -79,7 +79,7 @@ int ModbusIsts::getValue() const{ * input at the specified address with its initial value. */ template -void ModbusIsts::addToModbusServer(){ +void Modbus_Ists::addToModbusServer(){ this->_server->addIsts(this->_address, this->_value); } diff --git a/lib/Core/Categories/ModbusLongDecorator.h b/lib/Core/ModbusPoints/Modbus_LongDecorator.h similarity index 74% rename from lib/Core/Categories/ModbusLongDecorator.h rename to lib/Core/ModbusPoints/Modbus_LongDecorator.h index 2a5ae5e..bf366e8 100644 --- a/lib/Core/Categories/ModbusLongDecorator.h +++ b/lib/Core/ModbusPoints/Modbus_LongDecorator.h @@ -1,36 +1,36 @@ /** - * @file ModbusLongDecorator.h - * @brief Defines the ModbusLongDecorator class for handling 32-bit long values. + * @file Modbus_LongDecorator.h + * @brief Defines the Modbus_LongDecorator class for handling 32-bit long values. * @author Emmanuel Hernandez Cruz * @date 2025-09-05 * * This file contains the definition for a decorator that combines two 16-bit * Modbus registers to represent a single 32-bit long integer value. */ -#ifndef ModbusLongDecorator_h -#define ModbusLongDecorator_h +#ifndef Modbus_LongDecorator_h +#define Modbus_LongDecorator_h -#include "ModbusPointDecorator.h" +#include "Modbus_PointDecorator.h" /** - * @class ModbusLongDecorator + * @class Modbus_LongDecorator * @brief A decorator that combines two 16-bit registers into a 32-bit long. * - * This class wraps two consecutive ModbusPoint objects (a low-word and a + * This class wraps two consecutive Modbus_Point objects (a low-word and a * high-word point) and treats them as a single 32-bit long integer. It * overrides the necessary methods to handle reading, writing, and value * conversion across both underlying registers. */ template -class ModbusLongDecorator : public ModbusPointDecorator { +class Modbus_LongDecorator : public Modbus_PointDecorator { public: /** - * @brief Constructs a new ModbusLongDecorator. - * @param point A pointer to the ModbusPoint for the low-order word (LSW). - * @param highOrderPoint A pointer to the ModbusPoint for the high-order word (MSW). + * @brief Constructs a new Modbus_LongDecorator. + * @param point A pointer to the Modbus_Point for the low-order word (LSW). + * @param highOrderPoint A pointer to the Modbus_Point for the high-order word (MSW). */ - ModbusLongDecorator(ModbusPoint* point, ModbusPoint* highOrderPoint) - : ModbusPointDecorator(point), _highOrderPoint(highOrderPoint) {} + Modbus_LongDecorator(Modbus_Point* point, Modbus_Point* highOrderPoint) + : Modbus_PointDecorator(point), _highOrderPoint(highOrderPoint) {} /** * @brief Returns the logical type of the point. @@ -91,7 +91,7 @@ public: return static_cast(getLongValue()); } private: - ModbusPoint* _highOrderPoint; /**< @brief Pointer to the ModbusPoint for the high-order word. */ + Modbus_Point* _highOrderPoint; /**< @brief Pointer to the Modbus_Point for the high-order word. */ }; #endif \ No newline at end of file diff --git a/lib/Core/Categories/ModbusPoint.h b/lib/Core/ModbusPoints/Modbus_Point.h similarity index 87% rename from lib/Core/Categories/ModbusPoint.h rename to lib/Core/ModbusPoints/Modbus_Point.h index 7d0f37c..04a52b4 100644 --- a/lib/Core/Categories/ModbusPoint.h +++ b/lib/Core/ModbusPoints/Modbus_Point.h @@ -1,15 +1,15 @@ /** - * @file ModbusPoint.h + * @file Modbus_Point.h * @brief Defines the abstract base class for all Modbus points. * @author Emmanuel Hernandez Cruz * @date 2025-09-04 * - * This file contains the definition of the abstract ModbusPoint class, which + * This file contains the definition of the abstract Modbus_Point class, which * serves as the base for all specific Modbus point types (Coils, Registers, etc.). * It defines the common interface for interacting with Modbus points. */ -#ifndef ModbusPoint_h -#define ModbusPoint_h +#ifndef Modbus_Point_h +#define Modbus_Point_h #include /** * @enum PointType @@ -26,24 +26,24 @@ enum class PointType { }; /** - * @class ModbusPoint + * @class Modbus_Point * @brief Abstract base class representing a single point in the Modbus map. * * This class defines the common interface and data for all types of Modbus - * points. Concrete implementations (e.g., ModbusCoil, ModbusHreg) and decorators + * points. Concrete implementations (e.g., Modbus_Coil, Modbus_Hreg) and decorators * must inherit from this class and implement its pure virtual functions. */ template -class ModbusPoint{ +class Modbus_Point{ public: /** - * @brief Constructs a new ModbusPoint object. + * @brief Constructs a new Modbus_Point object. * @param server Pointer to the Modbus server instance (e.g., ModbusIP or ModbusRTU). * @param address The Modbus address of the point. * @param value The initial value of the point. * @param description A descriptive name for the point. */ - ModbusPoint(T* server, int address, int value, const char* description); + Modbus_Point(T* server, int address, int value, const char* description); // --- Getters --- /** @brief Gets a pointer to the Modbus server instance. */ @@ -81,7 +81,7 @@ public: void setDirty(bool dirty) { _dirty = dirty; } /** @brief Virtual destructor to ensure proper cleanup of derived classes. */ - virtual ~ModbusPoint() = default; + virtual ~Modbus_Point() = default; protected: T* _server; /**< @brief Pointer to the global Modbus server instance. */ @@ -92,7 +92,7 @@ protected: }; template -ModbusPoint::ModbusPoint(T* server, int address, int value, const char* description) +Modbus_Point::Modbus_Point(T* server, int address, int value, const char* description) : _server(server), _address(address), _value(value) { strncpy(_description, description, sizeof(_description) - 1); _description[sizeof(_description) - 1] = '\0'; diff --git a/lib/Core/Categories/ModbusPointDecorator.h b/lib/Core/ModbusPoints/Modbus_PointDecorator.h similarity index 61% rename from lib/Core/Categories/ModbusPointDecorator.h rename to lib/Core/ModbusPoints/Modbus_PointDecorator.h index fe8d9ff..c080dd8 100644 --- a/lib/Core/Categories/ModbusPointDecorator.h +++ b/lib/Core/ModbusPoints/Modbus_PointDecorator.h @@ -1,41 +1,41 @@ /** - * @file ModbusPointDecorator.h + * @file Modbus_PointDecorator.h * @brief Defines the base decorator class for Modbus points. * @author Emmanuel Hernandez Cruz * @date 2025-09-05 * - * This file contains the definition for ModbusPointDecorator, which is the + * This file contains the definition for Modbus_PointDecorator, which is the * abstract base class for all decorators in the Decorator design pattern. - * It wraps a ModbusPoint and forwards all calls to it by default. + * It wraps a Modbus_Point and forwards all calls to it by default. */ -#ifndef ModbusPointDecorator_h -#define ModbusPointDecorator_h -#include "ModbusPoint.h" +#ifndef Modbus_PointDecorator_h +#define Modbus_PointDecorator_h +#include "Modbus_Point.h" /** - * @class ModbusPointDecorator - * @brief An abstract base class for decorating ModbusPoint objects. + * @class Modbus_PointDecorator + * @brief An abstract base class for decorating Modbus_Point objects. * - * This class follows the Decorator pattern. It wraps a `ModbusPoint` object + * This class follows the Decorator pattern. It wraps a `Modbus_Point` object * and provides a default implementation for all virtual methods that simply * delegate the call to the wrapped object. Concrete decorators should inherit * from this class and override the specific methods they need to modify. */ template -class ModbusPointDecorator : public ModbusPoint{ +class Modbus_PointDecorator : public Modbus_Point{ public: /** - * @brief Constructs a new ModbusPointDecorator object. + * @brief Constructs a new Modbus_PointDecorator object. * - * Initializes the base ModbusPoint with the properties of the wrapped point + * Initializes the base Modbus_Point with the properties of the wrapped point * and stores a pointer to the wrapped point. * * @note The decorator does not take ownership of the wrapped point. The * caller is responsible for managing its lifecycle. * - * @param point A pointer to the ModbusPoint object to be decorated. + * @param point A pointer to the Modbus_Point object to be decorated. */ - ModbusPointDecorator(ModbusPoint* point) : ModbusPoint( + Modbus_PointDecorator(Modbus_Point* point) : Modbus_Point( point->getServer(), point->getAddress(), point->getInitialValue(), @@ -46,7 +46,7 @@ public: * @brief Virtual destructor. * Does not delete the wrapped `_point` as it does not own it. */ - virtual ~ModbusPointDecorator() = default; + virtual ~Modbus_PointDecorator() = default; // --- Delegated Methods --- // These methods simply forward the call to the wrapped _point object. @@ -54,7 +54,7 @@ public: /** * @brief Delegates the call to add the point to the Modbus server. - * Forwards the `addToModbusServer` call to the wrapped `ModbusPoint` object. + * Forwards the `addToModbusServer` call to the wrapped `Modbus_Point` object. */ void addToModbusServer() override{ _point->addToModbusServer(); @@ -62,14 +62,14 @@ public: /** * @brief Delegates the call to set the point's value. - * Forwards the `setValue` call to the wrapped `ModbusPoint` object. + * Forwards the `setValue` call to the wrapped `Modbus_Point` object. */ void setValue(int value) override { _point->setValue(value); } /** * @brief Delegates the call to get the point's value. - * Forwards the `getValue` call to the wrapped `ModbusPoint` object. + * Forwards the `getValue` call to the wrapped `Modbus_Point` object. * @return The value from the wrapped point. */ int getValue() const override{ @@ -77,6 +77,6 @@ public: } protected: - ModbusPoint* _point; /**< @brief Pointer to the wrapped ModbusPoint object. */ + Modbus_Point* _point; /**< @brief Pointer to the wrapped Modbus_Point object. */ }; #endif \ No newline at end of file diff --git a/lib/Core/Categories/ModbusPointFactory.h b/lib/Core/ModbusPoints/Modbus_PointFactory.h similarity index 52% rename from lib/Core/Categories/ModbusPointFactory.h rename to lib/Core/ModbusPoints/Modbus_PointFactory.h index 9526d20..3064421 100644 --- a/lib/Core/Categories/ModbusPointFactory.h +++ b/lib/Core/ModbusPoints/Modbus_PointFactory.h @@ -1,31 +1,31 @@ /** - * @file ModbusPointFactory.h - * @brief Defines the factory function for creating ModbusPoint objects. + * @file Modbus_PointFactory.h + * @brief Defines the factory function for creating Modbus_Point objects. * @author Emmanuel Hernandez Cruz * @date 2025-09-05 * * This file provides the interface for a factory function that simplifies the - * creation of various ModbusPoint types (e.g., Coils, Holding Registers) and + * creation of various Modbus_Point types (e.g., Coils, Holding Registers) and * their decorators (e.g., for scaling, float, or long values). */ -#ifndef ModbusPointFactory_h -#define ModbusPointFactory_h -#include "ModbusPoint.h" -#include "ModbusCoil.h" -#include "ModbusIsts.h" -#include "ModbusIreg.h" -#include "ModbusHreg.h" -#include "ModbusScaleDecorator.h" -#include "ModbusLongDecorator.h" -#include "ModbusFloatDecorator.h" +#ifndef Modbus_PointFactory_h +#define Modbus_PointFactory_h +#include "Modbus_Point.h" +#include "Modbus_Coil.h" +#include "Modbus_Ists.h" +#include "Modbus_Ireg.h" +#include "Modbus_Hreg.h" +#include "Modbus_ScaleDecorator.h" +#include "Modbus_LongDecorator.h" +#include "Modbus_FloatDecorator.h" #include /** - * @brief Creates and decorates a ModbusPoint object based on its type. + * @brief Creates and decorates a Modbus_Point object based on its type. * * This factory function acts as a centralized point for instantiating different - * concrete ModbusPoint classes and applying decorators (e.g., for scaling, + * concrete Modbus_Point classes and applying decorators (e.g., for scaling, * floats, or longs). It encapsulates the logic for building both simple * single-register points and complex multi-register points. * @@ -38,78 +38,78 @@ * @param value The initial value for the point. Note: This is ignored for * multi-register types, which are initialized to 0. * @param description A descriptive name for the point. - * @return A pointer to the newly created ModbusPoint object. - * @retval ModbusPoint* A pointer to the fully constructed (and possibly + * @return A pointer to the newly created Modbus_Point object. + * @retval Modbus_Point* A pointer to the fully constructed (and possibly * decorated) Modbus point. The caller is responsible for * managing the memory of this object. * @retval nullptr If the category code is not recognized. */ template -ModbusPoint* createModbusPoint(T* server, int category, int address, int value, const char* description); +Modbus_Point* createModbus_Point(T* server, int category, int address, int value, const char* description); /** - * @brief Implementation of the ModbusPoint factory function. + * @brief Implementation of the Modbus_Point factory function. * * This function contains the switch-case logic to determine which concrete - * ModbusPoint class to instantiate and which decorators to apply. + * Modbus_Point class to instantiate and which decorators to apply. */ template -ModbusPoint* createModbusPoint(T* server, int category, int address, int value, const char* description) { +Modbus_Point* createModbus_Point(T* server, int category, int address, int value, const char* description) { switch (category) { case COIL: Serial.printf("Creating Coil: %s\n", description); - return new ModbusCoil(server, address, value, description); + return new Modbus_Coil(server, address, value, description); case DI: Serial.printf("Creating Digital Input: %s\n", description); - return new ModbusIsts(server, address, value, description); + return new Modbus_Ists(server, address, value, description); case IR: Serial.printf("Creating Input Register: %s\n", description); - return new ModbusIreg(server, address, value, description); + return new Modbus_Ireg(server, address, value, description); case IR_10X: { Serial.printf("Creating Scaled Input Register (10x): %s\n", description); - ModbusPoint* point = new ModbusIreg(server, address, value, description); - return new ModbusScaleDecorator(point); + Modbus_Point* point = new Modbus_Ireg(server, address, value, description); + return new Modbus_ScaleDecorator(point); } case IR_LONG: { Serial.printf("Creating Input Register Long: %s\n", description); // Create the low and high word registers for the 32-bit long - ModbusPoint* point = new ModbusIreg(server, address, 0, description); - ModbusPoint* highOrderPoint = new ModbusIreg(server, address + 1, 0, ""); - return new ModbusLongDecorator(point, highOrderPoint); + Modbus_Point* point = new Modbus_Ireg(server, address, 0, description); + Modbus_Point* highOrderPoint = new Modbus_Ireg(server, address + 1, 0, ""); + return new Modbus_LongDecorator(point, highOrderPoint); } case IR_FLOAT: { Serial.printf("Creating Input Register Float: %s\n", description); // Create the low and high word registers for the 32-bit float - ModbusPoint* point = new ModbusIreg(server, address, 0, description); - ModbusPoint* highOrderPoint = new ModbusIreg(server, address + 1, 0, ""); - return new ModbusFloatDecorator(point, highOrderPoint); + Modbus_Point* point = new Modbus_Ireg(server, address, 0, description); + Modbus_Point* highOrderPoint = new Modbus_Ireg(server, address + 1, 0, ""); + return new Modbus_FloatDecorator(point, highOrderPoint); } case HR: Serial.printf("Creating Holding Register: %s\n", description); - return new ModbusHreg(server, address, value, description); + return new Modbus_Hreg(server, address, value, description); case HR_10x: { Serial.printf("Creating Scaled Holding Register (10x): %s\n", description); // Create a base holding register and wrap it with the scaling decorator - ModbusPoint* point = new ModbusHreg(server, address, value, description); - return new ModbusScaleDecorator(point); + Modbus_Point* point = new Modbus_Hreg(server, address, value, description); + return new Modbus_ScaleDecorator(point); } case HR_LONG: { Serial.printf("Creating Holding Register Long: %s\n", description); // Create the low and high word registers for the 32-bit long - ModbusPoint* point = new ModbusHreg(server, address, 0, description); - ModbusPoint* highOrderPoint = new ModbusHreg(server, address + 1 , 0, ""); - return new ModbusLongDecorator(point, highOrderPoint); + Modbus_Point* point = new Modbus_Hreg(server, address, 0, description); + Modbus_Point* highOrderPoint = new Modbus_Hreg(server, address + 1 , 0, ""); + return new Modbus_LongDecorator(point, highOrderPoint); } case HR_FLOAT: { Serial.printf("Creating Holding Register Float: %s\n", description); // Create the low and high word registers for the 32-bit float - ModbusPoint* point = new ModbusHreg(server, address, 0, description); - ModbusPoint* highOrderPoint = new ModbusHreg(server, address + 1 , 0, ""); - return new ModbusFloatDecorator(point, highOrderPoint); + Modbus_Point* point = new Modbus_Hreg(server, address, 0, description); + Modbus_Point* highOrderPoint = new Modbus_Hreg(server, address + 1 , 0, ""); + return new Modbus_FloatDecorator(point, highOrderPoint); } default: Serial.printf("ERROR: Unknown Modbus category %d for '%s'\n", category, description); diff --git a/lib/Core/Categories/ModbusScaleDecorator.h b/lib/Core/ModbusPoints/Modbus_ScaleDecorator.h similarity index 73% rename from lib/Core/Categories/ModbusScaleDecorator.h rename to lib/Core/ModbusPoints/Modbus_ScaleDecorator.h index e2336fc..0a4145c 100644 --- a/lib/Core/Categories/ModbusScaleDecorator.h +++ b/lib/Core/ModbusPoints/Modbus_ScaleDecorator.h @@ -1,6 +1,6 @@ /** - * @file ModbusScaleDecorator.h - * @brief Defines the ModbusScaleDecorator class for scaling Modbus point values. + * @file Modbus_ScaleDecorator.h + * @brief Defines the Modbus_ScaleDecorator class for scaling Modbus point values. * @author Emmanuel Hernandez Cruz * @date 2025-09-05 * @@ -8,16 +8,16 @@ * factor to a Modbus point. This is useful for representing decimal values * in integer registers (e.g., storing 12.3 as 123). */ -#ifndef ModbusScaleDecorator_h -#define ModbusScaleDecorator_h +#ifndef Modbus_ScaleDecorator_h +#define Modbus_ScaleDecorator_h -#include "ModbusPointDecorator.h" +#include "Modbus_PointDecorator.h" /** - * @class ModbusScaleDecorator + * @class Modbus_ScaleDecorator * @brief A decorator that multiplies/divides a Modbus point's value by 10. * - * This class wraps a ModbusPoint and intercepts its `getValue` and `setValue` + * This class wraps a Modbus_Point and intercepts its `getValue` and `setValue` * calls to implement fixed-point arithmetic. It allows a 16-bit integer * register to represent a value with one decimal place (e.g., storing the * logical value 12.3 as the integer 123). @@ -26,13 +26,13 @@ * - `getValue()` will read `123` from the underlying point and return `12`. */ template -class ModbusScaleDecorator : public ModbusPointDecorator { +class Modbus_ScaleDecorator : public Modbus_PointDecorator { public: /** - * @brief Constructs a new ModbusScaleDecorator. - * @param point A pointer to the ModbusPoint object to be decorated. + * @brief Constructs a new Modbus_ScaleDecorator. + * @param point A pointer to the Modbus_Point object to be decorated. */ - ModbusScaleDecorator(ModbusPoint* point) : ModbusPointDecorator(point) {} + Modbus_ScaleDecorator(Modbus_Point* point) : Modbus_PointDecorator(point) {} /** * @brief Sets the raw integer value on the underlying point. diff --git a/lib/Core/States/State.h b/lib/Core/States/State.h index 7850c17..bb3459c 100644 --- a/lib/Core/States/State.h +++ b/lib/Core/States/State.h @@ -14,8 +14,8 @@ #include #include #include "Strategies/Strategy_PID.h" -#include "Categories/ModbusFloatDecorator.h" -#include "Categories/ModbusPoint.h" +#include "ModbusPoints/Modbus_FloatDecorator.h" +#include "ModbusPoints/Modbus_Point.h" // Forward Declarations templateclass Equipment; @@ -66,7 +66,7 @@ protected: /** * @brief Gets the value of a Modbus point, handling float types correctly. * This is a helper function to safely read a value from a point, whether it's - * a standard integer register or a `ModbusFloatDecorator`. + * a standard integer register or a `Modbus_FloatDecorator`. * @param equipment Pointer to the Equipment instance. * @param pointName The description key of the Modbus point to read. * @return The value of the point as a float. Returns 0.0f if not found. @@ -75,7 +75,7 @@ protected: /** * @brief Sets the value of a Modbus point, handling float types correctly. * This is a helper function to safely write a value to a point, whether it's - * a standard integer register or a `ModbusFloatDecorator`. + * a standard integer register or a `Modbus_FloatDecorator`. * @param equipment Pointer to the Equipment instance. * @param pointName The description key of the Modbus point to write to. * @param value The float value to set. It will be rounded for integer points. @@ -113,7 +113,7 @@ void State::addStrategy(const std::string& pointDescription, Strategy_Behavio /** * @brief Gets the value of a Modbus point, correctly handling float types. - * This helper function checks if the point is a `ModbusFloatDecorator` and calls + * This helper function checks if the point is a `Modbus_FloatDecorator` and calls * `getFloatValue()` if it is. Otherwise, it gets the standard integer value and * casts it to a float. * @param equipment Pointer to the Equipment instance. @@ -122,12 +122,12 @@ void State::addStrategy(const std::string& pointDescription, Strategy_Behavio */ template float State::getPointValue(Equipment* equipment, const std::string& pointName) { - ModbusPoint* point = equipment->getModbusPoint(pointName); + Modbus_Point* point = equipment->getModbus_Point(pointName); if (!point) return 0.0f; if (point->getType() == PointType::FLOAT) { // If it's a float, cast and get the full float value - return static_cast*>(point)->getFloatValue(); + return static_cast*>(point)->getFloatValue(); } else { // Otherwise, get the standard integer value return static_cast(point->getValue()); @@ -136,7 +136,7 @@ float State::getPointValue(Equipment* equipment, const std::string& pointN /** * @brief Sets the value of a Modbus point, correctly handling float types. - * This helper function checks if the point is a `ModbusFloatDecorator` and calls + * This helper function checks if the point is a `Modbus_FloatDecorator` and calls * `setFloatValue()` if it is. Otherwise, it rounds the float to the nearest * integer and calls the standard `setValue()`. * @param equipment Pointer to the Equipment instance. @@ -145,11 +145,11 @@ float State::getPointValue(Equipment* equipment, const std::string& pointN */ template void State::setPointValue(Equipment* equipment, const std::string& pointName, float value) { - ModbusPoint* point = equipment->getModbusPoint(pointName); + Modbus_Point* point = equipment->getModbus_Point(pointName); if (!point) return; if (point->getType() == PointType::FLOAT) { - static_cast*>(point)->setFloatValue(value); + static_cast*>(point)->setFloatValue(value); } else { point->setValue(round(value)); } @@ -175,7 +175,7 @@ void State::_applyStrategies(Equipment* equipment) { Strategy_Behavior* strategy = pair.second; if (strategy->isReady(currentTime)) { - ModbusPoint* outputPoint = equipment->getModbusPoint(description); + Modbus_Point* outputPoint = equipment->getModbus_Point(description); if (!outputPoint) continue; float inputValue; @@ -184,7 +184,7 @@ void State::_applyStrategies(Equipment* equipment) { PIDStrategy* pid = static_cast(strategy); inputValue = getPointValue(equipment, pid->getInputSensorName()); - ModbusPoint* PIDsetpoint = equipment->getModbusPoint(pid->getSetpointName()); + Modbus_Point* PIDsetpoint = equipment->getModbus_Point(pid->getSetpointName()); if (PIDsetpoint) { pid->setSetpoint(PIDsetpoint->getValue()); } diff --git a/lib/Core/core.h b/lib/Core/core.h index f3c8015..63bda63 100644 --- a/lib/Core/core.h +++ b/lib/Core/core.h @@ -26,7 +26,7 @@ /** * @defgroup ModbusCategoryCodes Modbus Point Category Codes * @brief Integer constants used in the `modbusMap` to identify the type of Modbus point. - * These codes determine which `ModbusPoint` subclass is created by the factory. + * These codes determine which `Modbus_Point` subclass is created by the factory. * @{ */ const int COIL = 0; /**< @brief 0x: R/W Coil */ diff --git a/lib/README b/lib/README deleted file mode 100644 index 9379397..0000000 --- a/lib/README +++ /dev/null @@ -1,46 +0,0 @@ - -This directory is intended for project specific (private) libraries. -PlatformIO will compile them to static libraries and link into the executable file. - -The source code of each library should be placed in a separate directory -("lib/your_library_name/[Code]"). - -For example, see the structure of the following example libraries `Foo` and `Bar`: - -|--lib -| | -| |--Bar -| | |--docs -| | |--examples -| | |--src -| | |- Bar.c -| | |- Bar.h -| | |- library.json (optional. for custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html -| | -| |--Foo -| | |- Foo.c -| | |- Foo.h -| | -| |- README --> THIS FILE -| -|- platformio.ini -|--src - |- main.c - -Example contents of `src/main.c` using Foo and Bar: -``` -#include -#include - -int main (void) -{ - ... -} - -``` - -The PlatformIO Library Dependency Finder will find automatically dependent -libraries by scanning project source files. - -More information about PlatformIO Library Dependency Finder -- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/lib/README.md b/lib/README.md new file mode 100644 index 0000000..4a71669 --- /dev/null +++ b/lib/README.md @@ -0,0 +1,23 @@ +# Libraries + +## Core Library +The `Core` library contains the fundamental building blocks and architectural patterns for the Industrial Equipment Emulator. It is designed to be reusable and independent of any specific equipment implementation. + +### Directory Structure + +* **`/Equipment`**: Contains the `Equipment` class, which is the central context for the state machine. It manages the current state and holds all the Modbus points. + +* **`/Modbus_Points`** : Implements the **Decorator Pattern** for handling different Modbus data types. + * `Modbus_Point.h`: The base interface for all data points. + * `Modbus_PointDecorator.h`: The base class for wrappers that add functionality (e.g., scaling, float conversion). + * `Modbus_PointFactory.h`: A factory for creating and decorating Modbus points based on configuration. + +* **`/States`**: Implements the **State Pattern** to define the different operating modes of the equipment (e.g., Standby, Running, Fail). + * `State.h`: The base interface for all state classes. + * Concrete states like `State_Standby.h`, `State_Running.h`, etc., are implemented in the device-specific source folders (e.g., `src/CRAH_.../`) as they contain device-specific logic. + +* **`/Strategies`**: Implements the **Strategy Pattern** to define interchangeable behaviors for Modbus points within a given state. + * `Strategy_Behavior.h`: The base interface for all behavior algorithms. + * Concrete strategies like `Strategy_Ramp.h`, `Strategy_PID.h`, etc., provide reusable simulation logic. + +* **`core.h`**: A central header file containing shared definitions, enumerations (`COIL`, `HR_FLOAT`, etc.), and the `modbusMap` structure used across the project. \ No newline at end of file diff --git a/src/CH_Daikin_AWV026B_RTU/State_Fail.cpp b/src/CH_Daikin_AWV026B_RTU/State_Fail.cpp index 6666ff4..70da82d 100644 --- a/src/CH_Daikin_AWV026B_RTU/State_Fail.cpp +++ b/src/CH_Daikin_AWV026B_RTU/State_Fail.cpp @@ -7,10 +7,9 @@ * 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_Fail.h" #include "States/State_Standby.h" - -#include "Categories/ModbusPoint.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" @@ -55,7 +54,7 @@ template<> State* FailState::update(Equipment* equipment) { // STATE control, add conditions if change to a different state is needed Serial.println("Fail update function"); - ModbusPoint* clearAlm = equipment->getModbusPoint("Clear Alm"); + Modbus_Point* clearAlm = equipment->getModbus_Point("Clear Alm"); int nextStateId = clearAlm ? clearAlm->getValue() : 0; if (nextStateId == 1){ return new StandbyState(); @@ -72,7 +71,7 @@ template<> void FailState::enterState(Equipment* equipment) { // Logic to run when the equipment enters this state Serial.println("Enter Fail State..."); - ModbusPoint* alarm_common = equipment->getModbusPoint("Alarm Common"); + Modbus_Point* alarm_common = equipment->getModbus_Point("Alarm Common"); alarm_common->setValue(1); } @@ -84,6 +83,6 @@ template<> void FailState::exitState(Equipment* equipment) { // Cleanup logic to run when the equipment leaves this state Serial.println("Exit Fail State..."); - ModbusPoint* alarm_common = equipment->getModbusPoint("Alarm Common"); + Modbus_Point* alarm_common = equipment->getModbus_Point("Alarm Common"); alarm_common->setValue(0); } \ No newline at end of file diff --git a/src/CH_Daikin_AWV026B_RTU/State_Running.cpp b/src/CH_Daikin_AWV026B_RTU/State_Running.cpp index 5eab11e..d5c19db 100644 --- a/src/CH_Daikin_AWV026B_RTU/State_Running.cpp +++ b/src/CH_Daikin_AWV026B_RTU/State_Running.cpp @@ -7,15 +7,16 @@ * This file contains the implementation for the RunningState, which defines * the behavior of the equipment when it is actively running. */ -#include "States/State_Running.h" + #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_Totalizer.h" #include "Equipment/Equipment.h" -#include "Categories/ModbusPoint.h" -#include "Categories/ModbusFloatDecorator.h" +#include "ModbusPoints/Modbus_Point.h" +#include "ModbusPoints/Modbus_FloatDecorator.h" #include #include @@ -64,14 +65,14 @@ template<> State* RunningState::update(Equipment* equipment) { // STATE control, add conditions if change to a different state is needed Serial.println("Running update function"); - ModbusPoint* On_Off_Command = equipment->getModbusPoint("ON/OFF Command By BMS"); + Modbus_Point* On_Off_Command = equipment->getModbus_Point("ON/OFF Command By BMS"); int nextStateId = On_Off_Command ? On_Off_Command->getValue() : 0; Serial.println(nextStateId); if (nextStateId == 0){ return new StandbyState(); } - ModbusPoint* faultCode = equipment->getModbusPoint("Fault Code"); + Modbus_Point* faultCode = equipment->getModbus_Point("Fault Code"); int faultCodeValue = faultCode ? faultCode->getValue() : 0; if (faultCodeValue != 0) { // A fault has been triggered, transition to FailState @@ -105,7 +106,7 @@ void RunningState::enterState(Equipment* equipment) { // Loop through and set all motor statuses to 0 for (const auto& desc : motorStatusDescriptions) { - ModbusPoint* point = equipment->getModbusPoint(desc); + Modbus_Point* point = equipment->getModbus_Point(desc); if (point) { point->setValue(1); } diff --git a/src/CH_Daikin_AWV026B_RTU/State_Standby.cpp b/src/CH_Daikin_AWV026B_RTU/State_Standby.cpp index 46508a0..a0db75f 100644 --- a/src/CH_Daikin_AWV026B_RTU/State_Standby.cpp +++ b/src/CH_Daikin_AWV026B_RTU/State_Standby.cpp @@ -7,10 +7,10 @@ * 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_Standby.h" #include "States/State_Running.h" -#include "Categories/ModbusPoint.h" -#include "Categories/ModbusFloatDecorator.h" +#include "States/State_Fail.h" +#include "ModbusPoints/Modbus_Point.h" +#include "ModbusPoints/Modbus_FloatDecorator.h" #include "Equipment/Equipment.h" #include "Strategies/Strategy_Random.h" @@ -53,7 +53,7 @@ template<> State* StandbyState::update(Equipment* equipment) { // STATE control, add conditions if change to a different state is needed Serial.println("Standby update function"); - ModbusPoint* chillerOnOff = equipment->getModbusPoint("Chiller On-Off"); + Modbus_Point* chillerOnOff = equipment->getModbus_Point("Chiller On-Off"); int nextStateId = chillerOnOff ? chillerOnOff->getValue() : 0; Serial.println(nextStateId); if (nextStateId == 1){ diff --git a/src/CH_Daikin_AWV026B_RTU/main.cpp b/src/CH_Daikin_AWV026B_RTU/main.cpp index cacad11..5dbc9f1 100644 --- a/src/CH_Daikin_AWV026B_RTU/main.cpp +++ b/src/CH_Daikin_AWV026B_RTU/main.cpp @@ -22,13 +22,13 @@ * @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 ModbusPoint.h for the base class for all Modbus points. + * @see Modbus_Point.h for the base class for all Modbus points. */ //================================================================================================================================= //Libraries and declaration of variables. #include #include "config.h" -#include "Categories/ModbusPointFactory.h" +#include "ModbusPoints/Modbus_PointFactory.h" //================================================================================================================================= /** @@ -47,10 +47,10 @@ void setup() { mb.slave(MODBUS_ID); // Set the slave ID for(int i = 0; i < map_size; i++){ - ModbusPoint* point = createModbusPoint(&mb, mb_map[i].category, mb_map[i].address, mb_map[i].value, mb_map[i].description); + 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.addModbusPoint(mb_map[i].description, point); + EquipmentInstance.addModbus_Point(mb_map[i].description, point); } } Serial.println("Setup function ended"); diff --git a/src/CRAH_PAHHC_600_C6_TCP/State_Fail.cpp b/src/CRAH_PAHHC_600_C6_TCP/State_Fail.cpp index fd5a185..046bf00 100644 --- a/src/CRAH_PAHHC_600_C6_TCP/State_Fail.cpp +++ b/src/CRAH_PAHHC_600_C6_TCP/State_Fail.cpp @@ -7,7 +7,7 @@ * This file contains the implementation for the FailState, which defines * the behavior of the equipment when it has entered a fault condition. */ -#include "Categories/ModbusPoint.h" +#include "ModbusPoints/Modbus_Point.h" #include "Equipment/Equipment.h" #include "Strategies/Strategy_Ramp.h" #include "Strategies/Strategy_SingleValue.h" @@ -56,7 +56,7 @@ template<> State* FailState::update(Equipment* equipment) { // STATE control, add conditions if change to a different state is needed Serial.println("Fail update function"); - ModbusPoint* alarmReset = equipment->getModbusPoint("Alarm Reset"); + Modbus_Point* alarmReset = equipment->getModbus_Point("Alarm Reset"); int nextStateId = alarmReset ? alarmReset->getValue() : 0; if (nextStateId == 1){ return new StandbyState(); @@ -74,7 +74,7 @@ template<> void FailState::enterState(Equipment* equipment) { // Logic to run when the equipment enters this state Serial.println("Enter Fail State..."); - ModbusPoint* alarm_common = equipment->getModbusPoint("Alarm Common"); + Modbus_Point* alarm_common = equipment->getModbus_Point("Alarm Common"); alarm_common->setValue(1); } @@ -87,6 +87,6 @@ template<> void FailState::exitState(Equipment* equipment) { // Cleanup logic to run when the equipment leaves this state Serial.println("Exit Fail State..."); - ModbusPoint* alarm_common = equipment->getModbusPoint("Alarm Common"); + Modbus_Point* alarm_common = equipment->getModbus_Point("Alarm Common"); alarm_common->setValue(0); } \ No newline at end of file diff --git a/src/CRAH_PAHHC_600_C6_TCP/State_Running.cpp b/src/CRAH_PAHHC_600_C6_TCP/State_Running.cpp index c9c25ff..b0f5399 100644 --- a/src/CRAH_PAHHC_600_C6_TCP/State_Running.cpp +++ b/src/CRAH_PAHHC_600_C6_TCP/State_Running.cpp @@ -7,8 +7,8 @@ * This file contains the implementation for the RunningState, which defines * the behavior of the equipment when it is actively running. */ -#include "Categories/ModbusPoint.h" -#include "Categories/ModbusFloatDecorator.h" +#include "ModbusPoints/Modbus_Point.h" +#include "ModbusPoints/Modbus_FloatDecorator.h" #include "Equipment/Equipment.h" #include "Strategies/Strategy_Ramp.h" #include "Strategies/Strategy_Random.h" @@ -67,14 +67,14 @@ template<> State* RunningState::update(Equipment* equipment) { // STATE control, add conditions if change to a different state is needed Serial.println("Running update function"); - ModbusPoint* On_Off_Command = equipment->getModbusPoint("ON/OFF Command By BMS"); + Modbus_Point* On_Off_Command = equipment->getModbus_Point("ON/OFF Command By BMS"); int nextStateId = On_Off_Command ? On_Off_Command->getValue() : 0; Serial.println(nextStateId); if (nextStateId == 0){ return new StandbyState(); } - ModbusPoint* faultCode = equipment->getModbusPoint("Fault Code"); + Modbus_Point* faultCode = equipment->getModbus_Point("Fault Code"); int faultCodeValue = faultCode ? faultCode->getValue() : 0; switch (faultCodeValue){ case 1: @@ -155,7 +155,7 @@ void RunningState::enterState(Equipment* equipment) { // Loop through and set all motor statuses to 0 for (const auto& desc : motorStatusDescriptions) { - ModbusPoint* point = equipment->getModbusPoint(desc); + Modbus_Point* point = equipment->getModbus_Point(desc); if (point) { point->setValue(1); } @@ -179,7 +179,7 @@ void RunningState::exitState(Equipment* equipment) { // Loop through and set all motor statuses to 0 for (const auto& desc : motorStatusDescriptions) { - ModbusPoint* point = equipment->getModbusPoint(desc); + Modbus_Point* point = equipment->getModbus_Point(desc); if (point) { point->setValue(0); } diff --git a/src/CRAH_PAHHC_600_C6_TCP/State_Standby.cpp b/src/CRAH_PAHHC_600_C6_TCP/State_Standby.cpp index 6c27ac1..1ee0de6 100644 --- a/src/CRAH_PAHHC_600_C6_TCP/State_Standby.cpp +++ b/src/CRAH_PAHHC_600_C6_TCP/State_Standby.cpp @@ -7,8 +7,8 @@ * 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 "Categories/ModbusPoint.h" -#include "Categories/ModbusFloatDecorator.h" +#include "ModbusPoints/Modbus_Point.h" +#include "ModbusPoints/Modbus_FloatDecorator.h" #include "Equipment/Equipment.h" #include "Strategies/Strategy_Ramp.h" #include "Strategies/Strategy_Random.h" @@ -109,7 +109,7 @@ void StandbyState::enterState(Equipment* equipment) { // Loop through and set all alarms to 0 for (const auto& desc : alarmDescriptions) { - ModbusPoint* point = equipment->getModbusPoint(desc); + Modbus_Point* point = equipment->getModbus_Point(desc); if (point) { point->setValue(0); } @@ -117,7 +117,7 @@ void StandbyState::enterState(Equipment* equipment) { // Loop through and set all motor statuses to 0 for (const auto& desc : motorStatusDescriptions) { - ModbusPoint* point = equipment->getModbusPoint(desc); + Modbus_Point* point = equipment->getModbus_Point(desc); if (point) { point->setValue(0); } diff --git a/src/CRAH_PAHHC_600_C6_TCP/main.cpp b/src/CRAH_PAHHC_600_C6_TCP/main.cpp index f911995..286a98c 100644 --- a/src/CRAH_PAHHC_600_C6_TCP/main.cpp +++ b/src/CRAH_PAHHC_600_C6_TCP/main.cpp @@ -22,13 +22,13 @@ * @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 ModbusPoint.h for the base class for all Modbus points. + * @see Modbus_Point.h for the base class for all Modbus points. */ //================================================================================================================================= //Libraries and declaration of variables. #include #include "config.h" -#include "Categories/ModbusPointFactory.h" +#include "ModbusPoints/Modbus_PointFactory.h" #if defined(USE_MODBUS_IP) #include #else @@ -54,10 +54,10 @@ void setup() { Serial.println("Server Created"); Serial.println(map_size); for(int i = 0; i < map_size; i++){ - ModbusPoint* point = createModbusPoint(&mb, mb_map[i].category, mb_map[i].address, mb_map[i].value, mb_map[i].description); + 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.addModbusPoint(mb_map[i].description, point); + EquipmentInstance.addModbus_Point(mb_map[i].description, point); } } Serial.println("All modbus Points created");