Documentation updated

This commit is contained in:
2025-09-15 09:19:13 -05:00
parent ac20b82496
commit 5a0b02ccdf
41 changed files with 673 additions and 377 deletions

View File

@@ -56,7 +56,7 @@ public:
*/
virtual void exitState(Equipment<T>* equipment) {}
/**
* @brief Logic to apply all strategies created.
* @brief Applies all registered strategies for the current state.
* @param equipment Pointer to the Equipment instance.
*/
virtual void _applyStrategies(Equipment<T>* equipment);
@@ -64,14 +64,30 @@ public:
protected:
/**
* @brief Adds a behavior strategy for a specific Modbus point.
* @param pointDescription The description of the Modbus point to apply the strategy to.
* @param strategy A pointer to the Strategy_Behavior object. The State will take ownership.
* @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`.
* @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.
*/
float getPointValue(Equipment<T>* equipment, const std::string& pointName);
/**
* @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`.
* @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.
*/
void setPointValue(Equipment<T>* equipment, const std::string& pointName, float value);
/**
* @brief Adds a behavior strategy for a specific Modbus point in this state.
* @param pointDescription The description of the Modbus point to apply the strategy to.
* @param strategy A pointer to the Strategy_Behavior object. The State takes ownership.
*/
void addStrategy(const std::string& pointDescription, Strategy_Behavior* strategy);
std::map<std::string, Strategy_Behavior*> _strategies;
std::map<std::string, Strategy_Behavior*> _strategies; /**< @brief Map of strategies active in this state, keyed by point description. */
};
template<typename T>
@@ -95,6 +111,15 @@ void State<T>::addStrategy(const std::string& pointDescription, Strategy_Behavio
this->_strategies[pointDescription] = strategy;
}
/**
* @brief Gets the value of a Modbus point, correctly handling float types.
* This helper function checks if the point is a `ModbusFloatDecorator` 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.
* @param pointName The description key of the Modbus point.
* @return The point's value as a float. Returns 0.0f if the point is not found.
*/
template<typename T>
float State<T>::getPointValue(Equipment<T>* equipment, const std::string& pointName) {
ModbusPoint<T>* point = equipment->getModbusPoint(pointName);
@@ -109,6 +134,15 @@ 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
* `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.
* @param pointName The description key of the Modbus point.
* @param value The value to set.
*/
template<typename T>
void State<T>::setPointValue(Equipment<T>* equipment, const std::string& pointName, float value) {
ModbusPoint<T>* point = equipment->getModbusPoint(pointName);

View File

@@ -30,21 +30,33 @@ template<typename T>
class FailState : public State<T> {
public:
/**
* @brief Constructs a new FailState object.
* This is where strategies for failure behavior would be initialized.
* @brief Constructs a new FailState object with a list of active alarms.
* @param activeAlarms A vector of strings, where each string is the
* description of a Modbus point to be set as an active alarm.
*/
FailState(const std::vector<std::string>& activeAlarms);
/**
* @brief Executes the fail state's logic for one update cycle.
* This method applies the state's strategies and checks for a state transition command.
* This method applies any failure-related strategies and checks for a
* command to clear the alarm (e.g., via a Modbus write), which would
* trigger a transition back to a safe state like Standby.
* @param equipment Pointer to the Equipment instance.
* @return A pointer to a new State if a transition should occur, otherwise nullptr.
*/
State<T>* update(Equipment<T>* equipment) override;
/** @brief Logic to execute once when entering the fail state. */
/**
* @brief Logic to execute once when entering the fail state.
* Typically sets alarm bits and brings the equipment to a safe, non-operational condition.
*/
void enterState(Equipment<T>* equipment) override;
/** @brief Logic to execute once when exiting the fail state. */
/**
* @brief Logic to execute once when exiting the fail state.
* Typically clears alarm bits before transitioning to the next state.
*/
void exitState(Equipment<T>* equipment) override;
private:
std::vector<std::string> _activeAlarms; /**< @brief Stores the descriptions of points to be set as active alarms. */
};
#endif

View File

@@ -34,14 +34,26 @@ public:
/**
* @brief Executes the running state's logic for one update cycle.
* This method applies the state's strategies and checks for a state transition command.
* This method applies all active strategies (e.g., for fan speeds, temperatures)
* and checks for conditions that would trigger a state transition, such as a
* command to stop or a fault condition.
* @param equipment Pointer to the Equipment instance.
* @return A pointer to a new State if a transition should occur, otherwise nullptr.
*/
State<T>* update(Equipment<T>* equipment) override;
/** @brief Logic to execute once when entering the running state. */
/**
* @brief Logic to execute once when entering the running state.
* Typically sets status bits to indicate the equipment is active (e.g.,
* setting an "On/Off" point to 1).
* @param equipment Pointer to the Equipment instance.
*/
void enterState(Equipment<T>* equipment) override;
/** @brief Logic to execute once when exiting the running state. */
/**
* @brief Logic to execute once when exiting the running state.
* Typically resets status bits to indicate the equipment is no longer
* active before transitioning to the next state.
* @param equipment Pointer to the Equipment instance.
*/
void exitState(Equipment<T>* equipment) override;
};
#endif

View File

@@ -35,14 +35,27 @@ public:
/**
* @brief Executes the standby state's logic for one update cycle.
* This method applies the state's strategies and checks for a state transition command.
* This method applies any standby-specific strategies and checks for conditions
* that would trigger a state transition, such as a "start" command received
* via a Modbus write.
* @param equipment Pointer to the Equipment instance.
* @return A pointer to a new State if a transition should occur, otherwise nullptr.
*/
State<T>* update(Equipment<T>* equipment) override;
/** @brief Logic to execute once when entering the standby state. */
/**
* @brief Logic to execute once when entering the standby state.
* Typically sets status bits to indicate the equipment is idle (e.g.,
* setting an "On/Off" point to 0).
* @param equipment Pointer to the Equipment instance.
*/
void enterState(Equipment<T>* equipment) override;
/** @brief Logic to execute once when exiting the standby state. */
/**
* @brief Logic to execute once when exiting the standby state.
* This method is called just before transitioning to a new state. It can be
* used to perform any cleanup specific to the standby state before the new
* state's `enterState` is called.
* @param equipment Pointer to the Equipment instance.
*/
void exitState(Equipment<T>* equipment) override;
};
#endif