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 FwSizeType size);
46 
56  void setup(U8* const buffer, const FwSizeType size);
57 
65  Fw::SerializeStatus serialize(const U8* const buffer, const FwSizeType size);
66 
73  Fw::SerializeStatus peek(char& value, FwSizeType offset = 0) const;
80  Fw::SerializeStatus peek(U8& value, FwSizeType offset = 0) const;
87  Fw::SerializeStatus peek(U32& value, FwSizeType offset = 0) const;
88 
96  Fw::SerializeStatus peek(U8* buffer, FwSizeType size, FwSizeType offset = 0) const;
97 
105 
111 
117  FwSizeType get_free_size() const;
118 
123  FwSizeType get_capacity() const;
124 
129 
133  void clear_high_water_mark();
134 
135  PRIVATE:
142  FwSizeType advance_idx(FwSizeType idx, FwSizeType amount = 1) const;
144  U8* m_store;
146  FwSizeType m_store_size;
149  FwSizeType m_head_idx;
151  FwSizeType m_allocated_size;
153  FwSizeType m_high_water_mark;
154 };
155 } //End Namespace Types
156 #endif
157 
PlatformSizeType FwSizeType
Definition: FpConfig.h:35
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
C++-compatible configuration header for fprime configuration.
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:32
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