Name updated, Categories folder to ModbuPoints, less generic to be self documented

This commit is contained in:
2025-09-15 12:51:34 -05:00
parent 5a0b02ccdf
commit 14cf23281d
24 changed files with 274 additions and 297 deletions

View File

@@ -18,7 +18,7 @@
// Forward Declarations
template<typename T> class State;
template<typename T> class ModbusPoint;
template<typename T> 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<T>* point);
void addModbus_Point(const std::string& description, Modbus_Point<T>* 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<T>* getModbusPoint(const std::string& description);
Modbus_Point<T>* 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<T>* _state; /**< @brief Pointer to the current state object. */
std::map<std::string, ModbusPoint<T>*> _points;/**< @brief Map of all Modbus points, keyed by description. */
std::map<std::string, Modbus_Point<T>*> _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<T>::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<typename T>
void Equipment<T>::addModbusPoint(const std::string& description, ModbusPoint<T>* point) {
void Equipment<T>::addModbus_Point(const std::string& description, Modbus_Point<T>* 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<typename T>
ModbusPoint<T>* Equipment<T>::getModbusPoint(const std::string& description) {
Modbus_Point<T>* Equipment<T>::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<T>* Equipment<T>::getModbusPoint(const std::string& description) {
* @param value The value to set. This float is cast to an int before being passed.
*/
template<typename T>
void Equipment<T>::setModbusPoint(const std::string& description, float value) {
ModbusPoint<T>* point = getModbusPoint(description);
void Equipment<T>::setModbus_Point(const std::string& description, float value) {
Modbus_Point<T>* point = getModbus_Point(description);
if (point != nullptr) {
point->setValue(value);
}

View File

@@ -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<typename T>
class ModbusCoil : public ModbusPoint<T>{
class Modbus_Coil : public Modbus_Point<T>{
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<typename T>
ModbusCoil<T>::ModbusCoil(T* server, int address, int value, const char* description)
: ModbusPoint<T>(server, address, value, description) {}
Modbus_Coil<T>::Modbus_Coil(T* server, int address, int value, const char* description)
: Modbus_Point<T>(server, address, value, description) {}
/**
* @brief Adds the coil to the Modbus server's register map.
@@ -59,7 +59,7 @@ ModbusCoil<T>::ModbusCoil(T* server, int address, int value, const char* descrip
* at the specified address with its initial value.
*/
template<typename T>
void ModbusCoil<T>::addToModbusServer(){
void Modbus_Coil<T>::addToModbusServer(){
this->_server->addCoil(this->_address, this->_value);
}
@@ -70,7 +70,7 @@ void ModbusCoil<T>::addToModbusServer(){
* @param value The new value for the coil.
*/
template<typename T>
void ModbusCoil<T>::setValue(int value){
void Modbus_Coil<T>::setValue(int value){
this->_server->Coil(this->_address, value);
}
@@ -79,7 +79,7 @@ void ModbusCoil<T>::setValue(int value){
* @return The current value.
*/
template<typename T>
int ModbusCoil<T>::getValue() const{
int Modbus_Coil<T>::getValue() const{
return this->_server->Coil(this->_address);
}

View File

@@ -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 <stdint.h>
#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<typename T>
class ModbusFloatDecorator : public ModbusPointDecorator<T> {
class Modbus_FloatDecorator : public Modbus_PointDecorator<T> {
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<T>* point, ModbusPoint<T>* highOrderPoint)
: ModbusPointDecorator<T>(point), _highOrderPoint(highOrderPoint) {}
Modbus_FloatDecorator(Modbus_Point<T>* point, Modbus_Point<T>* highOrderPoint)
: Modbus_PointDecorator<T>(point), _highOrderPoint(highOrderPoint) {}
/**
* @brief Returns the logical type of the point.
@@ -109,7 +109,7 @@ public:
}
private:
ModbusPoint<T>* _highOrderPoint; /**< @brief Pointer to the ModbusPoint for the high-order word. */
Modbus_Point<T>* _highOrderPoint; /**< @brief Pointer to the Modbus_Point for the high-order word. */
};
#endif

View File

@@ -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<typename T>
class ModbusHreg : public ModbusPoint<T>{
class Modbus_Hreg : public Modbus_Point<T>{
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<typename T>
ModbusHreg<T>::ModbusHreg(T* server, int address, int value, const char* description)
: ModbusPoint<T>(server, address, value, description) {}
Modbus_Hreg<T>::Modbus_Hreg(T* server, int address, int value, const char* description)
: Modbus_Point<T>(server, address, value, description) {}
/**
* @brief Adds the holding register to the Modbus server's register map.
@@ -64,7 +64,7 @@ ModbusHreg<T>::ModbusHreg(T* server, int address, int value, const char* descrip
* register at the specified address with its initial value.
*/
template<typename T>
void ModbusHreg<T>::addToModbusServer() {
void Modbus_Hreg<T>::addToModbusServer() {
this->_server->addHreg(this->_address, this->_value);
}
@@ -75,7 +75,7 @@ void ModbusHreg<T>::addToModbusServer() {
* @param value The new 16-bit value for the register.
*/
template<typename T>
void ModbusHreg<T>::setValue(int value) {
void Modbus_Hreg<T>::setValue(int value) {
this->_server->Hreg(this->_address, value);
}
@@ -84,7 +84,7 @@ void ModbusHreg<T>::setValue(int value) {
* @return The current 16-bit value from the register.
*/
template<typename T>
int ModbusHreg<T>::getValue() const {
int Modbus_Hreg<T>::getValue() const {
return this->_server->Hreg(this->_address);
}
#endif

View File

@@ -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<typename T>
class ModbusIreg : public ModbusPoint<T>{
class Modbus_Ireg : public Modbus_Point<T>{
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<typename T>
ModbusIreg<T>::ModbusIreg(T* server, int address, int value, const char* description)
: ModbusPoint<T>(server, address, value, description){}
Modbus_Ireg<T>::Modbus_Ireg(T* server, int address, int value, const char* description)
: Modbus_Point<T>(server, address, value, description){}
/**
* @brief Sets the value of the input register on the Modbus server.
@@ -61,7 +61,7 @@ ModbusIreg<T>::ModbusIreg(T* server, int address, int value, const char* descrip
* @param value The new 16-bit value for the register.
*/
template<typename T>
void ModbusIreg<T>::setValue(int value){
void Modbus_Ireg<T>::setValue(int value){
this->_server->Ireg(this->_address, value);
}
/**
@@ -69,7 +69,7 @@ void ModbusIreg<T>::setValue(int value){
* @return The current 16-bit value from the register.
*/
template<typename T>
int ModbusIreg<T>::getValue() const {
int Modbus_Ireg<T>::getValue() const {
return this->_server->Ireg(this->_address);
}
@@ -79,7 +79,7 @@ int ModbusIreg<T>::getValue() const {
* register at the specified address with its initial value.
*/
template<typename T>
void ModbusIreg<T>::addToModbusServer(){
void Modbus_Ireg<T>::addToModbusServer(){
this->_server->addIreg(this->_address, this->_value);
}

View File

@@ -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<typename T>
class ModbusIsts : public ModbusPoint<T>{
class Modbus_Ists : public Modbus_Point<T>{
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<typename T>
ModbusIsts<T>::ModbusIsts(T* server, int address, int value, const char* description)
: ModbusPoint<T>(server, address, value, description) {}
Modbus_Ists<T>::Modbus_Ists(T* server, int address, int value, const char* description)
: Modbus_Point<T>(server, address, value, description) {}
/**
* @brief Sets the value of the discrete input on the Modbus server.
@@ -62,7 +62,7 @@ ModbusIsts<T>::ModbusIsts(T* server, int address, int value, const char* descrip
* @param value The new value for the discrete input.
*/
template<typename T>
void ModbusIsts<T>::setValue(int value){
void Modbus_Ists<T>::setValue(int value){
this->_server->Ists(this->_address, value);
}
/**
@@ -70,7 +70,7 @@ void ModbusIsts<T>::setValue(int value){
* @return The current value.
*/
template<typename T>
int ModbusIsts<T>::getValue() const{
int Modbus_Ists<T>::getValue() const{
return this->_server->Ists(this->_address);
}
/**
@@ -79,7 +79,7 @@ int ModbusIsts<T>::getValue() const{
* input at the specified address with its initial value.
*/
template<typename T>
void ModbusIsts<T>::addToModbusServer(){
void Modbus_Ists<T>::addToModbusServer(){
this->_server->addIsts(this->_address, this->_value);
}

View File

@@ -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<typename T>
class ModbusLongDecorator : public ModbusPointDecorator<T> {
class Modbus_LongDecorator : public Modbus_PointDecorator<T> {
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<T>* point, ModbusPoint<T>* highOrderPoint)
: ModbusPointDecorator<T>(point), _highOrderPoint(highOrderPoint) {}
Modbus_LongDecorator(Modbus_Point<T>* point, Modbus_Point<T>* highOrderPoint)
: Modbus_PointDecorator<T>(point), _highOrderPoint(highOrderPoint) {}
/**
* @brief Returns the logical type of the point.
@@ -91,7 +91,7 @@ public:
return static_cast<int>(getLongValue());
}
private:
ModbusPoint<T>* _highOrderPoint; /**< @brief Pointer to the ModbusPoint for the high-order word. */
Modbus_Point<T>* _highOrderPoint; /**< @brief Pointer to the Modbus_Point for the high-order word. */
};
#endif

View File

@@ -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 <string.h>
/**
* @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<typename T>
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<typename T>
ModbusPoint<T>::ModbusPoint(T* server, int address, int value, const char* description)
Modbus_Point<T>::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';

View File

@@ -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<typename T>
class ModbusPointDecorator : public ModbusPoint<T>{
class Modbus_PointDecorator : public Modbus_Point<T>{
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<T>* point) : ModbusPoint<T>(
Modbus_PointDecorator(Modbus_Point<T>* point) : Modbus_Point<T>(
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<T>* _point; /**< @brief Pointer to the wrapped ModbusPoint object. */
Modbus_Point<T>* _point; /**< @brief Pointer to the wrapped Modbus_Point object. */
};
#endif

View File

@@ -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 <Arduino.h>
/**
* @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<typename T>
ModbusPoint<T>* createModbusPoint(T* server, int category, int address, int value, const char* description);
Modbus_Point<T>* 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<typename T>
ModbusPoint<T>* createModbusPoint(T* server, int category, int address, int value, const char* description) {
Modbus_Point<T>* 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<T>(server, address, value, description);
return new Modbus_Coil<T>(server, address, value, description);
case DI:
Serial.printf("Creating Digital Input: %s\n", description);
return new ModbusIsts<T>(server, address, value, description);
return new Modbus_Ists<T>(server, address, value, description);
case IR:
Serial.printf("Creating Input Register: %s\n", description);
return new ModbusIreg<T>(server, address, value, description);
return new Modbus_Ireg<T>(server, address, value, description);
case IR_10X: {
Serial.printf("Creating Scaled Input Register (10x): %s\n", description);
ModbusPoint<T>* point = new ModbusIreg<T>(server, address, value, description);
return new ModbusScaleDecorator<T>(point);
Modbus_Point<T>* point = new Modbus_Ireg<T>(server, address, value, description);
return new Modbus_ScaleDecorator<T>(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<T>* point = new ModbusIreg<T>(server, address, 0, description);
ModbusPoint<T>* highOrderPoint = new ModbusIreg<T>(server, address + 1, 0, "");
return new ModbusLongDecorator<T>(point, highOrderPoint);
Modbus_Point<T>* point = new Modbus_Ireg<T>(server, address, 0, description);
Modbus_Point<T>* highOrderPoint = new Modbus_Ireg<T>(server, address + 1, 0, "");
return new Modbus_LongDecorator<T>(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<T>* point = new ModbusIreg<T>(server, address, 0, description);
ModbusPoint<T>* highOrderPoint = new ModbusIreg<T>(server, address + 1, 0, "");
return new ModbusFloatDecorator<T>(point, highOrderPoint);
Modbus_Point<T>* point = new Modbus_Ireg<T>(server, address, 0, description);
Modbus_Point<T>* highOrderPoint = new Modbus_Ireg<T>(server, address + 1, 0, "");
return new Modbus_FloatDecorator<T>(point, highOrderPoint);
}
case HR:
Serial.printf("Creating Holding Register: %s\n", description);
return new ModbusHreg<T>(server, address, value, description);
return new Modbus_Hreg<T>(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<T>* point = new ModbusHreg<T>(server, address, value, description);
return new ModbusScaleDecorator<T>(point);
Modbus_Point<T>* point = new Modbus_Hreg<T>(server, address, value, description);
return new Modbus_ScaleDecorator<T>(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<T>* point = new ModbusHreg<T>(server, address, 0, description);
ModbusPoint<T>* highOrderPoint = new ModbusHreg<T>(server, address + 1 , 0, "");
return new ModbusLongDecorator<T>(point, highOrderPoint);
Modbus_Point<T>* point = new Modbus_Hreg<T>(server, address, 0, description);
Modbus_Point<T>* highOrderPoint = new Modbus_Hreg<T>(server, address + 1 , 0, "");
return new Modbus_LongDecorator<T>(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<T>* point = new ModbusHreg<T>(server, address, 0, description);
ModbusPoint<T>* highOrderPoint = new ModbusHreg<T>(server, address + 1 , 0, "");
return new ModbusFloatDecorator<T>(point, highOrderPoint);
Modbus_Point<T>* point = new Modbus_Hreg<T>(server, address, 0, description);
Modbus_Point<T>* highOrderPoint = new Modbus_Hreg<T>(server, address + 1 , 0, "");
return new Modbus_FloatDecorator<T>(point, highOrderPoint);
}
default:
Serial.printf("ERROR: Unknown Modbus category %d for '%s'\n", category, description);

View File

@@ -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<typename T>
class ModbusScaleDecorator : public ModbusPointDecorator<T> {
class Modbus_ScaleDecorator : public Modbus_PointDecorator<T> {
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<T>(ModbusPoint<T>* point) : ModbusPointDecorator<T>(point) {}
Modbus_ScaleDecorator<T>(Modbus_Point<T>* point) : Modbus_PointDecorator<T>(point) {}
/**
* @brief Sets the raw integer value on the underlying point.

View File

@@ -14,8 +14,8 @@
#include <Arduino.h>
#include <map>
#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
template<typename T>class 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<T>::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<T>::addStrategy(const std::string& pointDescription, Strategy_Behavio
*/
template<typename T>
float State<T>::getPointValue(Equipment<T>* equipment, const std::string& pointName) {
ModbusPoint<T>* point = equipment->getModbusPoint(pointName);
Modbus_Point<T>* 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<ModbusFloatDecorator<T>*>(point)->getFloatValue();
return static_cast<Modbus_FloatDecorator<T>*>(point)->getFloatValue();
} else {
// Otherwise, get the standard integer value
return static_cast<float>(point->getValue());
@@ -136,7 +136,7 @@ float State<T>::getPointValue(Equipment<T>* 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<T>::getPointValue(Equipment<T>* equipment, const std::string& pointN
*/
template<typename T>
void State<T>::setPointValue(Equipment<T>* equipment, const std::string& pointName, float value) {
ModbusPoint<T>* point = equipment->getModbusPoint(pointName);
Modbus_Point<T>* point = equipment->getModbus_Point(pointName);
if (!point) return;
if (point->getType() == PointType::FLOAT) {
static_cast<ModbusFloatDecorator<T>*>(point)->setFloatValue(value);
static_cast<Modbus_FloatDecorator<T>*>(point)->setFloatValue(value);
} else {
point->setValue(round(value));
}
@@ -175,7 +175,7 @@ void State<T>::_applyStrategies(Equipment<T>* equipment) {
Strategy_Behavior* strategy = pair.second;
if (strategy->isReady(currentTime)) {
ModbusPoint<T>* outputPoint = equipment->getModbusPoint(description);
Modbus_Point<T>* outputPoint = equipment->getModbus_Point(description);
if (!outputPoint) continue;
float inputValue;
@@ -184,7 +184,7 @@ void State<T>::_applyStrategies(Equipment<T>* equipment) {
PIDStrategy* pid = static_cast<PIDStrategy*>(strategy);
inputValue = getPointValue(equipment, pid->getInputSensorName());
ModbusPoint<T>* PIDsetpoint = equipment->getModbusPoint(pid->getSetpointName());
Modbus_Point<T>* PIDsetpoint = equipment->getModbus_Point(pid->getSetpointName());
if (PIDsetpoint) {
pid->setSetpoint(PIDsetpoint->getValue());
}

View File

@@ -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 */