13 ESP_LOGV(TAG,
"Sending ACK");
14 this->
write(RF_CODE_START);
15 this->
write(RF_CODE_ACK);
16 this->
write(RF_CODE_STOP);
35 ESP_LOGVV(TAG,
"Processing byte: 0x%02X",
byte);
39 return byte == RF_CODE_START;
43 return byte >= RF_CODE_ACK &&
byte <= RF_CODE_RFIN_BUCKET;
44 uint8_t action =
raw[1];
48 ESP_LOGD(TAG,
"Action OK");
50 case RF_CODE_LEARN_KO:
51 ESP_LOGD(TAG,
"Learning timeout");
53 case RF_CODE_LEARN_OK:
55 if (
byte != RF_CODE_STOP || at < RF_MESSAGE_SIZE + 2)
64 if (action == RF_CODE_LEARN_OK) {
65 ESP_LOGD(TAG,
"Learning success");
69 "Received RFBridge Code: sync=0x%04" PRIX16
" low=0x%04" PRIX16
" high=0x%04" PRIX16
71 data.sync, data.low, data.high, data.code);
75 case RF_CODE_LEARN_OK_NEW:
76 case RF_CODE_ADVANCED_RFIN: {
77 if (
byte != RF_CODE_STOP) {
78 return at < (
raw[2] + 3);
84 data.protocol =
raw[3];
86 for (uint8_t i = 0; i + 1 < data.length; i++) {
87 buf_append_printf(next_byte,
sizeof(next_byte), 0,
"%02X",
raw[4 + i]);
88 data.code += next_byte;
91 ESP_LOGI(TAG,
"Received RFBridge Advanced Code: length=0x%02X protocol=0x%02X code=0x%s", data.length,
92 data.protocol, data.code.c_str());
96 case RF_CODE_RFIN_BUCKET: {
101 return byte != 0 &&
byte <= B1_MAX_BUCKET_COUNT;
114 ESP_LOGW(TAG,
"Unknown action: 0x%02X", action);
118 ESP_LOGVV(TAG,
"Parsed: 0x%02X",
byte);
120 if (
byte == RF_CODE_STOP && action != RF_CODE_ACK)
137 const size_t at = this->
rx_buffer_.size() - 1;
139 uint8_t buckets =
raw[2] << 1;
143 for (
uint32_t i = 0; i <= at; i++) {
144 buf_append_printf(next_byte,
sizeof(next_byte), 0,
"%02X",
raw[i]);
146 if ((i > 3) && buckets) {
149 if ((i < 3) || (buckets % 2) || (i == at - 1)) {
153 ESP_LOGI(TAG,
"Received RFBridge Bucket: %s", str.c_str());
170 int size = codes.length();
171 for (
int i = 0; i <
size; i += 2) {
172 code = strtol(codes.substr(i, 2).c_str(),
nullptr, 16);
186 const bool receiving_bucket = this->
rx_buffer_.size() >= 2 && this->
rx_buffer_[1] == RF_CODE_RFIN_BUCKET;
187 if (receiving_bucket) {
192 ESP_LOGD(TAG,
"Discarding incomplete RFBridge Bucket frame (%u bytes)",
193 static_cast<unsigned>(this->
rx_buffer_.size()));
205 [
this, now](uint8_t
byte) {
206 if (this->
rx_buffer_.size() > MAX_RX_BUFFER_SIZE) {
211 ESP_LOGVV(TAG,
"Parsed: 0x%02X",
byte);
222 ESP_LOGD(TAG,
"Sending code: sync=0x%04" PRIX16
" low=0x%04" PRIX16
" high=0x%04" PRIX16
" code=0x%06" PRIX32,
223 data.sync, data.low, data.high, data.code);
224 this->
write(RF_CODE_START);
225 this->
write(RF_CODE_RFOUT);
228 this->
write((data.
low >> 8) & 0xFF);
235 this->
write(RF_CODE_STOP);
240 ESP_LOGD(TAG,
"Sending advanced code: length=0x%02X protocol=0x%02X code=0x%s", data.length, data.protocol,
242 this->
write(RF_CODE_START);
243 this->
write(RF_CODE_RFOUT_NEW);
247 this->
write(RF_CODE_STOP);
252 ESP_LOGD(TAG,
"Learning mode");
253 this->
write(RF_CODE_START);
254 this->
write(RF_CODE_LEARN);
255 this->
write(RF_CODE_STOP);
262 ESP_LOGI(TAG,
"Advanced Sniffing on");
263 this->
write(RF_CODE_START);
264 this->
write(RF_CODE_SNIFFING_ON);
265 this->
write(RF_CODE_STOP);
270 ESP_LOGI(TAG,
"Advanced Sniffing off");
271 this->
write(RF_CODE_START);
272 this->
write(RF_CODE_SNIFFING_OFF);
273 this->
write(RF_CODE_STOP);
278 ESP_LOGI(TAG,
"Raw Bucket Sniffing on");
279 this->
write(RF_CODE_START);
280 this->
write(RF_CODE_RFIN_BUCKET);
281 this->
write(RF_CODE_STOP);
286 ESP_LOGD(TAG,
"Sending Raw Code: %s", raw_code.c_str());
293 ESP_LOGD(TAG,
"Beeping for %hu ms", ms);
295 this->
write(RF_CODE_START);
296 this->
write(RF_CODE_BEEP);
297 this->
write((ms >> 8) & 0xFF);
298 this->
write(ms & 0xFF);
299 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
bool bucket_frame_candidate_
void stop_advanced_sniffing()
bool parse_bridge_byte_(uint8_t byte)
void finish_bucket_frame_()
void send_code(RFBridgeData data)
std::vector< uint8_t > rx_buffer_
bool read_available(F &&on_byte)
Same as read_available_chunks(), calling on_byte(uint8_t) once per byte.
size_t write(uint8_t data)
ESPHOME_LOG_TAG(TAG, "rf_bridge")
constexpr uint32_t encode_uint24(uint8_t byte1, uint8_t byte2, uint8_t byte3)
Encode a 24-bit value given three bytes in most to least significant byte order.
constexpr uint16_t encode_uint16(uint8_t msb, uint8_t lsb)
Encode a 16-bit value given the most and least significant byte.
Application App
Global storage of Application pointer - only one Application can exist.