HasParametersIF less confusing
This commit is contained in:
parent
9a70f75a4b
commit
02b7c51318
@ -194,7 +194,7 @@ ReturnValue_t DataPoolAdmin::handleParameterCommand(CommandMessage* command) {
|
||||
case ParameterMessage::CMD_PARAMETER_DUMP: {
|
||||
uint8_t domain = HasParametersIF::getDomain(
|
||||
ParameterMessage::getParameterId(command));
|
||||
uint16_t parameterId = HasParametersIF::getMatrixId(
|
||||
uint16_t parameterId = HasParametersIF::getUniqueIdentifierId(
|
||||
ParameterMessage::getParameterId(command));
|
||||
|
||||
DataPoolParameterWrapper wrapper;
|
||||
@ -210,7 +210,7 @@ ReturnValue_t DataPoolAdmin::handleParameterCommand(CommandMessage* command) {
|
||||
|
||||
uint8_t domain = HasParametersIF::getDomain(
|
||||
ParameterMessage::getParameterId(command));
|
||||
uint16_t parameterId = HasParametersIF::getMatrixId(
|
||||
uint16_t parameterId = HasParametersIF::getUniqueIdentifierId(
|
||||
ParameterMessage::getParameterId(command));
|
||||
uint8_t index = HasParametersIF::getIndex(
|
||||
ParameterMessage::getParameterId(command));
|
||||
|
@ -1,12 +1,16 @@
|
||||
#ifndef FSFW_PARAMETERS_HASPARAMETERSIF_H_
|
||||
#define FSFW_PARAMETERS_HASPARAMETERSIF_H_
|
||||
|
||||
#include "../parameters/ParameterWrapper.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
|
||||
@ -19,7 +23,7 @@ typedef uint32_t ParameterId_t;
|
||||
* 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
|
||||
* Yeah, is it matrix ID or parameter ID now and is index a 16 bit number
|
||||
* of a 8 bit number now?
|
||||
*/
|
||||
class HasParametersIF {
|
||||
@ -34,17 +38,24 @@ public:
|
||||
return id >> 24;
|
||||
}
|
||||
|
||||
static uint16_t getMatrixId(ParameterId_t id) {
|
||||
return id >> 8;
|
||||
static uint8_t getUniqueIdentifierId(ParameterId_t id) {
|
||||
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;
|
||||
}
|
||||
|
||||
static uint32_t getFullParameterId(uint8_t domainId, uint16_t parameterId,
|
||||
uint8_t index) {
|
||||
return (domainId << 24) + (parameterId << 8) + index;
|
||||
static uint32_t getFullParameterId(uint8_t domainId,
|
||||
uint8_t uniqueIdentifier, uint16_t linearIndex) {
|
||||
return (domainId << 24) + (uniqueIdentifier << 16) + linearIndex;
|
||||
}
|
||||
|
||||
virtual ~HasParametersIF() {}
|
||||
@ -56,11 +67,12 @@ public:
|
||||
* @param parameterId
|
||||
* @param parameterWrapper
|
||||
* @param newValues
|
||||
* @param startAtIndex
|
||||
* @param startAtIndex Linear index, runs left to right, top to bottom for
|
||||
* matrix indexes.
|
||||
* @return
|
||||
*/
|
||||
virtual ReturnValue_t getParameter(uint8_t domainId, uint16_t parameterId,
|
||||
ParameterWrapper *parameterWrapper,
|
||||
virtual ReturnValue_t getParameter(uint8_t domainId,
|
||||
uint16_t uniqueIdentifier, ParameterWrapper *parameterWrapper,
|
||||
const ParameterWrapper *newValues, uint16_t startAtIndex) = 0;
|
||||
};
|
||||
|
||||
|
@ -15,9 +15,9 @@ ReturnValue_t ParameterHelper::handleParameterMessage(CommandMessage *message) {
|
||||
ParameterWrapper description;
|
||||
uint8_t domain = HasParametersIF::getDomain(
|
||||
ParameterMessage::getParameterId(message));
|
||||
uint16_t parameterId = HasParametersIF::getMatrixId(
|
||||
uint8_t uniqueIdentifier = HasParametersIF::getUniqueIdentifierId(
|
||||
ParameterMessage::getParameterId(message));
|
||||
result = owner->getParameter(domain, parameterId,
|
||||
result = owner->getParameter(domain, uniqueIdentifier,
|
||||
&description, &description, 0);
|
||||
if (result == HasReturnvaluesIF::RETURN_OK) {
|
||||
result = sendParameter(message->getSender(),
|
||||
@ -26,12 +26,11 @@ ReturnValue_t ParameterHelper::handleParameterMessage(CommandMessage *message) {
|
||||
}
|
||||
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));
|
||||
ParameterId_t parameterId = ParameterMessage::getParameterId(message);
|
||||
uint8_t domain = HasParametersIF::getDomain(parameterId);
|
||||
uint8_t uniqueIdentifier = HasParametersIF::getUniqueIdentifierId(
|
||||
parameterId);
|
||||
uint16_t index = HasParametersIF::getIndex(parameterId);
|
||||
|
||||
const uint8_t *storedStream = nullptr;
|
||||
size_t storedStreamSize = 0;
|
||||
@ -52,7 +51,7 @@ ReturnValue_t ParameterHelper::handleParameterMessage(CommandMessage *message) {
|
||||
}
|
||||
|
||||
ParameterWrapper ownerWrapper;
|
||||
result = owner->getParameter(domain, parameterId, &ownerWrapper,
|
||||
result = owner->getParameter(domain, uniqueIdentifier, &ownerWrapper,
|
||||
&streamWrapper, index);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
storage->deleteData(ParameterMessage::getStoreId(message));
|
||||
|
@ -202,11 +202,11 @@ ReturnValue_t ParameterWrapper::set(const uint8_t *stream, size_t streamSize,
|
||||
|
||||
ReturnValue_t ParameterWrapper::copyFrom(const ParameterWrapper *from,
|
||||
uint16_t startWritingAtIndex) {
|
||||
if (data == NULL) {
|
||||
if (data == nullptr) {
|
||||
return READONLY;
|
||||
}
|
||||
|
||||
if (from->readonlyData == NULL) {
|
||||
if (from->readonlyData == nullptr) {
|
||||
return SOURCE_NOT_SET;
|
||||
}
|
||||
|
||||
@ -215,8 +215,10 @@ ReturnValue_t ParameterWrapper::copyFrom(const ParameterWrapper *from,
|
||||
}
|
||||
|
||||
//check if from fits into this
|
||||
uint8_t startingRow = startWritingAtIndex / columns;
|
||||
uint8_t startingColumn = startWritingAtIndex % columns;
|
||||
uint8_t startingRow = 0;
|
||||
uint8_t startingColumn = 0;
|
||||
ParameterWrapper::convertLinearIndexToRowAndColumn(startWritingAtIndex,
|
||||
&startingRow, &startingColumn);
|
||||
|
||||
if ((from->rows > (rows - startingRow))
|
||||
|| (from->columns > (columns - startingColumn))) {
|
||||
@ -279,3 +281,17 @@ ReturnValue_t ParameterWrapper::copyFrom(const ParameterWrapper *from,
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -113,6 +113,13 @@ public:
|
||||
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;
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "PowerComponent.h"
|
||||
#include "../serialize/SerializeAdapter.h"
|
||||
|
||||
PowerComponent::PowerComponent(): switchId1(0xFF), switchId2(0xFF),
|
||||
doIHaveTwoSwitches(false) {
|
||||
|
Loading…
Reference in New Issue
Block a user