F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
RawTime.hpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title Os/RawTime.hpp
3 // \brief common definitions for Os::RawTime
4 // ======================================================================
5 #ifndef OS_RAWTIME_HPP_
6 #define OS_RAWTIME_HPP_
7 
11 #include <Os/Os.hpp>
12 
13 namespace Os {
14 
15 struct RawTimeHandle {};
16 
17 class RawTime; // Forward declaration
18 
20  public:
21  // Serialization size for RawTime objects, configured in config/FpConfig.h
23 
24  enum Status {
30  };
31 
33  RawTimeInterface() = default;
34 
36  virtual ~RawTimeInterface() = default;
37 
40  virtual RawTimeHandle* getHandle() = 0;
41 
43  static RawTimeInterface* getDelegate(RawTimeHandleStorage& aligned_new_memory,
44  const RawTimeInterface* to_copy = nullptr);
45 
46  // ------------------------------------------------------------------
47  // RawTime operations to be implemented by an OSAL implementation
48  // ------------------------------------------------------------------
49 
56  virtual Status now() = 0;
57 
66  virtual Status getTimeInterval(const Os::RawTime& other, Fw::TimeInterval& interval) const = 0;
67 
82  Fw::Endianness mode = Fw::Endianness::BIG) const = 0;
83 
99 
100  // ------------------------------------------------------------------
101  // Common virtual functions built on top of OS-specific functions
102  // ------------------------------------------------------------------
103 
116  virtual Status getDiffUsec(const RawTime& other, U32& result) const;
117 };
118 
119 class RawTime final : public RawTimeInterface {
120  public:
121  RawTime();
122  ~RawTime() final;
123 
125  RawTime(const RawTime& other);
126 
128  RawTime& operator=(const RawTime& other);
129 
132  RawTimeHandle* getHandle() override;
133 
134  // ------------------------------------------------------------
135  // Implementation-specific RawTime member functions
136  // ------------------------------------------------------------
137 
144  Status now() override;
145 
154  Status getTimeInterval(const Os::RawTime& other, Fw::TimeInterval& interval) const override;
155 
170  Fw::Endianness mode = Fw::Endianness::BIG) const override;
171 
186  Fw::Endianness mode = Fw::Endianness::BIG) override;
187 
200  Status getDiffUsec(const RawTime& other, U32& result) const override;
201 
202  // ------------------------------------------------------------
203  // Common functions built on top of OS-specific functions
204  // ------------------------------------------------------------
205 
207  bool operator==(const RawTime& other) const;
208 
209  private:
210  // This section is used to store the implementation-defined RawTime handle. To Os::RawTime and fprime, this type is
211  // opaque and thus normal allocation cannot be done. Instead, we allow the implementor to store the handle in
212  // the byte-array here and set `m_handle_storage` to that address for storage.
213  //
214  alignas(FW_HANDLE_ALIGNMENT) RawTimeHandleStorage m_handle_storage;
215  RawTimeInterface& m_delegate;
216 };
217 } // namespace Os
218 
219 #endif
PlatformSizeType FwSizeType
Status getDiffUsec(const RawTime &other, U32 &result) const override
Calculate the difference in microseconds between two RawTime objects.
Definition: RawTime.cpp:56
Operation was successful.
Definition: RawTime.hpp:25
U8 RawTimeHandleStorage[FW_RAW_TIME_HANDLE_MAX_SIZE]
Definition: Os.hpp:21
virtual Status now()=0
Get the current time.
static const FwSizeType SERIALIZED_SIZE
Definition: RawTime.hpp:22
Status now() override
Get the current time.
Definition: RawTime.cpp:36
RawTime()
Constructor.
Definition: RawTime.cpp:10
virtual Status getDiffUsec(const RawTime &other, U32 &result) const
Calculate the difference in microseconds between two RawTime objects.
Definition: RawTime.cpp:61
static RawTimeInterface * getDelegate(RawTimeHandleStorage &aligned_new_memory, const RawTimeInterface *to_copy=nullptr)
provide a pointer to a RawTime delegate object
virtual ~RawTimeInterface()=default
default virtual destructor
SerializeStatus
forward declaration for string
RawTimeHandle * getHandle() override
return the underlying RawTime handle (implementation specific)
Definition: RawTime.cpp:31
RawTime does not support operation.
Definition: RawTime.hpp:28
virtual Fw::SerializeStatus serializeTo(Fw::SerialBufferBase &buffer, Fw::Endianness mode=Fw::Endianness::BIG) const =0
Serialize the contents of the RawTimeInterface object into a buffer.
virtual RawTimeHandle * getHandle()=0
return the underlying RawTime handle (implementation specific)
Operation result caused an overflow.
Definition: RawTime.hpp:26
bool operator==(const RawTime &other) const
Compare whether two RawTime objects are the same (i.e. refer to the same microsecond) ...
Definition: RawTime.cpp:85
~RawTime() final
Destructor.
Definition: RawTime.cpp:14
RawTimeInterface()=default
default constructor
Parameters invalid for current platform.
Definition: RawTime.hpp:27
RawTime & operator=(const RawTime &other)
assignment operator that copies the internal representation
Definition: RawTime.cpp:24
Fw::SerializeStatus serializeTo(Fw::SerialBufferBase &buffer, Fw::Endianness mode=Fw::Endianness::BIG) const override
Serialize the contents of the RawTimeInterface object into a buffer.
Definition: RawTime.cpp:46
Status getTimeInterval(const Os::RawTime &other, Fw::TimeInterval &interval) const override
Calculate the time interval between this and another raw time.
Definition: RawTime.cpp:41
Fw::SerializeStatus deserializeFrom(Fw::SerialBufferBase &buffer, Fw::Endianness mode=Fw::Endianness::BIG) override
Deserialize the contents of the RawTimeInterface object from a buffer.
Definition: RawTime.cpp:51
Endianness
virtual Status getTimeInterval(const Os::RawTime &other, Fw::TimeInterval &interval) const =0
Calculate the time interval between this and another raw time.
virtual Fw::SerializeStatus deserializeFrom(Fw::SerialBufferBase &buffer, Fw::Endianness mode=Fw::Endianness::BIG)=0
Deserialize the contents of the RawTimeInterface object from a buffer.
Big endian serialization.