From 5ac3762dc51752ba4538817d8ddd87dc50766ec7 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sun, 31 Jan 2021 20:53:25 +0100 Subject: [PATCH] srv20 improvements and bugfixes --- parameters/ParameterHelper.cpp | 2 +- parameters/ParameterWrapper.cpp | 8 ++-- pus/Service20ParameterManagement.cpp | 1 + pus/servicepackets/Service20Packets.h | 62 +++++++++++++++++++++++++-- 4 files changed, 64 insertions(+), 9 deletions(-) diff --git a/parameters/ParameterHelper.cpp b/parameters/ParameterHelper.cpp index 4ad5cdf2..24d0b2b1 100644 --- a/parameters/ParameterHelper.cpp +++ b/parameters/ParameterHelper.cpp @@ -90,7 +90,7 @@ ReturnValue_t ParameterHelper::sendParameter(MessageQueueId_t to, uint32_t id, const ParameterWrapper* description) { size_t serializedSize = description->getSerializedSize(); - uint8_t *storeElement; + uint8_t *storeElement = nullptr; store_address_t address; ReturnValue_t result = storage->getFreeElement(&address, serializedSize, diff --git a/parameters/ParameterWrapper.cpp b/parameters/ParameterWrapper.cpp index 124f2eda..660d7db7 100644 --- a/parameters/ParameterWrapper.cpp +++ b/parameters/ParameterWrapper.cpp @@ -7,13 +7,13 @@ ParameterWrapper::ParameterWrapper() : } ParameterWrapper::ParameterWrapper(Type type, uint8_t rows, uint8_t columns, - void *data) : + void *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) : + const void *data): pointsToStream(false), type(type), rows(rows), columns(columns), data(nullptr), readonlyData(data) { } @@ -42,8 +42,8 @@ ReturnValue_t ParameterWrapper::serialize(uint8_t **buffer, size_t *size, return result; } - //serialize uses readonlyData, as it is always valid - if (readonlyData == NULL) { + /* serialize uses readonlyData, as it is always valid */ + if (readonlyData == nullptr) { return NOT_SET; } switch (type) { diff --git a/pus/Service20ParameterManagement.cpp b/pus/Service20ParameterManagement.cpp index 2d69f77a..bc3a9119 100644 --- a/pus/Service20ParameterManagement.cpp +++ b/pus/Service20ParameterManagement.cpp @@ -172,6 +172,7 @@ ReturnValue_t Service20ParameterManagement::handleReply( if(parameterData.first != HasReturnvaluesIF::RETURN_OK) { return HasReturnvaluesIF::RETURN_FAILED; } + ParameterId_t parameterId = ParameterMessage::getParameterId(reply); ParameterDumpReply parameterReply(objectId, parameterId, parameterData.second.data(), parameterData.second.size()); diff --git a/pus/servicepackets/Service20Packets.h b/pus/servicepackets/Service20Packets.h index d108dba4..33bd153d 100644 --- a/pus/servicepackets/Service20Packets.h +++ b/pus/servicepackets/Service20Packets.h @@ -1,28 +1,57 @@ #ifndef FSFW_PUS_SERVICEPACKETS_SERVICE20PACKETS_H_ #define FSFW_PUS_SERVICEPACKETS_SERVICE20PACKETS_H_ +#include #include #include #include #include +#include /** - * @brief + * @brief This class encapsulates the packets sent to the PUS service 20 or sent by the + * PUS service 20 * @details + * This command can be used to handle both load and dump commands as well. * @author */ class ParameterCommand: public SerialLinkedListAdapter { //!< [EXPORT] : [SUBSERVICE] 128, 129, 130 public: + + /** + * This constructor is used for load replies. The data is expected in the correct formast + * in the store pointer. + * @param storePointer + * @param parameterDataLen + */ ParameterCommand(uint8_t* storePointer, size_t parameterDataLen): parameterBuffer(storePointer, parameterDataLen) { - setLinks(); +#if FSFW_VERBOSE_LEVEL >= 1 + if(parameterDataLen < sizeof(object_id_t) + sizeof(ParameterId_t) + 4) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "ParameterCommand: Parameter data length is less than 12!" + << std::endl; +#else + sif::printWarning("ParameterCommand: Parameter data length is less than 12!\n"); +#endif + } +#endif /* FSFW_VERBOSE_LEVEL >= 1 */ + setLoadLinks(); } + /** + * This constructor is used for dump replies. It is assumed the 4 byte parameter + * information field is located inside the parameter buffer. + * @param objectId + * @param parameterId + * @param parameterBuffer + * @param parameterBufferSize + */ ParameterCommand(object_id_t objectId, ParameterId_t parameterId, const uint8_t* parameterBuffer, size_t parameterBufferSize): objectId(objectId), parameterId(parameterId), parameterBuffer(parameterBuffer, parameterBufferSize) { - setLinks(); + setDumpReplyLinks(); } ParameterId_t getParameterId() const { @@ -37,6 +66,18 @@ public: return parameterBuffer.getSerializedSize(); } + uint8_t getDomainId() const { + return (parameterId.entry >> 24) & 0xff; + } + + uint8_t getUniqueId() const { + return (parameterId.entry >> 16) & 0xff; + } + + uint16_t getLinearIndex() const { + return parameterId.entry & 0xffff; + } + uint8_t getPtc() const { return ccsdsType.entry >> 8 & 0xff; } @@ -54,7 +95,7 @@ public: } private: - void setLinks() { + void setLoadLinks() { setStart(&objectId); objectId.setNext(¶meterId); parameterId.setNext(&ccsdsType); @@ -63,6 +104,19 @@ private: columns.setNext(¶meterBuffer); } + void setDumpReplyLinks() { + /* For a dump reply, the parameter information is contained in the parameter buffer + with the actual parameters */ + setStart(&objectId); + objectId.setNext(¶meterId); + parameterId.setNext(¶meterBuffer); + } + + void setDumpRequestLinks() { + setStart(&objectId); + objectId.setNext(¶meterId); + } + SerializeElement objectId = 0; SerializeElement parameterId = 0; //! [EXPORT] : [COMMENT] Type consisting of one byte PTC and one byte PFC.