F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
CircularBuffer.hpp
Go to the documentation of this file.
1 /*
2  * CircularBuffer.hpp:
3  *
4  * Buffer used to efficiently store data in ring data structure. Uses an externally supplied
5  * data store as the backing for this buffer. Thus it is dependent on receiving sole ownership
6  * of the supplied buffer.
7  *
8  * Note: this given implementation loses one byte of the data store in order to ensure that a
9  * separate wrap-around tracking variable is not needed.
10  *
11  * Created on: Apr 4, 2019
12  * Author: lestarch
13  * Revised March 2022
14  * Author: bocchino
15  */
16 
17 #ifndef TYPES_CIRCULAR_BUFFER_HPP
18 #define TYPES_CIRCULAR_BUFFER_HPP
19 
20 #include <Fw/FPrimeBasicTypes.hpp>
22 #include <config/CircularBufferCfg.hpp>
23 
24 namespace Types {
25 
27  friend class CircularBufferTester;
28 
29  public:
37 
48  CircularBuffer(U8* const buffer, const FwSizeType size);
49 
59  void setup(U8* const buffer, const FwSizeType size);
60 
68  Fw::SerializeStatus serialize(const U8* const buffer, const FwSizeType size);
69 
79  Fw::SerializeStatus serialize(const Fw::Serializable& serializable, const FwSizeType size);
80 
92 
99  Fw::SerializeStatus peek(char& value, FwSizeType offset = 0) const;
106  Fw::SerializeStatus peek(U8& value, FwSizeType offset = 0) const;
113  Fw::SerializeStatus peek(U32& value, FwSizeType offset = 0) const;
114 
122  Fw::SerializeStatus peek(U8* buffer, FwSizeType size, FwSizeType offset = 0) const;
123 
133  Fw::SerializeStatus peek(Fw::Serializable& serializable, FwSizeType size, FwSizeType offset = 0) const;
134 
145  Fw::SerializeStatus peek(Fw::LinearBufferBase& buffer, FwSizeType size, FwSizeType offset = 0) const;
146 
154 
162 
168 
174  FwSizeType get_free_size() const;
175 
180  FwSizeType get_capacity() const;
181 
186 
190  void clear_high_water_mark();
191 
192  private:
196 
203  template <typename T>
204  Fw::SerializeStatus serialize_impl(const T& serializable, const FwSizeType size);
205 
213  template <typename T>
214  Fw::SerializeStatus peek_impl(T& serializable, FwSizeType size, FwSizeType offset) const;
215 
222  FwSizeType advance_idx(FwSizeType idx, FwSizeType amount = 1) const;
224  U8* m_store;
226  FwSizeType m_store_size;
229  FwSizeType m_head_idx;
231  FwSizeType m_allocated_size;
233  FwSizeType m_high_water_mark;
234 };
235 } // End Namespace Types
236 #endif
PlatformSizeType FwSizeType
friend class CircularBufferTester
SerializeStatus
forward declaration for string
FwSizeType get_high_water_mark() const
Fw::SerializeStatus serialize(const U8 *const buffer, const FwSizeType size)
Fw::SerializeStatus rotate(FwSizeType amount)
FwSizeType get_allocated_size() const
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:54
FwSizeType get_capacity() const
Fw::SerializeStatus peek(char &value, FwSizeType offset=0) const
void setup(U8 *const buffer, const FwSizeType size)
FwSizeType get_free_size() const
Fw::SerializeStatus trim(FwSizeType amount)
constexpr FwSizeType STAGING_BUFFER_SIZE