parameters IF doc and improvement

This commit is contained in:
Robin Müller 2020-08-01 19:03:03 +02:00
parent 7475e6a9b8
commit ebf5d41a78
3 changed files with 84 additions and 50 deletions

View File

@ -5,8 +5,23 @@
#include <framework/returnvalues/HasReturnvaluesIF.h> #include <framework/returnvalues/HasReturnvaluesIF.h>
#include <stdint.h> #include <stdint.h>
/** Each parameter is identified with a unique parameter ID */
typedef uint32_t ParameterId_t; typedef uint32_t ParameterId_t;
/**
* @brief This interface is used by components which have modifiable
* parameters, e.g. atittude controllers
* @details
* Each parameter has a unique parameter ID. The first byte of the parameter
* ID is the domain ID which can be used to identify unqiue spacecraft domains
* (e.g. control and sensor domain in the AOCS controller).
*
* The second and third byte represent the matrix ID, which can represent
* a 8-bit row and column number and the last byte...
*
* Yeah, it it matrix ID oder parameter ID now and is index a 16 bit number
* of a 8 bit number now?
*/
class HasParametersIF { class HasParametersIF {
public: public:
static const uint8_t INTERFACE_ID = CLASS_ID::HAS_PARAMETERS_IF; static const uint8_t INTERFACE_ID = CLASS_ID::HAS_PARAMETERS_IF;
@ -32,13 +47,11 @@ public:
return (domainId << 24) + (parameterId << 8) + index; return (domainId << 24) + (parameterId << 8) + index;
} }
virtual ~HasParametersIF() { virtual ~HasParametersIF() {}
}
/** /**
* Always set parameter before checking newValues! * Always set parameter before checking newValues!
* *
*
* @param domainId * @param domainId
* @param parameterId * @param parameterId
* @param parameterWrapper * @param parameterWrapper

View File

@ -1,20 +1,19 @@
#include <framework/parameters/ParameterWrapper.h> #include <framework/parameters/ParameterWrapper.h>
ParameterWrapper::ParameterWrapper() : ParameterWrapper::ParameterWrapper() :
pointsToStream(false), type(Type::UNKNOWN_TYPE), rows(0), columns(0), data( pointsToStream(false), type(Type::UNKNOWN_TYPE) {
NULL), readonlyData(NULL) {
} }
ParameterWrapper::ParameterWrapper(Type type, uint8_t rows, uint8_t columns, ParameterWrapper::ParameterWrapper(Type type, uint8_t rows, uint8_t columns,
void *data) : void *data) :
pointsToStream(false), type(type), rows(rows), columns(columns), data( pointsToStream(false), type(type), rows(rows), columns(columns),
data), readonlyData(data) { data(data), readonlyData(data) {
} }
ParameterWrapper::ParameterWrapper(Type type, uint8_t rows, uint8_t columns, ParameterWrapper::ParameterWrapper(Type type, uint8_t rows, uint8_t columns,
const void *data) : const void *data) :
pointsToStream(false), type(type), rows(rows), columns(columns), data( pointsToStream(false), type(type), rows(rows), columns(columns),
NULL), readonlyData(data) { data(nullptr), readonlyData(data) {
} }
ParameterWrapper::~ParameterWrapper() { ParameterWrapper::~ParameterWrapper() {
@ -266,15 +265,14 @@ ReturnValue_t ParameterWrapper::copyFrom(const ParameterWrapper *from,
result = UNKNOW_DATATYPE; result = UNKNOW_DATATYPE;
break; break;
} }
} else { }
else {
//need a type to do arithmetic //need a type to do arithmetic
uint8_t *toDataWithType = (uint8_t*) data; uint8_t* typedData = static_cast<uint8_t*>(data);
for (uint8_t fromRow = 0; fromRow < from->rows; fromRow++) { for (uint8_t fromRow = 0; fromRow < from->rows; fromRow++) {
memcpy( uint8_t offset = (((startingRow + fromRow) * columns) + startingColumn) * typeSize;
toDataWithType std::memcpy(typedData + offset, from->readonlyData,
+ (((startingRow + fromRow) * columns) typeSize * from->columns);
+ startingColumn) * typeSize,
from->readonlyData, typeSize * from->columns);
} }
} }

View File

@ -1,5 +1,5 @@
#ifndef PARAMETERWRAPPER_H_ #ifndef FRAMEWORK_PARAMETERS_PARAMETERWRAPPER_H_
#define PARAMETERWRAPPER_H_ #define FRAMEWORK_PARAMETERS_PARAMETERWRAPPER_H_
#include <framework/returnvalues/HasReturnvaluesIF.h> #include <framework/returnvalues/HasReturnvaluesIF.h>
#include <framework/serialize/SerializeAdapter.h> #include <framework/serialize/SerializeAdapter.h>
@ -7,6 +7,10 @@
#include <stddef.h> #include <stddef.h>
#include <framework/globalfunctions/Type.h> #include <framework/globalfunctions/Type.h>
/**
* @brief
* @details
*/
class ParameterWrapper: public SerializeIF { class ParameterWrapper: public SerializeIF {
friend class DataPoolParameterWrapper; friend class DataPoolParameterWrapper;
public: public:
@ -36,32 +40,21 @@ public:
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
Endianness streamEndianness, uint16_t startWritingAtIndex = 0); Endianness streamEndianness, uint16_t startWritingAtIndex = 0);
/**
* Get a specific parameter value by supplying the row and the column.
* @tparam T Type of target data
* @param value [out] Pointer to storage location
* @param row
* @param column
* @return
* -@c RETURN_OK if element was retrieved successfully
* -@c NOT_SET data has not been set yet
* -@c DATATYPE_MISSMATCH Invalid supplied type
* -@c OUT_OF_BOUNDS Invalid row and/or column.
*/
template<typename T> template<typename T>
ReturnValue_t getElement(T *value, uint8_t row = 0, uint8_t column = 0) const { ReturnValue_t getElement(T *value, uint8_t row = 0,
if (readonlyData == NULL){ uint8_t column = 0) const;
return NOT_SET;
}
if (PodTypeConversion<T>::type != type) {
return DATATYPE_MISSMATCH;
}
if ((row >= rows) || (column >= columns)) {
return OUT_OF_BOUNDS;
}
if (pointsToStream) {
const uint8_t *streamWithtype = (const uint8_t *) readonlyData;
streamWithtype += (row * columns + column) * type.getSize();
int32_t size = type.getSize();
return SerializeAdapter::deSerialize(value, &streamWithtype,
&size, true);
} else {
const T *dataWithType = (const T *) readonlyData;
*value = dataWithType[row * columns + column];
return HasReturnvaluesIF::RETURN_OK;
}
}
template<typename T> template<typename T>
void set(T *data, uint8_t rows, uint8_t columns) { void set(T *data, uint8_t rows, uint8_t columns) {
@ -111,21 +104,22 @@ public:
void setMatrix(const T& member) { void setMatrix(const T& member) {
this->set(member[0], sizeof(member)/sizeof(member[0]), sizeof(member[0])/sizeof(member[0][0])); this->set(member[0], sizeof(member)/sizeof(member[0]), sizeof(member[0])/sizeof(member[0][0]));
} }
ReturnValue_t set(const uint8_t *stream, size_t streamSize, ReturnValue_t set(const uint8_t *stream, size_t streamSize,
const uint8_t **remainingStream = NULL, size_t *remainingSize = const uint8_t **remainingStream = nullptr,
NULL); size_t *remainingSize = nullptr);
ReturnValue_t copyFrom(const ParameterWrapper *from, ReturnValue_t copyFrom(const ParameterWrapper *from,
uint16_t startWritingAtIndex); uint16_t startWritingAtIndex);
private: private:
bool pointsToStream; bool pointsToStream = false;
Type type; Type type;
uint8_t rows; uint8_t rows = 0;
uint8_t columns; uint8_t columns = 0;
void *data; void *data = nullptr;
const void *readonlyData; const void *readonlyData = nullptr;
template<typename T> template<typename T>
ReturnValue_t serializeData(uint8_t** buffer, size_t* size, ReturnValue_t serializeData(uint8_t** buffer, size_t* size,
@ -136,4 +130,33 @@ private:
const void *from, uint8_t fromRows, uint8_t fromColumns); const void *from, uint8_t fromRows, uint8_t fromColumns);
}; };
template <typename T>
inline ReturnValue_t ParameterWrapper::getElement(T *value, uint8_t row,
uint8_t column) const {
if (readonlyData == nullptr){
return NOT_SET;
}
if (PodTypeConversion<T>::type != type) {
return DATATYPE_MISSMATCH;
}
if ((row >= rows) or (column >= columns)) {
return OUT_OF_BOUNDS;
}
if (pointsToStream) {
const uint8_t *streamWithType = static_cast<const uint8_t*>(readonlyData);
streamWithType += (row * columns + column) * type.getSize();
int32_t size = type.getSize();
return SerializeAdapter::deSerialize(value, &streamWithType,
&size, true);
}
else {
const T *dataWithType = static_cast<const T*>(readonlyData);
*value = dataWithType[row * columns + column];
return HasReturnvaluesIF::RETURN_OK;
}
}
#endif /* PARAMETERWRAPPER_H_ */ #endif /* PARAMETERWRAPPER_H_ */