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 < data.length - 1; 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;
96 for (uint32_t i = 0; i <= at; i++) {
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++) {
149 ESP_LOGVV(TAG,
"Parsed: 0x%02X", buf[i]);
159 ESP_LOGD(TAG,
"Sending code: sync=0x%04" PRIX16
" low=0x%04" PRIX16
" high=0x%04" PRIX16
" code=0x%06" PRIX32,
161 this->
write(RF_CODE_START);
162 this->
write(RF_CODE_RFOUT);
165 this->
write((data.
low >> 8) & 0xFF);
172 this->
write(RF_CODE_STOP);
177 ESP_LOGD(TAG,
"Sending advanced code: length=0x%02X protocol=0x%02X code=0x%s", data.
length, data.
protocol,
179 this->
write(RF_CODE_START);
180 this->
write(RF_CODE_RFOUT_NEW);
184 this->
write(RF_CODE_STOP);
189 ESP_LOGD(TAG,
"Learning mode");
190 this->
write(RF_CODE_START);
191 this->
write(RF_CODE_LEARN);
192 this->
write(RF_CODE_STOP);
197 ESP_LOGCONFIG(TAG,
"RF_Bridge:");
202 ESP_LOGI(TAG,
"Advanced Sniffing on");
203 this->
write(RF_CODE_START);
204 this->
write(RF_CODE_SNIFFING_ON);
205 this->
write(RF_CODE_STOP);
210 ESP_LOGI(TAG,
"Advanced Sniffing off");
211 this->
write(RF_CODE_START);
212 this->
write(RF_CODE_SNIFFING_OFF);
213 this->
write(RF_CODE_STOP);
218 ESP_LOGI(TAG,
"Raw Bucket Sniffing on");
219 this->
write(RF_CODE_START);
220 this->
write(RF_CODE_RFIN_BUCKET);
221 this->
write(RF_CODE_STOP);
226 ESP_LOGD(TAG,
"Sending Raw Code: %s", raw_code.c_str());
233 ESP_LOGD(TAG,
"Beeping for %hu ms", ms);
235 this->
write(RF_CODE_START);
236 this->
write(RF_CODE_BEEP);
237 this->
write((ms >> 8) & 0xFF);
238 this->
write(ms & 0xFF);
239 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.