13static constexpr size_t MAX_FRAME_TYPE_LEN = 8;
15static constexpr size_t MIN_FRAME_LENGTH = 2;
16static constexpr uint8_t NO_SLOT = 0xFF;
37 if (payload.size() <
len)
39 for (
size_t i = 0; i <
len; i++) {
51 uint16_t max_frame_length, uint8_t max_queue_size, uint8_t *rx_payload, uint8_t *tx_queue,
52 uint16_t *tx_queue_len)
65 void setup()
override;
80 void set_dump_frames(
bool dump_frames) { this->flags_.dump_frames = dump_frames; }
86 bool queue_raw_frame(std::span<const uint8_t> frame_type, std::span<const uint8_t> payload);
99 void encode_crc_(
const uint8_t *data,
size_t len,
bool include_header, uint8_t *
out)
const;
106 template<
typename F>
void encode_wire_(
const uint8_t *data,
size_t len, F &&put)
const {
109 for (
size_t i = 0; i <
len; i++) {
111 if (data[i] == this->
dle_)
123 void log_frame_(
const LogString *dir,
const uint8_t *data,
size_t len);
163 } flags_{.accept_header_crc =
true, .accept_payload_crc =
true};
BedjetMode mode
BedJet operating mode.
Hub for a DLE-framed RS485 bus: RX framer, CRC engine, gated TX queue and on_frame callbacks.
bool gate_allows_send_(uint32_t now)
Whether the released frame may go out once its gate delay has passed.
void set_tx_gate_mode(TxGateMode mode)
void set_queue_policy(QueuePolicy policy)
const uint8_t * tx_gate_frame_type_
void set_accept_payload_crc(bool accept)
void process_frame_(uint32_t now)
void handle_rx_byte_(uint8_t byte, uint32_t now)
uint16_t in_frame_timeout_ms_
void set_dump_frames(bool dump_frames)
void dump_config() override
void encode_crc_(const uint8_t *data, size_t len, bool include_header, uint8_t *out) const
void set_tx_gate_frame_type(const uint8_t *frame_type, size_t len)
bool queue_raw_frame(std::span< const uint8_t > frame_type, std::span< const uint8_t > payload)
Frame and queue frame_type followed by payload; both may live in PROGMEM.
uint16_t *const tx_queue_len_
uint8_t * tx_slot_(size_t index) const
uint8_t tx_gate_frame_type_len_
bool crc_matches_(bool include_header) const
void add_on_frame_callback(F &&callback)
Called with the unescaped payload (frame_type first, CRC removed) of every valid frame.
void send_next_(uint32_t now)
uint16_t last_tx_wire_ms_
void maybe_tx_(uint32_t now)
uint8_t *const rx_payload_
void set_tx_crc_variant(CrcVariant variant)
void log_frame_(const LogString *dir, const uint8_t *data, size_t len)
bool bus_silent_(uint32_t now) const
uint16_t wire_time_ms_(size_t len) const
bool queue_frame(const uint8_t *data, size_t len)
Frame and queue an unframed payload; data may live in PROGMEM.
void append_rx_(uint8_t byte)
CrcVariant tx_crc_variant_
uint16_t max_frame_length_
void set_in_frame_timeout(uint16_t ms)
RS485FrameHub(uint8_t dle, uint8_t stx, uint8_t etx, uint8_t escape_marker, CrcType crc_type, uint16_t max_frame_length, uint8_t max_queue_size, uint8_t *rx_payload, uint8_t *tx_queue, uint16_t *tx_queue_len)
Buffers are sized by codegen; tx_queue and tx_queue_len are nullptr on a sniffer_only hub.
LazyCallbackManager< void(std::span< const uint8_t >)> frame_callback_
void set_accept_header_crc(bool accept)
QueuePolicy queue_policy_
void transmit_head_(uint32_t now)
void set_tx_gate_delay(uint16_t delay)
uint16_t tx_gate_interval_
uint32_t last_activity_time_
void set_tx_gate_interval(uint16_t interval)
void encode_wire_(const uint8_t *data, size_t len, F &&put) const
Passes the wire bytes of an unescaped frame to put: DLE STX, the escaped frame, DLE ETX.
std::vector< uint8_t > & out
constexpr uint8_t crc_length(CrcType type)
bool frame_has_prefix(std::span< const uint8_t > payload, const uint8_t *prefix, size_t len)
True when payload starts with the len-byte prefix, which may live in PROGMEM.
RxState
The _DLE states mean the last byte was a DLE.
@ CRC_TYPE_SUM16_LITTLE_ENDIAN
@ CRC_TYPE_SUM16_BIG_ENDIAN
void HOT delay(uint32_t ms)
uint8_t progmem_read_byte(const uint8_t *addr)
uint8_t accept_header_crc
uint8_t accept_payload_crc