9 static const char *
const TAG =
"rf_bridge";
12 ESP_LOGV(TAG,
"Sending ACK");
13 this->
write(RF_CODE_START);
14 this->
write(RF_CODE_ACK);
15 this->
write(RF_CODE_STOP);
24 ESP_LOGVV(TAG,
"Processing byte: 0x%02X", byte);
28 return byte == RF_CODE_START;
32 return byte >= RF_CODE_ACK && byte <= RF_CODE_RFIN_BUCKET;
33 uint8_t action = raw[1];
37 ESP_LOGD(TAG,
"Action OK");
39 case RF_CODE_LEARN_KO:
40 ESP_LOGD(TAG,
"Learning timeout");
42 case RF_CODE_LEARN_OK:
44 if (byte != RF_CODE_STOP || at < RF_MESSAGE_SIZE + 2)
48 data.
sync = (raw[2] << 8) | raw[3];
49 data.
low = (raw[4] << 8) | raw[5];
50 data.
high = (raw[6] << 8) | raw[7];
51 data.
code = (raw[8] << 16) | (raw[9] << 8) | raw[10];
53 if (action == RF_CODE_LEARN_OK) {
54 ESP_LOGD(TAG,
"Learning success");
58 "Received RFBridge Code: sync=0x%04" PRIX16
" low=0x%04" PRIX16
" high=0x%04" PRIX16
64 case RF_CODE_LEARN_OK_NEW:
65 case RF_CODE_ADVANCED_RFIN: {
66 if (byte != RF_CODE_STOP) {
67 return at < (raw[2] + 3);
73 data.protocol = raw[3];
75 for (uint8_t i = 0; i < data.length - 1; i++) {
76 sprintf(next_byte,
"%02X", raw[4 + i]);
77 data.code += next_byte;
80 ESP_LOGI(TAG,
"Received RFBridge Advanced Code: length=0x%02X protocol=0x%02X code=0x%s", data.length,
81 data.protocol, data.code.c_str());
85 case RF_CODE_RFIN_BUCKET: {
86 if (byte != RF_CODE_STOP) {
90 uint8_t buckets = raw[2] << 1;
94 for (uint32_t i = 0; i <= at; i++) {
95 sprintf(next_byte,
"%02X", raw[i]);
97 if ((i > 3) && buckets) {
100 if ((i < 3) || (buckets % 2) || (i == at - 1)) {
104 ESP_LOGI(TAG,
"Received RFBridge Bucket: %s", str.c_str());
108 ESP_LOGW(TAG,
"Unknown action: 0x%02X", action);
112 ESP_LOGVV(TAG,
"Parsed: 0x%02X", byte);
114 if (byte == RF_CODE_STOP && action != RF_CODE_ACK)
123 int size = codes.length();
124 for (
int i = 0; i < size; i += 2) {
125 code = strtol(codes.substr(i, 2).c_str(),
nullptr, 16);
131 const uint32_t now =
millis();
141 ESP_LOGVV(TAG,
"Parsed: 0x%02X", byte);
150 ESP_LOGD(TAG,
"Sending code: sync=0x%04" PRIX16
" low=0x%04" PRIX16
" high=0x%04" PRIX16
" code=0x%06" PRIX32,
152 this->
write(RF_CODE_START);
153 this->
write(RF_CODE_RFOUT);
156 this->
write((data.
low >> 8) & 0xFF);
163 this->
write(RF_CODE_STOP);
168 ESP_LOGD(TAG,
"Sending advanced code: length=0x%02X protocol=0x%02X code=0x%s", data.
length, data.
protocol,
170 this->
write(RF_CODE_START);
171 this->
write(RF_CODE_RFOUT_NEW);
175 this->
write(RF_CODE_STOP);
180 ESP_LOGD(TAG,
"Learning mode");
181 this->
write(RF_CODE_START);
182 this->
write(RF_CODE_LEARN);
183 this->
write(RF_CODE_STOP);
188 ESP_LOGCONFIG(TAG,
"RF_Bridge:");
193 ESP_LOGI(TAG,
"Advanced Sniffing on");
194 this->
write(RF_CODE_START);
195 this->
write(RF_CODE_SNIFFING_ON);
196 this->
write(RF_CODE_STOP);
201 ESP_LOGI(TAG,
"Advanced Sniffing off");
202 this->
write(RF_CODE_START);
203 this->
write(RF_CODE_SNIFFING_OFF);
204 this->
write(RF_CODE_STOP);
209 ESP_LOGI(TAG,
"Raw Bucket Sniffing on");
210 this->
write(RF_CODE_START);
211 this->
write(RF_CODE_RFIN_BUCKET);
212 this->
write(RF_CODE_STOP);
217 ESP_LOGD(TAG,
"Sending Raw Code: %s", raw_code.c_str());
224 ESP_LOGD(TAG,
"Beeping for %hu ms", ms);
226 this->
write(RF_CODE_START);
227 this->
write(RF_CODE_BEEP);
228 this->
write((ms >> 8) & 0xFF);
229 this->
write(ms & 0xFF);
230 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
Implementation of SPI Controller mode.
void write_byte_str_(const std::string &codes)
size_t write(uint8_t data)