Skip to content
Snippets Groups Projects
Unverified Commit daf4247d authored by Grigoris Pavlakis's avatar Grigoris Pavlakis
Browse files

Convert ParameterBase to common virtual interface

ParameterBase merely provides a virtual setter and getter, and also
acts as a common type which will be used to store pointers to Parameter
objects in an array, so as to enable ID-based parameter fetching and updating.

Rewrite of documentation and of the rest of the service is underway.
parent fd77363f
No related branches found
No related tags found
No related merge requests found
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
#include "etl/String.hpp" #include "etl/String.hpp"
#include "ECSS_Definitions.hpp" #include "ECSS_Definitions.hpp"
#include <iostream>
/** /**
* Implementation of a Parameter field, as specified in ECSS-E-ST-70-41C. * Implementation of a Parameter field, as specified in ECSS-E-ST-70-41C.
* Fully compliant with the standard's requirements. * Fully compliant with the standard's requirements.
...@@ -51,44 +50,75 @@ typedef uint16_t ParamId; ...@@ -51,44 +50,75 @@ typedef uint16_t ParamId;
*/ */
class ParameterBase { class ParameterBase {
protected:
uint8_t sizeInBytes;
void* valuePtr;
public: public:
virtual String<ECSS_ST_20_MAX_STRING_LENGTH> getValueAsString() = 0; 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> template <typename DataType>
class Parameter : public ParameterBase { class Parameter : public ParameterBase {
void (* ptr)(ValueType*); DataType currentValue;
ValueType currentValue; void (* updateFunction)(DataType*);
public: public:
Parameter(ValueType initialValue = 0, void(* newPtr)(ValueType*) = nullptr) { Parameter(DataType initialValue, void (* updateFunction)(DataType*) = nullptr) {
ptr = newPtr; this.updateFunction = updateFunction;
sizeInBytes = sizeof(initialValue);
// previously null valuePtr now points to the currentValue field if (this.updateFunction != nullptr) {
valuePtr = static_cast<void*>(&currentValue); (*updateFunction)(&currentValue);
}
if (ptr != nullptr) { else {
(*ptr)(&currentValue); // call the update function for the initial value
} else {
currentValue = initialValue; 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> getValueAsString() override {
String<ECSS_ST_20_MAX_STRING_LENGTH> contents(reinterpret_cast<uint8_t*>(&currentValue), sizeInBytes); // TODO: implement getValueAsString()
return contents; 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*>(&currentValue);
// if (ptr != nullptr) {
// (*ptr)(&currentValue); // 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*>(&currentValue), sizeInBytes);
// return contents;
// }
// };
#endif //ECSS_SERVICES_PARAMETER_HPP #endif //ECSS_SERVICES_PARAMETER_HPP
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment