11static const char *
const TAG =
"rf_bridge";
14 ESP_LOGV(TAG,
"Sending ACK");
15 this->
write(RF_CODE_START);
16 this->
write(RF_CODE_ACK);
17 this->
write(RF_CODE_STOP);
26 ESP_LOGVV(TAG,
"Processing byte: 0x%02X",
byte);
30 return byte == RF_CODE_START;
34 return byte >= RF_CODE_ACK &&
byte <= RF_CODE_RFIN_BUCKET;
35 uint8_t action =
raw[1];
39 ESP_LOGD(TAG,
"Action OK");
41 case RF_CODE_LEARN_KO:
42 ESP_LOGD(TAG,
"Learning timeout");
44 case RF_CODE_LEARN_OK:
46 if (
byte != RF_CODE_STOP || at < RF_MESSAGE_SIZE + 2)
55 if (action == RF_CODE_LEARN_OK) {
56 ESP_LOGD(TAG,
"Learning success");
60 "Received RFBridge Code: sync=0x%04" PRIX16
" low=0x%04" PRIX16
" high=0x%04" PRIX16
66 case RF_CODE_LEARN_OK_NEW:
67 case RF_CODE_ADVANCED_RFIN: {
68 if (
byte != RF_CODE_STOP) {
69 return at < (
raw[2] + 3);
75 data.protocol =
raw[3];
77 for (uint8_t i = 0; i + 1 < data.length; i++) {
78 buf_append_printf(next_byte,
sizeof(next_byte), 0,
"%02X",
raw[4 + i]);
79 data.code += next_byte;
82 ESP_LOGI(TAG,
"Received RFBridge Advanced Code: length=0x%02X protocol=0x%02X code=0x%s", data.length,
83 data.protocol, data.code.c_str());
87 case RF_CODE_RFIN_BUCKET: {
88 if (
byte != RF_CODE_STOP) {
92 uint8_t buckets =
raw[2] << 1;
97 buf_append_printf(next_byte,
sizeof(next_byte), 0,
"%02X",
raw[i]);
99 if ((i > 3) && buckets) {
102 if ((i < 3) || (buckets % 2) || (i == at - 1)) {
106 ESP_LOGI(TAG,
"Received RFBridge Bucket: %s", str.c_str());
110 ESP_LOGW(TAG,
"Unknown action: 0x%02X", action);
114 ESP_LOGVV(TAG,
"Parsed: 0x%02X",
byte);
116 if (
byte == RF_CODE_STOP && action != RF_CODE_ACK)
125 int size = codes.length();
126 for (
int i = 0; i <
size; i += 2) {
127 code = strtol(codes.substr(i, 2).c_str(),
nullptr, 16);
142 size_t to_read = std::min(avail,
sizeof(buf));
147 for (
size_t i = 0; i < to_read; i++) {
148 if (this->
rx_buffer_.size() > MAX_RX_BUFFER_SIZE) {
152 ESP_LOGVV(TAG,
"Parsed: 0x%02X", buf[i]);
162 ESP_LOGD(TAG,
"Sending code: sync=0x%04" PRIX16
" low=0x%04" PRIX16
" high=0x%04" PRIX16
" code=0x%06" PRIX32,
164 this->
write(RF_CODE_START);
165 this->
write(RF_CODE_RFOUT);
168 this->
write((data.
low >> 8) & 0xFF);
175 this->
write(RF_CODE_STOP);
180 ESP_LOGD(TAG,
"Sending advanced code: length=0x%02X protocol=0x%02X code=0x%s", data.
length, data.
protocol,
182 this->
write(RF_CODE_START);
183 this->
write(RF_CODE_RFOUT_NEW);
187 this->
write(RF_CODE_STOP);
192 ESP_LOGD(TAG,
"Learning mode");
193 this->
write(RF_CODE_START);
194 this->
write(RF_CODE_LEARN);
195 this->
write(RF_CODE_STOP);
200 ESP_LOGCONFIG(TAG,
"RF_Bridge:");
205 ESP_LOGI(TAG,
"Advanced Sniffing on");
206 this->
write(RF_CODE_START);
207 this->
write(RF_CODE_SNIFFING_ON);
208 this->
write(RF_CODE_STOP);
213 ESP_LOGI(TAG,
"Advanced Sniffing off");
214 this->
write(RF_CODE_START);
215 this->
write(RF_CODE_SNIFFING_OFF);
216 this->
write(RF_CODE_STOP);
221 ESP_LOGI(TAG,
"Raw Bucket Sniffing on");
222 this->
write(RF_CODE_START);
223 this->
write(RF_CODE_RFIN_BUCKET);
224 this->
write(RF_CODE_STOP);
229 ESP_LOGD(TAG,
"Sending Raw Code: %s", raw_code.c_str());
236 ESP_LOGD(TAG,
"Beeping for %hu ms", ms);
238 this->
write(RF_CODE_START);
239 this->
write(RF_CODE_BEEP);
240 this->
write((ms >> 8) & 0xFF);
241 this->
write(ms & 0xFF);
242 this->
write(RF_CODE_STOP);
uint32_t IRAM_ATTR HOT get_loop_component_start_time() const
Get the cached time in milliseconds from when the current component started its loop execution.
void send_raw(const std::string &code)
uint32_t last_bridge_byte_
CallbackManager< void(RFBridgeAdvancedData)> advanced_data_callback_
void send_advanced_code(const RFBridgeAdvancedData &data)
void start_bucket_sniffing()
void start_advanced_sniffing()
CallbackManager< void(RFBridgeData)> data_callback_
void write_byte_str_(const std::string &codes)
void dump_config() override
void stop_advanced_sniffing()
bool parse_bridge_byte_(uint8_t byte)
void send_code(RFBridgeData data)
std::vector< uint8_t > rx_buffer_
optional< std::array< uint8_t, N > > read_array()
void check_uart_settings(uint32_t baud_rate, uint8_t stop_bits=1, UARTParityOptions parity=UART_CONFIG_PARITY_NONE, uint8_t data_bits=8)
Check that the configuration of the UART bus matches the provided values and otherwise print a warnin...
size_t write(uint8_t data)
Providing packet encoding functions for exchanging data with a remote host.
Application App
Global storage of Application pointer - only one Application can exist.