ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
ash_acknowledger.h
Go to the documentation of this file.
1#pragma once
2
3#include "ash_protocol.h"
4
5#include <cstddef>
6#include <cstdint>
7
9
10// Reassembles one direction of the byte stream into unstuffed, CRC-checked frames. Only
11// the first ASH_HEADER_SIZE bytes of a frame are kept, as the CRC is checked as bytes
12// arrive and acknowledging needs nothing past the header.
14 public:
15 // Returns true when the byte completes a frame with a valid CRC
16 bool feed(uint8_t byte);
17 void reset();
18
19 // The first min(length(), ASH_HEADER_SIZE) bytes of the last completed frame's body.
20 // Valid only until the next feed() call, which begins overwriting them.
21 const uint8_t *header() const { return this->header_; }
22 size_t length() const { return this->frame_length_; }
23
24 private:
25 uint8_t header_[ASH_HEADER_SIZE];
26 size_t index_{0}; // body bytes read so far in the frame being read
27 size_t frame_length_{0}; // body length of the last completed frame
28 uint16_t crc_{ASH_CRC_INIT};
29 bool escaped_{false};
30 bool discarding_{false};
31 bool poisoned_{false};
32};
33
34// Works out which acknowledgements an NCP is owed while a client has handed them to this
35// device. Whether to acknowledge at all is the client's decision, made by putting the port
36// in PROTOCOL mode, so this only follows the NCP's frame numbering.
38 public:
39 // Forgets the NCP's frame numbering. The next RSTACK or DATA frame sets it again.
40 void reset();
41
42 // Feed a byte from the NCP. Returns true when it completes a frame that is owed ack_num().
43 bool feed(uint8_t byte);
44 uint8_t ack_num() const { return this->rx_sequence_; }
45
46 protected:
47 bool handle_frame_();
48
50 uint8_t rx_sequence_{0};
51 bool synced_{false};
52};
53
54} // namespace esphome::ezsp_proxy_tap