10static const char *
const TAG =
"rf_bridge";
13 ESP_LOGV(TAG,
"Sending ACK");
14 this->
write(RF_CODE_START);
15 this->
write(RF_CODE_ACK);
16 this->
write(RF_CODE_STOP);
25 ESP_LOGVV(TAG,
"Processing byte: 0x%02X",
byte);
29 return byte == RF_CODE_START;
33 return byte >= RF_CODE_ACK &&
byte <= RF_CODE_RFIN_BUCKET;
34 uint8_t action =
raw[1];
38 ESP_LOGD(TAG,
"Action OK");
40 case RF_CODE_LEARN_KO:
41 ESP_LOGD(TAG,
"Learning timeout");
43 case RF_CODE_LEARN_OK:
45 if (
byte != RF_CODE_STOP || at < RF_MESSAGE_SIZE + 2)
54 if (action == RF_CODE_LEARN_OK) {
55 ESP_LOGD(TAG,
"Learning success");
59 "Received RFBridge Code: sync=0x%04" PRIX16
" low=0x%04" PRIX16
" high=0x%04" PRIX16
65 case RF_CODE_LEARN_OK_NEW:
66 case RF_CODE_ADVANCED_RFIN: {
67 if (
byte != RF_CODE_STOP) {
68 return at < (
raw[2] + 3);
74 data.protocol =
raw[3];
76 for (uint8_t i = 0; i < data.length - 1; i++) {
77 sprintf(next_byte,
"%02X",
raw[4 + i]);
78 data.code += next_byte;
81 ESP_LOGI(TAG,
"Received RFBridge Advanced Code: length=0x%02X protocol=0x%02X code=0x%s", data.length,
82 data.protocol, data.code.c_str());
86 case RF_CODE_RFIN_BUCKET: {
87 if (
byte != RF_CODE_STOP) {
91 uint8_t buckets =
raw[2] << 1;
95 for (uint32_t i = 0; i <= at; i++) {
96 sprintf(next_byte,
"%02X",
raw[i]);
98 if ((i > 3) && buckets) {
101 if ((i < 3) || (buckets % 2) || (i == at - 1)) {
105 ESP_LOGI(TAG,
"Received RFBridge Bucket: %s", str.c_str());
109 ESP_LOGW(TAG,
"Unknown action: 0x%02X", action);
113 ESP_LOGVV(TAG,
"Parsed: 0x%02X",
byte);
115 if (
byte == RF_CODE_STOP && action != RF_CODE_ACK)
124 int size = codes.length();
125 for (
int i = 0; i < size; i += 2) {
126 code = strtol(codes.substr(i, 2).c_str(),
nullptr, 16);
142 ESP_LOGVV(TAG,
"Parsed: 0x%02X",
byte);
151 ESP_LOGD(TAG,
"Sending code: sync=0x%04" PRIX16
" low=0x%04" PRIX16
" high=0x%04" PRIX16
" code=0x%06" PRIX32,
153 this->
write(RF_CODE_START);
154 this->
write(RF_CODE_RFOUT);
157 this->
write((data.
low >> 8) & 0xFF);
164 this->
write(RF_CODE_STOP);
169 ESP_LOGD(TAG,
"Sending advanced code: length=0x%02X protocol=0x%02X code=0x%s", data.
length, data.
protocol,
171 this->
write(RF_CODE_START);
172 this->
write(RF_CODE_RFOUT_NEW);
176 this->
write(RF_CODE_STOP);
181 ESP_LOGD(TAG,
"Learning mode");
182 this->
write(RF_CODE_START);
183 this->
write(RF_CODE_LEARN);
184 this->
write(RF_CODE_STOP);
189 ESP_LOGCONFIG(TAG,
"RF_Bridge:");
194 ESP_LOGI(TAG,
"Advanced Sniffing on");
195 this->
write(RF_CODE_START);
196 this->
write(RF_CODE_SNIFFING_ON);
197 this->
write(RF_CODE_STOP);
202 ESP_LOGI(TAG,
"Advanced Sniffing off");
203 this->
write(RF_CODE_START);
204 this->
write(RF_CODE_SNIFFING_OFF);
205 this->
write(RF_CODE_STOP);
210 ESP_LOGI(TAG,
"Raw Bucket Sniffing on");
211 this->
write(RF_CODE_START);
212 this->
write(RF_CODE_RFIN_BUCKET);
213 this->
write(RF_CODE_STOP);
218 ESP_LOGD(TAG,
"Sending Raw Code: %s", raw_code.c_str());
225 ESP_LOGD(TAG,
"Beeping for %hu ms", ms);
227 this->
write(RF_CODE_START);
228 this->
write(RF_CODE_BEEP);
229 this->
write((ms >> 8) & 0xFF);
230 this->
write(ms & 0xFF);
231 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_
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...
bool read_byte(uint8_t *data)
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.