Complied V2 version, ready to start testing and start developing GUI

This commit is contained in:
Emmanuel HC
2026-07-09 02:38:18 -05:00
parent c4a30b62f8
commit 9b68b219cd
447 changed files with 12911 additions and 29278 deletions

View File

@@ -11,6 +11,7 @@
#ifndef Modbus_Point_h
#define Modbus_Point_h
#include <string.h>
#include "Strategies/Strategy_Behavior.h"
/**
* @enum PointType
* @brief Identifies the logical type of a Modbus point.
@@ -68,7 +69,18 @@ public:
virtual int getValue() const = 0;
// --- Dirty Flag ---
void setStrategy(Strategy_Behavior* strategy) {
if (_strategy != nullptr) delete _strategy;
_strategy = strategy;
}
void updateStrategy(unsigned long currentMillis) {
if (_strategy != nullptr && _strategy->isReady(currentMillis)) {
float currentVal = this->getValue();
float newVal = _strategy->execute(currentVal);
this->setValue(newVal);
}
}
/**
* @brief Checks if the point's value has changed since the last write.
* @return True if the value is dirty, false otherwise.
@@ -88,7 +100,8 @@ protected:
int _address; /**< @brief The Modbus address of this point. */
int _value; /**< @brief The current internal value of this point. */
char _description[35]; /**< @brief A descriptive name for this point. */
bool _dirty = false; /**< @brief Flag to track if the value has changed and needs to be written. */
bool _dirty = false;
Strategy_Behavior* _strategy = nullptr; /**< @brief Flag to track if the value has changed and needs to be written. */
};
template<typename T>

View File

@@ -19,8 +19,20 @@
#include "Modbus_LongDecorator.h"
#include "Modbus_FloatDecorator.h"
#include <Arduino.h>
#include <ModbusIP_ESP8266.h>
enum ModbusCategory {
COIL = 1,
DI = 2,
IR = 3,
IR_10x = 31,
IR_LONG = 32,
IR_FLOAT = 33,
HR = 4,
HR_10x = 41,
HR_LONG = 42,
HR_FLOAT = 43
};
/**
* @brief Creates and decorates a Modbus_Point object based on its type.
*
@@ -55,56 +67,57 @@ Modbus_Point<T>* createModbus_Point(T* server, int category, int address, int va
*/
template<typename T>
Modbus_Point<T>* createModbus_Point(T* server, int category, int address, int value, const char* description) {
ModbusCategory mc = static_cast<ModbusCategory>(category);
switch (category) {
case COIL:
case 1:
Serial.printf("Creating Coil: %s\n", description);
return new Modbus_Coil<T>(server, address, value, description);
case DI:
case 2:
Serial.printf("Creating Digital Input: %s\n", description);
return new Modbus_Ists<T>(server, address, value, description);
case IR:
case 3:
Serial.printf("Creating Input Register: %s\n", description);
return new Modbus_Ireg<T>(server, address, value, description);
case IR_10x: {
case 31: {
Serial.printf("Creating Scaled Input Register (10x): %s\n", description);
Modbus_Point<T>* point = new Modbus_Ireg<T>(server, address, value, description);
return new Modbus_ScaleDecorator<T>(point);
}
case IR_LONG: {
case 32: {
Serial.printf("Creating Input Register Long: %s\n", description);
// Create the low and high word registers for the 32-bit long
Modbus_Point<T>* point = new Modbus_Ireg<T>(server, address, 0, description);
Modbus_Point<T>* highOrderPoint = new Modbus_Ireg<T>(server, address + 1, 0, "");
return new Modbus_LongDecorator<T>(point, highOrderPoint);
}
case IR_FLOAT: {
case 33: {
Serial.printf("Creating Input Register Float: %s\n", description);
// Create the low and high word registers for the 32-bit float
Modbus_Point<T>* point = new Modbus_Ireg<T>(server, address, 0, description);
Modbus_Point<T>* highOrderPoint = new Modbus_Ireg<T>(server, address + 1, 0, "");
return new Modbus_FloatDecorator<T>(point, highOrderPoint);
}
case HR:
case 4:
Serial.printf("Creating Holding Register: %s\n", description);
return new Modbus_Hreg<T>(server, address, value, description);
case HR_10x: {
case 41: {
Serial.printf("Creating Scaled Holding Register (10x): %s\n", description);
// Create a base holding register and wrap it with the scaling decorator
Modbus_Point<T>* point = new Modbus_Hreg<T>(server, address, value, description);
return new Modbus_ScaleDecorator<T>(point);
}
case HR_LONG: {
case 42: {
Serial.printf("Creating Holding Register Long: %s\n", description);
// Create the low and high word registers for the 32-bit long
Modbus_Point<T>* point = new Modbus_Hreg<T>(server, address, 0, description);
Modbus_Point<T>* highOrderPoint = new Modbus_Hreg<T>(server, address + 1 , 0, "");
return new Modbus_LongDecorator<T>(point, highOrderPoint);
}
case HR_FLOAT: {
case 43: {
Serial.printf("Creating Holding Register Float: %s\n", description);
// Create the low and high word registers for the 32-bit float
Modbus_Point<T>* point = new Modbus_Hreg<T>(server, address, 0, description);