ESPHome
2024.12.2
|
#include <ring_buffer.h>
Public Member Functions | |
~RingBuffer () | |
size_t | read (void *data, size_t len, TickType_t ticks_to_wait=0) |
Reads from the ring buffer, waiting up to a specified number of ticks if necessary. More... | |
size_t | write (const void *data, size_t len) |
Writes to the ring buffer, overwriting oldest data if necessary. More... | |
size_t | write_without_replacement (const void *data, size_t len, TickType_t ticks_to_wait=0) |
Writes to the ring buffer without overwriting oldest data. More... | |
size_t | available () const |
Returns the number of available bytes in the ring buffer. More... | |
size_t | free () const |
Returns the number of free bytes in the ring buffer. More... | |
BaseType_t | reset () |
Resets the ring buffer, discarding all stored data. More... | |
Static Public Member Functions | |
static std::unique_ptr< RingBuffer > | create (size_t len) |
Protected Member Functions | |
bool | discard_bytes_ (size_t discard_bytes) |
Discards data from the ring buffer. More... | |
Protected Attributes | |
RingbufHandle_t | handle_ {nullptr} |
StaticRingbuffer_t | structure_ |
uint8_t * | storage_ {nullptr} |
size_t | size_ {0} |
Definition at line 13 of file ring_buffer.h.
esphome::RingBuffer::~RingBuffer | ( | ) |
Definition at line 14 of file ring_buffer.cpp.
size_t esphome::RingBuffer::available | ( | ) | const |
Returns the number of available bytes in the ring buffer.
This function provides the number of bytes that can be read from the ring buffer without blocking the calling FreeRTOS task.
Definition at line 93 of file ring_buffer.cpp.
|
static |
Definition at line 22 of file ring_buffer.cpp.
|
protected |
Discards data from the ring buffer.
discard_bytes | amount of bytes to discard |
Definition at line 106 of file ring_buffer.cpp.
size_t esphome::RingBuffer::free | ( | ) | const |
Returns the number of free bytes in the ring buffer.
This function provides the number of bytes that can be written to the ring buffer without overwriting data or blocking the calling FreeRTOS task.
Definition at line 99 of file ring_buffer.cpp.
size_t esphome::RingBuffer::read | ( | void * | data, |
size_t | len, | ||
TickType_t | ticks_to_wait = 0 |
||
) |
Reads from the ring buffer, waiting up to a specified number of ticks if necessary.
Available bytes are read into the provided data pointer. If not enough bytes are available, the function will wait up to ticks_to_wait
FreeRTOS ticks before reading what is available.
data | Pointer to copy read data into |
len | Number of bytes to read |
ticks_to_wait | Maximum number of FreeRTOS ticks to wait (default: 0) |
Definition at line 39 of file ring_buffer.cpp.
BaseType_t esphome::RingBuffer::reset | ( | ) |
Resets the ring buffer, discarding all stored data.
Definition at line 101 of file ring_buffer.cpp.
size_t esphome::RingBuffer::write | ( | const void * | data, |
size_t | len | ||
) |
Writes to the ring buffer, overwriting oldest data if necessary.
The provided data is written to the ring buffer. If not enough space is available, the function will overwrite the oldest data in the ring buffer.
data | Pointer to data for writing |
len | Number of bytes to write |
Definition at line 72 of file ring_buffer.cpp.
size_t esphome::RingBuffer::write_without_replacement | ( | const void * | data, |
size_t | len, | ||
TickType_t | ticks_to_wait = 0 |
||
) |
Writes to the ring buffer without overwriting oldest data.
The provided data is written to the ring buffer. If not enough space is available, the function will wait up to ticks_to_wait
FreeRTOS ticks before writing as much as possible.
data | Pointer to data for writing |
len | Number of bytes to write |
ticks_to_wait | Maximum number of FreeRTOS ticks to wait (default: 0) |
Definition at line 81 of file ring_buffer.cpp.
|
protected |
Definition at line 90 of file ring_buffer.h.
|
protected |
Definition at line 93 of file ring_buffer.h.
|
protected |
Definition at line 92 of file ring_buffer.h.
|
protected |
Definition at line 91 of file ring_buffer.h.