Merge branch 'mueller/refactor-tmtc-stack' into mueller/cfdp-routers

This commit is contained in:
Robin Müller 2022-09-05 16:19:34 +02:00
commit a5d1c38b22
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
12 changed files with 84 additions and 146 deletions

View File

@ -360,7 +360,8 @@ if(NOT FSFW_CONFIG_PATH)
if(NOT FSFW_BUILD_DOCS)
message(
WARNING
"${MSG_PREFIX} Flight Software Framework configuration path not set")
"${MSG_PREFIX} Flight Software Framework configuration path FSFW_CONFIG_PATH not set"
)
message(
WARNING
"${MSG_PREFIX} Setting default configuration from ${DEF_CONF_PATH} ..")

View File

@ -124,6 +124,13 @@ void SerialBufferAdapter<count_t>::setBuffer(const uint8_t* data, count_t len) {
this->bufferLength = len;
}
template <typename count_t>
void SerialBufferAdapter<count_t>::setConstBuffer(const uint8_t* buf, count_t bufLen) {
this->buffer = nullptr;
this->bufferLength = bufLen;
this->constBuffer = buf;
}
// forward Template declaration for linker
template class SerialBufferAdapter<uint8_t>;
template class SerialBufferAdapter<uint16_t>;

View File

@ -21,6 +21,7 @@
template <typename count_t>
class SerialBufferAdapter : public SerializeIF {
public:
SerialBufferAdapter() = default;
/**
* Constructor for constant uint8_t buffer. Length field can be serialized optionally.
* Type of length can be supplied as template type.
@ -42,7 +43,7 @@ class SerialBufferAdapter : public SerializeIF {
~SerialBufferAdapter() override;
ReturnValue_t serialize(uint8_t** buffer_, size_t* size, size_t maxSize,
ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize,
Endianness streamEndianness) const override;
[[nodiscard]] size_t getSerializedSize() const override;
@ -59,12 +60,13 @@ class SerialBufferAdapter : public SerializeIF {
* @param bigEndian
* @return
*/
ReturnValue_t deSerialize(const uint8_t** buffer_, size_t* size,
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
Endianness streamEndianness) override;
uint8_t* getBuffer();
[[nodiscard]] const uint8_t* getConstBuffer() const;
void setBuffer(const uint8_t* buffer, count_t bufferLength);
void setBuffer(uint8_t* buffer, count_t bufferLength);
void setConstBuffer(const uint8_t* buf, count_t bufLen);
private:
bool serializeLength = false;

View File

@ -7,6 +7,6 @@ class CustomUserDataIF {
public:
virtual ~CustomUserDataIF() = default;
virtual ReturnValue_t setRawUserData(const uint8_t* data, size_t len) = 0;
virtual ReturnValue_t setSerializableUserData(SerializeIF& serializable) = 0;
virtual ReturnValue_t setSerializableUserData(const SerializeIF& serializable) = 0;
};
#endif // FSFW_TMTCPACKET_CREATORDATAIF_H

View File

@ -14,7 +14,6 @@ PusTcCreator::PusTcCreator(SpacePacketParams spParams, PusTcParams pusParams)
ReturnValue_t PusTcCreator::serialize(uint8_t **buffer, size_t *size, size_t maxSize,
SerializeIF::Endianness streamEndianness) const {
const uint8_t *start = *buffer;
size_t userDataLen = pusParams.dataWrapper.getLength();
if (*size + getSerializedSize() > maxSize) {
return SerializeIF::BUFFER_TOO_SHORT;
}
@ -37,17 +36,8 @@ ReturnValue_t PusTcCreator::serialize(uint8_t **buffer, size_t *size, size_t max
if (result != returnvalue::OK) {
return result;
}
if (pusParams.dataWrapper.type == util::DataTypes::RAW) {
const uint8_t *data = pusParams.dataWrapper.dataUnion.raw.data;
if (data != nullptr and userDataLen > 0) {
std::memcpy(*buffer, data, userDataLen);
*buffer += userDataLen;
*size += userDataLen;
}
} else if (pusParams.dataWrapper.type == util::DataTypes::SERIALIZABLE and
pusParams.dataWrapper.dataUnion.serializable != nullptr) {
result = pusParams.dataWrapper.dataUnion.serializable->serialize(buffer, size, maxSize,
streamEndianness);
if (pusParams.appData != nullptr) {
result = pusParams.appData->serialize(buffer, size, maxSize, streamEndianness);
if (result != returnvalue::OK) {
return result;
}
@ -58,9 +48,11 @@ ReturnValue_t PusTcCreator::serialize(uint8_t **buffer, size_t *size, size_t max
}
void PusTcCreator::updateSpLengthField() {
spCreator.setCcsdsLenFromTotalDataFieldLen(ecss::PusTcDataFieldHeader::MIN_SIZE +
pusParams.dataWrapper.getLength() +
sizeof(ecss::PusChecksumT));
size_t len = ecss::PusTcDataFieldHeader::MIN_SIZE + sizeof(ecss::PusChecksumT);
if (pusParams.appData != nullptr) {
len += pusParams.appData->getSerializedSize();
}
spCreator.setCcsdsLenFromTotalDataFieldLen(len);
}
size_t PusTcCreator::getSerializedSize() const { return spCreator.getFullPacketLen(); }
@ -92,14 +84,15 @@ SpacePacketParams &PusTcCreator::getSpParams() { return spCreator.getParams(); }
ReturnValue_t PusTcCreator::setRawUserData(const uint8_t *data, size_t len) {
// TODO: Check length field?
pusParams.dataWrapper.setRawData({data, len});
pusParams.bufAdapter.setConstBuffer(data, len);
pusParams.appData = &pusParams.bufAdapter;
updateSpLengthField();
return returnvalue::OK;
}
ReturnValue_t PusTcCreator::setSerializableUserData(SerializeIF &serializable) {
ReturnValue_t PusTcCreator::setSerializableUserData(const SerializeIF &serializable) {
// TODO: Check length field?
pusParams.dataWrapper.setSerializable(serializable);
pusParams.appData = &serializable;
updateSpLengthField();
return returnvalue::OK;
}

View File

@ -1,22 +1,30 @@
#ifndef FSFW_TMTCPACKET_TCPACKETDESERIALIZER_H
#define FSFW_TMTCPACKET_TCPACKETDESERIALIZER_H
#include "fsfw/serialize/SerialBufferAdapter.h"
#include "fsfw/tmtcpacket/RedirectableDataPointerIF.h"
#include "fsfw/tmtcpacket/ccsds/SpacePacketCreator.h"
#include "fsfw/tmtcpacket/ccsds/SpacePacketIF.h"
#include "fsfw/tmtcpacket/pus/CustomUserDataIF.h"
#include "fsfw/tmtcpacket/pus/defs.h"
#include "fsfw/tmtcpacket/pus/tc/PusTcIF.h"
#include "fsfw/util/dataWrapper.h"
struct PusTcParams {
PusTcParams(uint8_t service_, uint8_t subservice_) : service(service_), subservice(subservice_) {}
void setRawAppData(const uint8_t *data, size_t len) {
bufAdapter.setConstBuffer(data, len);
appData = &bufAdapter;
}
void setSerializableAppData(const SerializeIF &serializable) { appData = &serializable; }
uint8_t service;
uint8_t subservice;
uint8_t ackFlags = ecss::ACK_ALL;
uint16_t sourceId = 0;
util::DataWrapper dataWrapper{};
SerialBufferAdapter<uint8_t> bufAdapter;
const SerializeIF *appData = nullptr;
uint8_t pusVersion = ecss::PusVersion::PUS_C;
};
@ -52,7 +60,7 @@ class PusTcCreator : public PusTcIF, public SerializeIF, public CustomUserDataIF
[[nodiscard]] uint8_t getSubService() const override;
[[nodiscard]] uint16_t getSourceId() const override;
ReturnValue_t setRawUserData(const uint8_t *data, size_t len) override;
ReturnValue_t setSerializableUserData(SerializeIF &serializable) override;
ReturnValue_t setSerializableUserData(const SerializeIF &serializable) override;
// Load all big endian helpers into the class namespace
using SerializeIF::serializeBe;

View File

@ -51,7 +51,6 @@ ReturnValue_t PusTmCreator::serialize(uint8_t** buffer, size_t* size, size_t max
if (result != returnvalue::OK) {
return result;
}
size_t userDataLen = pusParams.dataWrapper.getLength();
**buffer =
((pusParams.secHeader.pusVersion << 4) & 0xF0) | (pusParams.secHeader.scTimeRefStatus & 0x0F);
*buffer += 1;
@ -77,15 +76,8 @@ ReturnValue_t PusTmCreator::serialize(uint8_t** buffer, size_t* size, size_t max
}
}
if (pusParams.dataWrapper.type == util::DataTypes::RAW and
pusParams.dataWrapper.dataUnion.raw.data != nullptr) {
std::memcpy(*buffer, pusParams.dataWrapper.dataUnion.raw.data, userDataLen);
*buffer += userDataLen;
*size += userDataLen;
} else if (pusParams.dataWrapper.type == util::DataTypes::SERIALIZABLE and
pusParams.dataWrapper.dataUnion.serializable != nullptr) {
result = pusParams.dataWrapper.dataUnion.serializable->serialize(buffer, size, maxSize,
streamEndianness);
if (pusParams.sourceData != nullptr) {
result = pusParams.sourceData->serialize(buffer, size, maxSize, streamEndianness);
if (result != returnvalue::OK) {
return result;
}
@ -111,8 +103,10 @@ TimeWriterIF* PusTmCreator::getTimestamper() const { return pusParams.secHeader.
SpacePacketParams& PusTmCreator::getSpParams() { return spCreator.getParams(); }
void PusTmCreator::updateSpLengthField() {
size_t headerLen =
PusTmIF::MIN_SEC_HEADER_LEN + pusParams.dataWrapper.getLength() + sizeof(ecss::PusChecksumT);
size_t headerLen = PusTmIF::MIN_SEC_HEADER_LEN + sizeof(ecss::PusChecksumT);
if (pusParams.sourceData != nullptr) {
headerLen += pusParams.sourceData->getSerializedSize();
}
if (pusParams.secHeader.timeStamper != nullptr) {
headerLen += pusParams.secHeader.timeStamper->getSerializedSize();
}
@ -134,12 +128,17 @@ void PusTmCreator::setMessageTypeCounter(uint16_t messageTypeCounter) {
void PusTmCreator::setDestId(uint16_t destId) { pusParams.secHeader.destId = destId; }
ReturnValue_t PusTmCreator::setRawUserData(const uint8_t* data, size_t len) {
pusParams.dataWrapper.setRawData({data, len});
if (data == nullptr or len == 0) {
pusParams.sourceData = nullptr;
} else {
pusParams.adapter.setConstBuffer(data, len);
pusParams.sourceData = &pusParams.adapter;
}
updateSpLengthField();
return returnvalue::OK;
}
ReturnValue_t PusTmCreator::setSerializableUserData(SerializeIF& serializable) {
pusParams.dataWrapper.setSerializable(serializable);
ReturnValue_t PusTmCreator::setSerializableUserData(const SerializeIF& serializable) {
pusParams.sourceData = &serializable;
updateSpLengthField();
return returnvalue::OK;
}

View File

@ -2,9 +2,9 @@
#define FSFW_TMTCPACKET_TMPACKETCREATOR_H
#include "PusTmIF.h"
#include "fsfw/serialize/SerialBufferAdapter.h"
#include "fsfw/tmtcpacket/ccsds/SpacePacketCreator.h"
#include "fsfw/tmtcpacket/pus/CustomUserDataIF.h"
#include "fsfw/util/dataWrapper.h"
struct PusTmSecHeader {
PusTmSecHeader() = default;
@ -23,19 +23,25 @@ struct PusTmSecHeader {
struct PusTmParams {
PusTmParams() = default;
explicit PusTmParams(PusTmSecHeader secHeader) : secHeader(secHeader){};
PusTmParams(PusTmSecHeader secHeader, util::DataWrapper dataWrapper)
: secHeader(secHeader), dataWrapper(dataWrapper) {}
PusTmParams(PusTmSecHeader secHeader, const SerializeIF& data)
: secHeader(secHeader), sourceData(&data) {}
PusTmParams(PusTmSecHeader secHeader, const uint8_t* data, size_t dataLen)
: secHeader(secHeader), adapter(data, dataLen), sourceData(&adapter) {}
PusTmParams(uint8_t service, uint8_t subservice, TimeWriterIF* timeStamper)
: secHeader(service, subservice, timeStamper) {}
PusTmParams(uint8_t service, uint8_t subservice, TimeWriterIF* timeStamper,
util::DataWrapper dataWrapper_)
const SerializeIF& data_)
: PusTmParams(service, subservice, timeStamper) {
dataWrapper = dataWrapper_;
sourceData = &data_;
}
PusTmParams(uint8_t service, uint8_t subservice, TimeWriterIF* timeStamper, const uint8_t* data,
size_t dataLen)
: secHeader(service, subservice, timeStamper), adapter(data, dataLen), sourceData(&adapter) {}
PusTmSecHeader secHeader;
util::DataWrapper dataWrapper{};
SerialBufferAdapter<uint8_t> adapter;
const SerializeIF* sourceData = nullptr;
};
class TimeWriterIF;
@ -88,7 +94,7 @@ class PusTmCreator : public SerializeIF, public PusTmIF, public CustomUserDataIF
[[nodiscard]] size_t getSerializedSize() const override;
[[nodiscard]] TimeWriterIF* getTimestamper() const;
ReturnValue_t setRawUserData(const uint8_t* data, size_t len) override;
ReturnValue_t setSerializableUserData(SerializeIF& serializable) override;
ReturnValue_t setSerializableUserData(const SerializeIF& serializable) override;
// Load all big endian (network endian) helpers into scope
using SerializeIF::serializeBe;

View File

@ -10,48 +10,33 @@ namespace telemetry {
class DataWithObjectIdPrefix : public SerializeIF {
public:
DataWithObjectIdPrefix(object_id_t objectId, const uint8_t* srcData, size_t srcDataLen)
: objectId(objectId) {
dataWrapper.type = util::DataTypes::RAW;
dataWrapper.dataUnion.raw.data = srcData;
dataWrapper.dataUnion.raw.len = srcDataLen;
}
: objectId(objectId), bufAdapter(srcData, srcDataLen), userData(&bufAdapter) {}
DataWithObjectIdPrefix(object_id_t objectId, SerializeIF& serializable) : objectId(objectId) {
dataWrapper.type = util::DataTypes::SERIALIZABLE;
dataWrapper.dataUnion.serializable = &serializable;
}
DataWithObjectIdPrefix(object_id_t objectId, const SerializeIF& serializable)
: objectId(objectId), userData(&serializable) {}
ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize,
Endianness streamEndianness) const override {
if (*size + getSerializedSize() > maxSize) {
return SerializeIF::BUFFER_TOO_SHORT;
}
if (dataWrapper.type != util::DataTypes::RAW) {
if ((dataWrapper.dataUnion.raw.data == nullptr) and (dataWrapper.dataUnion.raw.len > 0)) {
return returnvalue::FAILED;
}
} else if (dataWrapper.type == util::DataTypes::SERIALIZABLE) {
if (dataWrapper.dataUnion.serializable == nullptr) {
return returnvalue::FAILED;
}
}
ReturnValue_t result =
SerializeAdapter::serialize(&objectId, buffer, size, maxSize, streamEndianness);
if (result != returnvalue::OK) {
return result;
}
if (dataWrapper.type != util::DataTypes::RAW) {
std::memcpy(*buffer, dataWrapper.dataUnion.raw.data, dataWrapper.dataUnion.raw.len);
*buffer += dataWrapper.dataUnion.raw.len;
*size += dataWrapper.dataUnion.raw.len;
} else {
return dataWrapper.dataUnion.serializable->serialize(buffer, size, maxSize, streamEndianness);
if (userData != nullptr) {
return userData->serialize(buffer, size, maxSize, streamEndianness);
}
return returnvalue::OK;
}
[[nodiscard]] size_t getSerializedSize() const override {
return sizeof(objectId) + dataWrapper.getLength();
size_t len = 0;
if (userData != nullptr) {
len += userData->getSerializedSize();
}
return len;
}
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
@ -63,7 +48,8 @@ class DataWithObjectIdPrefix : public SerializeIF {
private:
object_id_t objectId;
util::DataWrapper dataWrapper{};
SerialBufferAdapter<uint8_t> bufAdapter;
const SerializeIF* userData = nullptr;
};
} // namespace telemetry

View File

@ -1,60 +0,0 @@
#ifndef FSFW_UTIL_DATAWRAPPER_H
#define FSFW_UTIL_DATAWRAPPER_H
#include <cstddef>
#include <cstdint>
#include <utility>
#include "fsfw/serialize.h"
namespace util {
struct RawData {
const uint8_t* data = nullptr;
size_t len = 0;
};
enum DataTypes { NONE, RAW, SERIALIZABLE };
union DataUnion {
RawData raw;
SerializeIF* serializable = nullptr;
};
struct DataWrapper {
DataTypes type = DataTypes::NONE;
DataUnion dataUnion;
using BufPairT = std::pair<const uint8_t*, size_t>;
[[nodiscard]] size_t getLength() const {
if (type == DataTypes::RAW) {
return dataUnion.raw.len;
} else if (type == DataTypes::SERIALIZABLE and dataUnion.serializable != nullptr) {
return dataUnion.serializable->getSerializedSize();
}
return 0;
}
[[nodiscard]] bool isNull() const {
if ((type == DataTypes::NONE) or (type == DataTypes::RAW and dataUnion.raw.data == nullptr) or
(type == DataTypes::SERIALIZABLE and dataUnion.serializable == nullptr)) {
return true;
}
return false;
}
void setRawData(BufPairT bufPair) {
type = DataTypes::RAW;
dataUnion.raw.data = bufPair.first;
dataUnion.raw.len = bufPair.second;
}
void setSerializable(SerializeIF& serializable) {
type = DataTypes::SERIALIZABLE;
dataUnion.serializable = &serializable;
}
};
} // namespace util
#endif // FSFW_UTIL_DATAWRAPPER_H

View File

@ -71,7 +71,7 @@ TEST_CASE("PUS TC Creator", "[pus-tc-creator]") {
SECTION("Test with Application Data Raw") {
auto& params = creator.getPusParams();
std::array<uint8_t, 3> data{1, 2, 3};
params.dataWrapper.setRawData({data.data(), data.size()});
params.setRawAppData(data.data(), data.size());
// To get correct size information, the SP length field needs to be updated automatically
REQUIRE(creator.getSerializedSize() == 13);
creator.updateSpLengthField();

View File

@ -44,9 +44,7 @@ TEST_CASE("TM Store And Send Helper", "[tm-store-send-helper]") {
REQUIRE(creator.getSubService() == 2);
REQUIRE(creator.getService() == 17);
auto& params = creator.getParams();
REQUIRE(params.dataWrapper.type == util::DataTypes::RAW);
REQUIRE(params.dataWrapper.dataUnion.raw.data == nullptr);
REQUIRE(params.dataWrapper.dataUnion.raw.len == 0);
REQUIRE(params.sourceData == nullptr);
REQUIRE(tmHelper.sendCounter == 0);
REQUIRE(tmHelper.storeAndSendTmPacket() == returnvalue::OK);
REQUIRE(tmHelper.sendCounter == 1);
@ -65,9 +63,9 @@ TEST_CASE("TM Store And Send Helper", "[tm-store-send-helper]") {
REQUIRE(tmHelper.prepareTmPacket(2, data.data(), data.size()) == returnvalue::OK);
auto& creator = storeHelper.getCreatorRef();
auto& params = creator.getParams();
REQUIRE(params.dataWrapper.type == util::DataTypes::RAW);
REQUIRE(params.dataWrapper.dataUnion.raw.data == data.data());
REQUIRE(params.dataWrapper.dataUnion.raw.len == data.size());
REQUIRE(params.sourceData != nullptr);
REQUIRE(params.sourceData->getSerializedSize() == data.size());
REQUIRE(params.adapter.getConstBuffer() == data.data());
}
SECTION("Serializable Helper") {
@ -75,8 +73,7 @@ TEST_CASE("TM Store And Send Helper", "[tm-store-send-helper]") {
REQUIRE(tmHelper.prepareTmPacket(2, simpleSer) == returnvalue::OK);
auto& creator = storeHelper.getCreatorRef();
auto& params = creator.getParams();
REQUIRE(params.dataWrapper.type == util::DataTypes::SERIALIZABLE);
REQUIRE(params.dataWrapper.dataUnion.serializable == &simpleSer);
REQUIRE(params.sourceData == &simpleSer);
}
SECTION("Object ID prefix Helper") {
@ -86,8 +83,7 @@ TEST_CASE("TM Store And Send Helper", "[tm-store-send-helper]") {
REQUIRE(tmHelper.prepareTmPacket(2, dataWithObjId) == returnvalue::OK);
auto& creator = storeHelper.getCreatorRef();
auto& params = creator.getParams();
REQUIRE(params.dataWrapper.type == util::DataTypes::SERIALIZABLE);
REQUIRE(params.dataWrapper.dataUnion.serializable == &dataWithObjId);
REQUIRE(params.sourceData == &dataWithObjId);
}
// TODO: Error handling