verify successfull TM serialization

This commit is contained in:
Robin Müller 2022-07-22 16:06:31 +02:00
parent bfee4fd90a
commit 67776241de
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
7 changed files with 170 additions and 30 deletions

View File

@ -22,9 +22,9 @@ class TimeStamperIF : public SerializeIF {
//! size reserved for timestamps. //! size reserved for timestamps.
// static const uint8_t MISSION_TIMESTAMP_SIZE = fsfwconfig::FSFW_MISSION_TIMESTAMP_SIZE; // static const uint8_t MISSION_TIMESTAMP_SIZE = fsfwconfig::FSFW_MISSION_TIMESTAMP_SIZE;
[[nodiscard]] virtual size_t getTimestampSize() const = 0; [[nodiscard]] virtual size_t getTimestampSize() const { return getSerializedSize(); }
virtual ReturnValue_t addTimeStamp(uint8_t* buffer, uint8_t maxSize) = 0;
virtual ReturnValue_t addTimeStamp(uint8_t* buffer, uint8_t maxSize) = 0;
~TimeStamperIF() override = default; ~TimeStamperIF() override = default;
}; };

View File

@ -5,15 +5,12 @@
#include "fsfw/globalfunctions/CRC.h" #include "fsfw/globalfunctions/CRC.h"
#include "fsfw/timemanager/TimeStamperIF.h" #include "fsfw/timemanager/TimeStamperIF.h"
PusTmCreator::PusTmCreator(SpacePacketParams initSpParams, PusTmParams initPusParams, PusTmCreator::PusTmCreator(SpacePacketParams initSpParams, PusTmParams initPusParams)
TimeStamperIF* timeStamper) : pusParams(initPusParams), spCreator(std::move(initSpParams)) {
: pusParams(initPusParams), spCreator(std::move(initSpParams)) {} setup();
PusTmCreator::PusTmCreator(TimeStamperIF* timeStamper_) {
pusParams.secHeader.timeStamper = timeStamper_;
} }
PusTmCreator::PusTmCreator() = default; PusTmCreator::PusTmCreator() { setup(); }
uint16_t PusTmCreator::getPacketIdRaw() const { return spCreator.getPacketIdRaw(); } uint16_t PusTmCreator::getPacketIdRaw() const { return spCreator.getPacketIdRaw(); }
uint16_t PusTmCreator::getPacketSeqCtrlRaw() const { return spCreator.getPacketSeqCtrlRaw(); } uint16_t PusTmCreator::getPacketSeqCtrlRaw() const { return spCreator.getPacketSeqCtrlRaw(); }
@ -31,6 +28,7 @@ uint16_t PusTmCreator::getDestId() { return 0; }
ReturnValue_t PusTmCreator::serialize(uint8_t** buffer, size_t* size, size_t maxSize, ReturnValue_t PusTmCreator::serialize(uint8_t** buffer, size_t* size, size_t maxSize,
SerializeIF::Endianness streamEndianness) const { SerializeIF::Endianness streamEndianness) const {
const uint8_t* start = *buffer;
if (*size + getSerializedSize() > maxSize) { if (*size + getSerializedSize() > maxSize) {
return SerializeIF::BUFFER_TOO_SHORT; return SerializeIF::BUFFER_TOO_SHORT;
} }
@ -74,7 +72,7 @@ ReturnValue_t PusTmCreator::serialize(uint8_t** buffer, size_t* size, size_t max
return result; return result;
} }
} }
uint16_t crc16 = CRC::crc16ccitt(*buffer, getFullPacketLen() - sizeof(ecss::PusChecksumT)); uint16_t crc16 = CRC::crc16ccitt(start, getFullPacketLen() - sizeof(ecss::PusChecksumT));
return SerializeAdapter::serialize(&crc16, buffer, size, maxSize, streamEndianness); return SerializeAdapter::serialize(&crc16, buffer, size, maxSize, streamEndianness);
} }
@ -85,15 +83,25 @@ ReturnValue_t PusTmCreator::deSerialize(const uint8_t** buffer, size_t* size,
} }
ecss::DataWrapper& PusTmCreator::getDataWrapper() { return pusParams.dataWrapper; } ecss::DataWrapper& PusTmCreator::getDataWrapper() { return pusParams.dataWrapper; }
TimeStamperIF* PusTmCreator::getTimestamper() { return pusParams.secHeader.timeStamper; } TimeStamperIF* PusTmCreator::getTimestamper() const { return pusParams.secHeader.timeStamper; }
SpacePacketParams& PusTmCreator::getSpParams() { return spCreator.getParams(); } SpacePacketParams& PusTmCreator::getSpParams() { return spCreator.getParams(); }
void PusTmCreator::updateSpLengthField() { void PusTmCreator::updateSpLengthField() {
size_t headerLen = PusTmIF::MIN_SIZE; size_t headerLen = PusTmIF::MIN_SEC_HEADER_LEN + pusParams.dataWrapper.getLength() +
sizeof(ecss::PusChecksumT) - 1;
if (pusParams.secHeader.timeStamper != nullptr) { if (pusParams.secHeader.timeStamper != nullptr) {
headerLen += pusParams.secHeader.timeStamper->getSerializedSize(); headerLen += pusParams.secHeader.timeStamper->getSerializedSize();
} }
spCreator.setDataLen(headerLen + pusParams.dataWrapper.getLength() + 1); spCreator.setDataLen(headerLen);
} }
void PusTmCreator::setApid(uint16_t apid) { spCreator.setApid(apid); } void PusTmCreator::setApid(uint16_t apid) { spCreator.setApid(apid); }
ReturnValue_t PusTmCreator::serialize(uint8_t** buffer, size_t* size, size_t maxSize) const {
return serialize(buffer, size, maxSize, SerializeIF::Endianness::NETWORK);
}
void PusTmCreator::setup() {
updateSpLengthField();
spCreator.setPacketType(ccsds::PacketType::TM);
}

View File

@ -6,18 +6,35 @@
#include "fsfw/tmtcpacket/pus/CreatorDataIF.h" #include "fsfw/tmtcpacket/pus/CreatorDataIF.h"
struct PusTmSecHeader { struct PusTmSecHeader {
uint8_t pusVersion; PusTmSecHeader() = default;
uint8_t scTimeRefStatus; PusTmSecHeader(uint8_t service, uint8_t subservice, TimeStamperIF* timeStamper)
uint8_t service; : service(service), subservice(subservice), timeStamper(timeStamper) {}
uint8_t subservice;
uint16_t messageTypeCounter; uint8_t service = 0;
uint16_t destId; uint8_t subservice = 0;
TimeStamperIF* timeStamper; TimeStamperIF* timeStamper = nullptr;
uint8_t pusVersion = ecss::PusVersion::PUS_C;
uint8_t scTimeRefStatus = 0;
uint16_t messageTypeCounter = 0;
uint16_t destId = 0;
}; };
struct PusTmParams { struct PusTmParams {
PusTmParams() = default;
explicit PusTmParams(PusTmSecHeader secHeader) : secHeader(secHeader){};
PusTmParams(PusTmSecHeader secHeader, ecss::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_)
: PusTmParams(service, subservice, timeStamper) {
dataWrapper = dataWrapper_;
}
PusTmSecHeader secHeader; PusTmSecHeader secHeader;
ecss::DataWrapper dataWrapper; ecss::DataWrapper dataWrapper{};
}; };
class TimeStamperIF; class TimeStamperIF;
@ -25,10 +42,7 @@ class TimeStamperIF;
class PusTmCreator : public SerializeIF, public PusTmIF, public CreatorDataIF { class PusTmCreator : public SerializeIF, public PusTmIF, public CreatorDataIF {
public: public:
PusTmCreator(); PusTmCreator();
PusTmCreator(SpacePacketParams initSpParams, PusTmParams initPusParams);
explicit PusTmCreator(TimeStamperIF* timeStamper);
PusTmCreator(SpacePacketParams initSpParams, PusTmParams initPusParams,
TimeStamperIF* timeStamper);
~PusTmCreator() override = default; ~PusTmCreator() override = default;
void setTimeStamper(TimeStamperIF* timeStamper); void setTimeStamper(TimeStamperIF* timeStamper);
@ -45,17 +59,19 @@ class PusTmCreator : public SerializeIF, public PusTmIF, public CreatorDataIF {
uint8_t getScTimeRefStatus() override; uint8_t getScTimeRefStatus() override;
uint16_t getMessageTypeCounter() override; uint16_t getMessageTypeCounter() override;
uint16_t getDestId() override; uint16_t getDestId() override;
ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize) const;
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;
[[nodiscard]] size_t getSerializedSize() const override; [[nodiscard]] size_t getSerializedSize() const override;
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
Endianness streamEndianness) override; Endianness streamEndianness) override;
TimeStamperIF* getTimestamper(); [[nodiscard]] TimeStamperIF* getTimestamper() const;
private: private:
ecss::DataWrapper& getDataWrapper() override; ecss::DataWrapper& getDataWrapper() override;
private: private:
void setup();
PusTmParams pusParams{}; PusTmParams pusParams{};
SpacePacketCreator spCreator; SpacePacketCreator spCreator;
}; };

View File

@ -4,12 +4,12 @@
TmStoreHelper::TmStoreHelper(uint16_t defaultApid, StorageManagerIF* tmStore, TmStoreHelper::TmStoreHelper(uint16_t defaultApid, StorageManagerIF* tmStore,
TimeStamperIF* timeStamper) TimeStamperIF* timeStamper)
: creator(timeStamper), tmStore(tmStore) { : tmStore(tmStore) {
creator.setApid(defaultApid); creator.setApid(defaultApid);
creator.setTimeStamper(timeStamper);
} }
TmStoreHelper::TmStoreHelper(uint16_t defaultApid, StorageManagerIF* tmStore) TmStoreHelper::TmStoreHelper(uint16_t defaultApid, StorageManagerIF* tmStore) : tmStore(tmStore) {
: creator(nullptr), tmStore(tmStore) {
creator.setApid(defaultApid); creator.setApid(defaultApid);
} }

View File

@ -0,0 +1,53 @@
#ifndef FSFW_TESTS_CDSSHORTTIMESTAMPERMOCK_H
#define FSFW_TESTS_CDSSHORTTIMESTAMPERMOCK_H
#include <array>
#include "fsfw/timemanager/TimeStamperIF.h"
class CdsShortTimestamperMock : public TimeStamperIF {
public:
unsigned int serializeCallCount = 0;
ReturnValue_t lastSerializeResult = HasReturnvaluesIF::RETURN_OK;
unsigned int getSizeCallCount = 0;
std::array<uint8_t, 7> valueToStamp{};
CdsShortTimestamperMock() = default;
explicit CdsShortTimestamperMock(std::array<uint8_t, 7> valueToStamp)
: valueToStamp(valueToStamp) {}
ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize,
Endianness streamEndianness) const override {
auto &thisNonConst = const_cast<CdsShortTimestamperMock &>(*this);
thisNonConst.serializeCallCount += 1;
if (*size + getSerializedSize() > maxSize) {
thisNonConst.lastSerializeResult = SerializeIF::BUFFER_TOO_SHORT;
return lastSerializeResult;
}
std::copy(valueToStamp.begin(), valueToStamp.end(), *buffer);
thisNonConst.lastSerializeResult = HasReturnvaluesIF::RETURN_OK;
*buffer += getSerializedSize();
*size += getSerializedSize();
return lastSerializeResult;
}
[[nodiscard]] size_t getSerializedSize() const override {
auto &thisNonConst = const_cast<CdsShortTimestamperMock &>(*this);
thisNonConst.getSizeCallCount += 1;
return valueToStamp.size();
}
ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size,
Endianness streamEndianness) override {
return HasReturnvaluesIF::RETURN_FAILED;
}
[[nodiscard]] size_t getTimestampSize() const override { return getSerializedSize(); }
ReturnValue_t addTimeStamp(uint8_t *buffer, uint8_t maxSize) override { return 0; }
void reset() {
serializeCallCount = 0;
getSizeCallCount = 0;
}
private:
};
#endif // FSFW_TESTS_CDSSHORTTIMESTAMPERMOCK_H

View File

@ -16,6 +16,7 @@ TEST_CASE("PUS TC Creator", "[pus-tc-creator]") {
size_t serLen = 0; size_t serLen = 0;
SECTION("State") { SECTION("State") {
REQUIRE(creator.isTc());
REQUIRE(creator.getService() == 17); REQUIRE(creator.getService() == 17);
REQUIRE(creator.getSubService() == 1); REQUIRE(creator.getSubService() == 1);
REQUIRE(creator.getApid() == 0x02); REQUIRE(creator.getApid() == 0x02);

View File

@ -1,3 +1,65 @@
#include <catch2/catch_test_macros.hpp> #include <catch2/catch_test_macros.hpp>
TEST_CASE("PUS TM Creator", "[pus-tm-creator]") {} #include "fsfw/globalfunctions/arrayprinter.h"
#include "fsfw/tmtcpacket/pus/tm.h"
#include "fsfw/globalfunctions/CRC.h"
#include "mocks/CdsShortTimestamperMock.h"
TEST_CASE("PUS TM Creator", "[pus-tm-creator]") {
auto packetId = PacketId(ccsds::PacketType::TC, true, 0xef);
auto spParams =
SpacePacketParams(packetId, PacketSeqCtrl(ccsds::SequenceFlags::UNSEGMENTED, 22), 0x00);
auto timeStamper = CdsShortTimestamperMock();
auto pusTmParams = PusTmParams(17, 2, &timeStamper);
timeStamper.valueToStamp = {1, 2, 3, 4, 5, 6, 7};
PusTmCreator creator(spParams, pusTmParams);
std::array<uint8_t, 32> buf{};
uint8_t* dataPtr = buf.data();
size_t serLen = 0;
SECTION("State") {
REQUIRE(creator.isTm());
REQUIRE(creator.getApid() == 0xef);
REQUIRE(creator.getService() == 17);
REQUIRE(creator.getSubService() == 2);
REQUIRE(creator.getTimestamper() == &timeStamper);
REQUIRE(creator.getSequenceFlags() == ccsds::SequenceFlags::UNSEGMENTED);
REQUIRE(creator.getSequenceCount() == 22);
// 6 bytes CCSDS header, 7 bytes secondary header, 7 bytes CDS short timestamp,
// 0 bytes application data, 2 bytes CRC
REQUIRE(creator.getFullPacketLen() == 22);
// As specified in standard, the data length fields is the total size of the packet without
// the primary header minus 1
REQUIRE(creator.getPacketDataLen() == 15);
REQUIRE(timeStamper.getSizeCallCount == 1);
}
SECTION("Serialization") {
REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(buf[0] == 0x08);
REQUIRE(buf[1] == 0xef);
// Unsegmented is the default
REQUIRE(buf[2] == 0xc0);
REQUIRE(buf[3] == 22);
REQUIRE(buf[4] == 0);
REQUIRE(buf[5] == 15);
REQUIRE(((buf[6] >> 4) & 0b1111) == ecss::PusVersion::PUS_C);
// SC time reference field
REQUIRE((buf[6] & 0b1111) == 0);
// Service and subservice field
REQUIRE(buf[7] == 17);
REQUIRE(buf[8] == 2);
// Message Sequence Count
REQUIRE(((buf[9] << 8) | buf[10]) == 0);
// Destination ID
REQUIRE(((buf[11] << 8) | buf[12]) == 0);
// Custom timestamp
for(size_t i = 1; i < 8; i++) {
REQUIRE(buf[12 + i] == i);
}
REQUIRE(serLen == 22);
REQUIRE(CRC::crc16ccitt(buf.data(), serLen) == 0);
REQUIRE(buf[20] == 0x03);
REQUIRE(buf[21] == 0x79);
}
}