ESPHome  2024.12.2
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes
esphome::RingBuffer Class Reference

#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< RingBuffercreate (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}
 

Detailed Description

Definition at line 13 of file ring_buffer.h.

Constructor & Destructor Documentation

◆ ~RingBuffer()

esphome::RingBuffer::~RingBuffer ( )

Definition at line 14 of file ring_buffer.cpp.

Member Function Documentation

◆ available()

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.

Returns
Number of available bytes

Definition at line 93 of file ring_buffer.cpp.

◆ create()

std::unique_ptr< RingBuffer > esphome::RingBuffer::create ( size_t  len)
static

Definition at line 22 of file ring_buffer.cpp.

◆ discard_bytes_()

bool esphome::RingBuffer::discard_bytes_ ( size_t  discard_bytes)
protected

Discards data from the ring buffer.

Parameters
discard_bytesamount of bytes to discard
Returns
True if all bytes were successfully discarded, false otherwise

Definition at line 106 of file ring_buffer.cpp.

◆ free()

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.

Returns
Number of free bytes

Definition at line 99 of file ring_buffer.cpp.

◆ read()

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.

Parameters
dataPointer to copy read data into
lenNumber of bytes to read
ticks_to_waitMaximum number of FreeRTOS ticks to wait (default: 0)
Returns
Number of bytes read

Definition at line 39 of file ring_buffer.cpp.

◆ reset()

BaseType_t esphome::RingBuffer::reset ( )

Resets the ring buffer, discarding all stored data.

Returns
pdPASS if successful, pdFAIL otherwise

Definition at line 101 of file ring_buffer.cpp.

◆ write()

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.

Parameters
dataPointer to data for writing
lenNumber of bytes to write
Returns
Number of bytes written

Definition at line 72 of file ring_buffer.cpp.

◆ write_without_replacement()

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.

Parameters
dataPointer to data for writing
lenNumber of bytes to write
ticks_to_waitMaximum number of FreeRTOS ticks to wait (default: 0)
Returns
Number of bytes written

Definition at line 81 of file ring_buffer.cpp.

Field Documentation

◆ handle_

RingbufHandle_t esphome::RingBuffer::handle_ {nullptr}
protected

Definition at line 90 of file ring_buffer.h.

◆ size_

size_t esphome::RingBuffer::size_ {0}
protected

Definition at line 93 of file ring_buffer.h.

◆ storage_

uint8_t* esphome::RingBuffer::storage_ {nullptr}
protected

Definition at line 92 of file ring_buffer.h.

◆ structure_

StaticRingbuffer_t esphome::RingBuffer::structure_
protected

Definition at line 91 of file ring_buffer.h.


The documentation for this class was generated from the following files: