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 class RawTime final : public RawTimeInterface {
102  public:
103  RawTime();
104  ~RawTime() final;
105 
107  RawTime(const RawTime& other);
108 
110  RawTime& operator=(const RawTime& other);
111 
114  RawTimeHandle* getHandle() override;
115 
116  // ------------------------------------------------------------
117  // Implementation-specific RawTime member functions
118  // ------------------------------------------------------------
119 
126  Status now() override;
127 
136  Status getTimeInterval(const Os::RawTime& other, Fw::TimeInterval& interval) const override;
137 
152  Fw::Endianness mode = Fw::Endianness::BIG) const override;
153 
168  Fw::Endianness mode = Fw::Endianness::BIG) override;
169 
170  // ------------------------------------------------------------
171  // Common functions built on top of OS-specific functions
172  // ------------------------------------------------------------
173 
186  Status getDiffUsec(const RawTime& other, U32& result) const;
187 
189  bool operator==(const RawTime& other) const;
190 
191  private:
192  // This section is used to store the implementation-defined RawTime handle. To Os::RawTime and fprime, this type is
193  // opaque and thus normal allocation cannot be done. Instead, we allow the implementor to store the handle in
194  // the byte-array here and set `m_handle_storage` to that address for storage.
195  //
196  alignas(FW_HANDLE_ALIGNMENT) RawTimeHandleStorage m_handle_storage;
197  RawTimeInterface& m_delegate;
198 };
199 } // namespace Os
200 
201 #endif
PlatformSizeType FwSizeType
Operation was successful.
Definition: RawTime.hpp:25
U8 RawTimeHandleStorage[FW_RAW_TIME_HANDLE_MAX_SIZE]
Definition: Os.hpp:20
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
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:80
~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.
Status getDiffUsec(const RawTime &other, U32 &result) const
Calculate the difference in microseconds between two RawTime objects.
Definition: RawTime.cpp:56
Big endian serialization.