ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
esphome::FrameReader< N, HEADER > Class Template Reference

Collects fixed length binary frames of N bytes that start with the header bytes HEADER...; the binary twin of LineReader. More...

#include <frame_reader.h>

Public Member Functions

const uint8_t * feed (uint8_t c)
 Feed one byte; returns the completed frame, header included, valid until the next call, or nullptr.
 
size_t length () const
 Number of bytes of the partial frame; 0 after a frame is returned and while looking for a header.
 
void reset ()
 Forget the partial frame and look for a header from the next byte.
 
void resync ()
 For a frame the caller rejected (bad checksum): drop its first byte and realign on a header in the rest.
 

Protected Member Functions

void replay_ (size_t last)
 

Static Protected Member Functions

static constexpr uint8_t header_byte (size_t i)
 

Protected Attributes

uint8_t buf_ [N]
 
pos_t pos_ {0}
 

Detailed Description

template<size_t N, uint8_t... HEADER>
class esphome::FrameReader< N, HEADER >

Collects fixed length binary frames of N bytes that start with the header bytes HEADER...; the binary twin of LineReader.

Bytes before a header are skipped; checksums are left to the caller.

Definition at line 11 of file frame_reader.h.

Member Function Documentation

◆ feed()

template<size_t N, uint8_t... HEADER>
const uint8_t * esphome::FrameReader< N, HEADER >::feed ( uint8_t c)
inline

Feed one byte; returns the completed frame, header included, valid until the next call, or nullptr.

Definition at line 19 of file frame_reader.h.

◆ header_byte()

template<size_t N, uint8_t... HEADER>
static constexpr uint8_t esphome::FrameReader< N, HEADER >::header_byte ( size_t i)
inlinestaticconstexprprotected

Definition at line 48 of file frame_reader.h.

◆ length()

template<size_t N, uint8_t... HEADER>
size_t esphome::FrameReader< N, HEADER >::length ( ) const
inline

Number of bytes of the partial frame; 0 after a frame is returned and while looking for a header.

Definition at line 37 of file frame_reader.h.

◆ replay_()

template<size_t N, uint8_t... HEADER>
void esphome::FrameReader< N, HEADER >::replay_ ( size_t last)
inlineprotected

Definition at line 56 of file frame_reader.h.

◆ reset()

template<size_t N, uint8_t... HEADER>
void esphome::FrameReader< N, HEADER >::reset ( )
inline

Forget the partial frame and look for a header from the next byte.

Definition at line 40 of file frame_reader.h.

◆ resync()

template<size_t N, uint8_t... HEADER>
void esphome::FrameReader< N, HEADER >::resync ( )
inline

For a frame the caller rejected (bad checksum): drop its first byte and realign on a header in the rest.

Call only right after feed() returned that frame; use reset() otherwise.

Definition at line 44 of file frame_reader.h.

Field Documentation

◆ buf_

template<size_t N, uint8_t... HEADER>
uint8_t esphome::FrameReader< N, HEADER >::buf_[N]
protected

Definition at line 63 of file frame_reader.h.

◆ pos_

template<size_t N, uint8_t... HEADER>
pos_t esphome::FrameReader< N, HEADER >::pos_ {0}
protected

Definition at line 64 of file frame_reader.h.


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