ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
ash_protocol.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4#include <cstdint>
5
7
8// ASH Protocol Constants
9static constexpr uint8_t ASH_FLAG_BYTE = 0x7E; // Frame delimiter
10static constexpr uint8_t ASH_ESCAPE_BYTE = 0x7D; // Escape/substitution byte
11static constexpr uint8_t ASH_XOR_BYTE = 0x20; // XOR mask for escaped bytes
12static constexpr uint8_t ASH_SUBSTITUTE_BYTE = 0x18; // Substitution for invalid bytes
13
14static constexpr uint8_t ASH_XON_BYTE = 0x11; // Resume transmission
15static constexpr uint8_t ASH_XOFF_BYTE = 0x13; // Pause transmission
16static constexpr uint8_t ASH_CANCEL_BYTE = 0x1A; // Discards the partial frame before it
17// Sent between frames by sleepy NCPs to signal pending callbacks. No control byte is 0xFF.
18static constexpr uint8_t ASH_WAKE_BYTE = 0xFF;
19
20static constexpr size_t ASH_MAX_DATA_FIELD_SIZE = 220;
21static constexpr size_t MAX_ASH_FRAME_SIZE = 1 + ASH_MAX_DATA_FIELD_SIZE + 2;
22
23// The control byte, then the first Data Field byte (an RSTACK's version)
24static constexpr size_t ASH_HEADER_SIZE = 2;
25
26// Protocol limits
27static constexpr uint8_t ASH_MAX_SEQUENCE = 7; // 3-bit sequence number (0-7)
28
29// The frame CRC is CRC-CCITT: crc16be() with this initial value, transmitted big-endian
30static constexpr uint16_t ASH_CRC_INIT = 0xFFFF;
31
32// FLAG, control byte, two CRC bytes, FLAG. None of the eight ACKs has a byte that needs
33// escaping, so the size is fixed.
34static constexpr size_t ASH_ACK_FRAME_SIZE = 5;
35
36// Writes the ACK frame for `ack_num` into `output`
37void ash_build_ack_frame(uint8_t *output, uint8_t ack_num);
38
39} // namespace esphome::ezsp_proxy_tap
void ash_build_ack_frame(uint8_t *output, uint8_t ack_num)