Name updated, Categories folder to ModbuPoints, less generic to be self documented
This commit is contained in:
@@ -14,8 +14,8 @@
|
||||
#include <Arduino.h>
|
||||
#include <map>
|
||||
#include "Strategies/Strategy_PID.h"
|
||||
#include "Categories/ModbusFloatDecorator.h"
|
||||
#include "Categories/ModbusPoint.h"
|
||||
#include "ModbusPoints/Modbus_FloatDecorator.h"
|
||||
#include "ModbusPoints/Modbus_Point.h"
|
||||
|
||||
// Forward Declarations
|
||||
template<typename T>class Equipment;
|
||||
@@ -66,7 +66,7 @@ protected:
|
||||
/**
|
||||
* @brief Gets the value of a Modbus point, handling float types correctly.
|
||||
* This is a helper function to safely read a value from a point, whether it's
|
||||
* a standard integer register or a `ModbusFloatDecorator`.
|
||||
* a standard integer register or a `Modbus_FloatDecorator`.
|
||||
* @param equipment Pointer to the Equipment instance.
|
||||
* @param pointName The description key of the Modbus point to read.
|
||||
* @return The value of the point as a float. Returns 0.0f if not found.
|
||||
@@ -75,7 +75,7 @@ protected:
|
||||
/**
|
||||
* @brief Sets the value of a Modbus point, handling float types correctly.
|
||||
* This is a helper function to safely write a value to a point, whether it's
|
||||
* a standard integer register or a `ModbusFloatDecorator`.
|
||||
* a standard integer register or a `Modbus_FloatDecorator`.
|
||||
* @param equipment Pointer to the Equipment instance.
|
||||
* @param pointName The description key of the Modbus point to write to.
|
||||
* @param value The float value to set. It will be rounded for integer points.
|
||||
@@ -113,7 +113,7 @@ void State<T>::addStrategy(const std::string& pointDescription, Strategy_Behavio
|
||||
|
||||
/**
|
||||
* @brief Gets the value of a Modbus point, correctly handling float types.
|
||||
* This helper function checks if the point is a `ModbusFloatDecorator` and calls
|
||||
* This helper function checks if the point is a `Modbus_FloatDecorator` and calls
|
||||
* `getFloatValue()` if it is. Otherwise, it gets the standard integer value and
|
||||
* casts it to a float.
|
||||
* @param equipment Pointer to the Equipment instance.
|
||||
@@ -122,12 +122,12 @@ void State<T>::addStrategy(const std::string& pointDescription, Strategy_Behavio
|
||||
*/
|
||||
template<typename T>
|
||||
float State<T>::getPointValue(Equipment<T>* equipment, const std::string& pointName) {
|
||||
ModbusPoint<T>* point = equipment->getModbusPoint(pointName);
|
||||
Modbus_Point<T>* point = equipment->getModbus_Point(pointName);
|
||||
if (!point) return 0.0f;
|
||||
|
||||
if (point->getType() == PointType::FLOAT) {
|
||||
// If it's a float, cast and get the full float value
|
||||
return static_cast<ModbusFloatDecorator<T>*>(point)->getFloatValue();
|
||||
return static_cast<Modbus_FloatDecorator<T>*>(point)->getFloatValue();
|
||||
} else {
|
||||
// Otherwise, get the standard integer value
|
||||
return static_cast<float>(point->getValue());
|
||||
@@ -136,7 +136,7 @@ float State<T>::getPointValue(Equipment<T>* equipment, const std::string& pointN
|
||||
|
||||
/**
|
||||
* @brief Sets the value of a Modbus point, correctly handling float types.
|
||||
* This helper function checks if the point is a `ModbusFloatDecorator` and calls
|
||||
* This helper function checks if the point is a `Modbus_FloatDecorator` and calls
|
||||
* `setFloatValue()` if it is. Otherwise, it rounds the float to the nearest
|
||||
* integer and calls the standard `setValue()`.
|
||||
* @param equipment Pointer to the Equipment instance.
|
||||
@@ -145,11 +145,11 @@ float State<T>::getPointValue(Equipment<T>* equipment, const std::string& pointN
|
||||
*/
|
||||
template<typename T>
|
||||
void State<T>::setPointValue(Equipment<T>* equipment, const std::string& pointName, float value) {
|
||||
ModbusPoint<T>* point = equipment->getModbusPoint(pointName);
|
||||
Modbus_Point<T>* point = equipment->getModbus_Point(pointName);
|
||||
if (!point) return;
|
||||
|
||||
if (point->getType() == PointType::FLOAT) {
|
||||
static_cast<ModbusFloatDecorator<T>*>(point)->setFloatValue(value);
|
||||
static_cast<Modbus_FloatDecorator<T>*>(point)->setFloatValue(value);
|
||||
} else {
|
||||
point->setValue(round(value));
|
||||
}
|
||||
@@ -175,7 +175,7 @@ void State<T>::_applyStrategies(Equipment<T>* equipment) {
|
||||
Strategy_Behavior* strategy = pair.second;
|
||||
|
||||
if (strategy->isReady(currentTime)) {
|
||||
ModbusPoint<T>* outputPoint = equipment->getModbusPoint(description);
|
||||
Modbus_Point<T>* outputPoint = equipment->getModbus_Point(description);
|
||||
if (!outputPoint) continue;
|
||||
|
||||
float inputValue;
|
||||
@@ -184,7 +184,7 @@ void State<T>::_applyStrategies(Equipment<T>* equipment) {
|
||||
PIDStrategy* pid = static_cast<PIDStrategy*>(strategy);
|
||||
inputValue = getPointValue(equipment, pid->getInputSensorName());
|
||||
|
||||
ModbusPoint<T>* PIDsetpoint = equipment->getModbusPoint(pid->getSetpointName());
|
||||
Modbus_Point<T>* PIDsetpoint = equipment->getModbus_Point(pid->getSetpointName());
|
||||
if (PIDsetpoint) {
|
||||
pid->setSetpoint(PIDsetpoint->getValue());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user