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);
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)
59 data.sync = (
raw[2] << 8) |
raw[3];
60 data.low = (
raw[4] << 8) |
raw[5];
61 data.high = (
raw[6] << 8) |
raw[7];
62 data.code = (
raw[8] << 16) | (
raw[9] << 8) |
raw[10];
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()));
206 size_t to_read = std::min(avail,
sizeof(buf));
211 for (
size_t i = 0; i < to_read; i++) {
212 if (this->
rx_buffer_.size() > MAX_RX_BUFFER_SIZE) {
217 ESP_LOGVV(TAG,
"Parsed: 0x%02X", buf[i]);
228 ESP_LOGD(TAG,
"Sending code: sync=0x%04" PRIX16
" low=0x%04" PRIX16
" high=0x%04" PRIX16
" code=0x%06" PRIX32,
229 data.sync, data.low, data.high, data.code);
230 this->
write(RF_CODE_START);
231 this->
write(RF_CODE_RFOUT);
234 this->
write((data.
low >> 8) & 0xFF);
241 this->
write(RF_CODE_STOP);
246 ESP_LOGD(TAG,
"Sending advanced code: length=0x%02X protocol=0x%02X code=0x%s", data.length, data.protocol,
248 this->
write(RF_CODE_START);
249 this->
write(RF_CODE_RFOUT_NEW);
253 this->
write(RF_CODE_STOP);
258 ESP_LOGD(TAG,
"Learning mode");
259 this->
write(RF_CODE_START);
260 this->
write(RF_CODE_LEARN);
261 this->
write(RF_CODE_STOP);
268 ESP_LOGI(TAG,
"Advanced Sniffing on");
269 this->
write(RF_CODE_START);
270 this->
write(RF_CODE_SNIFFING_ON);
271 this->
write(RF_CODE_STOP);
276 ESP_LOGI(TAG,
"Advanced Sniffing off");
277 this->
write(RF_CODE_START);
278 this->
write(RF_CODE_SNIFFING_OFF);
279 this->
write(RF_CODE_STOP);
284 ESP_LOGI(TAG,
"Raw Bucket Sniffing on");
285 this->
write(RF_CODE_START);
286 this->
write(RF_CODE_RFIN_BUCKET);
287 this->
write(RF_CODE_STOP);
292 ESP_LOGD(TAG,
"Sending Raw Code: %s", raw_code.c_str());
299 ESP_LOGD(TAG,
"Beeping for %hu ms", ms);
301 this->
write(RF_CODE_START);
302 this->
write(RF_CODE_BEEP);
303 this->
write((ms >> 8) & 0xFF);
304 this->
write(ms & 0xFF);
305 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_
optional< std::array< uint8_t, N > > read_array()
size_t write(uint8_t data)
Application App
Global storage of Application pointer - only one Application can exist.