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

@@ -14,6 +14,7 @@
#include <map>
#include <string>
#include <vector>
#include "ModbusPoints/Modbus_Point.h"
#include "States/State_Standby.h"
// Forward Declarations
@@ -36,6 +37,7 @@ public:
* Initializes the device in the default initial state (Standby).
*/
Equipment();
~Equipment();
Equipment(T* server);
/** @brief The main update loop for the equipment, called repeatedly. Delegates to the current state. */
@@ -80,6 +82,9 @@ public:
*/
void setModbus_Point(const std::string& description, float value);
void updateAllPoints();
void clearEquipment();
private:
State<T>* _state; /**< @brief Pointer to the current state object. */
std::map<std::string, Modbus_Point<T>*> _points;/**< @brief Map of all Modbus points, keyed by description. */
@@ -89,20 +94,22 @@ private:
template<typename T>
Equipment<T>::Equipment() : _server(nullptr) {
this->_state = new StandbyState<T>();
this->_state->enterState(this);
}
template<typename T>
Equipment<T>::~Equipment() {
clearEquipment();}
/**
* @brief Constructs a new Equipment object with a server instance.
* @param server Pointer to the Modbus server instance (e.g., ModbusIP, ModbusRTU).
*/
template<typename T>
Equipment<T>::Equipment(T* server)
: _server(server)
: _server(server), _state(nullptr), _stateId(0)
{
this->_state = new StandbyState<T>();
this->_state->enterState(this);
}
/**
@@ -162,6 +169,28 @@ Modbus_Point<T>* Equipment<T>::getModbus_Point(const std::string& description) {
return nullptr;
}
template<typename T>
void Equipment<T>::updateAllPoints() {
unsigned long currentMillis = millis();
// Iterate safely though the map of points and call updateStrategy on each one
for (auto const& [description, point] : _points) {
if (point != nullptr) {
point->updateStrategy(currentMillis); //Each point execute its own strategy update
}
}
}
template<typename T>
void Equipment<T>::clearEquipment() {
// Delete all Modbus points
for (auto const& [description, point] : _points) {
if (point != nullptr) {
delete point;
}
}
_points.clear();
Serial.println(F("[Equipment] Modbus memory map successfully cleared."));
}
/**
* @brief Sets the value of a specific Modbus point.
* Finds the point by its description and calls its `setValue` method.