pfodParser  5.0.1
The pfodParser library is handles commands sent from the Android pfodApp, pfodApp supports WiFi, BLE, Bluetooth and SMS connections
pfodCircularLineBuffer Class Reference

pfodCircularLineBuffer - Line-aware circular buffer for CSV data streaming More...

#include <pfodCircularLineBuffer.h>

Inherits Stream.

Public Member Functions

 pfodCircularLineBuffer (size_t bufferSize=4096)
 Constructor - Initializes empty circular buffer with specified size. More...
 
 ~pfodCircularLineBuffer ()
 Destructor - Cleans up buffer memory. More...
 
size_t addLine (const char *line)
 Adds a complete line to the buffer (must include \r
terminator). More...
 
size_t addLine (const String &line)
 Adds a complete line to the buffer (must include \r
terminator). More...
 
void getRange (size_t fromLineCount, BufferRange &range)
 Gets buffer range starting from specified line number. More...
 
void getAllRange (BufferRange &range)
 Gets buffer range for all available data. More...
 
void setReadRange (const BufferRange &range)
 Sets the current read position to a specific buffer range. More...
 
void resetForRead ()
 Resets read position to beginning of all available data. More...
 
size_t getStartLineCount () const
 Gets the current start line number (oldest available line). More...
 
size_t getEndLineCount () const
 Gets the current end line number (newest line + 1). More...
 
size_t getLineCount () const
 Gets total number of lines currently in buffer. More...
 
size_t getBufferSize () const
 Gets the configured buffer size. More...
 
size_t getUsedBytes () const
 Gets number of bytes currently used in buffer. More...
 
size_t getAvailableBytes () const
 Gets number of bytes available in buffer. More...
 
bool isEmpty () const
 Checks if buffer is empty. More...
 
void clear ()
 Clears all data from buffer and resets line counts. More...
 
void debugBufferRange (Print *outPtr)
 Prints debug information about buffer state and positions. More...
 
virtual int available () override
 Returns number of bytes available to read from current read range. More...
 
virtual int peek () override
 Reads one byte from current read range without advancing position. More...
 
virtual int read () override
 Reads one byte from current read range and advances position. More...
 
virtual size_t write (uint8_t c) override
 Write single byte to buffer. More...
 
virtual size_t write (const uint8_t *buffer, size_t size) override
 Write buffer. More...
 

Detailed Description

pfodCircularLineBuffer - Line-aware circular buffer for CSV data streaming

Maintains complete lines only, automatically adjusting start position when buffer wraps to ensure no partial lines. Tracks line counts for efficient retrieval by line number.

Implements Arduino Stream interface for reading data.

Definition at line 40 of file pfodCircularLineBuffer.h.

Constructor & Destructor Documentation

◆ pfodCircularLineBuffer()

pfodCircularLineBuffer::pfodCircularLineBuffer ( size_t  bufferSize = 4096)

Constructor - Initializes empty circular buffer with specified size.

buffersize must be > line lenght, if buffersize is < line length no data will be available to read

Parameters
bufferSizeSize of buffer in bytes (default: 4096)

◆ ~pfodCircularLineBuffer()

pfodCircularLineBuffer::~pfodCircularLineBuffer ( )

Destructor - Cleans up buffer memory.

Member Function Documentation

◆ addLine() [1/2]

size_t pfodCircularLineBuffer::addLine ( const char *  line)

Adds a complete line to the buffer (must include \r
terminator).

Uses Print interface to write characters. If wrapping occurs and overwrites start position, adjusts start to next complete line.

Parameters
lineString containing complete line with \r
terminator
Returns
Number of bytes written

◆ addLine() [2/2]

size_t pfodCircularLineBuffer::addLine ( const String &  line)

Adds a complete line to the buffer (must include \r
terminator).

Uses Print interface to write characters. If wrapping occurs and overwrites start position, adjusts start to next complete line.

Parameters
lineString containing complete line with \r
terminator
Returns
Number of bytes written

◆ available()

virtual int pfodCircularLineBuffer::available ( )
overridevirtual

Returns number of bytes available to read from current read range.

Returns
Number of bytes available

◆ clear()

void pfodCircularLineBuffer::clear ( )

Clears all data from buffer and resets line counts.

◆ debugBufferRange()

void pfodCircularLineBuffer::debugBufferRange ( Print *  outPtr)

Prints debug information about buffer state and positions.

Outputs buffer range, stream positions, line counts, and usage stats.

Parameters
outPtrPointer to Print object for output (e.g., &Serial). Returns silently if null.

◆ getAllRange()

void pfodCircularLineBuffer::getAllRange ( BufferRange range)

Gets buffer range for all available data.

Parameters
rangeOutput parameter filled with start/end byte positions and line counts

◆ getAvailableBytes()

size_t pfodCircularLineBuffer::getAvailableBytes ( ) const
inline

Gets number of bytes available in buffer.

Returns
Bytes available for new data

Definition at line 148 of file pfodCircularLineBuffer.h.

◆ getBufferSize()

size_t pfodCircularLineBuffer::getBufferSize ( ) const
inline

Gets the configured buffer size.

Returns
Total buffer size in bytes

Definition at line 134 of file pfodCircularLineBuffer.h.

◆ getEndLineCount()

size_t pfodCircularLineBuffer::getEndLineCount ( ) const
inline

Gets the current end line number (newest line + 1).

Returns
Line number after last line in buffer

Definition at line 120 of file pfodCircularLineBuffer.h.

◆ getLineCount()

size_t pfodCircularLineBuffer::getLineCount ( ) const
inline

Gets total number of lines currently in buffer.

Returns
Number of complete lines stored

Definition at line 127 of file pfodCircularLineBuffer.h.

◆ getRange()

void pfodCircularLineBuffer::getRange ( size_t  fromLineCount,
BufferRange range 
)

Gets buffer range starting from specified line number.

Returns data from that line until end of buffer. If requested line is older than available, returns from earliest line.

Parameters
fromLineCountLine number to start from
rangeOutput parameter filled with start/end byte positions and line counts

◆ getStartLineCount()

size_t pfodCircularLineBuffer::getStartLineCount ( ) const
inline

Gets the current start line number (oldest available line).

Returns
Line number of first available line in buffer

Definition at line 113 of file pfodCircularLineBuffer.h.

◆ getUsedBytes()

size_t pfodCircularLineBuffer::getUsedBytes ( ) const

Gets number of bytes currently used in buffer.

Returns
Bytes of data stored

◆ isEmpty()

bool pfodCircularLineBuffer::isEmpty ( ) const
inline

Checks if buffer is empty.

Returns
true if buffer contains no data

Definition at line 155 of file pfodCircularLineBuffer.h.

◆ peek()

virtual int pfodCircularLineBuffer::peek ( )
overridevirtual

Reads one byte from current read range without advancing position.

Returns
Byte value (0-255) or -1 if no data available

◆ read()

virtual int pfodCircularLineBuffer::read ( )
overridevirtual

Reads one byte from current read range and advances position.

Returns
Byte value (0-255) or -1 if no data available

◆ resetForRead()

void pfodCircularLineBuffer::resetForRead ( )

Resets read position to beginning of all available data.

Convenience method that calls getAllRange() and setReadRange(). Subsequent Stream read operations will read from start of buffer.

◆ setReadRange()

void pfodCircularLineBuffer::setReadRange ( const BufferRange range)

Sets the current read position to a specific buffer range.

Subsequent Stream read operations will read from this range.

Parameters
rangeBufferRange specifying what to read

◆ write() [1/2]

virtual size_t pfodCircularLineBuffer::write ( const uint8_t *  buffer,
size_t  size 
)
overridevirtual

Write buffer.

Calls write(uint8_t) for each byte.

Parameters
bufferData to write
sizeNumber of bytes
Returns
Number of bytes written

◆ write() [2/2]

virtual size_t pfodCircularLineBuffer::write ( uint8_t  c)
overridevirtual

Write single byte to buffer.

Used by addLine() via Print interface. Automatically wraps and adjusts start position when \r
detected.

Parameters
cByte to write
Returns
1 if written, 0 if failed