restructure repository
This commit is contained in:
81
inc/fsfw/parameters/HasParametersIF.h
Normal file
81
inc/fsfw/parameters/HasParametersIF.h
Normal file
@ -0,0 +1,81 @@
|
||||
#ifndef FSFW_PARAMETERS_HASPARAMETERSIF_H_
|
||||
#define FSFW_PARAMETERS_HASPARAMETERSIF_H_
|
||||
|
||||
#include "ParameterWrapper.h"
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
#include <cstdint>
|
||||
|
||||
/**
|
||||
* Each parameter is identified with a unique parameter ID
|
||||
* The first byte of the parameter ID will denote the domain ID.
|
||||
* The second and third byte will be the unique identifier number.
|
||||
*/
|
||||
using ParameterId_t = uint32_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 byte is a unique identfier ID.
|
||||
*
|
||||
* The third and fourth byte can be used as a linear index for matrix or array
|
||||
* parameter entries.
|
||||
*/
|
||||
class HasParametersIF {
|
||||
public:
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::HAS_PARAMETERS_IF;
|
||||
static const ReturnValue_t INVALID_IDENTIFIER_ID = MAKE_RETURN_CODE(0x01);
|
||||
static const ReturnValue_t INVALID_DOMAIN_ID = MAKE_RETURN_CODE(0x02);
|
||||
static const ReturnValue_t INVALID_VALUE = MAKE_RETURN_CODE(0x03);
|
||||
static const ReturnValue_t READ_ONLY = MAKE_RETURN_CODE(0x05);
|
||||
|
||||
static uint8_t getDomain(ParameterId_t id) {
|
||||
return id >> 24;
|
||||
}
|
||||
|
||||
static uint8_t getUniqueIdentifierId(ParameterId_t id) {
|
||||
return id >> 16;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the index of a parameter. Please note that the index is always a
|
||||
* linear index. For a vector, this is straightforward.
|
||||
* For a matrix, the linear indexing run from left to right, top to bottom.
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
static uint16_t getIndex(ParameterId_t id) {
|
||||
return id;
|
||||
}
|
||||
|
||||
static uint32_t getFullParameterId(uint8_t domainId, uint8_t uniqueId, uint16_t linearIndex) {
|
||||
return (domainId << 24) + (uniqueId << 16) + linearIndex;
|
||||
}
|
||||
|
||||
virtual ~HasParametersIF() {}
|
||||
|
||||
/**
|
||||
* This is the generic function overriden by child classes to set
|
||||
* parameters. To set a parameter, the parameter wrapper is used with
|
||||
* a variety of set functions. The provided values can be checked with
|
||||
* newValues.
|
||||
* Always set parameter before checking newValues!
|
||||
*
|
||||
* @param domainId
|
||||
* @param parameterId
|
||||
* @param parameterWrapper
|
||||
* @param newValues
|
||||
* @param startAtIndex Linear index, runs left to right, top to bottom for
|
||||
* matrix indexes.
|
||||
* @return
|
||||
*/
|
||||
virtual ReturnValue_t getParameter(uint8_t domainId, uint8_t uniqueIdentifier,
|
||||
ParameterWrapper *parameterWrapper, const ParameterWrapper *newValues,
|
||||
uint16_t startAtIndex) = 0;
|
||||
};
|
||||
|
||||
#endif /* FSFW_PARAMETERS_HASPARAMETERSIF_H_ */
|
36
inc/fsfw/parameters/ParameterHelper.h
Normal file
36
inc/fsfw/parameters/ParameterHelper.h
Normal file
@ -0,0 +1,36 @@
|
||||
#ifndef FSFW_PARAMETERS_PARAMETERHELPER_H_
|
||||
#define FSFW_PARAMETERS_PARAMETERHELPER_H_
|
||||
|
||||
#include "ParameterMessage.h"
|
||||
#include "ReceivesParameterMessagesIF.h"
|
||||
#include "../ipc/MessageQueueIF.h"
|
||||
|
||||
/**
|
||||
* @brief Helper class to handle parameter messages.
|
||||
* @details
|
||||
* This class simplfies handling of parameter messages, which are sent
|
||||
* to a class which implements ReceivesParameterMessagesIF.
|
||||
*/
|
||||
class ParameterHelper {
|
||||
public:
|
||||
ParameterHelper(ReceivesParameterMessagesIF *owner);
|
||||
virtual ~ParameterHelper();
|
||||
|
||||
ReturnValue_t handleParameterMessage(CommandMessage *message);
|
||||
|
||||
ReturnValue_t initialize();
|
||||
private:
|
||||
ReceivesParameterMessagesIF *owner;
|
||||
|
||||
MessageQueueId_t ownerQueueId = MessageQueueIF::NO_QUEUE;
|
||||
|
||||
StorageManagerIF *storage = nullptr;
|
||||
|
||||
ReturnValue_t sendParameter(MessageQueueId_t to, uint32_t id,
|
||||
const ParameterWrapper *description);
|
||||
|
||||
void rejectCommand(MessageQueueId_t to, ReturnValue_t reason,
|
||||
Command_t initialCommand);
|
||||
};
|
||||
|
||||
#endif /* FSFW_PARAMETERS_PARAMETERHELPER_H_ */
|
62
inc/fsfw/parameters/ParameterMessage.h
Normal file
62
inc/fsfw/parameters/ParameterMessage.h
Normal file
@ -0,0 +1,62 @@
|
||||
#ifndef FSFW_PARAMETERS_PARAMETERMESSAGE_H_
|
||||
#define FSFW_PARAMETERS_PARAMETERMESSAGE_H_
|
||||
|
||||
#include "HasParametersIF.h"
|
||||
#include "../ipc/CommandMessage.h"
|
||||
#include "../storagemanager/StorageManagerIF.h"
|
||||
|
||||
/**
|
||||
* @brief ParameterMessage interface
|
||||
* @details
|
||||
* General structure of a parameter message:
|
||||
* 1. 4-byte Object ID
|
||||
* 2. 4-byte Parameter ID, first byte is Domain ID, second byte is unique
|
||||
* identifier, third and fourth byte is linear index to start from
|
||||
* 3. 4-byte Parameter Settings. First byte and second byte are the PTC and PFC
|
||||
* ECSS type identifiers (see ECSS-E-ST-70-41C15 p.428 or Type class in
|
||||
* globalfunctions). Third byte is the number of rows and fourth byte
|
||||
* is the number of columns. For single variable parameters, this will
|
||||
* be [1, 1].
|
||||
*
|
||||
*/
|
||||
class ParameterMessage {
|
||||
private:
|
||||
ParameterMessage();
|
||||
public:
|
||||
static const uint8_t MESSAGE_ID = messagetypes::PARAMETER;
|
||||
static const Command_t CMD_PARAMETER_LOAD = MAKE_COMMAND_ID( 0x01 );
|
||||
static const Command_t CMD_PARAMETER_DUMP = MAKE_COMMAND_ID( 0x02 );
|
||||
static const Command_t REPLY_PARAMETER_DUMP = MAKE_COMMAND_ID( 0x03 );
|
||||
|
||||
static ParameterId_t getParameterId(const CommandMessage* message);
|
||||
static store_address_t getStoreId(const CommandMessage* message);
|
||||
static void setParameterDumpCommand(CommandMessage* message,
|
||||
ParameterId_t id);
|
||||
static void setParameterDumpReply(CommandMessage* message,
|
||||
ParameterId_t id, store_address_t storageID);
|
||||
|
||||
/**
|
||||
* Command to set a load parameter message. The CCSDS / ECSS type in
|
||||
* form of a PTC and a PFC is expected. See ECSS-E-ST-70-41C15 p.428
|
||||
* for all types or the Type class in globalfunctions.
|
||||
* @param message
|
||||
* @param id
|
||||
* @param storeId
|
||||
* @param ptc Type information according to CCSDS/ECSS standards
|
||||
* @param pfc Type information according to CCSDS/ECSS standards
|
||||
* @param rows Set number of rows in parameter set, minimum one.
|
||||
* @param columns Set number of columns in parameter set, minimum one
|
||||
*/
|
||||
static void setParameterLoadCommand(CommandMessage* message,
|
||||
ParameterId_t id, store_address_t storeId, uint8_t ptc,
|
||||
uint8_t pfc, uint8_t rows, uint8_t columns);
|
||||
|
||||
static store_address_t getParameterLoadCommand(
|
||||
const CommandMessage* message, ParameterId_t* parameterId,
|
||||
uint8_t* ptc, uint8_t* pfc, uint8_t* rows, uint8_t* columns) ;
|
||||
|
||||
static void clear(CommandMessage* message);
|
||||
|
||||
};
|
||||
|
||||
#endif /* FSFW_PARAMETERS_PARAMETERMESSAGE_H_ */
|
199
inc/fsfw/parameters/ParameterWrapper.h
Normal file
199
inc/fsfw/parameters/ParameterWrapper.h
Normal file
@ -0,0 +1,199 @@
|
||||
#ifndef FSFW_PARAMETERS_PARAMETERWRAPPER_H_
|
||||
#define FSFW_PARAMETERS_PARAMETERWRAPPER_H_
|
||||
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
#include "../serialize/SerializeAdapter.h"
|
||||
#include "../serialize/SerializeIF.h"
|
||||
#include "../globalfunctions/Type.h"
|
||||
#include <cstddef>
|
||||
|
||||
/**
|
||||
* @brief This wrapper encapsulates the access to parameters provided by HasParametersIF.
|
||||
* @details
|
||||
* This wrapper is used by the ParameterHelper to interface with the on-board parameters
|
||||
* exposed by the software via the HasParametersIF. A handle of this wrapper is passed
|
||||
* to the user which then can be used to set or dump the parameters.
|
||||
*
|
||||
* The wrapper provides a set of setter functions. The user should call those setter functions,
|
||||
* supplying an address to the local parameters. The user can also deserialize or
|
||||
* serialize the parameter data. Please note that this will also serialize and deserialize
|
||||
* the parameter information field (4 bytes) containing the ECSS PTC, PFC and rows and columns
|
||||
* number.
|
||||
*/
|
||||
class ParameterWrapper: public SerializeIF {
|
||||
friend class DataPoolParameterWrapper;
|
||||
public:
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::PARAMETER_WRAPPER;
|
||||
static const ReturnValue_t UNKNOWN_DATATYPE = MAKE_RETURN_CODE(0x01);
|
||||
static const ReturnValue_t DATATYPE_MISSMATCH = MAKE_RETURN_CODE(0x02);
|
||||
static const ReturnValue_t READONLY = MAKE_RETURN_CODE(0x03);
|
||||
static const ReturnValue_t TOO_BIG = MAKE_RETURN_CODE(0x04);
|
||||
static const ReturnValue_t SOURCE_NOT_SET = MAKE_RETURN_CODE(0x05);
|
||||
static const ReturnValue_t OUT_OF_BOUNDS = MAKE_RETURN_CODE(0x06);
|
||||
static const ReturnValue_t NOT_SET = MAKE_RETURN_CODE(0x07);
|
||||
static const ReturnValue_t COLUMN_OR_ROWS_ZERO = MAKE_RETURN_CODE(0x08);
|
||||
|
||||
ParameterWrapper();
|
||||
ParameterWrapper(Type type, uint8_t rows, uint8_t columns, void *data);
|
||||
ParameterWrapper(Type type, uint8_t rows, uint8_t columns, const void *data);
|
||||
virtual ~ParameterWrapper();
|
||||
|
||||
virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size,
|
||||
size_t maxSize, Endianness streamEndianness) const override;
|
||||
|
||||
virtual size_t getSerializedSize() const override;
|
||||
|
||||
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
||||
Endianness streamEndianness) override;
|
||||
|
||||
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;
|
||||
|
||||
template<typename T>
|
||||
void set(T *data, uint8_t rows, uint8_t columns) {
|
||||
this->data = data;
|
||||
this->readonlyData = data;
|
||||
this->type = PodTypeConversion<T>::type;
|
||||
this->rows = rows;
|
||||
this->columns = columns;
|
||||
this->pointsToStream = false;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void set(const T *readonlyData, uint8_t rows, uint8_t columns) {
|
||||
this->data = nullptr;
|
||||
this->readonlyData = readonlyData;
|
||||
this->type = PodTypeConversion<T>::type;
|
||||
this->rows = rows;
|
||||
this->columns = columns;
|
||||
this->pointsToStream = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter function for scalar non-const entries
|
||||
* @tparam T
|
||||
* @param member
|
||||
*/
|
||||
template<typename T>
|
||||
void set(T& member) {
|
||||
this->set(&member, 1, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter function for scalar const entries.
|
||||
* TODO: This is confusing, it should not be called set. Maybe we should call all functions
|
||||
* assign instead?
|
||||
* @tparam T
|
||||
* @param readonlyMember
|
||||
*/
|
||||
template<typename T>
|
||||
void set(const T& readonlyMember) {
|
||||
this->set(&readonlyMember, 1, 1);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void setVector(T& member) {
|
||||
/* For a vector entry, the number of rows will be one
|
||||
(left to right, top to bottom indexing) */
|
||||
this->set(member, 1, sizeof(member) / sizeof(member[0]));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void setVector(const T& member) {
|
||||
/* For a vector entry, the number of rows will be one
|
||||
(left to right, top to bottom indexing) */
|
||||
this->set(member, 1, sizeof(member) / sizeof(member[0]));
|
||||
}
|
||||
template<typename T>
|
||||
void setMatrix(T& member) {
|
||||
this->set(member[0], sizeof(member)/sizeof(member[0]),
|
||||
sizeof(member[0])/sizeof(member[0][0]));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void setMatrix(const T& member) {
|
||||
this->set(member[0], sizeof(member)/sizeof(member[0]),
|
||||
sizeof(member[0])/sizeof(member[0][0]));
|
||||
}
|
||||
|
||||
ReturnValue_t set(Type type, uint8_t rows, uint8_t columns,
|
||||
const void *data, size_t dataSize);
|
||||
|
||||
ReturnValue_t set(const uint8_t *stream, size_t streamSize,
|
||||
const uint8_t **remainingStream = nullptr,
|
||||
size_t *remainingSize = nullptr);
|
||||
|
||||
ReturnValue_t copyFrom(const ParameterWrapper *from,
|
||||
uint16_t startWritingAtIndex);
|
||||
|
||||
private:
|
||||
|
||||
void convertLinearIndexToRowAndColumn(uint16_t index,
|
||||
uint8_t *row, uint8_t *column);
|
||||
|
||||
uint16_t convertRowAndColumnToLinearIndex(uint8_t row,
|
||||
uint8_t column);
|
||||
|
||||
bool pointsToStream = false;
|
||||
|
||||
Type type;
|
||||
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,
|
||||
size_t maxSize, Endianness streamEndianness) const;
|
||||
|
||||
template<typename T>
|
||||
ReturnValue_t deSerializeData(uint8_t startingRow, uint8_t startingColumn,
|
||||
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();
|
||||
size_t size = type.getSize();
|
||||
return SerializeAdapter::deSerialize(value, &streamWithType,
|
||||
&size, SerializeIF::Endianness::BIG);
|
||||
}
|
||||
else {
|
||||
const T *dataWithType = static_cast<const T*>(readonlyData);
|
||||
*value = dataWithType[row * columns + column];
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* FSFW_PARAMETERS_PARAMETERWRAPPER_H_ */
|
19
inc/fsfw/parameters/ReceivesParameterMessagesIF.h
Normal file
19
inc/fsfw/parameters/ReceivesParameterMessagesIF.h
Normal file
@ -0,0 +1,19 @@
|
||||
#ifndef FSFW_PARAMETERS_RECEIVESPARAMETERMESSAGESIF_H_
|
||||
#define FSFW_PARAMETERS_RECEIVESPARAMETERMESSAGESIF_H_
|
||||
|
||||
|
||||
#include "HasParametersIF.h"
|
||||
#include "../ipc/MessageQueueSenderIF.h"
|
||||
|
||||
class ReceivesParameterMessagesIF : public HasParametersIF {
|
||||
public:
|
||||
|
||||
static const uint8_t DOMAIN_ID_BASE = 0;
|
||||
virtual ~ReceivesParameterMessagesIF() {
|
||||
}
|
||||
|
||||
virtual MessageQueueId_t getCommandQueue() const = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif /* FSFW_PARAMETERS_RECEIVESPARAMETERMESSAGESIF_H_ */
|
Reference in New Issue
Block a user