parameters IF doc and improvement
This commit is contained in:
parent
7475e6a9b8
commit
ebf5d41a78
@ -5,8 +5,23 @@
|
||||
#include <framework/returnvalues/HasReturnvaluesIF.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/** Each parameter is identified with a unique parameter ID */
|
||||
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 {
|
||||
public:
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::HAS_PARAMETERS_IF;
|
||||
@ -32,13 +47,11 @@ public:
|
||||
return (domainId << 24) + (parameterId << 8) + index;
|
||||
}
|
||||
|
||||
virtual ~HasParametersIF() {
|
||||
}
|
||||
virtual ~HasParametersIF() {}
|
||||
|
||||
/**
|
||||
* Always set parameter before checking newValues!
|
||||
*
|
||||
*
|
||||
* @param domainId
|
||||
* @param parameterId
|
||||
* @param parameterWrapper
|
||||
|
@ -1,20 +1,19 @@
|
||||
#include <framework/parameters/ParameterWrapper.h>
|
||||
|
||||
ParameterWrapper::ParameterWrapper() :
|
||||
pointsToStream(false), type(Type::UNKNOWN_TYPE), rows(0), columns(0), data(
|
||||
NULL), readonlyData(NULL) {
|
||||
pointsToStream(false), type(Type::UNKNOWN_TYPE) {
|
||||
}
|
||||
|
||||
ParameterWrapper::ParameterWrapper(Type type, uint8_t rows, uint8_t columns,
|
||||
void *data) :
|
||||
pointsToStream(false), type(type), rows(rows), columns(columns), data(
|
||||
data), readonlyData(data) {
|
||||
pointsToStream(false), type(type), rows(rows), columns(columns),
|
||||
data(data), readonlyData(data) {
|
||||
}
|
||||
|
||||
ParameterWrapper::ParameterWrapper(Type type, uint8_t rows, uint8_t columns,
|
||||
const void *data) :
|
||||
pointsToStream(false), type(type), rows(rows), columns(columns), data(
|
||||
NULL), readonlyData(data) {
|
||||
pointsToStream(false), type(type), rows(rows), columns(columns),
|
||||
data(nullptr), readonlyData(data) {
|
||||
}
|
||||
|
||||
ParameterWrapper::~ParameterWrapper() {
|
||||
@ -266,15 +265,14 @@ ReturnValue_t ParameterWrapper::copyFrom(const ParameterWrapper *from,
|
||||
result = UNKNOW_DATATYPE;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
//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++) {
|
||||
memcpy(
|
||||
toDataWithType
|
||||
+ (((startingRow + fromRow) * columns)
|
||||
+ startingColumn) * typeSize,
|
||||
from->readonlyData, typeSize * from->columns);
|
||||
uint8_t offset = (((startingRow + fromRow) * columns) + startingColumn) * typeSize;
|
||||
std::memcpy(typedData + offset, from->readonlyData,
|
||||
typeSize * from->columns);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
#ifndef PARAMETERWRAPPER_H_
|
||||
#define PARAMETERWRAPPER_H_
|
||||
#ifndef FRAMEWORK_PARAMETERS_PARAMETERWRAPPER_H_
|
||||
#define FRAMEWORK_PARAMETERS_PARAMETERWRAPPER_H_
|
||||
|
||||
#include <framework/returnvalues/HasReturnvaluesIF.h>
|
||||
#include <framework/serialize/SerializeAdapter.h>
|
||||
@ -7,6 +7,10 @@
|
||||
#include <stddef.h>
|
||||
#include <framework/globalfunctions/Type.h>
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* @details
|
||||
*/
|
||||
class ParameterWrapper: public SerializeIF {
|
||||
friend class DataPoolParameterWrapper;
|
||||
public:
|
||||
@ -36,32 +40,21 @@ public:
|
||||
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
||||
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>
|
||||
ReturnValue_t getElement(T *value, uint8_t row = 0, uint8_t column = 0) const {
|
||||
if (readonlyData == NULL){
|
||||
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;
|
||||
}
|
||||
}
|
||||
ReturnValue_t getElement(T *value, uint8_t row = 0,
|
||||
uint8_t column = 0) const;
|
||||
|
||||
template<typename T>
|
||||
void set(T *data, uint8_t rows, uint8_t columns) {
|
||||
@ -111,21 +104,22 @@ public:
|
||||
void setMatrix(const T& member) {
|
||||
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,
|
||||
const uint8_t **remainingStream = NULL, size_t *remainingSize =
|
||||
NULL);
|
||||
const uint8_t **remainingStream = nullptr,
|
||||
size_t *remainingSize = nullptr);
|
||||
|
||||
ReturnValue_t copyFrom(const ParameterWrapper *from,
|
||||
uint16_t startWritingAtIndex);
|
||||
|
||||
private:
|
||||
bool pointsToStream;
|
||||
bool pointsToStream = false;
|
||||
|
||||
Type type;
|
||||
uint8_t rows;
|
||||
uint8_t columns;
|
||||
void *data;
|
||||
const void *readonlyData;
|
||||
uint8_t rows = 0;
|
||||
uint8_t columns = 0;
|
||||
void *data = nullptr;
|
||||
const void *readonlyData = nullptr;
|
||||
|
||||
template<typename T>
|
||||
ReturnValue_t serializeData(uint8_t** buffer, size_t* size,
|
||||
@ -136,4 +130,33 @@ private:
|
||||
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_ */
|
||||
|
Loading…
Reference in New Issue
Block a user