refactor tm helper

This commit is contained in:
Robin Müller 2022-09-05 16:10:06 +02:00
parent 4c3f9feb93
commit f5421e9abd
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
4 changed files with 16 additions and 28 deletions

View File

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

View File

@ -1,12 +1,12 @@
#ifndef FSFW_TMTCPACKET_TCPACKETDESERIALIZER_H #ifndef FSFW_TMTCPACKET_TCPACKETDESERIALIZER_H
#define FSFW_TMTCPACKET_TCPACKETDESERIALIZER_H #define FSFW_TMTCPACKET_TCPACKETDESERIALIZER_H
#include "fsfw/serialize/SerialBufferAdapter.h"
#include "fsfw/tmtcpacket/RedirectableDataPointerIF.h" #include "fsfw/tmtcpacket/RedirectableDataPointerIF.h"
#include "fsfw/tmtcpacket/ccsds/SpacePacketCreator.h" #include "fsfw/tmtcpacket/ccsds/SpacePacketCreator.h"
#include "fsfw/tmtcpacket/ccsds/SpacePacketIF.h" #include "fsfw/tmtcpacket/ccsds/SpacePacketIF.h"
#include "fsfw/tmtcpacket/pus/CustomUserDataIF.h" #include "fsfw/tmtcpacket/pus/CustomUserDataIF.h"
#include "fsfw/tmtcpacket/pus/defs.h" #include "fsfw/tmtcpacket/pus/defs.h"
#include "fsfw/serialize/SerialBufferAdapter.h"
#include "fsfw/tmtcpacket/pus/tc/PusTcIF.h" #include "fsfw/tmtcpacket/pus/tc/PusTcIF.h"
struct PusTcParams { struct PusTcParams {

View File

@ -2,6 +2,7 @@
#define FSFW_TMTCPACKET_TMPACKETCREATOR_H #define FSFW_TMTCPACKET_TMPACKETCREATOR_H
#include "PusTmIF.h" #include "PusTmIF.h"
#include "fsfw/serialize/SerialBufferAdapter.h"
#include "fsfw/tmtcpacket/ccsds/SpacePacketCreator.h" #include "fsfw/tmtcpacket/ccsds/SpacePacketCreator.h"
#include "fsfw/tmtcpacket/pus/CustomUserDataIF.h" #include "fsfw/tmtcpacket/pus/CustomUserDataIF.h"

View File

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