ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
rf_bridge.h
Go to the documentation of this file.
1#pragma once
2
3#include <utility>
4#include <vector>
5
8
9namespace esphome::rf_bridge {
10
11static const uint8_t RF_MESSAGE_SIZE = 9;
12static const uint8_t RF_CODE_START = 0xAA;
13static const uint8_t RF_CODE_ACK = 0xA0;
14static const uint8_t RF_CODE_LEARN = 0xA1;
15static const uint8_t RF_CODE_LEARN_KO = 0xA2;
16static const uint8_t RF_CODE_LEARN_OK = 0xA3;
17static const uint8_t RF_CODE_RFIN = 0xA4;
18static const uint8_t RF_CODE_RFOUT = 0xA5;
19static const uint8_t RF_CODE_ADVANCED_RFIN = 0xA6;
20static const uint8_t RF_CODE_SNIFFING_ON = 0xA6;
21static const uint8_t RF_CODE_SNIFFING_OFF = 0xA7;
22static const uint8_t RF_CODE_RFOUT_NEW = 0xA8;
23static const uint8_t RF_CODE_LEARN_NEW = 0xA9;
24static const uint8_t RF_CODE_LEARN_KO_NEW = 0xAA;
25static const uint8_t RF_CODE_LEARN_OK_NEW = 0xAB;
26static const uint8_t RF_CODE_RFOUT_BUCKET = 0xB0;
27static const uint8_t RF_CODE_RFIN_BUCKET = 0xB1;
28static const uint8_t RF_CODE_BEEP = 0xC0;
29static const uint8_t RF_CODE_STOP = 0x55;
30static const uint8_t RF_DEBOUNCE = 200;
31static const size_t MAX_RX_BUFFER_SIZE = 512;
32// ~10 byte times at 19200 baud: long enough to prove the UART went quiet
33// after a possible bucket-frame terminator, short enough to finish well
34// before the next radio capture can be delivered.
35static const uint32_t BUCKET_CANDIDATE_QUIET_MS = 5;
36// Portisch drains a B1 frame's header, bucket table, and pulse data as
37// separate UART writes, so an in-progress bucket frame tolerates a longer
38// inter-region gap than the generic 50 ms inter-byte timeout.
39static const uint32_t BUCKET_FRAME_TIMEOUT_MS = 250;
40// Portisch's uart_put_RF_buckets sends at most 7 buckets plus the sync
41// bucket, so a B1 count byte above 8 (or 0) is malformed for any protocol.
42static const uint8_t B1_MAX_BUCKET_COUNT = 8;
43
45 uint16_t sync;
46 uint16_t low;
47 uint16_t high;
49};
50
52 uint8_t length;
53 uint8_t protocol;
54 std::string code;
55};
56
57class RFBridgeComponent final : public uart::UARTDevice, public Component {
58 public:
59 void loop() override;
60 void dump_config() override;
61 template<typename F> void add_on_code_received_callback(F &&callback) {
62 this->data_callback_.add(std::forward<F>(callback));
63 }
64 template<typename F> void add_on_advanced_code_received_callback(F &&callback) {
65 this->advanced_data_callback_.add(std::forward<F>(callback));
66 }
67 void send_code(RFBridgeData data);
69 void learn();
73 void send_raw(const std::string &code);
74 void beep(uint16_t ms);
75
76 protected:
77 void ack_();
78 void decode_();
79 bool parse_bridge_byte_(uint8_t byte);
81 void write_byte_str_(const std::string &codes);
82
83 std::vector<uint8_t> rx_buffer_;
86
89};
90
91} // namespace esphome::rf_bridge
void send_raw(const std::string &code)
CallbackManager< void(RFBridgeAdvancedData)> advanced_data_callback_
Definition rf_bridge.h:88
void send_advanced_code(const RFBridgeAdvancedData &data)
CallbackManager< void(RFBridgeData)> data_callback_
Definition rf_bridge.h:87
void write_byte_str_(const std::string &codes)
void add_on_advanced_code_received_callback(F &&callback)
Definition rf_bridge.h:64
void send_code(RFBridgeData data)
std::vector< uint8_t > rx_buffer_
Definition rf_bridge.h:83
void add_on_code_received_callback(F &&callback)
Definition rf_bridge.h:61
static void uint32_t