Update FSFW from upstream #71
@ -19,6 +19,12 @@ struct PusTcParams {
|
||||
uint8_t pusVersion = ecss::PusVersion::PUS_C;
|
||||
};
|
||||
|
||||
/**
|
||||
* This class provides a high-level interface to create PUS TC packets and then @serialize
|
||||
* them into a raw byte format. It implements @SerializeIF for that purpose.
|
||||
* A custom time stamper can be set, with the implementation of @TimeStamperIF as the only
|
||||
* requirement.
|
||||
*/
|
||||
class PusTcCreator : public PusTcIF, public SerializeIF, public CustomUserDataIF {
|
||||
public:
|
||||
PusTcCreator(SpacePacketParams initSpParams, PusTcParams initPusParams);
|
||||
|
@ -39,8 +39,18 @@ struct PusTmParams {
|
||||
|
||||
class TimeStamperIF;
|
||||
|
||||
/**
|
||||
* This class provides a high-level interface to create PUS TM packets and then @serialize
|
||||
* them into a raw byte format. It implements @SerializeIF for that purpose.
|
||||
* A custom time stamper can be set, with the implementation of @TimeStamperIF as the only
|
||||
* requirement.
|
||||
*/
|
||||
class PusTmCreator : public SerializeIF, public PusTmIF, public CustomUserDataIF {
|
||||
public:
|
||||
/**
|
||||
* Empty creator with all-default parameters. Please note that serializing this will
|
||||
* generate an invalid PUS packet with no timestamp.
|
||||
*/
|
||||
PusTmCreator();
|
||||
PusTmCreator(SpacePacketParams initSpParams, PusTmParams initPusParams);
|
||||
~PusTmCreator() override = default;
|
||||
|
@ -86,6 +86,6 @@ ReturnValue_t PusTmReader::parseData(bool crcCheck) {
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
bool PusTmReader::isNull() const { return spReader.isNull(); }
|
||||
bool PusTmReader::isNull() const { return spReader.isNull() or pointers.secHeaderStart == nullptr; }
|
||||
|
||||
PusTmReader::operator bool() const { return not isNull(); }
|
||||
|
@ -8,6 +8,18 @@
|
||||
#include "fsfw/tmtcpacket/pus/RawUserDataReaderIF.h"
|
||||
#include "fsfw/tmtcpacket/pus/tm/PusTmIF.h"
|
||||
|
||||
/**
|
||||
* This object can be used to read existing PUS TM packets in raw byte format.
|
||||
* It is a zero-copy object, so reading a TM packet with will not copy anything.
|
||||
*
|
||||
* Please note that a parser function must be called after the constructor. This will also check
|
||||
* the packet for validity.
|
||||
*
|
||||
* There are two parser function, where one does not perform the CRC check. This is useful
|
||||
* if the CRC calculation will is performed in a separate step.
|
||||
* This object also requires an explicit time stamp reader to allow flexibility in the used
|
||||
* timestamp.
|
||||
*/
|
||||
class PusTmReader : public PusTmIF,
|
||||
public RawUserDataReaderIF,
|
||||
public ReadablePacketIF,
|
||||
@ -17,11 +29,30 @@ class PusTmReader : public PusTmIF,
|
||||
PusTmReader(const uint8_t* data, size_t size);
|
||||
PusTmReader(TimeReaderIF* timeReader, const uint8_t* data, size_t size);
|
||||
|
||||
/**
|
||||
* No CRC check will be performed
|
||||
* @return
|
||||
*/
|
||||
ReturnValue_t parseDataWithoutCrcCheck();
|
||||
/**
|
||||
* Performs a CRC check on the data as well
|
||||
* @return
|
||||
* - HasReturnvaluesIF::RETURN_OK: Successfully parsed the packet
|
||||
* - SerializeIF::STREAM_TOO_SHORT: Stream too short for detected packet size
|
||||
* - PusIF::INVALID_CRC_16 on invalid CRC
|
||||
*/
|
||||
ReturnValue_t parseDataWithCrcCheck();
|
||||
[[nodiscard]] const uint8_t* getFullData() const override;
|
||||
|
||||
/**
|
||||
* Returns @isNull
|
||||
* @return
|
||||
*/
|
||||
explicit operator bool() const;
|
||||
/**
|
||||
* No (valid) data was set yet or the parse function was not called yet.
|
||||
* @return
|
||||
*/
|
||||
[[nodiscard]] bool isNull() const;
|
||||
void setTimeReader(TimeReaderIF* timeReader);
|
||||
TimeReaderIF* getTimeReader();
|
||||
|
@ -6,12 +6,18 @@ PusTmZeroCopyWriter::PusTmZeroCopyWriter(TimeReaderIF& timeReader, uint8_t* data
|
||||
: PusTmReader(&timeReader, data, size) {}
|
||||
|
||||
void PusTmZeroCopyWriter::setSequenceCount(uint16_t seqCount) {
|
||||
if (isNull()) {
|
||||
return;
|
||||
}
|
||||
auto* spHeader =
|
||||
reinterpret_cast<ccsds::PrimaryHeader*>(const_cast<uint8_t*>((pointers.spHeaderStart)));
|
||||
ccsds::setSequenceCount(*spHeader, seqCount);
|
||||
}
|
||||
|
||||
void PusTmZeroCopyWriter::updateErrorControl() {
|
||||
if (isNull()) {
|
||||
return;
|
||||
}
|
||||
auto* crcStart = const_cast<uint8_t*>((pointers.crcStart));
|
||||
uint16_t crc16 =
|
||||
CRC::crc16ccitt(PusTmReader::getFullData(), getFullPacketLen() - sizeof(ecss::PusChecksumT));
|
||||
|
@ -2,6 +2,13 @@
|
||||
#define FSFW_EXAMPLE_HOSTED_PUSTMZCWRITER_H
|
||||
|
||||
#include "PusTmReader.h"
|
||||
|
||||
/**
|
||||
* This packet allows to update specific fields of a PUS TM packet where it is useful or necessary
|
||||
* to update them in a second step. Otherwise, it offers the same interface as @PusTmReader.
|
||||
*
|
||||
* Right now, this class supports updating the CCSDS Sequence Count and the Error Control.
|
||||
*/
|
||||
class PusTmZeroCopyWriter : public PusTmReader {
|
||||
public:
|
||||
PusTmZeroCopyWriter(TimeReaderIF& timeReader, uint8_t* data, size_t size);
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include "fsfw/globalfunctions/CRC.h"
|
||||
#include "fsfw/tmtcpacket/pus/tm.h"
|
||||
#include "fsfw/tmtcpacket/pus/tm/PusTmZcWriter.h"
|
||||
#include "mocks/CdsShortTimestamperMock.h"
|
||||
@ -16,8 +17,26 @@ TEST_CASE("TM ZC Helper", "[tm-zc-helper]") {
|
||||
uint8_t* dataPtr = buf.data();
|
||||
size_t serLen = 0;
|
||||
|
||||
SECTION("No Crash For Uninitialized Object") {
|
||||
REQUIRE(creator.serialize(dataPtr, serLen, buf.size()) == result::OK);
|
||||
PusTmZeroCopyWriter writer(timeStamper, dataPtr, serLen);
|
||||
REQUIRE(writer.getSequenceCount() == 22);
|
||||
writer.setSequenceCount(23);
|
||||
// Can't set anything, parse function was not called
|
||||
REQUIRE(writer.getSequenceCount() == 22);
|
||||
writer.updateErrorControl();
|
||||
}
|
||||
|
||||
SECTION("Basic") {
|
||||
REQUIRE(creator.serialize(dataPtr, serLen, buf.size()) == result::OK);
|
||||
PusTmZeroCopyWriter(timeStamper, dataPtr, serLen);
|
||||
PusTmZeroCopyWriter writer(timeStamper, dataPtr, serLen);
|
||||
REQUIRE(writer.parseDataWithoutCrcCheck() == result::OK);
|
||||
REQUIRE(writer.getSequenceCount() == 22);
|
||||
writer.setSequenceCount(23);
|
||||
REQUIRE(writer.getSequenceCount() == 23);
|
||||
// CRC is invalid now
|
||||
REQUIRE(CRC::crc16ccitt(dataPtr, serLen) != 0);
|
||||
writer.updateErrorControl();
|
||||
REQUIRE(CRC::crc16ccitt(dataPtr, serLen) == 0);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user