Name updated, Categories folder to ModbuPoints, less generic to be self documented
This commit is contained in:
18
README.md
18
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.
|
* **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:**
|
* **How it works here:**
|
||||||
* We start with a basic `ModbusPoint` (like `ModbusHreg` for a Holding Register).
|
* 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 `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 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 `ModbusScaleDecorator`.
|
* 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:**
|
* **Files to see:**
|
||||||
* `Categories/ModbusPoint.h`: The base for all points.
|
* `Modbus_Points/Modbus_Point.h`: The base for all points.
|
||||||
* `Categories/ModbusPointDecorator.h`: The base "wrapper" class.
|
* `Modbus_Points/Modbus_PointDecorator.h`: The base "wrapper" class.
|
||||||
* `Categories/ModbusFloatDecorator.h`: A specific wrapper that adds floating-point logic.
|
* `Modbus_Points/Modbus_FloatDecorator.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_PointFactory.cpp`: The factory that automatically creates and decorates points based on the `config.h` map.
|
||||||
|
|
||||||
## Project Structure
|
## 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.
|
* `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.
|
* `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.
|
* `/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`).
|
* `/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`).
|
* `/Strategies`: Contains the reusable behavior algorithms for Modbus points (e.g., `Strategy_Ramp`).
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
// Forward Declarations
|
// Forward Declarations
|
||||||
template<typename T> class State;
|
template<typename T> class State;
|
||||||
template<typename T> class ModbusPoint;
|
template<typename T> class Modbus_Point;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class Equipment
|
* @class Equipment
|
||||||
@@ -63,26 +63,26 @@ public:
|
|||||||
/**
|
/**
|
||||||
* @brief Adds a Modbus point to the equipment's internal map.
|
* @brief Adds a Modbus point to the equipment's internal map.
|
||||||
* @param description The unique string description used as a key.
|
* @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.
|
* @brief Retrieves a Modbus point by its description.
|
||||||
* @param description The string key for the Modbus point.
|
* @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.
|
* @brief Sets the value of a specific Modbus point.
|
||||||
* @param description The string key for the 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
|
* @param value The value to set. Note: This float may be truncated or cast
|
||||||
* depending on the underlying point's `setValue` implementation.
|
* 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:
|
private:
|
||||||
State<T>* _state; /**< @brief Pointer to the current state object. */
|
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. */
|
int _stateId; /**< @brief A simple integer identifier for the current state. */
|
||||||
T* _server;
|
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
|
* The point is added to a map for quick lookup by description and to a
|
||||||
* vector for simple iteration.
|
* vector for simple iteration.
|
||||||
* @param description The unique string description used as a key.
|
* @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>
|
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;
|
this->_points[description] = point;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Retrieves a Modbus point by its description.
|
* @brief Retrieves a Modbus point by its description.
|
||||||
* @param description The string key for the Modbus point.
|
* @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>
|
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);
|
auto it = this->_points.find(description);
|
||||||
if (it != this->_points.end()) {
|
if (it != this->_points.end()) {
|
||||||
return it->second;
|
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.
|
* @param value The value to set. This float is cast to an int before being passed.
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void Equipment<T>::setModbusPoint(const std::string& description, float value) {
|
void Equipment<T>::setModbus_Point(const std::string& description, float value) {
|
||||||
ModbusPoint<T>* point = getModbusPoint(description);
|
Modbus_Point<T>* point = getModbus_Point(description);
|
||||||
if (point != nullptr) {
|
if (point != nullptr) {
|
||||||
point->setValue(value);
|
point->setValue(value);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,35 +1,35 @@
|
|||||||
/**
|
/**
|
||||||
* @file ModbusCoil.h
|
* @file Modbus_Coil.h
|
||||||
* @brief Defines the ModbusCoil class for handling Modbus coils.
|
* @brief Defines the Modbus_Coil class for handling Modbus coils.
|
||||||
* @author Emmanuel Hernandez Cruz
|
* @author Emmanuel Hernandez Cruz
|
||||||
* @date 2025-09-04
|
* @date 2025-09-04
|
||||||
*
|
*
|
||||||
* This file contains the definition of the ModbusCoil class, which is a specific
|
* This file contains the definition of the Modbus_Coil class, which is a specific
|
||||||
* implementation of the ModbusPoint for handling coils (digital outputs).
|
* implementation of the Modbus_Point for handling coils (digital outputs).
|
||||||
*/
|
*/
|
||||||
#ifndef ModbusCoil_h
|
#ifndef Modbus_Coil_h
|
||||||
#define ModbusCoil_h
|
#define Modbus_Coil_h
|
||||||
#include "ModbusPoint.h"
|
#include "Modbus_Point.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class ModbusCoil
|
* @class Modbus_Coil
|
||||||
* @brief Represents a Modbus coil point.
|
* @brief Represents a Modbus coil point.
|
||||||
*
|
*
|
||||||
* This class provides a concrete implementation for a Modbus coil,
|
* 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.
|
* and implements its virtual functions for coil-specific operations.
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class ModbusCoil : public ModbusPoint<T>{
|
class Modbus_Coil : public Modbus_Point<T>{
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief Constructor for the ModbusCoil class.
|
* @brief Constructor for the Modbus_Coil class.
|
||||||
* @param server Pointer to the ModbusIP server instance.
|
* @param server Pointer to the ModbusIP server instance.
|
||||||
* @param address The Modbus address of the coil.
|
* @param address The Modbus address of the coil.
|
||||||
* @param value The initial value of the coil.
|
* @param value The initial value of the coil.
|
||||||
* @param description A description 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.
|
* @brief Adds the coil to the Modbus server.
|
||||||
@@ -50,8 +50,8 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
ModbusCoil<T>::ModbusCoil(T* server, int address, int value, const char* description)
|
Modbus_Coil<T>::Modbus_Coil(T* server, int address, int value, const char* description)
|
||||||
: ModbusPoint<T>(server, address, value, description) {}
|
: Modbus_Point<T>(server, address, value, description) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Adds the coil to the Modbus server's register map.
|
* @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.
|
* at the specified address with its initial value.
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void ModbusCoil<T>::addToModbusServer(){
|
void Modbus_Coil<T>::addToModbusServer(){
|
||||||
this->_server->addCoil(this->_address, this->_value);
|
this->_server->addCoil(this->_address, this->_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,7 +70,7 @@ void ModbusCoil<T>::addToModbusServer(){
|
|||||||
* @param value The new value for the coil.
|
* @param value The new value for the coil.
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void ModbusCoil<T>::setValue(int value){
|
void Modbus_Coil<T>::setValue(int value){
|
||||||
this->_server->Coil(this->_address, value);
|
this->_server->Coil(this->_address, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,7 +79,7 @@ void ModbusCoil<T>::setValue(int value){
|
|||||||
* @return The current value.
|
* @return The current value.
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
int ModbusCoil<T>::getValue() const{
|
int Modbus_Coil<T>::getValue() const{
|
||||||
return this->_server->Coil(this->_address);
|
return this->_server->Coil(this->_address);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,16 +1,16 @@
|
|||||||
/**
|
/**
|
||||||
* @file ModbusFloatDecorator.h
|
* @file Modbus_FloatDecorator.h
|
||||||
* @brief Defines the ModbusFloatDecorator class for handling 32-bit float values.
|
* @brief Defines the Modbus_FloatDecorator class for handling 32-bit float values.
|
||||||
* @author Emmanuel Hernandez Cruz
|
* @author Emmanuel Hernandez Cruz
|
||||||
* @date 2025-09-05
|
* @date 2025-09-05
|
||||||
*
|
*
|
||||||
* This file contains the definition for a decorator that combines two 16-bit
|
* This file contains the definition for a decorator that combines two 16-bit
|
||||||
* Modbus registers to represent a single 32-bit floating-point value.
|
* Modbus registers to represent a single 32-bit floating-point value.
|
||||||
*/
|
*/
|
||||||
#ifndef ModbusFloatDecorator_h
|
#ifndef Modbus_FloatDecorator_h
|
||||||
#define ModbusFloatDecorator_h
|
#define Modbus_FloatDecorator_h
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "ModbusPointDecorator.h"
|
#include "Modbus_PointDecorator.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @union cracked_float_t
|
* @union cracked_float_t
|
||||||
@@ -26,24 +26,24 @@ typedef union{
|
|||||||
} cracked_float_t;
|
} cracked_float_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class ModbusFloatDecorator
|
* @class Modbus_FloatDecorator
|
||||||
* @brief A decorator that combines two 16-bit registers into a 32-bit float.
|
* @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
|
* high-word point) and treats them as a single 32-bit float value. It
|
||||||
* overrides the necessary methods to handle reading, writing, and value
|
* overrides the necessary methods to handle reading, writing, and value
|
||||||
* conversion across both underlying registers.
|
* conversion across both underlying registers.
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class ModbusFloatDecorator : public ModbusPointDecorator<T> {
|
class Modbus_FloatDecorator : public Modbus_PointDecorator<T> {
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief Constructs a new ModbusFloatDecorator object.
|
* @brief Constructs a new Modbus_FloatDecorator object.
|
||||||
* @param point A pointer to the ModbusPoint for the low-order word (LSW).
|
* @param point A pointer to the Modbus_Point for the low-order word (LSW).
|
||||||
* @param highOrderPoint A pointer to the ModbusPoint for the high-order word.
|
* @param highOrderPoint A pointer to the Modbus_Point for the high-order word.
|
||||||
*/
|
*/
|
||||||
ModbusFloatDecorator(ModbusPoint<T>* point, ModbusPoint<T>* highOrderPoint)
|
Modbus_FloatDecorator(Modbus_Point<T>* point, Modbus_Point<T>* highOrderPoint)
|
||||||
: ModbusPointDecorator<T>(point), _highOrderPoint(highOrderPoint) {}
|
: Modbus_PointDecorator<T>(point), _highOrderPoint(highOrderPoint) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns the logical type of the point.
|
* @brief Returns the logical type of the point.
|
||||||
@@ -109,7 +109,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
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
|
#endif
|
||||||
@@ -1,36 +1,36 @@
|
|||||||
/**
|
/**
|
||||||
* @file ModbusHreg.h
|
* @file Modbus_Hreg.h
|
||||||
* @brief Defines the ModbusHreg class for handling Modbus holding registers.
|
* @brief Defines the Modbus_Hreg class for handling Modbus holding registers.
|
||||||
* @author Emmanuel Hernandez Cruz
|
* @author Emmanuel Hernandez Cruz
|
||||||
* @date 2025-09-04
|
* @date 2025-09-04
|
||||||
*
|
*
|
||||||
* This file contains the definition of the ModbusHreg class, which is a specific
|
* This file contains the definition of the Modbus_Hreg class, which is a specific
|
||||||
* implementation of the ModbusPoint for handling holding registers (16-bit).
|
* implementation of the Modbus_Point for handling holding registers (16-bit).
|
||||||
*/
|
*/
|
||||||
#ifndef ModbusHreg_h
|
#ifndef Modbus_Hreg_h
|
||||||
#define ModbusHreg_h
|
#define Modbus_Hreg_h
|
||||||
|
|
||||||
#include "ModbusPoint.h"
|
#include "Modbus_Point.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class ModbusHreg
|
* @class Modbus_Hreg
|
||||||
* @brief Represents a Modbus holding register point.
|
* @brief Represents a Modbus holding register point.
|
||||||
*
|
*
|
||||||
* This class provides a concrete implementation for a Modbus holding register,
|
* 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.
|
* and implements its virtual functions for holding register-specific operations.
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class ModbusHreg : public ModbusPoint<T>{
|
class Modbus_Hreg : public Modbus_Point<T>{
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief Constructor for the ModbusHreg class.
|
* @brief Constructor for the Modbus_Hreg class.
|
||||||
* @param server Pointer to the ModbusIP server instance.
|
* @param server Pointer to the ModbusIP server instance.
|
||||||
* @param address The Modbus address of the holding register.
|
* @param address The Modbus address of the holding register.
|
||||||
* @param value The initial value of the holding register.
|
* @param value The initial value of the holding register.
|
||||||
* @param description A description 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.
|
* @brief Adds the holding register to the Modbus server.
|
||||||
@@ -55,8 +55,8 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
ModbusHreg<T>::ModbusHreg(T* server, int address, int value, const char* description)
|
Modbus_Hreg<T>::Modbus_Hreg(T* server, int address, int value, const char* description)
|
||||||
: ModbusPoint<T>(server, address, value, description) {}
|
: Modbus_Point<T>(server, address, value, description) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Adds the holding register to the Modbus server's register map.
|
* @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.
|
* register at the specified address with its initial value.
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void ModbusHreg<T>::addToModbusServer() {
|
void Modbus_Hreg<T>::addToModbusServer() {
|
||||||
this->_server->addHreg(this->_address, this->_value);
|
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.
|
* @param value The new 16-bit value for the register.
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void ModbusHreg<T>::setValue(int value) {
|
void Modbus_Hreg<T>::setValue(int value) {
|
||||||
this->_server->Hreg(this->_address, 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.
|
* @return The current 16-bit value from the register.
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
int ModbusHreg<T>::getValue() const {
|
int Modbus_Hreg<T>::getValue() const {
|
||||||
return this->_server->Hreg(this->_address);
|
return this->_server->Hreg(this->_address);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -1,36 +1,36 @@
|
|||||||
/**
|
/**
|
||||||
* @file ModbusIreg.h
|
* @file Modbus_Ireg.h
|
||||||
* @brief Defines the ModbusIreg class for handling Modbus Input Registers.
|
* @brief Defines the Modbus_Ireg class for handling Modbus Input Registers.
|
||||||
* @author Emmanuel Hernandez Cruz
|
* @author Emmanuel Hernandez Cruz
|
||||||
* @date 2025-09-04
|
* @date 2025-09-04
|
||||||
*
|
*
|
||||||
* This file contains the definition of the ModbusIreg class, which is a specific
|
* This file contains the definition of the Modbus_Ireg class, which is a specific
|
||||||
* implementation of the ModbusPoint for handling input registers (16-bit read-only).
|
* implementation of the Modbus_Point for handling input registers (16-bit read-only).
|
||||||
*/
|
*/
|
||||||
#ifndef ModbusIreg_h
|
#ifndef Modbus_Ireg_h
|
||||||
#define ModbusIreg_h
|
#define Modbus_Ireg_h
|
||||||
|
|
||||||
#include "ModbusPoint.h"
|
#include "Modbus_Point.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class ModbusIreg
|
* @class Modbus_Ireg
|
||||||
* @brief Represents a Modbus Input Register point.
|
* @brief Represents a Modbus Input Register point.
|
||||||
*
|
*
|
||||||
* This class provides a concrete implementation for a Modbus input register,
|
* 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.
|
* and implements its virtual functions for input register-specific operations.
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class ModbusIreg : public ModbusPoint<T>{
|
class Modbus_Ireg : public Modbus_Point<T>{
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief Constructor for the ModbusIreg class.
|
* @brief Constructor for the Modbus_Ireg class.
|
||||||
* @param server Pointer to the ModbusIP server instance.
|
* @param server Pointer to the ModbusIP server instance.
|
||||||
* @param address The Modbus address of the input register.
|
* @param address The Modbus address of the input register.
|
||||||
* @param value The initial value of the input register.
|
* @param value The initial value of the input register.
|
||||||
* @param description A description 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.
|
* @brief Adds the input register to the Modbus server.
|
||||||
@@ -50,8 +50,8 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
ModbusIreg<T>::ModbusIreg(T* server, int address, int value, const char* description)
|
Modbus_Ireg<T>::Modbus_Ireg(T* server, int address, int value, const char* description)
|
||||||
: ModbusPoint<T>(server, address, value, description){}
|
: Modbus_Point<T>(server, address, value, description){}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Sets the value of the input register on the Modbus server.
|
* @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.
|
* @param value The new 16-bit value for the register.
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void ModbusIreg<T>::setValue(int value){
|
void Modbus_Ireg<T>::setValue(int value){
|
||||||
this->_server->Ireg(this->_address, 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.
|
* @return The current 16-bit value from the register.
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
int ModbusIreg<T>::getValue() const {
|
int Modbus_Ireg<T>::getValue() const {
|
||||||
return this->_server->Ireg(this->_address);
|
return this->_server->Ireg(this->_address);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,7 +79,7 @@ int ModbusIreg<T>::getValue() const {
|
|||||||
* register at the specified address with its initial value.
|
* register at the specified address with its initial value.
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void ModbusIreg<T>::addToModbusServer(){
|
void Modbus_Ireg<T>::addToModbusServer(){
|
||||||
this->_server->addIreg(this->_address, this->_value);
|
this->_server->addIreg(this->_address, this->_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,36 +1,36 @@
|
|||||||
/**
|
/**
|
||||||
* @file ModbusIsts.h
|
* @file Modbus_Ists.h
|
||||||
* @brief Defines the ModbusIsts class for handling Modbus Input Status (Discrete Inputs).
|
* @brief Defines the Modbus_Ists class for handling Modbus Input Status (Discrete Inputs).
|
||||||
* @author Emmanuel Hernandez Cruz
|
* @author Emmanuel Hernandez Cruz
|
||||||
* @date 2025-09-04
|
* @date 2025-09-04
|
||||||
*
|
*
|
||||||
* This file contains the definition of the ModbusIsts class, which is a specific
|
* This file contains the definition of the Modbus_Ists class, which is a specific
|
||||||
* implementation of the ModbusPoint for handling discrete inputs (read-only coils).
|
* implementation of the Modbus_Point for handling discrete inputs (read-only coils).
|
||||||
*/
|
*/
|
||||||
#ifndef ModbusIsts_h
|
#ifndef Modbus_Ists_h
|
||||||
#define ModbusIsts_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.
|
* @brief Represents a Modbus Input Status (Discrete Input) point.
|
||||||
*
|
*
|
||||||
* This class provides a concrete implementation for a Modbus discrete input,
|
* 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.
|
* and implements its virtual functions for discrete input-specific operations.
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class ModbusIsts : public ModbusPoint<T>{
|
class Modbus_Ists : public Modbus_Point<T>{
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief Constructor for the ModbusIsts class.
|
* @brief Constructor for the Modbus_Ists class.
|
||||||
* @param server Pointer to the ModbusIP server instance.
|
* @param server Pointer to the ModbusIP server instance.
|
||||||
* @param address The Modbus address of the discrete input.
|
* @param address The Modbus address of the discrete input.
|
||||||
* @param value The initial value of the discrete input.
|
* @param value The initial value of the discrete input.
|
||||||
* @param description A description 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.
|
* @brief Adds the discrete input to the Modbus server.
|
||||||
@@ -51,8 +51,8 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
ModbusIsts<T>::ModbusIsts(T* server, int address, int value, const char* description)
|
Modbus_Ists<T>::Modbus_Ists(T* server, int address, int value, const char* description)
|
||||||
: ModbusPoint<T>(server, address, value, description) {}
|
: Modbus_Point<T>(server, address, value, description) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Sets the value of the discrete input on the Modbus server.
|
* @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.
|
* @param value The new value for the discrete input.
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void ModbusIsts<T>::setValue(int value){
|
void Modbus_Ists<T>::setValue(int value){
|
||||||
this->_server->Ists(this->_address, value);
|
this->_server->Ists(this->_address, value);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -70,7 +70,7 @@ void ModbusIsts<T>::setValue(int value){
|
|||||||
* @return The current value.
|
* @return The current value.
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
int ModbusIsts<T>::getValue() const{
|
int Modbus_Ists<T>::getValue() const{
|
||||||
return this->_server->Ists(this->_address);
|
return this->_server->Ists(this->_address);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -79,7 +79,7 @@ int ModbusIsts<T>::getValue() const{
|
|||||||
* input at the specified address with its initial value.
|
* input at the specified address with its initial value.
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void ModbusIsts<T>::addToModbusServer(){
|
void Modbus_Ists<T>::addToModbusServer(){
|
||||||
this->_server->addIsts(this->_address, this->_value);
|
this->_server->addIsts(this->_address, this->_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,36 +1,36 @@
|
|||||||
/**
|
/**
|
||||||
* @file ModbusLongDecorator.h
|
* @file Modbus_LongDecorator.h
|
||||||
* @brief Defines the ModbusLongDecorator class for handling 32-bit long values.
|
* @brief Defines the Modbus_LongDecorator class for handling 32-bit long values.
|
||||||
* @author Emmanuel Hernandez Cruz
|
* @author Emmanuel Hernandez Cruz
|
||||||
* @date 2025-09-05
|
* @date 2025-09-05
|
||||||
*
|
*
|
||||||
* This file contains the definition for a decorator that combines two 16-bit
|
* This file contains the definition for a decorator that combines two 16-bit
|
||||||
* Modbus registers to represent a single 32-bit long integer value.
|
* Modbus registers to represent a single 32-bit long integer value.
|
||||||
*/
|
*/
|
||||||
#ifndef ModbusLongDecorator_h
|
#ifndef Modbus_LongDecorator_h
|
||||||
#define ModbusLongDecorator_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.
|
* @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
|
* high-word point) and treats them as a single 32-bit long integer. It
|
||||||
* overrides the necessary methods to handle reading, writing, and value
|
* overrides the necessary methods to handle reading, writing, and value
|
||||||
* conversion across both underlying registers.
|
* conversion across both underlying registers.
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class ModbusLongDecorator : public ModbusPointDecorator<T> {
|
class Modbus_LongDecorator : public Modbus_PointDecorator<T> {
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief Constructs a new ModbusLongDecorator.
|
* @brief Constructs a new Modbus_LongDecorator.
|
||||||
* @param point A pointer to the ModbusPoint for the low-order word (LSW).
|
* @param point A pointer to the Modbus_Point for the low-order word (LSW).
|
||||||
* @param highOrderPoint A pointer to the ModbusPoint for the high-order word (MSW).
|
* @param highOrderPoint A pointer to the Modbus_Point for the high-order word (MSW).
|
||||||
*/
|
*/
|
||||||
ModbusLongDecorator(ModbusPoint<T>* point, ModbusPoint<T>* highOrderPoint)
|
Modbus_LongDecorator(Modbus_Point<T>* point, Modbus_Point<T>* highOrderPoint)
|
||||||
: ModbusPointDecorator<T>(point), _highOrderPoint(highOrderPoint) {}
|
: Modbus_PointDecorator<T>(point), _highOrderPoint(highOrderPoint) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns the logical type of the point.
|
* @brief Returns the logical type of the point.
|
||||||
@@ -91,7 +91,7 @@ public:
|
|||||||
return static_cast<int>(getLongValue());
|
return static_cast<int>(getLongValue());
|
||||||
}
|
}
|
||||||
private:
|
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
|
#endif
|
||||||
@@ -1,15 +1,15 @@
|
|||||||
/**
|
/**
|
||||||
* @file ModbusPoint.h
|
* @file Modbus_Point.h
|
||||||
* @brief Defines the abstract base class for all Modbus points.
|
* @brief Defines the abstract base class for all Modbus points.
|
||||||
* @author Emmanuel Hernandez Cruz
|
* @author Emmanuel Hernandez Cruz
|
||||||
* @date 2025-09-04
|
* @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.).
|
* serves as the base for all specific Modbus point types (Coils, Registers, etc.).
|
||||||
* It defines the common interface for interacting with Modbus points.
|
* It defines the common interface for interacting with Modbus points.
|
||||||
*/
|
*/
|
||||||
#ifndef ModbusPoint_h
|
#ifndef Modbus_Point_h
|
||||||
#define ModbusPoint_h
|
#define Modbus_Point_h
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
/**
|
/**
|
||||||
* @enum PointType
|
* @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.
|
* @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
|
* 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.
|
* must inherit from this class and implement its pure virtual functions.
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class ModbusPoint{
|
class Modbus_Point{
|
||||||
public:
|
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 server Pointer to the Modbus server instance (e.g., ModbusIP or ModbusRTU).
|
||||||
* @param address The Modbus address of the point.
|
* @param address The Modbus address of the point.
|
||||||
* @param value The initial value of the point.
|
* @param value The initial value of the point.
|
||||||
* @param description A descriptive name for 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 ---
|
// --- Getters ---
|
||||||
/** @brief Gets a pointer to the Modbus server instance. */
|
/** @brief Gets a pointer to the Modbus server instance. */
|
||||||
@@ -81,7 +81,7 @@ public:
|
|||||||
void setDirty(bool dirty) { _dirty = dirty; }
|
void setDirty(bool dirty) { _dirty = dirty; }
|
||||||
|
|
||||||
/** @brief Virtual destructor to ensure proper cleanup of derived classes. */
|
/** @brief Virtual destructor to ensure proper cleanup of derived classes. */
|
||||||
virtual ~ModbusPoint() = default;
|
virtual ~Modbus_Point() = default;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
T* _server; /**< @brief Pointer to the global Modbus server instance. */
|
T* _server; /**< @brief Pointer to the global Modbus server instance. */
|
||||||
@@ -92,7 +92,7 @@ protected:
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
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) {
|
: _server(server), _address(address), _value(value) {
|
||||||
strncpy(_description, description, sizeof(_description) - 1);
|
strncpy(_description, description, sizeof(_description) - 1);
|
||||||
_description[sizeof(_description) - 1] = '\0';
|
_description[sizeof(_description) - 1] = '\0';
|
||||||
@@ -1,41 +1,41 @@
|
|||||||
/**
|
/**
|
||||||
* @file ModbusPointDecorator.h
|
* @file Modbus_PointDecorator.h
|
||||||
* @brief Defines the base decorator class for Modbus points.
|
* @brief Defines the base decorator class for Modbus points.
|
||||||
* @author Emmanuel Hernandez Cruz
|
* @author Emmanuel Hernandez Cruz
|
||||||
* @date 2025-09-05
|
* @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.
|
* 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
|
#ifndef Modbus_PointDecorator_h
|
||||||
#define ModbusPointDecorator_h
|
#define Modbus_PointDecorator_h
|
||||||
#include "ModbusPoint.h"
|
#include "Modbus_Point.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class ModbusPointDecorator
|
* @class Modbus_PointDecorator
|
||||||
* @brief An abstract base class for decorating ModbusPoint objects.
|
* @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
|
* and provides a default implementation for all virtual methods that simply
|
||||||
* delegate the call to the wrapped object. Concrete decorators should inherit
|
* delegate the call to the wrapped object. Concrete decorators should inherit
|
||||||
* from this class and override the specific methods they need to modify.
|
* from this class and override the specific methods they need to modify.
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class ModbusPointDecorator : public ModbusPoint<T>{
|
class Modbus_PointDecorator : public Modbus_Point<T>{
|
||||||
public:
|
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.
|
* and stores a pointer to the wrapped point.
|
||||||
*
|
*
|
||||||
* @note The decorator does not take ownership of the wrapped point. The
|
* @note The decorator does not take ownership of the wrapped point. The
|
||||||
* caller is responsible for managing its lifecycle.
|
* 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->getServer(),
|
||||||
point->getAddress(),
|
point->getAddress(),
|
||||||
point->getInitialValue(),
|
point->getInitialValue(),
|
||||||
@@ -46,7 +46,7 @@ public:
|
|||||||
* @brief Virtual destructor.
|
* @brief Virtual destructor.
|
||||||
* Does not delete the wrapped `_point` as it does not own it.
|
* Does not delete the wrapped `_point` as it does not own it.
|
||||||
*/
|
*/
|
||||||
virtual ~ModbusPointDecorator() = default;
|
virtual ~Modbus_PointDecorator() = default;
|
||||||
|
|
||||||
// --- Delegated Methods ---
|
// --- Delegated Methods ---
|
||||||
// These methods simply forward the call to the wrapped _point object.
|
// 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.
|
* @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{
|
void addToModbusServer() override{
|
||||||
_point->addToModbusServer();
|
_point->addToModbusServer();
|
||||||
@@ -62,14 +62,14 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Delegates the call to set the point's value.
|
* @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 {
|
void setValue(int value) override {
|
||||||
_point->setValue(value);
|
_point->setValue(value);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @brief Delegates the call to get the point's 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.
|
* @return The value from the wrapped point.
|
||||||
*/
|
*/
|
||||||
int getValue() const override{
|
int getValue() const override{
|
||||||
@@ -77,6 +77,6 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ModbusPoint<T>* _point; /**< @brief Pointer to the wrapped ModbusPoint object. */
|
Modbus_Point<T>* _point; /**< @brief Pointer to the wrapped Modbus_Point object. */
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
@@ -1,31 +1,31 @@
|
|||||||
/**
|
/**
|
||||||
* @file ModbusPointFactory.h
|
* @file Modbus_PointFactory.h
|
||||||
* @brief Defines the factory function for creating ModbusPoint objects.
|
* @brief Defines the factory function for creating Modbus_Point objects.
|
||||||
* @author Emmanuel Hernandez Cruz
|
* @author Emmanuel Hernandez Cruz
|
||||||
* @date 2025-09-05
|
* @date 2025-09-05
|
||||||
*
|
*
|
||||||
* This file provides the interface for a factory function that simplifies the
|
* 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).
|
* their decorators (e.g., for scaling, float, or long values).
|
||||||
*/
|
*/
|
||||||
#ifndef ModbusPointFactory_h
|
#ifndef Modbus_PointFactory_h
|
||||||
#define ModbusPointFactory_h
|
#define Modbus_PointFactory_h
|
||||||
#include "ModbusPoint.h"
|
#include "Modbus_Point.h"
|
||||||
#include "ModbusCoil.h"
|
#include "Modbus_Coil.h"
|
||||||
#include "ModbusIsts.h"
|
#include "Modbus_Ists.h"
|
||||||
#include "ModbusIreg.h"
|
#include "Modbus_Ireg.h"
|
||||||
#include "ModbusHreg.h"
|
#include "Modbus_Hreg.h"
|
||||||
#include "ModbusScaleDecorator.h"
|
#include "Modbus_ScaleDecorator.h"
|
||||||
#include "ModbusLongDecorator.h"
|
#include "Modbus_LongDecorator.h"
|
||||||
#include "ModbusFloatDecorator.h"
|
#include "Modbus_FloatDecorator.h"
|
||||||
#include <Arduino.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
|
* 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
|
* floats, or longs). It encapsulates the logic for building both simple
|
||||||
* single-register points and complex multi-register points.
|
* 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
|
* @param value The initial value for the point. Note: This is ignored for
|
||||||
* multi-register types, which are initialized to 0.
|
* multi-register types, which are initialized to 0.
|
||||||
* @param description A descriptive name for the point.
|
* @param description A descriptive name for the point.
|
||||||
* @return A pointer to the newly created ModbusPoint object.
|
* @return A pointer to the newly created Modbus_Point object.
|
||||||
* @retval ModbusPoint* A pointer to the fully constructed (and possibly
|
* @retval Modbus_Point* A pointer to the fully constructed (and possibly
|
||||||
* decorated) Modbus point. The caller is responsible for
|
* decorated) Modbus point. The caller is responsible for
|
||||||
* managing the memory of this object.
|
* managing the memory of this object.
|
||||||
* @retval nullptr If the category code is not recognized.
|
* @retval nullptr If the category code is not recognized.
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
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
|
* 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>
|
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) {
|
switch (category) {
|
||||||
case COIL:
|
case COIL:
|
||||||
Serial.printf("Creating Coil: %s\n", description);
|
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:
|
case DI:
|
||||||
Serial.printf("Creating Digital Input: %s\n", description);
|
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:
|
case IR:
|
||||||
Serial.printf("Creating Input Register: %s\n", description);
|
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: {
|
case IR_10X: {
|
||||||
Serial.printf("Creating Scaled Input Register (10x): %s\n", description);
|
Serial.printf("Creating Scaled Input Register (10x): %s\n", description);
|
||||||
ModbusPoint<T>* point = new ModbusIreg<T>(server, address, value, description);
|
Modbus_Point<T>* point = new Modbus_Ireg<T>(server, address, value, description);
|
||||||
return new ModbusScaleDecorator<T>(point);
|
return new Modbus_ScaleDecorator<T>(point);
|
||||||
}
|
}
|
||||||
case IR_LONG: {
|
case IR_LONG: {
|
||||||
Serial.printf("Creating Input Register Long: %s\n", description);
|
Serial.printf("Creating Input Register Long: %s\n", description);
|
||||||
// Create the low and high word registers for the 32-bit long
|
// Create the low and high word registers for the 32-bit long
|
||||||
ModbusPoint<T>* point = new ModbusIreg<T>(server, address, 0, description);
|
Modbus_Point<T>* point = new Modbus_Ireg<T>(server, address, 0, description);
|
||||||
ModbusPoint<T>* highOrderPoint = new ModbusIreg<T>(server, address + 1, 0, "");
|
Modbus_Point<T>* highOrderPoint = new Modbus_Ireg<T>(server, address + 1, 0, "");
|
||||||
return new ModbusLongDecorator<T>(point, highOrderPoint);
|
return new Modbus_LongDecorator<T>(point, highOrderPoint);
|
||||||
}
|
}
|
||||||
case IR_FLOAT: {
|
case IR_FLOAT: {
|
||||||
Serial.printf("Creating Input Register Float: %s\n", description);
|
Serial.printf("Creating Input Register Float: %s\n", description);
|
||||||
// Create the low and high word registers for the 32-bit float
|
// Create the low and high word registers for the 32-bit float
|
||||||
ModbusPoint<T>* point = new ModbusIreg<T>(server, address, 0, description);
|
Modbus_Point<T>* point = new Modbus_Ireg<T>(server, address, 0, description);
|
||||||
ModbusPoint<T>* highOrderPoint = new ModbusIreg<T>(server, address + 1, 0, "");
|
Modbus_Point<T>* highOrderPoint = new Modbus_Ireg<T>(server, address + 1, 0, "");
|
||||||
return new ModbusFloatDecorator<T>(point, highOrderPoint);
|
return new Modbus_FloatDecorator<T>(point, highOrderPoint);
|
||||||
}
|
}
|
||||||
case HR:
|
case HR:
|
||||||
Serial.printf("Creating Holding Register: %s\n", description);
|
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: {
|
case HR_10x: {
|
||||||
Serial.printf("Creating Scaled Holding Register (10x): %s\n", description);
|
Serial.printf("Creating Scaled Holding Register (10x): %s\n", description);
|
||||||
// Create a base holding register and wrap it with the scaling decorator
|
// Create a base holding register and wrap it with the scaling decorator
|
||||||
ModbusPoint<T>* point = new ModbusHreg<T>(server, address, value, description);
|
Modbus_Point<T>* point = new Modbus_Hreg<T>(server, address, value, description);
|
||||||
return new ModbusScaleDecorator<T>(point);
|
return new Modbus_ScaleDecorator<T>(point);
|
||||||
}
|
}
|
||||||
case HR_LONG: {
|
case HR_LONG: {
|
||||||
Serial.printf("Creating Holding Register Long: %s\n", description);
|
Serial.printf("Creating Holding Register Long: %s\n", description);
|
||||||
// Create the low and high word registers for the 32-bit long
|
// Create the low and high word registers for the 32-bit long
|
||||||
ModbusPoint<T>* point = new ModbusHreg<T>(server, address, 0, description);
|
Modbus_Point<T>* point = new Modbus_Hreg<T>(server, address, 0, description);
|
||||||
ModbusPoint<T>* highOrderPoint = new ModbusHreg<T>(server, address + 1 , 0, "");
|
Modbus_Point<T>* highOrderPoint = new Modbus_Hreg<T>(server, address + 1 , 0, "");
|
||||||
return new ModbusLongDecorator<T>(point, highOrderPoint);
|
return new Modbus_LongDecorator<T>(point, highOrderPoint);
|
||||||
}
|
}
|
||||||
case HR_FLOAT: {
|
case HR_FLOAT: {
|
||||||
Serial.printf("Creating Holding Register Float: %s\n", description);
|
Serial.printf("Creating Holding Register Float: %s\n", description);
|
||||||
// Create the low and high word registers for the 32-bit float
|
// Create the low and high word registers for the 32-bit float
|
||||||
ModbusPoint<T>* point = new ModbusHreg<T>(server, address, 0, description);
|
Modbus_Point<T>* point = new Modbus_Hreg<T>(server, address, 0, description);
|
||||||
ModbusPoint<T>* highOrderPoint = new ModbusHreg<T>(server, address + 1 , 0, "");
|
Modbus_Point<T>* highOrderPoint = new Modbus_Hreg<T>(server, address + 1 , 0, "");
|
||||||
return new ModbusFloatDecorator<T>(point, highOrderPoint);
|
return new Modbus_FloatDecorator<T>(point, highOrderPoint);
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
Serial.printf("ERROR: Unknown Modbus category %d for '%s'\n", category, description);
|
Serial.printf("ERROR: Unknown Modbus category %d for '%s'\n", category, description);
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
/**
|
/**
|
||||||
* @file ModbusScaleDecorator.h
|
* @file Modbus_ScaleDecorator.h
|
||||||
* @brief Defines the ModbusScaleDecorator class for scaling Modbus point values.
|
* @brief Defines the Modbus_ScaleDecorator class for scaling Modbus point values.
|
||||||
* @author Emmanuel Hernandez Cruz
|
* @author Emmanuel Hernandez Cruz
|
||||||
* @date 2025-09-05
|
* @date 2025-09-05
|
||||||
*
|
*
|
||||||
@@ -8,16 +8,16 @@
|
|||||||
* factor to a Modbus point. This is useful for representing decimal values
|
* factor to a Modbus point. This is useful for representing decimal values
|
||||||
* in integer registers (e.g., storing 12.3 as 123).
|
* in integer registers (e.g., storing 12.3 as 123).
|
||||||
*/
|
*/
|
||||||
#ifndef ModbusScaleDecorator_h
|
#ifndef Modbus_ScaleDecorator_h
|
||||||
#define ModbusScaleDecorator_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.
|
* @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
|
* 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
|
* register to represent a value with one decimal place (e.g., storing the
|
||||||
* logical value 12.3 as the integer 123).
|
* logical value 12.3 as the integer 123).
|
||||||
@@ -26,13 +26,13 @@
|
|||||||
* - `getValue()` will read `123` from the underlying point and return `12`.
|
* - `getValue()` will read `123` from the underlying point and return `12`.
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class ModbusScaleDecorator : public ModbusPointDecorator<T> {
|
class Modbus_ScaleDecorator : public Modbus_PointDecorator<T> {
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief Constructs a new ModbusScaleDecorator.
|
* @brief Constructs a new Modbus_ScaleDecorator.
|
||||||
* @param point A pointer to the ModbusPoint object to be decorated.
|
* @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.
|
* @brief Sets the raw integer value on the underlying point.
|
||||||
@@ -14,8 +14,8 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include "Strategies/Strategy_PID.h"
|
#include "Strategies/Strategy_PID.h"
|
||||||
#include "Categories/ModbusFloatDecorator.h"
|
#include "ModbusPoints/Modbus_FloatDecorator.h"
|
||||||
#include "Categories/ModbusPoint.h"
|
#include "ModbusPoints/Modbus_Point.h"
|
||||||
|
|
||||||
// Forward Declarations
|
// Forward Declarations
|
||||||
template<typename T>class Equipment;
|
template<typename T>class Equipment;
|
||||||
@@ -66,7 +66,7 @@ protected:
|
|||||||
/**
|
/**
|
||||||
* @brief Gets the value of a Modbus point, handling float types correctly.
|
* @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
|
* 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 equipment Pointer to the Equipment instance.
|
||||||
* @param pointName The description key of the Modbus point to read.
|
* @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.
|
* @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.
|
* @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
|
* 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 equipment Pointer to the Equipment instance.
|
||||||
* @param pointName The description key of the Modbus point to write to.
|
* @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.
|
* @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.
|
* @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
|
* `getFloatValue()` if it is. Otherwise, it gets the standard integer value and
|
||||||
* casts it to a float.
|
* casts it to a float.
|
||||||
* @param equipment Pointer to the Equipment instance.
|
* @param equipment Pointer to the Equipment instance.
|
||||||
@@ -122,12 +122,12 @@ void State<T>::addStrategy(const std::string& pointDescription, Strategy_Behavio
|
|||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
float State<T>::getPointValue(Equipment<T>* equipment, const std::string& pointName) {
|
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) return 0.0f;
|
||||||
|
|
||||||
if (point->getType() == PointType::FLOAT) {
|
if (point->getType() == PointType::FLOAT) {
|
||||||
// If it's a float, cast and get the full float value
|
// 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 {
|
} else {
|
||||||
// Otherwise, get the standard integer value
|
// Otherwise, get the standard integer value
|
||||||
return static_cast<float>(point->getValue());
|
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.
|
* @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
|
* `setFloatValue()` if it is. Otherwise, it rounds the float to the nearest
|
||||||
* integer and calls the standard `setValue()`.
|
* integer and calls the standard `setValue()`.
|
||||||
* @param equipment Pointer to the Equipment instance.
|
* @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>
|
template<typename T>
|
||||||
void State<T>::setPointValue(Equipment<T>* equipment, const std::string& pointName, float value) {
|
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) return;
|
||||||
|
|
||||||
if (point->getType() == PointType::FLOAT) {
|
if (point->getType() == PointType::FLOAT) {
|
||||||
static_cast<ModbusFloatDecorator<T>*>(point)->setFloatValue(value);
|
static_cast<Modbus_FloatDecorator<T>*>(point)->setFloatValue(value);
|
||||||
} else {
|
} else {
|
||||||
point->setValue(round(value));
|
point->setValue(round(value));
|
||||||
}
|
}
|
||||||
@@ -175,7 +175,7 @@ void State<T>::_applyStrategies(Equipment<T>* equipment) {
|
|||||||
Strategy_Behavior* strategy = pair.second;
|
Strategy_Behavior* strategy = pair.second;
|
||||||
|
|
||||||
if (strategy->isReady(currentTime)) {
|
if (strategy->isReady(currentTime)) {
|
||||||
ModbusPoint<T>* outputPoint = equipment->getModbusPoint(description);
|
Modbus_Point<T>* outputPoint = equipment->getModbus_Point(description);
|
||||||
if (!outputPoint) continue;
|
if (!outputPoint) continue;
|
||||||
|
|
||||||
float inputValue;
|
float inputValue;
|
||||||
@@ -184,7 +184,7 @@ void State<T>::_applyStrategies(Equipment<T>* equipment) {
|
|||||||
PIDStrategy* pid = static_cast<PIDStrategy*>(strategy);
|
PIDStrategy* pid = static_cast<PIDStrategy*>(strategy);
|
||||||
inputValue = getPointValue(equipment, pid->getInputSensorName());
|
inputValue = getPointValue(equipment, pid->getInputSensorName());
|
||||||
|
|
||||||
ModbusPoint<T>* PIDsetpoint = equipment->getModbusPoint(pid->getSetpointName());
|
Modbus_Point<T>* PIDsetpoint = equipment->getModbus_Point(pid->getSetpointName());
|
||||||
if (PIDsetpoint) {
|
if (PIDsetpoint) {
|
||||||
pid->setSetpoint(PIDsetpoint->getValue());
|
pid->setSetpoint(PIDsetpoint->getValue());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
/**
|
/**
|
||||||
* @defgroup ModbusCategoryCodes Modbus Point Category Codes
|
* @defgroup ModbusCategoryCodes Modbus Point Category Codes
|
||||||
* @brief Integer constants used in the `modbusMap` to identify the type of Modbus point.
|
* @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 */
|
const int COIL = 0; /**< @brief 0x: R/W Coil */
|
||||||
|
|||||||
46
lib/README
46
lib/README
@@ -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 <Foo.h>
|
|
||||||
#include <Bar.h>
|
|
||||||
|
|
||||||
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
|
|
||||||
23
lib/README.md
Normal file
23
lib/README.md
Normal file
@@ -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.
|
||||||
@@ -7,10 +7,9 @@
|
|||||||
* This file contains the implementation for the FailState, which defines
|
* This file contains the implementation for the FailState, which defines
|
||||||
* the behavior of the equipment when it has entered a fault condition.
|
* the behavior of the equipment when it has entered a fault condition.
|
||||||
*/
|
*/
|
||||||
#include "States/State_Fail.h"
|
|
||||||
#include "States/State_Standby.h"
|
#include "States/State_Standby.h"
|
||||||
|
#include "States/State_Fail.h"
|
||||||
#include "Categories/ModbusPoint.h"
|
#include "ModbusPoints/Modbus_Point.h"
|
||||||
#include "Equipment/Equipment.h"
|
#include "Equipment/Equipment.h"
|
||||||
#include "Strategies/Strategy_SingleValue.h"
|
#include "Strategies/Strategy_SingleValue.h"
|
||||||
#include "Strategies/Strategy_PID.h"
|
#include "Strategies/Strategy_PID.h"
|
||||||
@@ -55,7 +54,7 @@ template<>
|
|||||||
State<ModbusRTU>* FailState<ModbusRTU>::update(Equipment<ModbusRTU>* equipment) {
|
State<ModbusRTU>* FailState<ModbusRTU>::update(Equipment<ModbusRTU>* equipment) {
|
||||||
// STATE control, add conditions if change to a different state is needed
|
// STATE control, add conditions if change to a different state is needed
|
||||||
Serial.println("Fail update function");
|
Serial.println("Fail update function");
|
||||||
ModbusPoint<ModbusRTU>* clearAlm = equipment->getModbusPoint("Clear Alm");
|
Modbus_Point<ModbusRTU>* clearAlm = equipment->getModbus_Point("Clear Alm");
|
||||||
int nextStateId = clearAlm ? clearAlm->getValue() : 0;
|
int nextStateId = clearAlm ? clearAlm->getValue() : 0;
|
||||||
if (nextStateId == 1){
|
if (nextStateId == 1){
|
||||||
return new StandbyState<ModbusRTU>();
|
return new StandbyState<ModbusRTU>();
|
||||||
@@ -72,7 +71,7 @@ template<>
|
|||||||
void FailState<ModbusRTU>::enterState(Equipment<ModbusRTU>* equipment) {
|
void FailState<ModbusRTU>::enterState(Equipment<ModbusRTU>* equipment) {
|
||||||
// Logic to run when the equipment enters this state
|
// Logic to run when the equipment enters this state
|
||||||
Serial.println("Enter Fail State...");
|
Serial.println("Enter Fail State...");
|
||||||
ModbusPoint<ModbusRTU>* alarm_common = equipment->getModbusPoint("Alarm Common");
|
Modbus_Point<ModbusRTU>* alarm_common = equipment->getModbus_Point("Alarm Common");
|
||||||
alarm_common->setValue(1);
|
alarm_common->setValue(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,6 +83,6 @@ template<>
|
|||||||
void FailState<ModbusRTU>::exitState(Equipment<ModbusRTU>* equipment) {
|
void FailState<ModbusRTU>::exitState(Equipment<ModbusRTU>* equipment) {
|
||||||
// Cleanup logic to run when the equipment leaves this state
|
// Cleanup logic to run when the equipment leaves this state
|
||||||
Serial.println("Exit Fail State...");
|
Serial.println("Exit Fail State...");
|
||||||
ModbusPoint<ModbusRTU>* alarm_common = equipment->getModbusPoint("Alarm Common");
|
Modbus_Point<ModbusRTU>* alarm_common = equipment->getModbus_Point("Alarm Common");
|
||||||
alarm_common->setValue(0);
|
alarm_common->setValue(0);
|
||||||
}
|
}
|
||||||
@@ -7,15 +7,16 @@
|
|||||||
* This file contains the implementation for the RunningState, which defines
|
* This file contains the implementation for the RunningState, which defines
|
||||||
* the behavior of the equipment when it is actively running.
|
* the behavior of the equipment when it is actively running.
|
||||||
*/
|
*/
|
||||||
#include "States/State_Running.h"
|
|
||||||
#include "States/State_Standby.h"
|
#include "States/State_Standby.h"
|
||||||
|
#include "States/State_Running.h"
|
||||||
#include "States/State_Fail.h"
|
#include "States/State_Fail.h"
|
||||||
#include "Strategies/Strategy_Behavior.h"
|
#include "Strategies/Strategy_Behavior.h"
|
||||||
#include "Strategies/Strategy_PID.h"
|
#include "Strategies/Strategy_PID.h"
|
||||||
#include "Strategies/Strategy_Totalizer.h"
|
#include "Strategies/Strategy_Totalizer.h"
|
||||||
#include "Equipment/Equipment.h"
|
#include "Equipment/Equipment.h"
|
||||||
#include "Categories/ModbusPoint.h"
|
#include "ModbusPoints/Modbus_Point.h"
|
||||||
#include "Categories/ModbusFloatDecorator.h"
|
#include "ModbusPoints/Modbus_FloatDecorator.h"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -64,14 +65,14 @@ template<>
|
|||||||
State<ModbusRTU>* RunningState<ModbusRTU>::update(Equipment<ModbusRTU>* equipment) {
|
State<ModbusRTU>* RunningState<ModbusRTU>::update(Equipment<ModbusRTU>* equipment) {
|
||||||
// STATE control, add conditions if change to a different state is needed
|
// STATE control, add conditions if change to a different state is needed
|
||||||
Serial.println("Running update function");
|
Serial.println("Running update function");
|
||||||
ModbusPoint<ModbusRTU>* On_Off_Command = equipment->getModbusPoint("ON/OFF Command By BMS");
|
Modbus_Point<ModbusRTU>* On_Off_Command = equipment->getModbus_Point("ON/OFF Command By BMS");
|
||||||
int nextStateId = On_Off_Command ? On_Off_Command->getValue() : 0;
|
int nextStateId = On_Off_Command ? On_Off_Command->getValue() : 0;
|
||||||
Serial.println(nextStateId);
|
Serial.println(nextStateId);
|
||||||
if (nextStateId == 0){
|
if (nextStateId == 0){
|
||||||
return new StandbyState<ModbusRTU>();
|
return new StandbyState<ModbusRTU>();
|
||||||
}
|
}
|
||||||
|
|
||||||
ModbusPoint<ModbusRTU>* faultCode = equipment->getModbusPoint("Fault Code");
|
Modbus_Point<ModbusRTU>* faultCode = equipment->getModbus_Point("Fault Code");
|
||||||
int faultCodeValue = faultCode ? faultCode->getValue() : 0;
|
int faultCodeValue = faultCode ? faultCode->getValue() : 0;
|
||||||
if (faultCodeValue != 0) {
|
if (faultCodeValue != 0) {
|
||||||
// A fault has been triggered, transition to FailState
|
// A fault has been triggered, transition to FailState
|
||||||
@@ -105,7 +106,7 @@ void RunningState<ModbusRTU>::enterState(Equipment<ModbusRTU>* equipment) {
|
|||||||
|
|
||||||
// Loop through and set all motor statuses to 0
|
// Loop through and set all motor statuses to 0
|
||||||
for (const auto& desc : motorStatusDescriptions) {
|
for (const auto& desc : motorStatusDescriptions) {
|
||||||
ModbusPoint<ModbusRTU>* point = equipment->getModbusPoint(desc);
|
Modbus_Point<ModbusRTU>* point = equipment->getModbus_Point(desc);
|
||||||
if (point) {
|
if (point) {
|
||||||
point->setValue(1);
|
point->setValue(1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,10 +7,10 @@
|
|||||||
* This file contains the implementation for the StandbyState, which defines
|
* This file contains the implementation for the StandbyState, which defines
|
||||||
* the behavior of the equipment when it is in an idle or standby mode.
|
* 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 "States/State_Running.h"
|
||||||
#include "Categories/ModbusPoint.h"
|
#include "States/State_Fail.h"
|
||||||
#include "Categories/ModbusFloatDecorator.h"
|
#include "ModbusPoints/Modbus_Point.h"
|
||||||
|
#include "ModbusPoints/Modbus_FloatDecorator.h"
|
||||||
#include "Equipment/Equipment.h"
|
#include "Equipment/Equipment.h"
|
||||||
#include "Strategies/Strategy_Random.h"
|
#include "Strategies/Strategy_Random.h"
|
||||||
|
|
||||||
@@ -53,7 +53,7 @@ template<>
|
|||||||
State<ModbusRTU>* StandbyState<ModbusRTU>::update(Equipment<ModbusRTU>* equipment) {
|
State<ModbusRTU>* StandbyState<ModbusRTU>::update(Equipment<ModbusRTU>* equipment) {
|
||||||
// STATE control, add conditions if change to a different state is needed
|
// STATE control, add conditions if change to a different state is needed
|
||||||
Serial.println("Standby update function");
|
Serial.println("Standby update function");
|
||||||
ModbusPoint<ModbusRTU>* chillerOnOff = equipment->getModbusPoint("Chiller On-Off");
|
Modbus_Point<ModbusRTU>* chillerOnOff = equipment->getModbus_Point("Chiller On-Off");
|
||||||
int nextStateId = chillerOnOff ? chillerOnOff->getValue() : 0;
|
int nextStateId = chillerOnOff ? chillerOnOff->getValue() : 0;
|
||||||
Serial.println(nextStateId);
|
Serial.println(nextStateId);
|
||||||
if (nextStateId == 1){
|
if (nextStateId == 1){
|
||||||
|
|||||||
@@ -22,13 +22,13 @@
|
|||||||
* @see Equipment.h for the main equipment logic.
|
* @see Equipment.h for the main equipment logic.
|
||||||
* @see State.h for different equipment states.
|
* @see State.h for different equipment states.
|
||||||
* @see Strategies/Strategy_Behavior.h for value generation strategies.
|
* @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.
|
//Libraries and declaration of variables.
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include "config.h"
|
#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
|
mb.slave(MODBUS_ID); // Set the slave ID
|
||||||
|
|
||||||
for(int i = 0; i < map_size; i++){
|
for(int i = 0; i < map_size; i++){
|
||||||
ModbusPoint<ModbusRTU>* point = createModbusPoint(&mb, mb_map[i].category, mb_map[i].address, mb_map[i].value, mb_map[i].description);
|
Modbus_Point<ModbusRTU>* point = createModbus_Point(&mb, mb_map[i].category, mb_map[i].address, mb_map[i].value, mb_map[i].description);
|
||||||
if (point) {
|
if (point) {
|
||||||
point->addToModbusServer();
|
point->addToModbusServer();
|
||||||
EquipmentInstance.addModbusPoint(mb_map[i].description, point);
|
EquipmentInstance.addModbus_Point(mb_map[i].description, point);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Serial.println("Setup function ended");
|
Serial.println("Setup function ended");
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
* This file contains the implementation for the FailState, which defines
|
* This file contains the implementation for the FailState, which defines
|
||||||
* the behavior of the equipment when it has entered a fault condition.
|
* 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 "Equipment/Equipment.h"
|
||||||
#include "Strategies/Strategy_Ramp.h"
|
#include "Strategies/Strategy_Ramp.h"
|
||||||
#include "Strategies/Strategy_SingleValue.h"
|
#include "Strategies/Strategy_SingleValue.h"
|
||||||
@@ -56,7 +56,7 @@ template<>
|
|||||||
State<ModbusIP>* FailState<ModbusIP>::update(Equipment<ModbusIP>* equipment) {
|
State<ModbusIP>* FailState<ModbusIP>::update(Equipment<ModbusIP>* equipment) {
|
||||||
// STATE control, add conditions if change to a different state is needed
|
// STATE control, add conditions if change to a different state is needed
|
||||||
Serial.println("Fail update function");
|
Serial.println("Fail update function");
|
||||||
ModbusPoint<ModbusIP>* alarmReset = equipment->getModbusPoint("Alarm Reset");
|
Modbus_Point<ModbusIP>* alarmReset = equipment->getModbus_Point("Alarm Reset");
|
||||||
int nextStateId = alarmReset ? alarmReset->getValue() : 0;
|
int nextStateId = alarmReset ? alarmReset->getValue() : 0;
|
||||||
if (nextStateId == 1){
|
if (nextStateId == 1){
|
||||||
return new StandbyState<ModbusIP>();
|
return new StandbyState<ModbusIP>();
|
||||||
@@ -74,7 +74,7 @@ template<>
|
|||||||
void FailState<ModbusIP>::enterState(Equipment<ModbusIP>* equipment) {
|
void FailState<ModbusIP>::enterState(Equipment<ModbusIP>* equipment) {
|
||||||
// Logic to run when the equipment enters this state
|
// Logic to run when the equipment enters this state
|
||||||
Serial.println("Enter Fail State...");
|
Serial.println("Enter Fail State...");
|
||||||
ModbusPoint<ModbusIP>* alarm_common = equipment->getModbusPoint("Alarm Common");
|
Modbus_Point<ModbusIP>* alarm_common = equipment->getModbus_Point("Alarm Common");
|
||||||
alarm_common->setValue(1);
|
alarm_common->setValue(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,6 +87,6 @@ template<>
|
|||||||
void FailState<ModbusIP>::exitState(Equipment<ModbusIP>* equipment) {
|
void FailState<ModbusIP>::exitState(Equipment<ModbusIP>* equipment) {
|
||||||
// Cleanup logic to run when the equipment leaves this state
|
// Cleanup logic to run when the equipment leaves this state
|
||||||
Serial.println("Exit Fail State...");
|
Serial.println("Exit Fail State...");
|
||||||
ModbusPoint<ModbusIP>* alarm_common = equipment->getModbusPoint("Alarm Common");
|
Modbus_Point<ModbusIP>* alarm_common = equipment->getModbus_Point("Alarm Common");
|
||||||
alarm_common->setValue(0);
|
alarm_common->setValue(0);
|
||||||
}
|
}
|
||||||
@@ -7,8 +7,8 @@
|
|||||||
* This file contains the implementation for the RunningState, which defines
|
* This file contains the implementation for the RunningState, which defines
|
||||||
* the behavior of the equipment when it is actively running.
|
* the behavior of the equipment when it is actively running.
|
||||||
*/
|
*/
|
||||||
#include "Categories/ModbusPoint.h"
|
#include "ModbusPoints/Modbus_Point.h"
|
||||||
#include "Categories/ModbusFloatDecorator.h"
|
#include "ModbusPoints/Modbus_FloatDecorator.h"
|
||||||
#include "Equipment/Equipment.h"
|
#include "Equipment/Equipment.h"
|
||||||
#include "Strategies/Strategy_Ramp.h"
|
#include "Strategies/Strategy_Ramp.h"
|
||||||
#include "Strategies/Strategy_Random.h"
|
#include "Strategies/Strategy_Random.h"
|
||||||
@@ -67,14 +67,14 @@ template<>
|
|||||||
State<ModbusIP>* RunningState<ModbusIP>::update(Equipment<ModbusIP>* equipment) {
|
State<ModbusIP>* RunningState<ModbusIP>::update(Equipment<ModbusIP>* equipment) {
|
||||||
// STATE control, add conditions if change to a different state is needed
|
// STATE control, add conditions if change to a different state is needed
|
||||||
Serial.println("Running update function");
|
Serial.println("Running update function");
|
||||||
ModbusPoint<ModbusIP>* On_Off_Command = equipment->getModbusPoint("ON/OFF Command By BMS");
|
Modbus_Point<ModbusIP>* On_Off_Command = equipment->getModbus_Point("ON/OFF Command By BMS");
|
||||||
int nextStateId = On_Off_Command ? On_Off_Command->getValue() : 0;
|
int nextStateId = On_Off_Command ? On_Off_Command->getValue() : 0;
|
||||||
Serial.println(nextStateId);
|
Serial.println(nextStateId);
|
||||||
if (nextStateId == 0){
|
if (nextStateId == 0){
|
||||||
return new StandbyState<ModbusIP>();
|
return new StandbyState<ModbusIP>();
|
||||||
}
|
}
|
||||||
|
|
||||||
ModbusPoint<ModbusIP>* faultCode = equipment->getModbusPoint("Fault Code");
|
Modbus_Point<ModbusIP>* faultCode = equipment->getModbus_Point("Fault Code");
|
||||||
int faultCodeValue = faultCode ? faultCode->getValue() : 0;
|
int faultCodeValue = faultCode ? faultCode->getValue() : 0;
|
||||||
switch (faultCodeValue){
|
switch (faultCodeValue){
|
||||||
case 1:
|
case 1:
|
||||||
@@ -155,7 +155,7 @@ void RunningState<ModbusIP>::enterState(Equipment<ModbusIP>* equipment) {
|
|||||||
|
|
||||||
// Loop through and set all motor statuses to 0
|
// Loop through and set all motor statuses to 0
|
||||||
for (const auto& desc : motorStatusDescriptions) {
|
for (const auto& desc : motorStatusDescriptions) {
|
||||||
ModbusPoint<ModbusIP>* point = equipment->getModbusPoint(desc);
|
Modbus_Point<ModbusIP>* point = equipment->getModbus_Point(desc);
|
||||||
if (point) {
|
if (point) {
|
||||||
point->setValue(1);
|
point->setValue(1);
|
||||||
}
|
}
|
||||||
@@ -179,7 +179,7 @@ void RunningState<ModbusIP>::exitState(Equipment<ModbusIP>* equipment) {
|
|||||||
|
|
||||||
// Loop through and set all motor statuses to 0
|
// Loop through and set all motor statuses to 0
|
||||||
for (const auto& desc : motorStatusDescriptions) {
|
for (const auto& desc : motorStatusDescriptions) {
|
||||||
ModbusPoint<ModbusIP>* point = equipment->getModbusPoint(desc);
|
Modbus_Point<ModbusIP>* point = equipment->getModbus_Point(desc);
|
||||||
if (point) {
|
if (point) {
|
||||||
point->setValue(0);
|
point->setValue(0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,8 @@
|
|||||||
* This file contains the implementation for the StandbyState, which defines
|
* This file contains the implementation for the StandbyState, which defines
|
||||||
* the behavior of the equipment when it is in an idle or standby mode.
|
* the behavior of the equipment when it is in an idle or standby mode.
|
||||||
*/
|
*/
|
||||||
#include "Categories/ModbusPoint.h"
|
#include "ModbusPoints/Modbus_Point.h"
|
||||||
#include "Categories/ModbusFloatDecorator.h"
|
#include "ModbusPoints/Modbus_FloatDecorator.h"
|
||||||
#include "Equipment/Equipment.h"
|
#include "Equipment/Equipment.h"
|
||||||
#include "Strategies/Strategy_Ramp.h"
|
#include "Strategies/Strategy_Ramp.h"
|
||||||
#include "Strategies/Strategy_Random.h"
|
#include "Strategies/Strategy_Random.h"
|
||||||
@@ -109,7 +109,7 @@ void StandbyState<ModbusIP>::enterState(Equipment<ModbusIP>* equipment) {
|
|||||||
|
|
||||||
// Loop through and set all alarms to 0
|
// Loop through and set all alarms to 0
|
||||||
for (const auto& desc : alarmDescriptions) {
|
for (const auto& desc : alarmDescriptions) {
|
||||||
ModbusPoint<ModbusIP>* point = equipment->getModbusPoint(desc);
|
Modbus_Point<ModbusIP>* point = equipment->getModbus_Point(desc);
|
||||||
if (point) {
|
if (point) {
|
||||||
point->setValue(0);
|
point->setValue(0);
|
||||||
}
|
}
|
||||||
@@ -117,7 +117,7 @@ void StandbyState<ModbusIP>::enterState(Equipment<ModbusIP>* equipment) {
|
|||||||
|
|
||||||
// Loop through and set all motor statuses to 0
|
// Loop through and set all motor statuses to 0
|
||||||
for (const auto& desc : motorStatusDescriptions) {
|
for (const auto& desc : motorStatusDescriptions) {
|
||||||
ModbusPoint<ModbusIP>* point = equipment->getModbusPoint(desc);
|
Modbus_Point<ModbusIP>* point = equipment->getModbus_Point(desc);
|
||||||
if (point) {
|
if (point) {
|
||||||
point->setValue(0);
|
point->setValue(0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,13 +22,13 @@
|
|||||||
* @see Equipment.h for the main equipment logic.
|
* @see Equipment.h for the main equipment logic.
|
||||||
* @see State.h for different equipment states.
|
* @see State.h for different equipment states.
|
||||||
* @see Strategies/Strategy_Behavior.h for value generation strategies.
|
* @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.
|
//Libraries and declaration of variables.
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "Categories/ModbusPointFactory.h"
|
#include "ModbusPoints/Modbus_PointFactory.h"
|
||||||
#if defined(USE_MODBUS_IP)
|
#if defined(USE_MODBUS_IP)
|
||||||
#include <ModbusIP_ESP8266.h>
|
#include <ModbusIP_ESP8266.h>
|
||||||
#else
|
#else
|
||||||
@@ -54,10 +54,10 @@ void setup() {
|
|||||||
Serial.println("Server Created");
|
Serial.println("Server Created");
|
||||||
Serial.println(map_size);
|
Serial.println(map_size);
|
||||||
for(int i = 0; i < map_size; i++){
|
for(int i = 0; i < map_size; i++){
|
||||||
ModbusPoint<ModbusIP>* point = createModbusPoint(&mb, mb_map[i].category, mb_map[i].address, mb_map[i].value, mb_map[i].description);
|
Modbus_Point<ModbusIP>* point = createModbus_Point(&mb, mb_map[i].category, mb_map[i].address, mb_map[i].value, mb_map[i].description);
|
||||||
if (point) {
|
if (point) {
|
||||||
point->addToModbusServer();
|
point->addToModbusServer();
|
||||||
EquipmentInstance.addModbusPoint(mb_map[i].description, point);
|
EquipmentInstance.addModbus_Point(mb_map[i].description, point);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Serial.println("All modbus Points created");
|
Serial.println("All modbus Points created");
|
||||||
|
|||||||
Reference in New Issue
Block a user