| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // ====================================================================== | ||
| 2 | // \title Os/IntervalTimer.hpp | ||
| 3 | // \brief Definition for Os::IntervalTimer | ||
| 4 | // ====================================================================== | ||
| 5 | #ifndef _IntervalTimer_hpp_ | ||
| 6 | #define _IntervalTimer_hpp_ | ||
| 7 | |||
| 8 | #include <Fw/FPrimeBasicTypes.hpp> | ||
| 9 | #include <Os/RawTime.hpp> | ||
| 10 | |||
| 11 | namespace Os { | ||
| 12 | //! \brief Os::IntervalTimer measures time intervals using start/stop functionality. | ||
| 13 | //! | ||
| 14 | //! The IntervalTimer class provides methods to capture the start and stop times of an interval | ||
| 15 | //! and calculate the difference between these times. It is useful for measuring the duration | ||
| 16 | //! of operations or events. Intervals can be returned in Fw::TimeInterval or as a microsecond U32. | ||
| 17 | //! | ||
| 18 | //! \note The caller must ensure that the start() method is called before the stop() method to get | ||
| 19 | //! a relevant time interval. | ||
| 20 | //! | ||
| 21 | //! \example | ||
| 22 | //! IntervalTimer timer; | ||
| 23 | //! timer.start(); | ||
| 24 | //! // Perform some operations | ||
| 25 | //! timer.stop(); | ||
| 26 | //! Fw::TimeInterval interval = timer.getTimeInterval(); | ||
| 27 | class IntervalTimer { | ||
| 28 | public: | ||
| 29 | //! \brief Constructor | ||
| 30 | IntervalTimer(); | ||
| 31 | |||
| 32 | //! \brief Destructor | ||
| 33 | 5 | ~IntervalTimer() = default; | |
| 34 | |||
| 35 | //! \brief Capture the start time of the interval. | ||
| 36 | //! | ||
| 37 | //! This method records the current time as the start time of the interval for this timer instance. | ||
| 38 | void start(); | ||
| 39 | |||
| 40 | //! \brief Capture the stop time of the interval. | ||
| 41 | //! | ||
| 42 | //! This method records the current time as the stop time of the interval for this timer instance. | ||
| 43 | void stop(); | ||
| 44 | |||
| 45 | //! \brief Get the difference between start and stop times in microseconds. | ||
| 46 | //! | ||
| 47 | //! This method calculates and returns the time difference between the start and stop times | ||
| 48 | //! in microseconds. The start() and stop() methods must be called before calling this method. | ||
| 49 | //! | ||
| 50 | //! \warning Users should prefer the getTimeInterval() method for better error handling. | ||
| 51 | //! \warning This function will return the maximum U32 value if the time difference is too large to fit in a U32. | ||
| 52 | //! \warning This means the largest time difference that can be measured is 2^32 microseconds (about 71 minutes). | ||
| 53 | //! | ||
| 54 | //! \return U32: The time difference in microseconds. | ||
| 55 | U32 getDiffUsec() const; | ||
| 56 | |||
| 57 | //! \brief Get the time interval between the start and stop times. | ||
| 58 | //! | ||
| 59 | //! This method calculates and returns the time interval between the recorded start and stop times | ||
| 60 | //! as a Fw::TimeInterval object. | ||
| 61 | //! | ||
| 62 | //! \param interval [out] A reference to a Fw::TimeInterval object where the calculated interval will be stored. | ||
| 63 | //! \return bool: True if the interval was successfully calculated, false otherwise. | ||
| 64 | Os::RawTime::Status getTimeInterval(Fw::TimeInterval& interval) const; | ||
| 65 | |||
| 66 | private: | ||
| 67 | RawTime m_startTime; //!< Stored start time | ||
| 68 | RawTime m_stopTime; //!< Stored end time | ||
| 69 | |||
| 70 | //! Disabled (private) Copy Constructor | ||
| 71 | IntervalTimer(IntervalTimer&); | ||
| 72 | |||
| 73 | }; // class IntervalTimer | ||
| 74 | |||
| 75 | } // namespace Os | ||
| 76 | |||
| 77 | #endif | ||
| 78 |