Merge remote-tracking branch 'upstream/development' into mueller/LocalPoolRefactoring
This commit is contained in:
commit
9c59079e94
14
CHANGELOG
14
CHANGELOG
@ -19,6 +19,20 @@ a C file without issues
|
|||||||
|
|
||||||
- Interface of LocalPools has changed. LocalPool is not a template anymore. Instead the size and bucket number of the pools per page and the number of pages are passed to the ctor instead of two ctor arguments and a template parameter
|
- Interface of LocalPools has changed. LocalPool is not a template anymore. Instead the size and bucket number of the pools per page and the number of pages are passed to the ctor instead of two ctor arguments and a template parameter
|
||||||
|
|
||||||
|
### Parameter Service
|
||||||
|
|
||||||
|
- The API of the parameter service has been changed to prevent inconsistencies
|
||||||
|
between documentation and actual code and to clarify usage.
|
||||||
|
- The parameter ID now consists of:
|
||||||
|
1. Domain ID (1 byte)
|
||||||
|
2. Unique Identifier (1 byte)
|
||||||
|
3. Linear Index (2 bytes)
|
||||||
|
The linear index can be used for arrays as well as matrices.
|
||||||
|
The parameter load command now explicitely expects the ECSS PTC and PFC
|
||||||
|
information as well as the rows and column number. Rows and column will
|
||||||
|
default to one, which is equivalent to one scalar parameter (the most
|
||||||
|
important use-case)
|
||||||
|
|
||||||
### File System Interface
|
### File System Interface
|
||||||
|
|
||||||
- A new interfaces specifies the functions for a software object which exposes the file system of a given hardware to use message based file handling (e.g. PUS commanding)
|
- A new interfaces specifies the functions for a software object which exposes the file system of a given hardware to use message based file handling (e.g. PUS commanding)
|
||||||
|
@ -1,12 +1,16 @@
|
|||||||
#ifndef FSFW_PARAMETERS_HASPARAMETERSIF_H_
|
#ifndef FSFW_PARAMETERS_HASPARAMETERSIF_H_
|
||||||
#define FSFW_PARAMETERS_HASPARAMETERSIF_H_
|
#define FSFW_PARAMETERS_HASPARAMETERSIF_H_
|
||||||
|
|
||||||
#include "../parameters/ParameterWrapper.h"
|
#include "ParameterWrapper.h"
|
||||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||||
#include <stdint.h>
|
#include <cstdint>
|
||||||
|
|
||||||
/** Each parameter is identified with a unique parameter ID */
|
/**
|
||||||
typedef uint32_t ParameterId_t;
|
* 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
|
* @brief This interface is used by components which have modifiable
|
||||||
@ -16,16 +20,15 @@ typedef uint32_t ParameterId_t;
|
|||||||
* ID is the domain ID which can be used to identify unqiue spacecraft domains
|
* ID is the domain ID which can be used to identify unqiue spacecraft domains
|
||||||
* (e.g. control and sensor domain in the AOCS controller).
|
* (e.g. control and sensor domain in the AOCS controller).
|
||||||
*
|
*
|
||||||
* The second and third byte represent the matrix ID, which can represent
|
* The second byte is a unique identfier ID.
|
||||||
* 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
|
* The third and fourth byte can be used as a linear index for matrix or array
|
||||||
* of a 8 bit number now?
|
* parameter entries.
|
||||||
*/
|
*/
|
||||||
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;
|
||||||
static const ReturnValue_t INVALID_MATRIX_ID = MAKE_RETURN_CODE(0x01);
|
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_DOMAIN_ID = MAKE_RETURN_CODE(0x02);
|
||||||
static const ReturnValue_t INVALID_VALUE = MAKE_RETURN_CODE(0x03);
|
static const ReturnValue_t INVALID_VALUE = MAKE_RETURN_CODE(0x03);
|
||||||
static const ReturnValue_t READ_ONLY = MAKE_RETURN_CODE(0x05);
|
static const ReturnValue_t READ_ONLY = MAKE_RETURN_CODE(0x05);
|
||||||
@ -34,33 +37,45 @@ public:
|
|||||||
return id >> 24;
|
return id >> 24;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint16_t getMatrixId(ParameterId_t id) {
|
static uint8_t getUniqueIdentifierId(ParameterId_t id) {
|
||||||
return id >> 8;
|
return id >> 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t getIndex(ParameterId_t id) {
|
/**
|
||||||
|
* 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;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t getFullParameterId(uint8_t domainId, uint16_t parameterId,
|
static uint32_t getFullParameterId(uint8_t domainId,
|
||||||
uint8_t index) {
|
uint8_t uniqueIdentifier, uint16_t linearIndex) {
|
||||||
return (domainId << 24) + (parameterId << 8) + index;
|
return (domainId << 24) + (uniqueIdentifier << 16) + linearIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~HasParametersIF() {}
|
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!
|
* Always set parameter before checking newValues!
|
||||||
*
|
*
|
||||||
* @param domainId
|
* @param domainId
|
||||||
* @param parameterId
|
* @param parameterId
|
||||||
* @param parameterWrapper
|
* @param parameterWrapper
|
||||||
* @param newValues
|
* @param newValues
|
||||||
* @param startAtIndex
|
* @param startAtIndex Linear index, runs left to right, top to bottom for
|
||||||
|
* matrix indexes.
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
virtual ReturnValue_t getParameter(uint8_t domainId, uint16_t parameterId,
|
virtual ReturnValue_t getParameter(uint8_t domainId,
|
||||||
ParameterWrapper *parameterWrapper,
|
uint16_t uniqueIdentifier, ParameterWrapper *parameterWrapper,
|
||||||
const ParameterWrapper *newValues, uint16_t startAtIndex) = 0;
|
const ParameterWrapper *newValues, uint16_t startAtIndex) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2,131 +2,133 @@
|
|||||||
#include "ParameterMessage.h"
|
#include "ParameterMessage.h"
|
||||||
#include "../objectmanager/ObjectManagerIF.h"
|
#include "../objectmanager/ObjectManagerIF.h"
|
||||||
|
|
||||||
ParameterHelper::ParameterHelper(ReceivesParameterMessagesIF* owner) :
|
ParameterHelper::ParameterHelper(ReceivesParameterMessagesIF* owner):
|
||||||
owner(owner) {}
|
owner(owner) {}
|
||||||
|
|
||||||
ParameterHelper::~ParameterHelper() {
|
ParameterHelper::~ParameterHelper() {
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t ParameterHelper::handleParameterMessage(CommandMessage *message) {
|
ReturnValue_t ParameterHelper::handleParameterMessage(CommandMessage *message) {
|
||||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED;
|
if(storage == nullptr) {
|
||||||
switch (message->getCommand()) {
|
// ParameterHelper was not initialized
|
||||||
case ParameterMessage::CMD_PARAMETER_DUMP: {
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
ParameterWrapper description;
|
}
|
||||||
uint8_t domain = HasParametersIF::getDomain(
|
|
||||||
ParameterMessage::getParameterId(message));
|
|
||||||
uint16_t parameterId = HasParametersIF::getMatrixId(
|
|
||||||
ParameterMessage::getParameterId(message));
|
|
||||||
result = owner->getParameter(domain, parameterId,
|
|
||||||
&description, &description, 0);
|
|
||||||
if (result == HasReturnvaluesIF::RETURN_OK) {
|
|
||||||
result = sendParameter(message->getSender(),
|
|
||||||
ParameterMessage::getParameterId(message), &description);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case ParameterMessage::CMD_PARAMETER_LOAD: {
|
|
||||||
uint8_t domain = HasParametersIF::getDomain(
|
|
||||||
ParameterMessage::getParameterId(message));
|
|
||||||
uint16_t parameterId = HasParametersIF::getMatrixId(
|
|
||||||
ParameterMessage::getParameterId(message));
|
|
||||||
uint8_t index = HasParametersIF::getIndex(
|
|
||||||
ParameterMessage::getParameterId(message));
|
|
||||||
|
|
||||||
const uint8_t *storedStream = nullptr;
|
ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED;
|
||||||
size_t storedStreamSize = 0;
|
switch (message->getCommand()) {
|
||||||
result = storage->getData(
|
case ParameterMessage::CMD_PARAMETER_DUMP: {
|
||||||
ParameterMessage::getStoreId(message), &storedStream,
|
ParameterWrapper description;
|
||||||
&storedStreamSize);
|
uint8_t domain = HasParametersIF::getDomain(
|
||||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
ParameterMessage::getParameterId(message));
|
||||||
sif::error << "ParameterHelper::handleParameterMessage: Getting"
|
uint8_t uniqueIdentifier = HasParametersIF::getUniqueIdentifierId(
|
||||||
" store data failed for load command." << std::endl;
|
ParameterMessage::getParameterId(message));
|
||||||
break;
|
result = owner->getParameter(domain, uniqueIdentifier,
|
||||||
}
|
&description, &description, 0);
|
||||||
|
if (result == HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
result = sendParameter(message->getSender(),
|
||||||
|
ParameterMessage::getParameterId(message), &description);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ParameterMessage::CMD_PARAMETER_LOAD: {
|
||||||
|
ParameterId_t parameterId = 0;
|
||||||
|
uint8_t ptc = 0;
|
||||||
|
uint8_t pfc = 0;
|
||||||
|
uint8_t rows = 0;
|
||||||
|
uint8_t columns = 0;
|
||||||
|
store_address_t storeId = ParameterMessage::getParameterLoadCommand(
|
||||||
|
message, ¶meterId, &ptc, &pfc, &rows, &columns);
|
||||||
|
Type type(Type::getActualType(ptc, pfc));
|
||||||
|
|
||||||
ParameterWrapper streamWrapper;
|
uint8_t domain = HasParametersIF::getDomain(parameterId);
|
||||||
result = streamWrapper.set(storedStream, storedStreamSize);
|
uint8_t uniqueIdentifier = HasParametersIF::getUniqueIdentifierId(
|
||||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
parameterId);
|
||||||
storage->deleteData(ParameterMessage::getStoreId(message));
|
uint16_t linearIndex = HasParametersIF::getIndex(parameterId);
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
ParameterWrapper ownerWrapper;
|
ConstStorageAccessor accessor(storeId);
|
||||||
result = owner->getParameter(domain, parameterId, &ownerWrapper,
|
result = storage->getData(storeId, accessor);
|
||||||
&streamWrapper, index);
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
sif::error << "ParameterHelper::handleParameterMessage: Getting"
|
||||||
storage->deleteData(ParameterMessage::getStoreId(message));
|
<< " store data failed for load command." << std::endl;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = ownerWrapper.copyFrom(&streamWrapper, index);
|
ParameterWrapper streamWrapper;
|
||||||
|
result = streamWrapper.set(type, rows, columns, accessor.data(),
|
||||||
|
accessor.size());
|
||||||
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
storage->deleteData(ParameterMessage::getStoreId(message));
|
ParameterWrapper ownerWrapper;
|
||||||
|
result = owner->getParameter(domain, uniqueIdentifier, &ownerWrapper,
|
||||||
|
&streamWrapper, linearIndex);
|
||||||
|
|
||||||
if (result == HasReturnvaluesIF::RETURN_OK) {
|
result = ownerWrapper.copyFrom(&streamWrapper, linearIndex);
|
||||||
result = sendParameter(message->getSender(),
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
ParameterMessage::getParameterId(message), &ownerWrapper);
|
return result;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
result = sendParameter(message->getSender(),
|
||||||
rejectCommand(message->getSender(), result, message->getCommand());
|
ParameterMessage::getParameterId(message), &ownerWrapper);
|
||||||
}
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
rejectCommand(message->getSender(), result, message->getCommand());
|
||||||
|
}
|
||||||
|
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t ParameterHelper::sendParameter(MessageQueueId_t to, uint32_t id,
|
ReturnValue_t ParameterHelper::sendParameter(MessageQueueId_t to, uint32_t id,
|
||||||
const ParameterWrapper* description) {
|
const ParameterWrapper* description) {
|
||||||
size_t serializedSize = description->getSerializedSize();
|
size_t serializedSize = description->getSerializedSize();
|
||||||
|
|
||||||
uint8_t *storeElement;
|
uint8_t *storeElement;
|
||||||
store_address_t address;
|
store_address_t address;
|
||||||
|
|
||||||
ReturnValue_t result = storage->getFreeElement(&address, serializedSize,
|
ReturnValue_t result = storage->getFreeElement(&address, serializedSize,
|
||||||
&storeElement);
|
&storeElement);
|
||||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t storeElementSize = 0;
|
size_t storeElementSize = 0;
|
||||||
|
|
||||||
result = description->serialize(&storeElement, &storeElementSize,
|
result = description->serialize(&storeElement, &storeElementSize,
|
||||||
serializedSize, SerializeIF::Endianness::BIG);
|
serializedSize, SerializeIF::Endianness::BIG);
|
||||||
|
|
||||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
storage->deleteData(address);
|
storage->deleteData(address);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandMessage reply;
|
CommandMessage reply;
|
||||||
|
|
||||||
ParameterMessage::setParameterDumpReply(&reply, id, address);
|
ParameterMessage::setParameterDumpReply(&reply, id, address);
|
||||||
|
|
||||||
MessageQueueSenderIF::sendMessage(to, &reply, ownerQueueId);
|
MessageQueueSenderIF::sendMessage(to, &reply, ownerQueueId);
|
||||||
|
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t ParameterHelper::initialize() {
|
ReturnValue_t ParameterHelper::initialize() {
|
||||||
ownerQueueId = owner->getCommandQueue();
|
ownerQueueId = owner->getCommandQueue();
|
||||||
|
|
||||||
|
storage = objectManager->get<StorageManagerIF>(objects::IPC_STORE);
|
||||||
storage = objectManager->get<StorageManagerIF>(objects::IPC_STORE);
|
if (storage == nullptr) {
|
||||||
if (storage == NULL) {
|
return ObjectManagerIF::CHILD_INIT_FAILED;
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
}
|
||||||
} else {
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParameterHelper::rejectCommand(MessageQueueId_t to, ReturnValue_t reason,
|
void ParameterHelper::rejectCommand(MessageQueueId_t to, ReturnValue_t reason,
|
||||||
Command_t initialCommand) {
|
Command_t initialCommand) {
|
||||||
CommandMessage reply;
|
CommandMessage reply;
|
||||||
reply.setReplyRejected(reason, initialCommand);
|
reply.setReplyRejected(reason, initialCommand);
|
||||||
MessageQueueSenderIF::sendMessage(to, &reply, ownerQueueId);
|
MessageQueueSenderIF::sendMessage(to, &reply, ownerQueueId);
|
||||||
}
|
}
|
||||||
|
@ -25,10 +25,26 @@ void ParameterMessage::setParameterDumpReply(CommandMessage* message,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ParameterMessage::setParameterLoadCommand(CommandMessage* message,
|
void ParameterMessage::setParameterLoadCommand(CommandMessage* message,
|
||||||
ParameterId_t id, store_address_t storageID) {
|
ParameterId_t id, store_address_t storeId, uint8_t ptc, uint8_t pfc,
|
||||||
|
uint8_t rows = 1, uint8_t columns = 1) {
|
||||||
message->setCommand(CMD_PARAMETER_LOAD);
|
message->setCommand(CMD_PARAMETER_LOAD);
|
||||||
message->setParameter(id);
|
message->setParameter(id);
|
||||||
message->setParameter2(storageID.raw);
|
message->setParameter2(storeId.raw);
|
||||||
|
uint32_t packedParameterSettings = (ptc << 24) | (pfc << 16) |
|
||||||
|
(rows << 8) | columns;
|
||||||
|
message->setParameter3(packedParameterSettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
store_address_t ParameterMessage::getParameterLoadCommand(
|
||||||
|
const CommandMessage *message, ParameterId_t* parameterId, uint8_t *ptc,
|
||||||
|
uint8_t *pfc, uint8_t *rows, uint8_t *columns) {
|
||||||
|
*parameterId = message->getParameter2();
|
||||||
|
uint32_t packedParamSettings = message->getParameter3();
|
||||||
|
*ptc = packedParamSettings >> 24 & 0xff;
|
||||||
|
*pfc = packedParamSettings >> 16 & 0xff;
|
||||||
|
*rows = packedParamSettings >> 8 & 0xff;
|
||||||
|
*columns = packedParamSettings & 0xff;
|
||||||
|
return message->getParameter2();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParameterMessage::clear(CommandMessage* message) {
|
void ParameterMessage::clear(CommandMessage* message) {
|
||||||
|
@ -5,6 +5,20 @@
|
|||||||
#include "../ipc/CommandMessage.h"
|
#include "../ipc/CommandMessage.h"
|
||||||
#include "../storagemanager/StorageManagerIF.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 {
|
class ParameterMessage {
|
||||||
private:
|
private:
|
||||||
ParameterMessage();
|
ParameterMessage();
|
||||||
@ -20,8 +34,27 @@ public:
|
|||||||
ParameterId_t id);
|
ParameterId_t id);
|
||||||
static void setParameterDumpReply(CommandMessage* message,
|
static void setParameterDumpReply(CommandMessage* message,
|
||||||
ParameterId_t id, store_address_t storageID);
|
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,
|
static void setParameterLoadCommand(CommandMessage* message,
|
||||||
ParameterId_t id, store_address_t storageID);
|
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);
|
static void clear(CommandMessage* message);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -115,7 +115,7 @@ ReturnValue_t ParameterWrapper::deSerializeData(uint8_t startingRow,
|
|||||||
uint8_t fromColumns) {
|
uint8_t fromColumns) {
|
||||||
|
|
||||||
//treat from as a continuous Stream as we copy all of it
|
//treat from as a continuous Stream as we copy all of it
|
||||||
const uint8_t *fromAsStream = (const uint8_t*) from;
|
const uint8_t *fromAsStream = reinterpret_cast<const uint8_t*>(from);
|
||||||
size_t streamSize = fromRows * fromColumns * sizeof(T);
|
size_t streamSize = fromRows * fromColumns * sizeof(T);
|
||||||
|
|
||||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||||
@ -123,8 +123,9 @@ ReturnValue_t ParameterWrapper::deSerializeData(uint8_t startingRow,
|
|||||||
for (uint8_t fromRow = 0; fromRow < fromRows; fromRow++) {
|
for (uint8_t fromRow = 0; fromRow < fromRows; fromRow++) {
|
||||||
|
|
||||||
//get the start element of this row in data
|
//get the start element of this row in data
|
||||||
T *dataWithDataType = ((T*) data)
|
uint16_t offset = (((startingRow + fromRow) *
|
||||||
+ (((startingRow + fromRow) * columns) + startingColumn);
|
static_cast<uint16_t>(columns)) + startingColumn);
|
||||||
|
T *dataWithDataType = static_cast<T*>(data) + offset;
|
||||||
|
|
||||||
for (uint8_t fromColumn = 0; fromColumn < fromColumns; fromColumn++) {
|
for (uint8_t fromColumn = 0; fromColumn < fromColumns; fromColumn++) {
|
||||||
result = SerializeAdapter::deSerialize(
|
result = SerializeAdapter::deSerialize(
|
||||||
@ -159,6 +160,23 @@ ReturnValue_t ParameterWrapper::deSerialize(const uint8_t **buffer,
|
|||||||
return copyFrom(&streamDescription, startWritingAtIndex);
|
return copyFrom(&streamDescription, startWritingAtIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ReturnValue_t ParameterWrapper::set(Type type, uint8_t rows, uint8_t columns,
|
||||||
|
const void *data, size_t dataSize) {
|
||||||
|
this->type = type;
|
||||||
|
this->rows = rows;
|
||||||
|
this->columns = columns;
|
||||||
|
|
||||||
|
size_t expectedSize = type.getSize() * rows * columns;
|
||||||
|
if (expectedSize < dataSize) {
|
||||||
|
return SerializeIF::STREAM_TOO_SHORT;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->data = nullptr;
|
||||||
|
this->readonlyData = data;
|
||||||
|
pointsToStream = true;
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
ReturnValue_t ParameterWrapper::set(const uint8_t *stream, size_t streamSize,
|
ReturnValue_t ParameterWrapper::set(const uint8_t *stream, size_t streamSize,
|
||||||
const uint8_t **remainingStream, size_t *remainingSize) {
|
const uint8_t **remainingStream, size_t *remainingSize) {
|
||||||
ReturnValue_t result = SerializeAdapter::deSerialize(&type, &stream,
|
ReturnValue_t result = SerializeAdapter::deSerialize(&type, &stream,
|
||||||
@ -202,11 +220,13 @@ ReturnValue_t ParameterWrapper::set(const uint8_t *stream, size_t streamSize,
|
|||||||
|
|
||||||
ReturnValue_t ParameterWrapper::copyFrom(const ParameterWrapper *from,
|
ReturnValue_t ParameterWrapper::copyFrom(const ParameterWrapper *from,
|
||||||
uint16_t startWritingAtIndex) {
|
uint16_t startWritingAtIndex) {
|
||||||
if (data == NULL) {
|
// TODO: Optional diagnostic output (which can be disabled in FSFWConfig)
|
||||||
|
// to determined faulty implementations and configuration errors quickly.
|
||||||
|
if (data == nullptr) {
|
||||||
return READONLY;
|
return READONLY;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (from->readonlyData == NULL) {
|
if (from->readonlyData == nullptr) {
|
||||||
return SOURCE_NOT_SET;
|
return SOURCE_NOT_SET;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -214,9 +234,16 @@ ReturnValue_t ParameterWrapper::copyFrom(const ParameterWrapper *from,
|
|||||||
return DATATYPE_MISSMATCH;
|
return DATATYPE_MISSMATCH;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The smallest allowed value for rows and columns is one.
|
||||||
|
if(rows == 0 or columns == 0) {
|
||||||
|
return COLUMN_OR_ROWS_ZERO;
|
||||||
|
}
|
||||||
|
|
||||||
//check if from fits into this
|
//check if from fits into this
|
||||||
uint8_t startingRow = startWritingAtIndex / columns;
|
uint8_t startingRow = 0;
|
||||||
uint8_t startingColumn = startWritingAtIndex % columns;
|
uint8_t startingColumn = 0;
|
||||||
|
ParameterWrapper::convertLinearIndexToRowAndColumn(startWritingAtIndex,
|
||||||
|
&startingRow, &startingColumn);
|
||||||
|
|
||||||
if ((from->rows > (rows - startingRow))
|
if ((from->rows > (rows - startingRow))
|
||||||
|| (from->columns > (columns - startingColumn))) {
|
|| (from->columns > (columns - startingColumn))) {
|
||||||
@ -270,8 +297,8 @@ ReturnValue_t ParameterWrapper::copyFrom(const ParameterWrapper *from,
|
|||||||
//need a type to do arithmetic
|
//need a type to do arithmetic
|
||||||
uint8_t* typedData = static_cast<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++) {
|
||||||
size_t offset = (((startingRow + fromRow) * columns) +
|
size_t offset = (((startingRow + fromRow) * static_cast<uint16_t>(
|
||||||
startingColumn) * typeSize;
|
columns)) + startingColumn) * typeSize;
|
||||||
std::memcpy(typedData + offset, from->readonlyData,
|
std::memcpy(typedData + offset, from->readonlyData,
|
||||||
typeSize * from->columns);
|
typeSize * from->columns);
|
||||||
}
|
}
|
||||||
@ -279,3 +306,18 @@ ReturnValue_t ParameterWrapper::copyFrom(const ParameterWrapper *from,
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ParameterWrapper::convertLinearIndexToRowAndColumn(uint16_t index,
|
||||||
|
uint8_t *row, uint8_t *column) {
|
||||||
|
if(row == nullptr or column == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Integer division.
|
||||||
|
*row = index / columns;
|
||||||
|
*column = index % columns;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t ParameterWrapper::convertRowAndColumnToLinearIndex(uint8_t row,
|
||||||
|
uint8_t column) {
|
||||||
|
return row * columns + column;
|
||||||
|
}
|
||||||
|
@ -22,6 +22,7 @@ public:
|
|||||||
static const ReturnValue_t SOURCE_NOT_SET = MAKE_RETURN_CODE(0x05);
|
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 OUT_OF_BOUNDS = MAKE_RETURN_CODE(0x06);
|
||||||
static const ReturnValue_t NOT_SET = MAKE_RETURN_CODE(0x07);
|
static const ReturnValue_t NOT_SET = MAKE_RETURN_CODE(0x07);
|
||||||
|
static const ReturnValue_t COLUMN_OR_ROWS_ZERO = MAKE_RETURN_CODE(0x08);
|
||||||
|
|
||||||
ParameterWrapper();
|
ParameterWrapper();
|
||||||
ParameterWrapper(Type type, uint8_t rows, uint8_t columns, void *data);
|
ParameterWrapper(Type type, uint8_t rows, uint8_t columns, void *data);
|
||||||
@ -68,7 +69,7 @@ public:
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void set(const T *readonlyData, uint8_t rows, uint8_t columns) {
|
void set(const T *readonlyData, uint8_t rows, uint8_t columns) {
|
||||||
this->data = NULL;
|
this->data = nullptr;
|
||||||
this->readonlyData = readonlyData;
|
this->readonlyData = readonlyData;
|
||||||
this->type = PodTypeConversion<T>::type;
|
this->type = PodTypeConversion<T>::type;
|
||||||
this->rows = rows;
|
this->rows = rows;
|
||||||
@ -97,14 +98,19 @@ public:
|
|||||||
}
|
}
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void setMatrix(T& member) {
|
void setMatrix(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]));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
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(Type type, uint8_t rows, uint8_t columns,
|
||||||
|
const void *data, size_t dataSize);
|
||||||
|
|
||||||
ReturnValue_t set(const uint8_t *stream, size_t streamSize,
|
ReturnValue_t set(const uint8_t *stream, size_t streamSize,
|
||||||
const uint8_t **remainingStream = nullptr,
|
const uint8_t **remainingStream = nullptr,
|
||||||
size_t *remainingSize = nullptr);
|
size_t *remainingSize = nullptr);
|
||||||
@ -113,6 +119,13 @@ public:
|
|||||||
uint16_t startWritingAtIndex);
|
uint16_t startWritingAtIndex);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
void convertLinearIndexToRowAndColumn(uint16_t index,
|
||||||
|
uint8_t *row, uint8_t *column);
|
||||||
|
|
||||||
|
uint16_t convertRowAndColumnToLinearIndex(uint8_t row,
|
||||||
|
uint8_t column);
|
||||||
|
|
||||||
bool pointsToStream = false;
|
bool pointsToStream = false;
|
||||||
|
|
||||||
Type type;
|
Type type;
|
||||||
@ -148,9 +161,9 @@ inline ReturnValue_t ParameterWrapper::getElement(T *value, uint8_t row,
|
|||||||
if (pointsToStream) {
|
if (pointsToStream) {
|
||||||
const uint8_t *streamWithType = static_cast<const uint8_t*>(readonlyData);
|
const uint8_t *streamWithType = static_cast<const uint8_t*>(readonlyData);
|
||||||
streamWithType += (row * columns + column) * type.getSize();
|
streamWithType += (row * columns + column) * type.getSize();
|
||||||
int32_t size = type.getSize();
|
size_t size = type.getSize();
|
||||||
return SerializeAdapter::deSerialize(value, &streamWithType,
|
return SerializeAdapter::deSerialize(value, &streamWithType,
|
||||||
&size, true);
|
&size, SerializeIF::Endianness::BIG);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const T *dataWithType = static_cast<const T*>(readonlyData);
|
const T *dataWithType = static_cast<const T*>(readonlyData);
|
||||||
|
Loading…
Reference in New Issue
Block a user