| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // ====================================================================== | ||
| 2 | // \title Os/Posix/RawTime.hpp | ||
| 3 | // \brief Posix definitions for Os::RawTime | ||
| 4 | // ====================================================================== | ||
| 5 | #ifndef OS_POSIX_RAWTIME_HPP | ||
| 6 | #define OS_POSIX_RAWTIME_HPP | ||
| 7 | |||
| 8 | #include <Os/RawTime.hpp> | ||
| 9 | #include <ctime> | ||
| 10 | |||
| 11 | namespace Os { | ||
| 12 | namespace Posix { | ||
| 13 | namespace RawTime { | ||
| 14 | |||
| 15 | struct PosixRawTimeHandle : public RawTimeHandle { | ||
| 16 | timespec m_timespec = {0, 0}; | ||
| 17 | clockid_t m_clock_id = static_cast<clockid_t>(RAWTIME_DEFAULT); //!< Clock read by now() | ||
| 18 | }; | ||
| 19 | |||
| 20 | //! \brief Posix implementation of Os::RawTime | ||
| 21 | //! | ||
| 22 | //! Posix implementation of `RawTimeInterface` reading the `clock_gettime()` clock selected by `RawTimeSource`. | ||
| 23 | //! Intervals may only be computed between instances using the same clock. | ||
| 24 | //! | ||
| 25 | class PosixRawTime : public RawTimeInterface { | ||
| 26 | public: | ||
| 27 | //! \brief constructor using RAWTIME_DEFAULT as the clock source | ||
| 28 | PosixRawTime() = default; | ||
| 29 | |||
| 30 | //! \brief constructor selecting the clock source | ||
| 31 | //! \param source: clock source, whose value is the `clockid_t` passed to `clock_gettime()` | ||
| 32 | explicit PosixRawTime(RawTimeSource source); | ||
| 33 | |||
| 34 | //! \brief destructor | ||
| 35 | 4500 | ~PosixRawTime() override = default; | |
| 36 | |||
| 37 | //! \brief return the underlying RawTime handle (implementation specific) | ||
| 38 | //! \return internal RawTime handle representation | ||
| 39 | RawTimeHandle* getHandle() override; | ||
| 40 | |||
| 41 | // ------------------------------------------------------------ | ||
| 42 | // Implementation-specific RawTime overrides | ||
| 43 | // ------------------------------------------------------------ | ||
| 44 | //! \brief Get the current time. | ||
| 45 | //! | ||
| 46 | //! This function retrieves the current time and stores it in the RawTime object. | ||
| 47 | //! Each implementation should define its RawTimeHandle type for storing the time. | ||
| 48 | //! | ||
| 49 | //! \return Status indicating the result of the operation. | ||
| 50 | Status now() override; | ||
| 51 | |||
| 52 | //! \brief Calculate the time interval between this and another raw time. | ||
| 53 | //! | ||
| 54 | //! This function calculates the time interval between the current raw time and another | ||
| 55 | //! specified raw time. The result is stored in the provided (output) interval object. | ||
| 56 | //! | ||
| 57 | //! \param other The other RawTimeHandle to compare against. | ||
| 58 | //! \param interval Output parameter to store the calculated time interval. | ||
| 59 | //! \return Status indicating the result of the operation; INVALID_PARAMS if the clock sources differ. | ||
| 60 | Status getTimeInterval(const Os::RawTime& other, Fw::TimeInterval& interval) const override; | ||
| 61 | |||
| 62 | //! \brief Serialize the contents of the RawTimeInterface object into a buffer. | ||
| 63 | //! | ||
| 64 | //! This function serializes the contents of the RawTimeInterface object into the provided | ||
| 65 | //! buffer. | ||
| 66 | //! | ||
| 67 | //! \note The serialization must fit within `FW_RAW_TIME_SERIALIZATION_MAX_SIZE` bytes. This value is | ||
| 68 | //! defined in FpConfig.h. For example, Posix systems use a pair of U32 (sec, nanosec) and can therefore | ||
| 69 | //! serialize in 8 bytes. Should an OSAL implementation require more than this, the project must increase | ||
| 70 | //! that value in its config/ folder. | ||
| 71 | //! | ||
| 72 | //! \param buffer The buffer to serialize the contents into. | ||
| 73 | //! \param mode Endianness to use when serializing to buffer. | ||
| 74 | //! \return Fw::SerializeStatus indicating the result of the serialization. | ||
| 75 | Fw::SerializeStatus serializeTo(Fw::SerialBufferBase& buffer, | ||
| 76 | Fw::Endianness mode = Fw::Endianness::BIG) const override; | ||
| 77 | |||
| 78 | //! \brief Deserialize the contents of the RawTimeInterface object from a buffer. | ||
| 79 | //! | ||
| 80 | //! This function deserializes the contents of the RawTimeInterface object from the provided | ||
| 81 | //! buffer. | ||
| 82 | //! | ||
| 83 | //! \note The serialization must fit within `FW_RAW_TIME_SERIALIZATION_MAX_SIZE` bytes. This value is | ||
| 84 | //! defined in FpConfig.h. For example, Posix systems use a pair of U32 (sec, nanosec) and can therefore | ||
| 85 | //! serialize in 8 bytes. Should an OSAL implementation require more than this, the project must increase | ||
| 86 | //! that value in its config/ folder. | ||
| 87 | //! | ||
| 88 | //! \param buffer The buffer to deserialize the contents from. | ||
| 89 | //! \param mode Endianness to use when deserializing from the buffer. | ||
| 90 | //! \return Fw::SerializeStatus indicating the result of the deserialization. | ||
| 91 | Fw::SerializeStatus deserializeFrom(Fw::SerialBufferBase& buffer, | ||
| 92 | Fw::Endianness mode = Fw::Endianness::BIG) override; | ||
| 93 | |||
| 94 | private: | ||
| 95 | //! Handle for PosixRawTime | ||
| 96 | PosixRawTimeHandle m_handle; | ||
| 97 | }; | ||
| 98 | |||
| 99 | } // namespace RawTime | ||
| 100 | } // namespace Posix | ||
| 101 | } // namespace Os | ||
| 102 | #endif // OS_POSIX_RAWTIME_HPP | ||
| 103 |