Esp32.Protocol (esp32 v0.2.0)

Copy Markdown View Source

Packet building and parsing for the ESP serial bootloader protocol.

Request: <<0x00, op, size::little-16, checksum::little-32, data::binary>>. Response: <<0x01, op, size::little-16, value::little-32, data::binary>>, where data ends with two status bytes (ROM loaders append two more reserved bytes).

Summary

Functions

Checks the two status bytes that follow resp_data_len bytes of response data.

XOR checksum over data, seeded with 0xEF.

Splits a response frame; the size field is ignored because the stub under-reports it.

Types

op()

@type op() :: atom()

Functions

build_command(op, checksum, data)

@spec build_command(op(), non_neg_integer(), binary()) :: binary()

check_status(data, resp_data_len)

@spec check_status(binary(), non_neg_integer()) ::
  {:ok, binary()} | {:error, {:status, byte()} | :short_response}

Checks the two status bytes that follow resp_data_len bytes of response data.

Returns the response data on success or the error byte on failure.

checksum(data)

@spec checksum(binary()) :: byte()

XOR checksum over data, seeded with 0xEF.

command_id(op)

@spec command_id(op()) :: byte()

command_name(id)

@spec command_name(byte()) :: op() | nil

parse_response(arg1)

@spec parse_response(term()) :: {:ok, byte(), non_neg_integer(), binary()} | :error

Splits a response frame; the size field is ignored because the stub under-reports it.