diff --git a/inc/Services/Parameter.hpp b/inc/Services/Parameter.hpp index 20b8e8c55ec782ca2885d4640fabfe9424bc8265..bc101b524a0d3fd9577e75d071f29e264ff82566 100644 --- a/inc/Services/Parameter.hpp +++ b/inc/Services/Parameter.hpp @@ -3,7 +3,6 @@ #include "etl/String.hpp" #include "ECSS_Definitions.hpp" -#include <iostream> /** * Implementation of a Parameter field, as specified in ECSS-E-ST-70-41C. * Fully compliant with the standard's requirements. @@ -51,44 +50,75 @@ typedef uint16_t ParamId; */ class ParameterBase { -protected: - uint8_t sizeInBytes; - void* valuePtr; public: - virtual String<ECSS_ST_20_MAX_STRING_LENGTH> getValueAsString() = 0; - - template <typename ValueType> - void setCurrentValue(ValueType newVal) { - *reinterpret_cast<ValueType*>(valuePtr) = newVal; - } + virtual void setValueFromMessage(Message message) = 0; }; -template <typename ValueType> +template <typename DataType> class Parameter : public ParameterBase { - void (* ptr)(ValueType*); - ValueType currentValue; + DataType currentValue; + void (* updateFunction)(DataType*); public: - Parameter(ValueType initialValue = 0, void(* newPtr)(ValueType*) = nullptr) { - ptr = newPtr; - sizeInBytes = sizeof(initialValue); - // previously null valuePtr now points to the currentValue field - valuePtr = static_cast<void*>(¤tValue); - - if (ptr != nullptr) { - (*ptr)(¤tValue); // call the update function for the initial value - } else { + Parameter(DataType initialValue, void (* updateFunction)(DataType*) = nullptr) { + this.updateFunction = updateFunction; + + if (this.updateFunction != nullptr) { + (*updateFunction)(¤tValue); + } + else { currentValue = initialValue; } } + void setValueFromMessage(Message message) override { + // TODO: implement setValueForMessage + } + String<ECSS_ST_20_MAX_STRING_LENGTH> getValueAsString() override { - String<ECSS_ST_20_MAX_STRING_LENGTH> contents(reinterpret_cast<uint8_t*>(¤tValue), sizeInBytes); - return contents; + // TODO: implement getValueAsString() + return String<ECSS_ST_20_MAX_STRING_LENGTH>("DUMMY STRING"); } }; +// class ParameterBase { +// public: + +// virtual String<ECSS_ST_20_MAX_STRING_LENGTH> getValueAsString() = 0; +// virtual void setValueFromMessage(Message message) = 0; + +// template <typename ValueType> +// void setCurrentValue(ValueType newVal) { +// *reinterpret_cast<ValueType*>(valuePtr) = newVal; +// } +// }; + +// template <typename ValueType> +// class Parameter : public ParameterBase { +// void (* ptr)(ValueType*); +// ValueType currentValue; + +// public: +// Parameter(ValueType initialValue = 0, void(* newPtr)(ValueType*) = nullptr) { +// ptr = newPtr; +// sizeInBytes = sizeof(initialValue); +// // previously null valuePtr now points to the currentValue field +// valuePtr = static_cast<void*>(¤tValue); + +// if (ptr != nullptr) { +// (*ptr)(¤tValue); // call the update function for the initial value +// } else { +// currentValue = initialValue; +// } +// } + +// String<ECSS_ST_20_MAX_STRING_LENGTH> getValueAsString() override { +// String<ECSS_ST_20_MAX_STRING_LENGTH> contents(reinterpret_cast<uint8_t*>(¤tValue), sizeInBytes); +// return contents; +// } +// }; + #endif //ECSS_SERVICES_PARAMETER_HPP