Merge branch 'mueller/refactor-tmtc-stack' into mueller/refactor-local-pool-api
This commit is contained in:
commit
9202c6c17f
@ -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;
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
namespace tcverif {
|
||||
|
||||
enum VerifFlags : uint8_t {
|
||||
enum VerificationFlags : uint8_t {
|
||||
NONE = 0b0000,
|
||||
ACCEPTANCE = 0b0001,
|
||||
START = 0b0010,
|
||||
|
@ -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
|
||||
|
60
src/fsfw/util/dataWrapper.h
Normal file
60
src/fsfw/util/dataWrapper.h
Normal file
@ -0,0 +1,60 @@
|
||||
#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
|
@ -7,8 +7,8 @@
|
||||
#include "tmtc/pusIds.h"
|
||||
|
||||
TEST_CASE("PUS Service 11", "[pus-srvc11]") {
|
||||
Service11TelecommandScheduling<13> pusService11(objects::PUS_SERVICE_11_TC_SCHEDULER,
|
||||
apid::DEFAULT_APID, pus::PUS_SERVICE_11, nullptr);
|
||||
Service11TelecommandScheduling<13> pusService11({objects::PUS_SERVICE_11_TC_SCHEDULER,
|
||||
apid::DEFAULT_APID, pus::PUS_SERVICE_11}, nullptr);
|
||||
|
||||
// TODO test something...
|
||||
}
|
@ -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