mirror of
https://github.com/nasa/fprime.git
synced 2025-12-11 23:38:06 -06:00
* Add Os::RawTime and preliminary rule-based tests * Implement Stubs and stub tests tests + misc improvements * Update delay functions to use Fw::TimeInterval instead of Fw::Time * Replace TimerVal with Os::RawTime FPP type, SERIALIZED_SIZE fixed to 2*sizeof(U32) * Fix spelling and legacy code * Fix test import * Remove TimerVal files and misc clean up * Add Fw/Time as dependency of Os module * Fix include guards * Fix default constructors and missing getHandle stub * Add Handle and Serialization size to FpConfig, refactor interface for less vtable calls, refactor IntervalTimer * Fixes for new OS CMake API * Add RawTime FPP Model * Rename getRawTime to now(), better error handling, added docs for all functions * Correct handle size, spelling, and more robust test IntervalTimer test * Peer review changes * Move `Os.RawTime` to `Os/Types.fpp` * Fix unused variable * Fix spelling and comments * spelling extravaganza * Update metadata check-spelling run (pull_request_target) for os-interval-timer Signed-off-by: check-spelling-bot <check-spelling-bot@users.noreply.github.com> on-behalf-of: @check-spelling <check-spelling-bot@check-spelling.dev> * Reference based approach to minuend and subtrahend --------- Signed-off-by: check-spelling-bot <check-spelling-bot@users.noreply.github.com> Co-authored-by: Thomas Boyer-Chammard <thomas-bc@users.noreply.github.com> Co-authored-by: M Starch <LeStarch@googlemail.com>
78 lines
2.9 KiB
C++
78 lines
2.9 KiB
C++
// ======================================================================
|
|
// \title Os/IntervalTimer.hpp
|
|
// \brief Definition for Os::IntervalTimer
|
|
// ======================================================================
|
|
#ifndef _IntervalTimer_hpp_
|
|
#define _IntervalTimer_hpp_
|
|
|
|
#include <FpConfig.hpp>
|
|
#include <Os/RawTime.hpp>
|
|
|
|
namespace Os {
|
|
//! \brief Os::IntervalTimer measures time intervals using start/stop functionality.
|
|
//!
|
|
//! The IntervalTimer class provides methods to capture the start and stop times of an interval
|
|
//! and calculate the difference between these times. It is useful for measuring the duration
|
|
//! of operations or events. Intervals can be returned in Fw::TimeInterval or as a microsecond U32.
|
|
//!
|
|
//! \note The caller must ensure that the start() method is called before the stop() method to get
|
|
//! a relevant time interval.
|
|
//!
|
|
//! \example
|
|
//! IntervalTimer timer;
|
|
//! timer.start();
|
|
//! // Perform some operations
|
|
//! timer.stop();
|
|
//! Fw::TimeInterval interval = timer.getTimeInterval();
|
|
class IntervalTimer {
|
|
public:
|
|
//! \brief Constructor
|
|
IntervalTimer();
|
|
|
|
//! \brief Destructor
|
|
~IntervalTimer() = default;
|
|
|
|
//! \brief Capture the start time of the interval.
|
|
//!
|
|
//! This method records the current time as the start time of the interval for this timer instance.
|
|
void start();
|
|
|
|
//! \brief Capture the stop time of the interval.
|
|
//!
|
|
//! This method records the current time as the stop time of the interval for this timer instance.
|
|
void stop();
|
|
|
|
//! \brief Get the difference between start and stop times in microseconds.
|
|
//!
|
|
//! This method calculates and returns the time difference between the start and stop times
|
|
//! in microseconds. The start() and stop() methods must be called before calling this method.
|
|
//!
|
|
//! \warning Users should prefer the getTimeInterval() method for better error handling.
|
|
//! \warning This function will return the maximum U32 value if the time difference is too large to fit in a U32.
|
|
//! \warning This means the largest time difference that can be measured is 2^32 microseconds (about 71 minutes).
|
|
//!
|
|
//! \return U32: The time difference in microseconds.
|
|
U32 getDiffUsec() const;
|
|
|
|
//! \brief Get the time interval between the start and stop times.
|
|
//!
|
|
//! This method calculates and returns the time interval between the recorded start and stop times
|
|
//! as a Fw::TimeInterval object.
|
|
//!
|
|
//! \param interval [out] A reference to a Fw::TimeInterval object where the calculated interval will be stored.
|
|
//! \return bool: True if the interval was successfully calculated, false otherwise.
|
|
Os::RawTime::Status getTimeInterval(Fw::TimeInterval& interval) const;
|
|
|
|
PRIVATE:
|
|
RawTime m_startTime; //!< Stored start time
|
|
RawTime m_stopTime; //!< Stored end time
|
|
|
|
//! Disabled (private) Copy Constructor
|
|
IntervalTimer(IntervalTimer&);
|
|
|
|
}; // class IntervalTimer
|
|
|
|
} // namespace Os
|
|
|
|
#endif
|