Skip to content

Source: ImprovFrame.h

ImprovFrame

The wire framing for Improv-WiFi provisioning, in pure C++ with no ESP-IDF or network headers.

Enumerations

Name Description
ImprovFrameType Frame types from the spec, named without the prefix so they never shadow the library's own improv::ImprovSerialType where both are in scope.
ImprovFeedResult Result of feeding a byte to the parser.

ImprovFrameType

enum ImprovFrameType

Frame types from the spec, named without the prefix so they never shadow the library's own improv::ImprovSerialType where both are in scope.

Value Description
CurrentState
ErrorState
Rpc
RpcResponse

ImprovFeedResult

enum ImprovFeedResult

Result of feeding a byte to the parser.

Value Description
NeedMore
FrameReady
BadChecksum
OversizePayload

Functions

Return Name Description
uint8_t improvChecksum inline The spec's checksum, a sum taken modulo 256, exposed so builders and tests share one copy.
size_t buildImprovFrame inline Build one frame into out, returning the bytes written, or 0 when it does not fit.

improvChecksum

inline

inline uint8_t improvChecksum(const uint8_t * data, size_t len)

The spec's checksum, a sum taken modulo 256, exposed so builders and tests share one copy.


buildImprovFrame

inline

inline size_t buildImprovFrame(ImprovFrameType type, const uint8_t * payload, size_t payloadLen, uint8_t * out, size_t outLen)

Build one frame into out, returning the bytes written, or 0 when it does not fit.

Variables

Return Name Description
constexpr uint8_t kImprovMagic constexpr Framing constants, matching the spec verbatim so the header needs no library include.
constexpr uint8_t kImprovSerialVersion constexpr
constexpr size_t kImprovMaxPayload constexpr

kImprovMagic

constexpr

constexpr uint8_t kImprovMagic = {'I','M','P','R','O','V'}

Framing constants, matching the spec verbatim so the header needs no library include.


kImprovSerialVersion

constexpr

constexpr uint8_t kImprovSerialVersion = 1

kImprovMaxPayload

constexpr

constexpr size_t kImprovMaxPayload = 128

ImprovFrameParser

class ImprovFrameParser
src/core/util/ImprovFrame.h:58

Byte-at-a-time framing parser, one per UART channel, resetting to the magic search after every frame it completes or drops.

Public Methods

inline ImprovFeedResult feed(uint8_t byte) : Feed one received byte, the result naming what the parser now holds.

inline uint8_t lastType() const : The type byte of the last completed frame.

inline const uint8_t * lastPayload() const : The last completed frame's payload, valid until the next [feed].

inline uint8_t lastPayloadLen() const : How many bytes of [lastPayload] the last frame filled.

More info

The wire format

Every frame is the same shape, per the Improv serial spec:

[I][M][P][R][O][V][version=1][type][length][payload...length][checksum]

The parser is a state machine fed one byte at a time, and the builder writes the same shape into a caller-owned buffer.

Why framing is split from the RPC semantics

The payload inside a frame is an Improv RPC body, which the upstream improv/improv library parses through improv::parse_improv_data. Keeping that out of this header buys three things:

  • The framing is unit-tested on the host, in test/test_improv_frame.cpp.

  • The ESP32 task in platform_esp32.cpp stays thin, feeding UART bytes in and reacting to whole frames, including both headers and dispatching at the boundary.

  • The builder serves both the ESP32 send path and moondeck/build/improv_provision.py, which reimplements the same wire format in Python for the provisioning CLI.