8 static const char *
const TAG =
"rf_bridge";
11 ESP_LOGV(TAG,
"Sending ACK");
12 this->
write(RF_CODE_START);
13 this->
write(RF_CODE_ACK);
14 this->
write(RF_CODE_STOP);
23 ESP_LOGVV(TAG,
"Processing byte: 0x%02X", byte);
27 return byte == RF_CODE_START;
31 return byte >= RF_CODE_ACK && byte <= RF_CODE_RFIN_BUCKET;
32 uint8_t action = raw[1];
36 ESP_LOGD(TAG,
"Action OK");
38 case RF_CODE_LEARN_KO:
39 ESP_LOGD(TAG,
"Learning timeout");
41 case RF_CODE_LEARN_OK:
43 if (byte != RF_CODE_STOP || at < RF_MESSAGE_SIZE + 2)
47 data.
sync = (raw[2] << 8) | raw[3];
48 data.
low = (raw[4] << 8) | raw[5];
49 data.
high = (raw[6] << 8) | raw[7];
50 data.
code = (raw[8] << 16) | (raw[9] << 8) | raw[10];
52 if (action == RF_CODE_LEARN_OK)
53 ESP_LOGD(TAG,
"Learning success");
55 ESP_LOGI(TAG,
"Received RFBridge Code: sync=0x%04X low=0x%04X high=0x%04X code=0x%06X", data.
sync, data.
low,
60 case RF_CODE_LEARN_OK_NEW:
61 case RF_CODE_ADVANCED_RFIN: {
62 if (byte != RF_CODE_STOP) {
63 return at < (raw[2] + 3);
69 data.protocol = raw[3];
71 for (uint8_t i = 0; i < data.length - 1; i++) {
72 sprintf(next_byte,
"%02X", raw[4 + i]);
73 data.code += next_byte;
76 ESP_LOGI(TAG,
"Received RFBridge Advanced Code: length=0x%02X protocol=0x%02X code=0x%s", data.length,
77 data.protocol, data.code.c_str());
81 case RF_CODE_RFIN_BUCKET: {
82 if (byte != RF_CODE_STOP) {
86 uint8_t buckets = raw[2] << 1;
90 for (uint32_t i = 0; i <= at; i++) {
91 sprintf(next_byte,
"%02X", raw[i]);
93 if ((i > 3) && buckets) {
96 if ((i < 3) || (buckets % 2) || (i == at - 1)) {
100 ESP_LOGI(TAG,
"Received RFBridge Bucket: %s", str.c_str());
104 ESP_LOGW(TAG,
"Unknown action: 0x%02X", action);
108 ESP_LOGVV(TAG,
"Parsed: 0x%02X", byte);
110 if (byte == RF_CODE_STOP && action != RF_CODE_ACK)
119 int size = codes.length();
120 for (
int i = 0; i < size; i += 2) {
121 code = strtol(codes.substr(i, 2).c_str(),
nullptr, 16);
127 const uint32_t now =
millis();
137 ESP_LOGVV(TAG,
"Parsed: 0x%02X", byte);
146 ESP_LOGD(TAG,
"Sending code: sync=0x%04X low=0x%04X high=0x%04X code=0x%06X", data.
sync, data.
low, data.
high,
148 this->
write(RF_CODE_START);
149 this->
write(RF_CODE_RFOUT);
152 this->
write((data.
low >> 8) & 0xFF);
159 this->
write(RF_CODE_STOP);
164 ESP_LOGD(TAG,
"Sending advanced code: length=0x%02X protocol=0x%02X code=0x%s", data.
length, data.
protocol,
166 this->
write(RF_CODE_START);
167 this->
write(RF_CODE_RFOUT_NEW);
171 this->
write(RF_CODE_STOP);
176 ESP_LOGD(TAG,
"Learning mode");
177 this->
write(RF_CODE_START);
178 this->
write(RF_CODE_LEARN);
179 this->
write(RF_CODE_STOP);
184 ESP_LOGCONFIG(TAG,
"RF_Bridge:");
189 ESP_LOGI(TAG,
"Advanced Sniffing on");
190 this->
write(RF_CODE_START);
191 this->
write(RF_CODE_SNIFFING_ON);
192 this->
write(RF_CODE_STOP);
197 ESP_LOGI(TAG,
"Advanced Sniffing off");
198 this->
write(RF_CODE_START);
199 this->
write(RF_CODE_SNIFFING_OFF);
200 this->
write(RF_CODE_STOP);
205 ESP_LOGI(TAG,
"Raw Bucket Sniffing on");
206 this->
write(RF_CODE_START);
207 this->
write(RF_CODE_RFIN_BUCKET);
208 this->
write(RF_CODE_STOP);
213 ESP_LOGD(TAG,
"Sending Raw Code: %s", raw_code.c_str());
220 ESP_LOGD(TAG,
"Beeping for %hu ms", ms);
222 this->
write(RF_CODE_START);
223 this->
write(RF_CODE_BEEP);
224 this->
write((ms >> 8) & 0xFF);
225 this->
write(ms & 0xFF);
226 this->
write(RF_CODE_STOP);
void send_raw(const std::string &code)
CallbackManager< void(RFBridgeData)> data_callback_
CallbackManager< void(RFBridgeAdvancedData)> advanced_data_callback_
void send_code(RFBridgeData data)
uint32_t last_bridge_byte_
void start_advanced_sniffing()
void stop_advanced_sniffing()
bool parse_bridge_byte_(uint8_t byte)
uint32_t IRAM_ATTR HOT millis()
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)
void start_bucket_sniffing()
void send_advanced_code(const RFBridgeAdvancedData &data)
void dump_config() override
void write_byte_str_(const std::string &codes)
size_t write(uint8_t data)