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 <FpConfig.hpp>
22 
23 namespace Types {
24 
26  public:
34 
45  CircularBuffer(U8* const buffer, const NATIVE_UINT_TYPE size);
46 
56  void setup(U8* const buffer, const NATIVE_UINT_TYPE size);
57 
65  Fw::SerializeStatus serialize(const U8* const buffer, const NATIVE_UINT_TYPE size);
66 
73  Fw::SerializeStatus peek(char& value, NATIVE_UINT_TYPE offset = 0) const;
80  Fw::SerializeStatus peek(U8& value, NATIVE_UINT_TYPE offset = 0) const;
87  Fw::SerializeStatus peek(U32& value, NATIVE_UINT_TYPE offset = 0) const;
88 
96  Fw::SerializeStatus peek(U8* buffer, NATIVE_UINT_TYPE size, NATIVE_UINT_TYPE offset = 0) const;
97 
105 
111 
118 
124 
129 
133  void clear_high_water_mark();
134 
135  PRIVATE:
142  NATIVE_UINT_TYPE advance_idx(NATIVE_UINT_TYPE idx, NATIVE_UINT_TYPE amount = 1) const;
144  U8* m_store;
146  NATIVE_UINT_TYPE m_store_size;
149  NATIVE_UINT_TYPE m_head_idx;
151  NATIVE_UINT_TYPE m_allocated_size;
153  NATIVE_UINT_TYPE m_high_water_mark;
154 };
155 } //End Namespace Types
156 #endif
157 
PlatformUIntType NATIVE_UINT_TYPE
Definition: BasicTypes.h:56
NATIVE_UINT_TYPE get_capacity() const
void setup(U8 *const buffer, const NATIVE_UINT_TYPE size)
NATIVE_UINT_TYPE get_high_water_mark() const
NATIVE_UINT_TYPE get_allocated_size() const
SerializeStatus
forward declaration for string
Fw::SerializeStatus serialize(const U8 *const buffer, const NATIVE_UINT_TYPE size)
Fw::SerializeStatus rotate(NATIVE_UINT_TYPE amount)
C++-compatible configuration header for fprime configuration.
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:30
NATIVE_UINT_TYPE get_free_size() const
Fw::SerializeStatus peek(char &value, NATIVE_UINT_TYPE offset=0) const