pass timeReader to Pus ZC writer

This commit is contained in:
Robin Müller 2022-07-27 17:33:39 +02:00
parent c5ad9b5fa9
commit f591b9793c
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
10 changed files with 48 additions and 26 deletions

View File

@ -7,8 +7,6 @@
class CcsdsTimestampReader : public TimeReaderIF { class CcsdsTimestampReader : public TimeReaderIF {
public: public:
ReturnValue_t readTimeStamp(const uint8_t* buffer, uint8_t maxSize) override;
size_t getTimestampLen() override;
timeval& getTime() override; timeval& getTime() override;
private: private:

View File

@ -36,4 +36,14 @@ ReturnValue_t CdsShortTimeStamper::deSerialize(const uint8_t **buffer, size_t *s
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
ReturnValue_t CdsShortTimeStamper::readTimeStamp(const uint8_t *buffer, size_t maxSize) {
if (maxSize < getTimestampSize()) {
return SerializeIF::STREAM_TOO_SHORT;
}
size_t foundLen = 0;
return CCSDSTime::convertFromCcsds(&readTime, buffer, &foundLen, maxSize);
}
timeval &CdsShortTimeStamper::getTime() { return readTime; }
size_t CdsShortTimeStamper::getTimestampSize() const { return TIMESTAMP_LEN; } size_t CdsShortTimeStamper::getTimestampSize() const { return TIMESTAMP_LEN; }

View File

@ -2,6 +2,7 @@
#define FSFW_TIMEMANAGER_TIMESTAMPER_H_ #define FSFW_TIMEMANAGER_TIMESTAMPER_H_
#include "CCSDSTime.h" #include "CCSDSTime.h"
#include "TimeReaderIF.h"
#include "TimeStamperIF.h" #include "TimeStamperIF.h"
#include "fsfw/objectmanager/SystemObject.h" #include "fsfw/objectmanager/SystemObject.h"
@ -14,7 +15,7 @@
* overriding the #addTimeStamp function. * overriding the #addTimeStamp function.
* @ingroup utility * @ingroup utility
*/ */
class CdsShortTimeStamper : public TimeStamperIF, public SystemObject { class CdsShortTimeStamper : public TimeStamperIF, public TimeReaderIF, public SystemObject {
public: public:
static constexpr size_t TIMESTAMP_LEN = 7; static constexpr size_t TIMESTAMP_LEN = 7;
/** /**
@ -37,7 +38,12 @@ class CdsShortTimeStamper : public TimeStamperIF, public SystemObject {
[[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;
ReturnValue_t readTimeStamp(const uint8_t *buffer, size_t maxSize) override;
timeval &getTime() override;
[[nodiscard]] size_t getTimestampSize() const override; [[nodiscard]] size_t getTimestampSize() const override;
private:
timeval readTime{};
}; };
#endif /* FSFW_TIMEMANAGER_TIMESTAMPER_H_ */ #endif /* FSFW_TIMEMANAGER_TIMESTAMPER_H_ */

View File

@ -3,16 +3,13 @@
#include <cstdlib> #include <cstdlib>
#include "TimeStampIF.h"
#include "fsfw/returnvalues/HasReturnvaluesIF.h" #include "fsfw/returnvalues/HasReturnvaluesIF.h"
class TimeReaderIF { class TimeReaderIF : public TimeStampIF {
public: public:
virtual ~TimeReaderIF() = default; ~TimeReaderIF() override = default;
virtual ReturnValue_t readTimeStamp(const uint8_t* buffer, size_t maxSize) = 0; virtual ReturnValue_t readTimeStamp(const uint8_t* buffer, size_t maxSize) = 0;
// Would be nice to have this, but the clock backend needs to be redesigned
// virtual ReturnValue_t readTimestampLen(const uint8_t* buffer, uint8_t maxSize, size_t&
// timestampLen) = 0;
virtual size_t getTimestampLen() = 0;
virtual timeval& getTime() = 0; virtual timeval& getTime() = 0;
}; };

View File

@ -0,0 +1,20 @@
#ifndef FSFW_TIMEMANAGER_TIMESTAMPIF_H
#define FSFW_TIMEMANAGER_TIMESTAMPIF_H
#include <cstddef>
#include "fsfw/retval.h"
class TimeStampIF {
public:
static const uint8_t INTERFACE_ID = CLASS_ID::TIME_STAMPER_IF;
static const ReturnValue_t BAD_TIMESTAMP = MAKE_RETURN_CODE(1);
// I am going to assume there are no larger timestamps
static constexpr size_t MAXIMUM_TIMESTAMP_LEN = 16;
virtual ~TimeStampIF() = default;
[[nodiscard]] virtual size_t getTimestampSize() const = 0;
};
#endif // FSFW_TIMEMANAGER_TIMESTAMPIF_H

View File

@ -1,6 +1,7 @@
#ifndef FSFW_TIMEMANAGER_TIMESTAMPERIF_H_ #ifndef FSFW_TIMEMANAGER_TIMESTAMPERIF_H_
#define FSFW_TIMEMANAGER_TIMESTAMPERIF_H_ #define FSFW_TIMEMANAGER_TIMESTAMPERIF_H_
#include "TimeStampIF.h"
#include "fsfw/returnvalues/HasReturnvaluesIF.h" #include "fsfw/returnvalues/HasReturnvaluesIF.h"
#include "fsfw/serialize/SerializeIF.h" #include "fsfw/serialize/SerializeIF.h"
@ -10,22 +11,11 @@
* Implementors need to ensure that calling the method is thread-safe, i.e. * Implementors need to ensure that calling the method is thread-safe, i.e.
* addTimeStamp may be called in parallel from a different context. * addTimeStamp may be called in parallel from a different context.
*/ */
class TimeStamperIF : public SerializeIF { class TimeStamperIF : public SerializeIF, public TimeStampIF {
public: public:
static const uint8_t INTERFACE_ID = CLASS_ID::TIME_STAMPER_IF;
static const ReturnValue_t BAD_TIMESTAMP = MAKE_RETURN_CODE(1);
// I am going to assume there are no larger timestamps
static constexpr size_t MAXIMUM_TIMESTAMP_LEN = 16;
//! This is a mission-specific constant and determines the total
//! size reserved for timestamps.
// static const uint8_t MISSION_TIMESTAMP_SIZE = fsfwconfig::FSFW_MISSION_TIMESTAMP_SIZE;
[[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;
size_t getTimestampSize() const override { return getSerializedSize(); }
protected: protected:
}; };

View File

@ -66,7 +66,7 @@ ReturnValue_t PusTmReader::parseData(bool crcCheck) {
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
return result; return result;
} }
size_t timestampLen = timeReader->getTimestampLen(); size_t timestampLen = timeReader->getTimestampSize();
if (currentOffset + timestampLen > spReader.getBufSize()) { if (currentOffset + timestampLen > spReader.getBufSize()) {
return SerializeIF::STREAM_TOO_SHORT; return SerializeIF::STREAM_TOO_SHORT;
} }

View File

@ -19,7 +19,7 @@ class PusTmReader : public PusTmIF,
ReturnValue_t parseDataWithoutCrcCheck(); ReturnValue_t parseDataWithoutCrcCheck();
ReturnValue_t parseDataWithCrcCheck(); ReturnValue_t parseDataWithCrcCheck();
const uint8_t* getFullData() const override; [[nodiscard]] const uint8_t* getFullData() const override;
explicit operator bool() const; explicit operator bool() const;
[[nodiscard]] bool isNull() const; [[nodiscard]] bool isNull() const;

View File

@ -2,7 +2,8 @@
#include "fsfw/globalfunctions/CRC.h" #include "fsfw/globalfunctions/CRC.h"
PusTmZeroCopyWriter::PusTmZeroCopyWriter(uint8_t* data, size_t size) : PusTmReader(data, size) {} PusTmZeroCopyWriter::PusTmZeroCopyWriter(TimeReaderIF* timeReader, uint8_t* data, size_t size)
: PusTmReader(timeReader, data, size) {}
void PusTmZeroCopyWriter::setSequenceCount(uint16_t seqCount) { void PusTmZeroCopyWriter::setSequenceCount(uint16_t seqCount) {
auto* spHeader = auto* spHeader =

View File

@ -4,7 +4,7 @@
#include "PusTmReader.h" #include "PusTmReader.h"
class PusTmZeroCopyWriter : public PusTmReader { class PusTmZeroCopyWriter : public PusTmReader {
public: public:
PusTmZeroCopyWriter(uint8_t* data, size_t size); PusTmZeroCopyWriter(TimeReaderIF* timeReader, uint8_t* data, size_t size);
void setSequenceCount(uint16_t seqCount); void setSequenceCount(uint16_t seqCount);
void updateErrorControl(); void updateErrorControl();