move data wrapper
All checks were successful
fsfw/fsfw/pipeline/pr-development This commit looks good
All checks were successful
fsfw/fsfw/pipeline/pr-development This commit looks good
This commit is contained in:
parent
aea9db75cb
commit
a9277622ce
@ -13,44 +13,6 @@ using PusChecksumT = uint16_t;
|
||||
//! Version numbers according to ECSS-E-ST-70-41C p.439
|
||||
enum PusVersion : uint8_t { PUS_A = 1, PUS_C = 2 };
|
||||
|
||||
struct RawData {
|
||||
const uint8_t* data;
|
||||
size_t len;
|
||||
};
|
||||
|
||||
enum DataTypes { RAW, SERIALIZABLE };
|
||||
|
||||
union DataUnion {
|
||||
RawData raw;
|
||||
SerializeIF* serializable;
|
||||
};
|
||||
|
||||
struct DataWrapper {
|
||||
DataTypes type;
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* This struct defines the data structure of a Space Packet when accessed
|
||||
* via a pointer.
|
||||
|
@ -37,14 +37,14 @@ ReturnValue_t PusTcCreator::serialize(uint8_t **buffer, size_t *size, size_t max
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
if (pusParams.dataWrapper.type == ecss::DataTypes::RAW) {
|
||||
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 == ecss::DataTypes::SERIALIZABLE and
|
||||
} else if (pusParams.dataWrapper.type == util::DataTypes::SERIALIZABLE and
|
||||
pusParams.dataWrapper.dataUnion.serializable != nullptr) {
|
||||
result = pusParams.dataWrapper.dataUnion.serializable->serialize(buffer, size, maxSize,
|
||||
streamEndianness);
|
||||
|
@ -7,6 +7,7 @@
|
||||
#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_) {}
|
||||
@ -15,7 +16,7 @@ struct PusTcParams {
|
||||
uint8_t subservice;
|
||||
uint8_t ackFlags = ecss::ACK_ALL;
|
||||
uint16_t sourceId = 0;
|
||||
ecss::DataWrapper dataWrapper{};
|
||||
util::DataWrapper dataWrapper{};
|
||||
uint8_t pusVersion = ecss::PusVersion::PUS_C;
|
||||
};
|
||||
|
||||
|
@ -77,12 +77,12 @@ ReturnValue_t PusTmCreator::serialize(uint8_t** buffer, size_t* size, size_t max
|
||||
}
|
||||
}
|
||||
|
||||
if (pusParams.dataWrapper.type == ecss::DataTypes::RAW and
|
||||
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 == ecss::DataTypes::SERIALIZABLE and
|
||||
} else if (pusParams.dataWrapper.type == util::DataTypes::SERIALIZABLE and
|
||||
pusParams.dataWrapper.dataUnion.serializable != nullptr) {
|
||||
result = pusParams.dataWrapper.dataUnion.serializable->serialize(buffer, size, maxSize,
|
||||
streamEndianness);
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include "PusTmIF.h"
|
||||
#include "fsfw/tmtcpacket/ccsds/SpacePacketCreator.h"
|
||||
#include "fsfw/tmtcpacket/pus/CustomUserDataIF.h"
|
||||
#include "fsfw/util/dataWrapper.h"
|
||||
|
||||
struct PusTmSecHeader {
|
||||
PusTmSecHeader() = default;
|
||||
@ -22,19 +23,19 @@ struct PusTmSecHeader {
|
||||
struct PusTmParams {
|
||||
PusTmParams() = default;
|
||||
explicit PusTmParams(PusTmSecHeader secHeader) : secHeader(secHeader){};
|
||||
PusTmParams(PusTmSecHeader secHeader, ecss::DataWrapper dataWrapper)
|
||||
PusTmParams(PusTmSecHeader secHeader, util::DataWrapper dataWrapper)
|
||||
: secHeader(secHeader), dataWrapper(dataWrapper) {}
|
||||
|
||||
PusTmParams(uint8_t service, uint8_t subservice, TimeStamperIF* timeStamper)
|
||||
: secHeader(service, subservice, timeStamper) {}
|
||||
|
||||
PusTmParams(uint8_t service, uint8_t subservice, TimeStamperIF* timeStamper,
|
||||
ecss::DataWrapper dataWrapper_)
|
||||
util::DataWrapper dataWrapper_)
|
||||
: PusTmParams(service, subservice, timeStamper) {
|
||||
dataWrapper = dataWrapper_;
|
||||
}
|
||||
PusTmSecHeader secHeader;
|
||||
ecss::DataWrapper dataWrapper{};
|
||||
util::DataWrapper dataWrapper{};
|
||||
};
|
||||
|
||||
class TimeStamperIF;
|
||||
|
@ -11,13 +11,13 @@ class DataWithObjectIdPrefix : public SerializeIF {
|
||||
public:
|
||||
DataWithObjectIdPrefix(object_id_t objectId, const uint8_t* srcData, size_t srcDataLen)
|
||||
: objectId(objectId) {
|
||||
dataWrapper.type = ecss::DataTypes::RAW;
|
||||
dataWrapper.type = util::DataTypes::RAW;
|
||||
dataWrapper.dataUnion.raw.data = srcData;
|
||||
dataWrapper.dataUnion.raw.len = srcDataLen;
|
||||
}
|
||||
|
||||
DataWithObjectIdPrefix(object_id_t objectId, SerializeIF& serializable) : objectId(objectId) {
|
||||
dataWrapper.type = ecss::DataTypes::SERIALIZABLE;
|
||||
dataWrapper.type = util::DataTypes::SERIALIZABLE;
|
||||
dataWrapper.dataUnion.serializable = &serializable;
|
||||
}
|
||||
|
||||
@ -26,11 +26,11 @@ class DataWithObjectIdPrefix : public SerializeIF {
|
||||
if (*size + getSerializedSize() > maxSize) {
|
||||
return SerializeIF::BUFFER_TOO_SHORT;
|
||||
}
|
||||
if (dataWrapper.type != ecss::DataTypes::RAW) {
|
||||
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 == ecss::DataTypes::SERIALIZABLE) {
|
||||
} else if (dataWrapper.type == util::DataTypes::SERIALIZABLE) {
|
||||
if (dataWrapper.dataUnion.serializable == nullptr) {
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
@ -40,7 +40,7 @@ class DataWithObjectIdPrefix : public SerializeIF {
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
if (dataWrapper.type != ecss::DataTypes::RAW) {
|
||||
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;
|
||||
@ -63,7 +63,7 @@ class DataWithObjectIdPrefix : public SerializeIF {
|
||||
|
||||
private:
|
||||
object_id_t objectId;
|
||||
ecss::DataWrapper dataWrapper{};
|
||||
util::DataWrapper dataWrapper{};
|
||||
};
|
||||
|
||||
} // namespace telemetry
|
||||
|
52
src/fsfw/util/dataWrapper.h
Normal file
52
src/fsfw/util/dataWrapper.h
Normal file
@ -0,0 +1,52 @@
|
||||
#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;
|
||||
size_t len;
|
||||
};
|
||||
|
||||
enum DataTypes { RAW, SERIALIZABLE };
|
||||
|
||||
union DataUnion {
|
||||
RawData raw;
|
||||
SerializeIF* serializable;
|
||||
};
|
||||
|
||||
struct DataWrapper {
|
||||
DataTypes type;
|
||||
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;
|
||||
}
|
||||
|
||||
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
|
@ -44,7 +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 == ecss::DataTypes::RAW);
|
||||
REQUIRE(params.dataWrapper.type == util::DataTypes::RAW);
|
||||
REQUIRE(params.dataWrapper.dataUnion.raw.data == nullptr);
|
||||
REQUIRE(params.dataWrapper.dataUnion.raw.len == 0);
|
||||
REQUIRE(tmHelper.sendCounter == 0);
|
||||
@ -65,7 +65,7 @@ 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 == ecss::DataTypes::RAW);
|
||||
REQUIRE(params.dataWrapper.type == util::DataTypes::RAW);
|
||||
REQUIRE(params.dataWrapper.dataUnion.raw.data == data.data());
|
||||
REQUIRE(params.dataWrapper.dataUnion.raw.len == data.size());
|
||||
}
|
||||
@ -75,7 +75,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 == ecss::DataTypes::SERIALIZABLE);
|
||||
REQUIRE(params.dataWrapper.type == util::DataTypes::SERIALIZABLE);
|
||||
REQUIRE(params.dataWrapper.dataUnion.serializable == &simpleSer);
|
||||
}
|
||||
|
||||
@ -86,7 +86,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 == ecss::DataTypes::SERIALIZABLE);
|
||||
REQUIRE(params.dataWrapper.type == util::DataTypes::SERIALIZABLE);
|
||||
REQUIRE(params.dataWrapper.dataUnion.serializable == &dataWithObjId);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user