ESPHome  2024.11.1
Public Member Functions | Static Public 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 Attributes

StreamBufferHandle_t handle_
 
StaticStreamBuffer_t structure_
 
uint8_t * storage_
 
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 63 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.

◆ 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 65 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 38 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 67 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 49 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 59 of file ring_buffer.cpp.

Field Documentation

◆ handle_

StreamBufferHandle_t esphome::RingBuffer::handle_
protected

Definition at line 85 of file ring_buffer.h.

◆ size_

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

Definition at line 88 of file ring_buffer.h.

◆ storage_

uint8_t* esphome::RingBuffer::storage_
protected

Definition at line 87 of file ring_buffer.h.

◆ structure_

StaticStreamBuffer_t esphome::RingBuffer::structure_
protected

Definition at line 86 of file ring_buffer.h.


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