HasParametersIF less confusing

This commit is contained in:
Robin Müller 2020-10-18 16:54:55 +02:00
parent 9a70f75a4b
commit 02b7c51318
6 changed files with 64 additions and 29 deletions

View File

@ -194,7 +194,7 @@ ReturnValue_t DataPoolAdmin::handleParameterCommand(CommandMessage* command) {
case ParameterMessage::CMD_PARAMETER_DUMP: { case ParameterMessage::CMD_PARAMETER_DUMP: {
uint8_t domain = HasParametersIF::getDomain( uint8_t domain = HasParametersIF::getDomain(
ParameterMessage::getParameterId(command)); ParameterMessage::getParameterId(command));
uint16_t parameterId = HasParametersIF::getMatrixId( uint16_t parameterId = HasParametersIF::getUniqueIdentifierId(
ParameterMessage::getParameterId(command)); ParameterMessage::getParameterId(command));
DataPoolParameterWrapper wrapper; DataPoolParameterWrapper wrapper;
@ -210,7 +210,7 @@ ReturnValue_t DataPoolAdmin::handleParameterCommand(CommandMessage* command) {
uint8_t domain = HasParametersIF::getDomain( uint8_t domain = HasParametersIF::getDomain(
ParameterMessage::getParameterId(command)); ParameterMessage::getParameterId(command));
uint16_t parameterId = HasParametersIF::getMatrixId( uint16_t parameterId = HasParametersIF::getUniqueIdentifierId(
ParameterMessage::getParameterId(command)); ParameterMessage::getParameterId(command));
uint8_t index = HasParametersIF::getIndex( uint8_t index = HasParametersIF::getIndex(
ParameterMessage::getParameterId(command)); ParameterMessage::getParameterId(command));

View File

@ -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 "../returnvalues/HasReturnvaluesIF.h" #include "../returnvalues/HasReturnvaluesIF.h"
#include <stdint.h> #include "ParameterWrapper.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
@ -19,7 +23,7 @@ typedef uint32_t ParameterId_t;
* The second and third byte represent the matrix ID, which can represent * The second and third byte represent the matrix ID, which can represent
* a 8-bit row and column number and the last byte... * 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 * Yeah, is it matrix ID or parameter ID now and is index a 16 bit number
* of a 8 bit number now? * of a 8 bit number now?
*/ */
class HasParametersIF { class HasParametersIF {
@ -34,17 +38,24 @@ 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() {}
@ -56,11 +67,12 @@ public:
* @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;
}; };

View File

@ -15,9 +15,9 @@ ReturnValue_t ParameterHelper::handleParameterMessage(CommandMessage *message) {
ParameterWrapper description; ParameterWrapper description;
uint8_t domain = HasParametersIF::getDomain( uint8_t domain = HasParametersIF::getDomain(
ParameterMessage::getParameterId(message)); ParameterMessage::getParameterId(message));
uint16_t parameterId = HasParametersIF::getMatrixId( uint8_t uniqueIdentifier = HasParametersIF::getUniqueIdentifierId(
ParameterMessage::getParameterId(message)); ParameterMessage::getParameterId(message));
result = owner->getParameter(domain, parameterId, result = owner->getParameter(domain, uniqueIdentifier,
&description, &description, 0); &description, &description, 0);
if (result == HasReturnvaluesIF::RETURN_OK) { if (result == HasReturnvaluesIF::RETURN_OK) {
result = sendParameter(message->getSender(), result = sendParameter(message->getSender(),
@ -26,12 +26,11 @@ ReturnValue_t ParameterHelper::handleParameterMessage(CommandMessage *message) {
} }
break; break;
case ParameterMessage::CMD_PARAMETER_LOAD: { case ParameterMessage::CMD_PARAMETER_LOAD: {
uint8_t domain = HasParametersIF::getDomain( ParameterId_t parameterId = ParameterMessage::getParameterId(message);
ParameterMessage::getParameterId(message)); uint8_t domain = HasParametersIF::getDomain(parameterId);
uint16_t parameterId = HasParametersIF::getMatrixId( uint8_t uniqueIdentifier = HasParametersIF::getUniqueIdentifierId(
ParameterMessage::getParameterId(message)); parameterId);
uint8_t index = HasParametersIF::getIndex( uint16_t index = HasParametersIF::getIndex(parameterId);
ParameterMessage::getParameterId(message));
const uint8_t *storedStream = nullptr; const uint8_t *storedStream = nullptr;
size_t storedStreamSize = 0; size_t storedStreamSize = 0;
@ -52,7 +51,7 @@ ReturnValue_t ParameterHelper::handleParameterMessage(CommandMessage *message) {
} }
ParameterWrapper ownerWrapper; ParameterWrapper ownerWrapper;
result = owner->getParameter(domain, parameterId, &ownerWrapper, result = owner->getParameter(domain, uniqueIdentifier, &ownerWrapper,
&streamWrapper, index); &streamWrapper, index);
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
storage->deleteData(ParameterMessage::getStoreId(message)); storage->deleteData(ParameterMessage::getStoreId(message));

View File

@ -202,11 +202,11 @@ 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) { if (data == nullptr) {
return READONLY; return READONLY;
} }
if (from->readonlyData == NULL) { if (from->readonlyData == nullptr) {
return SOURCE_NOT_SET; return SOURCE_NOT_SET;
} }
@ -215,8 +215,10 @@ ReturnValue_t ParameterWrapper::copyFrom(const ParameterWrapper *from,
} }
//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))) {
@ -279,3 +281,17 @@ 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;
}
*row = index / columns;
*column = index % columns;
}
uint16_t ParameterWrapper::convertRowAndColumnToLinearIndex(uint8_t row,
uint8_t column) {
return row * columns + column;
}

View File

@ -113,6 +113,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;

View File

@ -1,4 +1,5 @@
#include "PowerComponent.h" #include "PowerComponent.h"
#include "../serialize/SerializeAdapter.h"
PowerComponent::PowerComponent(): switchId1(0xFF), switchId2(0xFF), PowerComponent::PowerComponent(): switchId1(0xFF), switchId2(0xFF),
doIHaveTwoSwitches(false) { doIHaveTwoSwitches(false) {