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)
message(
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(
WARNING
"${MSG_PREFIX} Setting default configuration from ${DEF_CONF_PATH} ..")

View File

@ -1,12 +1,12 @@
#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/serialize/SerialBufferAdapter.h"
#include "fsfw/tmtcpacket/pus/tc/PusTcIF.h"
struct PusTcParams {

View File

@ -2,6 +2,7 @@
#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"

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