diff --git a/src/fsfw/timemanager/CcsdsTimeStampReader.h b/src/fsfw/timemanager/CcsdsTimeStampReader.h index f323c87e..0bec2553 100644 --- a/src/fsfw/timemanager/CcsdsTimeStampReader.h +++ b/src/fsfw/timemanager/CcsdsTimeStampReader.h @@ -7,8 +7,6 @@ class CcsdsTimestampReader : public TimeReaderIF { public: - ReturnValue_t readTimeStamp(const uint8_t* buffer, uint8_t maxSize) override; - size_t getTimestampLen() override; timeval& getTime() override; private: diff --git a/src/fsfw/timemanager/CdsShortTimeStamper.cpp b/src/fsfw/timemanager/CdsShortTimeStamper.cpp index af0344e3..cdce62c1 100644 --- a/src/fsfw/timemanager/CdsShortTimeStamper.cpp +++ b/src/fsfw/timemanager/CdsShortTimeStamper.cpp @@ -36,4 +36,14 @@ ReturnValue_t CdsShortTimeStamper::deSerialize(const uint8_t **buffer, size_t *s 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; } diff --git a/src/fsfw/timemanager/CdsShortTimeStamper.h b/src/fsfw/timemanager/CdsShortTimeStamper.h index d392c1a6..4b1f6c28 100644 --- a/src/fsfw/timemanager/CdsShortTimeStamper.h +++ b/src/fsfw/timemanager/CdsShortTimeStamper.h @@ -2,6 +2,7 @@ #define FSFW_TIMEMANAGER_TIMESTAMPER_H_ #include "CCSDSTime.h" +#include "TimeReaderIF.h" #include "TimeStamperIF.h" #include "fsfw/objectmanager/SystemObject.h" @@ -14,7 +15,7 @@ * overriding the #addTimeStamp function. * @ingroup utility */ -class CdsShortTimeStamper : public TimeStamperIF, public SystemObject { +class CdsShortTimeStamper : public TimeStamperIF, public TimeReaderIF, public SystemObject { public: static constexpr size_t TIMESTAMP_LEN = 7; /** @@ -37,7 +38,12 @@ class CdsShortTimeStamper : public TimeStamperIF, public SystemObject { [[nodiscard]] size_t getSerializedSize() const override; ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size, Endianness streamEndianness) override; + ReturnValue_t readTimeStamp(const uint8_t *buffer, size_t maxSize) override; + timeval &getTime() override; [[nodiscard]] size_t getTimestampSize() const override; + + private: + timeval readTime{}; }; #endif /* FSFW_TIMEMANAGER_TIMESTAMPER_H_ */ diff --git a/src/fsfw/timemanager/TimeReaderIF.h b/src/fsfw/timemanager/TimeReaderIF.h index cfad90ff..289a0058 100644 --- a/src/fsfw/timemanager/TimeReaderIF.h +++ b/src/fsfw/timemanager/TimeReaderIF.h @@ -3,16 +3,13 @@ #include +#include "TimeStampIF.h" #include "fsfw/returnvalues/HasReturnvaluesIF.h" -class TimeReaderIF { +class TimeReaderIF : public TimeStampIF { public: - virtual ~TimeReaderIF() = default; + ~TimeReaderIF() override = default; 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; }; diff --git a/src/fsfw/timemanager/TimeStampIF.h b/src/fsfw/timemanager/TimeStampIF.h new file mode 100644 index 00000000..805cf3b1 --- /dev/null +++ b/src/fsfw/timemanager/TimeStampIF.h @@ -0,0 +1,20 @@ +#ifndef FSFW_TIMEMANAGER_TIMESTAMPIF_H +#define FSFW_TIMEMANAGER_TIMESTAMPIF_H + +#include + +#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 diff --git a/src/fsfw/timemanager/TimeStamperIF.h b/src/fsfw/timemanager/TimeStamperIF.h index 44cf0212..9f1ed940 100644 --- a/src/fsfw/timemanager/TimeStamperIF.h +++ b/src/fsfw/timemanager/TimeStamperIF.h @@ -1,6 +1,7 @@ #ifndef FSFW_TIMEMANAGER_TIMESTAMPERIF_H_ #define FSFW_TIMEMANAGER_TIMESTAMPERIF_H_ +#include "TimeStampIF.h" #include "fsfw/returnvalues/HasReturnvaluesIF.h" #include "fsfw/serialize/SerializeIF.h" @@ -10,22 +11,11 @@ * Implementors need to ensure that calling the method is thread-safe, i.e. * addTimeStamp may be called in parallel from a different context. */ -class TimeStamperIF : public SerializeIF { +class TimeStamperIF : public SerializeIF, public 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; - - //! 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; ~TimeStamperIF() override = default; + size_t getTimestampSize() const override { return getSerializedSize(); } protected: }; diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmReader.cpp b/src/fsfw/tmtcpacket/pus/tm/PusTmReader.cpp index a3dbb7b0..2aea80fe 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmReader.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmReader.cpp @@ -66,7 +66,7 @@ ReturnValue_t PusTmReader::parseData(bool crcCheck) { if (result != HasReturnvaluesIF::RETURN_OK) { return result; } - size_t timestampLen = timeReader->getTimestampLen(); + size_t timestampLen = timeReader->getTimestampSize(); if (currentOffset + timestampLen > spReader.getBufSize()) { return SerializeIF::STREAM_TOO_SHORT; } diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmReader.h b/src/fsfw/tmtcpacket/pus/tm/PusTmReader.h index fdad1b6c..c95fefae 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmReader.h +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmReader.h @@ -19,7 +19,7 @@ class PusTmReader : public PusTmIF, ReturnValue_t parseDataWithoutCrcCheck(); ReturnValue_t parseDataWithCrcCheck(); - const uint8_t* getFullData() const override; + [[nodiscard]] const uint8_t* getFullData() const override; explicit operator bool() const; [[nodiscard]] bool isNull() const; diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.cpp b/src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.cpp index 4c6c56d3..47bb749f 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.cpp @@ -2,7 +2,8 @@ #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) { auto* spHeader = diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.h b/src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.h index c3f5db35..d3a0e5f2 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.h +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.h @@ -4,7 +4,7 @@ #include "PusTmReader.h" class PusTmZeroCopyWriter : public PusTmReader { public: - PusTmZeroCopyWriter(uint8_t* data, size_t size); + PusTmZeroCopyWriter(TimeReaderIF* timeReader, uint8_t* data, size_t size); void setSequenceCount(uint16_t seqCount); void updateErrorControl();