CodexPadFrameDecoder Arduino Lib 1.0.3

Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
robust_frame::Parser Class Reference

robust_frame protocol frame parser (receiver only). More...

`#include <robust_frame.h>`

## Public Types
using | FrameCallback = void (*)(const uint8_t *data, void *user_data)
| Frame parse callback function type.

## Public Member Functions
| Parser (const size_t max_payload_size, FrameCallback callback, void *user_data)
| Constructor. Dynamically allocates the internal buffer based on the maximum payload size.
| ~Parser ()
| Destructor. Frees the internally allocated buffer.
void | Feed (const uint8_t byte)
| Core state machine for processing a single byte.

## Detailed Description

robust_frame protocol frame parser (receiver only).

Handles frame synchronization, escape reversal, and CRC verification, outputting complete payloads via callback. Does not depend on any specific communication method; only requires feeding bytes one at a time via Feed(). The maximum payload size is specified via the constructor parameter, and the internal buffer is dynamically allocated accordingly.

Definition at line 32 of file robust_frame.h.

## Member Typedef Documentation

## ◆ FrameCallback

using robust_frame::Parser::FrameCallback = void (*)(const uint8_t *data, void *user_data)

Frame parse callback function type.

Parameters

  data | Pointer to the payload data (excluding frame header, footer, and CRC).
  user_data | User-defined context pointer, passed in via the constructor and returned as-is in the callback.

Definition at line 46 of file robust_frame.h.

## Constructor & Destructor Documentation

## ◆ Parser()

robust_frame::Parser::Parser | ( | const size_t | max_payload_size,
|  | FrameCallback | callback,
|  | void * | user_data )

Constructor. Dynamically allocates the internal buffer based on the maximum payload size.

Parameters

  [in] | max_payload_size | Maximum payload size in bytes (excluding CRC). The actual allocated buffer size is max_payload_size + 1, where the extra byte is used to store the CRC checksum.
  [in] | callback | Callback function invoked when a frame is successfully parsed (no callback if nullptr).
  [in] | user_data | User-defined context pointer passed through to the callback (typically a `this` pointer).

Definition at line 23 of file robust_frame.cpp.

## ◆ ~Parser()

robust_frame::Parser::~Parser | ( |  | ) |

Destructor. Frees the internally allocated buffer.

Definition at line 27 of file robust_frame.cpp.

## Member Function Documentation

## ◆ Feed()

void robust_frame::Parser::Feed | ( | const uint8_t | byte | ) |

Core state machine for processing a single byte.

Parameters

  [in] | byte | The input byte.

State transition diagram:

- kSyncHeader: Wait for frame header 0xAA, enter kCollectPayload upon receiving it.
- kCollectPayload:
  - Receive 0x55 (frame footer) → Verify CRC, callback payload if valid, then Reset.
  - Receive 0xDB (escape character) → Enter kUnescape.
  - Receive 0xAA (unexpected frame header) or buffer full → Reset and resync starting from this byte.
  - Otherwise → Store into internal buffer.
- kUnescape: XOR the byte with 0x20 to restore, check if the result is a valid special character (0xAA/0x55/0xDB). If not, discard the current frame and resync; otherwise store the restored byte and return to kCollectPayload.

Note
  Buffer full or encountering an unexpected frame header will trigger Reset and attempt resync from the current byte.

Definition at line 31 of file robust_frame.cpp.

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

- src/robust_frame.h
- src/robust_frame.cpp