ESPHome
2026.11.0-dev
Loading...
Searching...
No Matches
esphome
components
ezsp_proxy_tap
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
8
namespace
esphome::ezsp_proxy_tap
{
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.
13
class
AshFrameScanner
{
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.
37
class
AshAcknowledger
{
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
49
AshFrameScanner
scanner_
;
50
uint8_t
rx_sequence_
{0};
51
bool
synced_
{
false
};
52
};
53
54
}
// namespace esphome::ezsp_proxy_tap
ash_protocol.h
esphome::ezsp_proxy_tap::AshAcknowledger
Definition
ash_acknowledger.h:37
esphome::ezsp_proxy_tap::AshAcknowledger::scanner_
AshFrameScanner scanner_
Definition
ash_acknowledger.h:49
esphome::ezsp_proxy_tap::AshAcknowledger::synced_
bool synced_
Definition
ash_acknowledger.h:51
esphome::ezsp_proxy_tap::AshAcknowledger::handle_frame_
bool handle_frame_()
Definition
ash_acknowledger.cpp:91
esphome::ezsp_proxy_tap::AshAcknowledger::rx_sequence_
uint8_t rx_sequence_
Definition
ash_acknowledger.h:50
esphome::ezsp_proxy_tap::AshAcknowledger::feed
bool feed(uint8_t byte)
Definition
ash_acknowledger.cpp:89
esphome::ezsp_proxy_tap::AshAcknowledger::ack_num
uint8_t ack_num() const
Definition
ash_acknowledger.h:44
esphome::ezsp_proxy_tap::AshAcknowledger::reset
void reset()
Definition
ash_acknowledger.cpp:83
esphome::ezsp_proxy_tap::AshFrameScanner
Definition
ash_acknowledger.h:13
esphome::ezsp_proxy_tap::AshFrameScanner::header
const uint8_t * header() const
Definition
ash_acknowledger.h:21
esphome::ezsp_proxy_tap::AshFrameScanner::feed
bool feed(uint8_t byte)
Definition
ash_acknowledger.cpp:25
esphome::ezsp_proxy_tap::AshFrameScanner::reset
void reset()
Definition
ash_acknowledger.cpp:17
esphome::ezsp_proxy_tap::AshFrameScanner::length
size_t length() const
Definition
ash_acknowledger.h:22
esphome::ezsp_proxy_tap
Definition
ash_acknowledger.cpp:5
Generated by
1.12.0