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 
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 
76  Fw::SerializeStatus peek(char& value, FwSizeType offset = 0) const;
83  Fw::SerializeStatus peek(U8& value, FwSizeType offset = 0) const;
90  Fw::SerializeStatus peek(U32& value, FwSizeType offset = 0) const;
91 
99  Fw::SerializeStatus peek(U8* buffer, FwSizeType size, FwSizeType offset = 0) const;
100 
108 
114 
120  FwSizeType get_free_size() const;
121 
126  FwSizeType get_capacity() const;
127 
132 
136  void clear_high_water_mark();
137 
138  private:
145  FwSizeType advance_idx(FwSizeType idx, FwSizeType amount = 1) const;
147  U8* m_store;
149  FwSizeType m_store_size;
152  FwSizeType m_head_idx;
154  FwSizeType m_allocated_size;
156  FwSizeType m_high_water_mark;
157 };
158 } //End Namespace Types
159 #endif
160 
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:56
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