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 
23 namespace Types {
24 
26  friend class CircularBufferTester;
27 
28  public:
36 
47  CircularBuffer(U8* const buffer, const FwSizeType size);
48 
58  void setup(U8* const buffer, const FwSizeType size);
59 
67  Fw::SerializeStatus serialize(const U8* const buffer, const FwSizeType size);
68 
75  Fw::SerializeStatus peek(char& value, FwSizeType offset = 0) const;
82  Fw::SerializeStatus peek(U8& value, FwSizeType offset = 0) const;
89  Fw::SerializeStatus peek(U32& value, FwSizeType offset = 0) const;
90 
98  Fw::SerializeStatus peek(U8* buffer, FwSizeType size, FwSizeType offset = 0) const;
99 
107 
113 
119  FwSizeType get_free_size() const;
120 
125  FwSizeType get_capacity() const;
126 
131 
135  void clear_high_water_mark();
136 
137  private:
144  FwSizeType advance_idx(FwSizeType idx, FwSizeType amount = 1) const;
146  U8* m_store;
148  FwSizeType m_store_size;
151  FwSizeType m_head_idx;
153  FwSizeType m_allocated_size;
155  FwSizeType m_high_water_mark;
156 };
157 } // End Namespace Types
158 #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:53
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