Merge branch 'mueller/refactor-tmtc-stack' into mueller/cfdp-routers
This commit is contained in:
commit
935f35a40d
@ -13,44 +13,6 @@ using PusChecksumT = uint16_t;
|
|||||||
//! Version numbers according to ECSS-E-ST-70-41C p.439
|
//! Version numbers according to ECSS-E-ST-70-41C p.439
|
||||||
enum PusVersion : uint8_t { PUS_A = 1, PUS_C = 2 };
|
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
|
* This struct defines the data structure of a Space Packet when accessed
|
||||||
* via a pointer.
|
* via a pointer.
|
||||||
|
@ -37,14 +37,14 @@ ReturnValue_t PusTcCreator::serialize(uint8_t **buffer, size_t *size, size_t max
|
|||||||
if (result != returnvalue::OK) {
|
if (result != returnvalue::OK) {
|
||||||
return result;
|
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;
|
const uint8_t *data = pusParams.dataWrapper.dataUnion.raw.data;
|
||||||
if (data != nullptr and userDataLen > 0) {
|
if (data != nullptr and userDataLen > 0) {
|
||||||
std::memcpy(*buffer, data, userDataLen);
|
std::memcpy(*buffer, data, userDataLen);
|
||||||
*buffer += userDataLen;
|
*buffer += userDataLen;
|
||||||
*size += 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) {
|
pusParams.dataWrapper.dataUnion.serializable != nullptr) {
|
||||||
result = pusParams.dataWrapper.dataUnion.serializable->serialize(buffer, size, maxSize,
|
result = pusParams.dataWrapper.dataUnion.serializable->serialize(buffer, size, maxSize,
|
||||||
streamEndianness);
|
streamEndianness);
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#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/tmtcpacket/pus/tc/PusTcIF.h"
|
#include "fsfw/tmtcpacket/pus/tc/PusTcIF.h"
|
||||||
|
#include "fsfw/util/dataWrapper.h"
|
||||||
|
|
||||||
struct PusTcParams {
|
struct PusTcParams {
|
||||||
PusTcParams(uint8_t service_, uint8_t subservice_) : service(service_), subservice(subservice_) {}
|
PusTcParams(uint8_t service_, uint8_t subservice_) : service(service_), subservice(subservice_) {}
|
||||||
@ -15,7 +16,7 @@ struct PusTcParams {
|
|||||||
uint8_t subservice;
|
uint8_t subservice;
|
||||||
uint8_t ackFlags = ecss::ACK_ALL;
|
uint8_t ackFlags = ecss::ACK_ALL;
|
||||||
uint16_t sourceId = 0;
|
uint16_t sourceId = 0;
|
||||||
ecss::DataWrapper dataWrapper{};
|
util::DataWrapper dataWrapper{};
|
||||||
uint8_t pusVersion = ecss::PusVersion::PUS_C;
|
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) {
|
pusParams.dataWrapper.dataUnion.raw.data != nullptr) {
|
||||||
std::memcpy(*buffer, pusParams.dataWrapper.dataUnion.raw.data, userDataLen);
|
std::memcpy(*buffer, pusParams.dataWrapper.dataUnion.raw.data, userDataLen);
|
||||||
*buffer += userDataLen;
|
*buffer += userDataLen;
|
||||||
*size += 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) {
|
pusParams.dataWrapper.dataUnion.serializable != nullptr) {
|
||||||
result = pusParams.dataWrapper.dataUnion.serializable->serialize(buffer, size, maxSize,
|
result = pusParams.dataWrapper.dataUnion.serializable->serialize(buffer, size, maxSize,
|
||||||
streamEndianness);
|
streamEndianness);
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include "PusTmIF.h"
|
#include "PusTmIF.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"
|
||||||
|
#include "fsfw/util/dataWrapper.h"
|
||||||
|
|
||||||
struct PusTmSecHeader {
|
struct PusTmSecHeader {
|
||||||
PusTmSecHeader() = default;
|
PusTmSecHeader() = default;
|
||||||
@ -22,19 +23,19 @@ struct PusTmSecHeader {
|
|||||||
struct PusTmParams {
|
struct PusTmParams {
|
||||||
PusTmParams() = default;
|
PusTmParams() = default;
|
||||||
explicit PusTmParams(PusTmSecHeader secHeader) : secHeader(secHeader){};
|
explicit PusTmParams(PusTmSecHeader secHeader) : secHeader(secHeader){};
|
||||||
PusTmParams(PusTmSecHeader secHeader, ecss::DataWrapper dataWrapper)
|
PusTmParams(PusTmSecHeader secHeader, util::DataWrapper dataWrapper)
|
||||||
: secHeader(secHeader), dataWrapper(dataWrapper) {}
|
: secHeader(secHeader), dataWrapper(dataWrapper) {}
|
||||||
|
|
||||||
PusTmParams(uint8_t service, uint8_t subservice, TimeStamperIF* timeStamper)
|
PusTmParams(uint8_t service, uint8_t subservice, TimeStamperIF* timeStamper)
|
||||||
: secHeader(service, subservice, timeStamper) {}
|
: secHeader(service, subservice, timeStamper) {}
|
||||||
|
|
||||||
PusTmParams(uint8_t service, uint8_t subservice, TimeStamperIF* timeStamper,
|
PusTmParams(uint8_t service, uint8_t subservice, TimeStamperIF* timeStamper,
|
||||||
ecss::DataWrapper dataWrapper_)
|
util::DataWrapper dataWrapper_)
|
||||||
: PusTmParams(service, subservice, timeStamper) {
|
: PusTmParams(service, subservice, timeStamper) {
|
||||||
dataWrapper = dataWrapper_;
|
dataWrapper = dataWrapper_;
|
||||||
}
|
}
|
||||||
PusTmSecHeader secHeader;
|
PusTmSecHeader secHeader;
|
||||||
ecss::DataWrapper dataWrapper{};
|
util::DataWrapper dataWrapper{};
|
||||||
};
|
};
|
||||||
|
|
||||||
class TimeStamperIF;
|
class TimeStamperIF;
|
||||||
|
@ -11,13 +11,13 @@ 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) {
|
||||||
dataWrapper.type = ecss::DataTypes::RAW;
|
dataWrapper.type = util::DataTypes::RAW;
|
||||||
dataWrapper.dataUnion.raw.data = srcData;
|
dataWrapper.dataUnion.raw.data = srcData;
|
||||||
dataWrapper.dataUnion.raw.len = srcDataLen;
|
dataWrapper.dataUnion.raw.len = srcDataLen;
|
||||||
}
|
}
|
||||||
|
|
||||||
DataWithObjectIdPrefix(object_id_t objectId, SerializeIF& serializable) : objectId(objectId) {
|
DataWithObjectIdPrefix(object_id_t objectId, SerializeIF& serializable) : objectId(objectId) {
|
||||||
dataWrapper.type = ecss::DataTypes::SERIALIZABLE;
|
dataWrapper.type = util::DataTypes::SERIALIZABLE;
|
||||||
dataWrapper.dataUnion.serializable = &serializable;
|
dataWrapper.dataUnion.serializable = &serializable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,11 +26,11 @@ class DataWithObjectIdPrefix : public SerializeIF {
|
|||||||
if (*size + getSerializedSize() > maxSize) {
|
if (*size + getSerializedSize() > maxSize) {
|
||||||
return SerializeIF::BUFFER_TOO_SHORT;
|
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)) {
|
if ((dataWrapper.dataUnion.raw.data == nullptr) and (dataWrapper.dataUnion.raw.len > 0)) {
|
||||||
return returnvalue::FAILED;
|
return returnvalue::FAILED;
|
||||||
}
|
}
|
||||||
} else if (dataWrapper.type == ecss::DataTypes::SERIALIZABLE) {
|
} else if (dataWrapper.type == util::DataTypes::SERIALIZABLE) {
|
||||||
if (dataWrapper.dataUnion.serializable == nullptr) {
|
if (dataWrapper.dataUnion.serializable == nullptr) {
|
||||||
return returnvalue::FAILED;
|
return returnvalue::FAILED;
|
||||||
}
|
}
|
||||||
@ -40,7 +40,7 @@ class DataWithObjectIdPrefix : public SerializeIF {
|
|||||||
if (result != returnvalue::OK) {
|
if (result != returnvalue::OK) {
|
||||||
return result;
|
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);
|
std::memcpy(*buffer, dataWrapper.dataUnion.raw.data, dataWrapper.dataUnion.raw.len);
|
||||||
*buffer += dataWrapper.dataUnion.raw.len;
|
*buffer += dataWrapper.dataUnion.raw.len;
|
||||||
*size += dataWrapper.dataUnion.raw.len;
|
*size += dataWrapper.dataUnion.raw.len;
|
||||||
@ -63,7 +63,7 @@ class DataWithObjectIdPrefix : public SerializeIF {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
object_id_t objectId;
|
object_id_t objectId;
|
||||||
ecss::DataWrapper dataWrapper{};
|
util::DataWrapper dataWrapper{};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace telemetry
|
} // 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"
|
#include "tmtc/pusIds.h"
|
||||||
|
|
||||||
TEST_CASE("PUS Service 11", "[pus-srvc11]") {
|
TEST_CASE("PUS Service 11", "[pus-srvc11]") {
|
||||||
Service11TelecommandScheduling<13> pusService11(objects::PUS_SERVICE_11_TC_SCHEDULER,
|
Service11TelecommandScheduling<13> pusService11({objects::PUS_SERVICE_11_TC_SCHEDULER,
|
||||||
apid::DEFAULT_APID, pus::PUS_SERVICE_11, nullptr);
|
apid::DEFAULT_APID, pus::PUS_SERVICE_11}, nullptr);
|
||||||
|
|
||||||
// TODO test something...
|
// TODO test something...
|
||||||
}
|
}
|
@ -44,7 +44,7 @@ TEST_CASE("TM Store And Send Helper", "[tm-store-send-helper]") {
|
|||||||
REQUIRE(creator.getSubService() == 2);
|
REQUIRE(creator.getSubService() == 2);
|
||||||
REQUIRE(creator.getService() == 17);
|
REQUIRE(creator.getService() == 17);
|
||||||
auto& params = creator.getParams();
|
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.data == nullptr);
|
||||||
REQUIRE(params.dataWrapper.dataUnion.raw.len == 0);
|
REQUIRE(params.dataWrapper.dataUnion.raw.len == 0);
|
||||||
REQUIRE(tmHelper.sendCounter == 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);
|
REQUIRE(tmHelper.prepareTmPacket(2, data.data(), data.size()) == returnvalue::OK);
|
||||||
auto& creator = storeHelper.getCreatorRef();
|
auto& creator = storeHelper.getCreatorRef();
|
||||||
auto& params = creator.getParams();
|
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.data == data.data());
|
||||||
REQUIRE(params.dataWrapper.dataUnion.raw.len == data.size());
|
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);
|
REQUIRE(tmHelper.prepareTmPacket(2, simpleSer) == returnvalue::OK);
|
||||||
auto& creator = storeHelper.getCreatorRef();
|
auto& creator = storeHelper.getCreatorRef();
|
||||||
auto& params = creator.getParams();
|
auto& params = creator.getParams();
|
||||||
REQUIRE(params.dataWrapper.type == ecss::DataTypes::SERIALIZABLE);
|
REQUIRE(params.dataWrapper.type == util::DataTypes::SERIALIZABLE);
|
||||||
REQUIRE(params.dataWrapper.dataUnion.serializable == &simpleSer);
|
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);
|
REQUIRE(tmHelper.prepareTmPacket(2, dataWithObjId) == returnvalue::OK);
|
||||||
auto& creator = storeHelper.getCreatorRef();
|
auto& creator = storeHelper.getCreatorRef();
|
||||||
auto& params = creator.getParams();
|
auto& params = creator.getParams();
|
||||||
REQUIRE(params.dataWrapper.type == ecss::DataTypes::SERIALIZABLE);
|
REQUIRE(params.dataWrapper.type == util::DataTypes::SERIALIZABLE);
|
||||||
REQUIRE(params.dataWrapper.dataUnion.serializable == &dataWithObjId);
|
REQUIRE(params.dataWrapper.dataUnion.serializable == &dataWithObjId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user