mirror of
https://github.com/esphome/esphome.git
synced 2024-11-28 09:44:12 +01:00
some CI linting fixes
This commit is contained in:
parent
083000679b
commit
d89c9a2da6
2 changed files with 19 additions and 24 deletions
|
@ -34,6 +34,19 @@ static void application_task(void *param) {
|
||||||
application->runner();
|
application->runner();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string format_mac_addr(const uint8_t *mac) {
|
||||||
|
char buf[20];
|
||||||
|
sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
void show_packet(std::string title, ESPNowPacket *packet) {
|
||||||
|
ESP_LOGVV(TAG, "%s packet: M:%s H:%cx%cx%c P:%c%c%c 0x%02x S:%02x C:ox%02x~0x%02x S:%02d V:%s", title.c_str(),
|
||||||
|
format_mac_addr(packet->peer_as_bytes()).c_str(), packet->content_at(0), packet->content_at(1),
|
||||||
|
packet->content_at(2), packet->content_at(3), packet->content_at(4), packet->content_at(5),
|
||||||
|
packet->content_at(6), packet->content_at(7), packet->crc(), packet->calc_crc() packet->get_size(),
|
||||||
|
packet->is_valid() ? "Yes" : "No");
|
||||||
|
}
|
||||||
|
|
||||||
/* ESPNowPacket ********************************************************************** */
|
/* ESPNowPacket ********************************************************************** */
|
||||||
|
|
||||||
ESPNowPacket::ESPNowPacket(uint64_t peer, const uint8_t *data, uint8_t size, uint32_t protocol) {
|
ESPNowPacket::ESPNowPacket(uint64_t peer, const uint8_t *data, uint8_t size, uint32_t protocol) {
|
||||||
|
@ -77,15 +90,6 @@ ESPNowComponent::ESPNowComponent() { global_esp_now = this; }
|
||||||
void ESPNowComponent::dump_config() {
|
void ESPNowComponent::dump_config() {
|
||||||
ESP_LOGCONFIG(TAG, "esp_now:");
|
ESP_LOGCONFIG(TAG, "esp_now:");
|
||||||
ESP_LOGCONFIG(TAG, " MAC Address: 0x%12llx.", ESPNOW_ADDR_SELF);
|
ESP_LOGCONFIG(TAG, " MAC Address: 0x%12llx.", ESPNOW_ADDR_SELF);
|
||||||
ESPNowPacket *packet = new ESPNowPacket(0x112233445566, (uint8_t *) TAG, 6, 0xabcdef);
|
|
||||||
ESP_LOGI(TAG, "test: %s |H:%02x%02x%02x A:%02x%02x%02x %02x T:%02x C:%02x%02x S:%02d", packet->content_bytes(),
|
|
||||||
packet->content_at(0), packet->content_at(1), packet->content_at(2), packet->content_at(3),
|
|
||||||
packet->content_at(4), packet->content_at(5), packet->content_at(6), packet->content_at(7),
|
|
||||||
packet->content_at(8), packet->content_at(9), packet->get_size());
|
|
||||||
|
|
||||||
ESP_LOGI(TAG, "test: A:%06" PRIx32 " R:%02x C:%04x S:%d", packet->get_protocol(), packet->get_sequents(),
|
|
||||||
packet->crc(), packet->get_size());
|
|
||||||
ESP_LOGI(TAG, "test: is_valid: %s", packet->is_valid() ? "Yes" : "No");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ESPNowComponent::validate_channel_(uint8_t channel) {
|
bool ESPNowComponent::validate_channel_(uint8_t channel) {
|
||||||
|
@ -261,10 +265,7 @@ void ESPNowComponent::on_data_received(const uint8_t *addr, const uint8_t *data,
|
||||||
} else {
|
} else {
|
||||||
packet->timestamp = millis();
|
packet->timestamp = millis();
|
||||||
}
|
}
|
||||||
ESP_LOGVV(TAG, "Read: H:%02x%02x%02x P:%02x%02x%02x%02x T:%02x S:%02d", packet->content_at(0),
|
show_packet("Receive", packet);
|
||||||
packet->content_at(1), packet->content_at(2), packet->content_at(3), packet->content_at(4),
|
|
||||||
packet->content_at(5), packet->content_at(6), packet->content_at(7), packet->content_at(8),
|
|
||||||
packet->content_at(9), packet->get_size());
|
|
||||||
|
|
||||||
if (packet->is_valid()) {
|
if (packet->is_valid()) {
|
||||||
xQueueSendToBack(global_esp_now->receive_queue_, packet, 10);
|
xQueueSendToBack(global_esp_now->receive_queue_, packet, 10);
|
||||||
|
@ -275,11 +276,7 @@ void ESPNowComponent::on_data_received(const uint8_t *addr, const uint8_t *data,
|
||||||
|
|
||||||
bool ESPNowComponent::write(ESPNowPacket *packet) {
|
bool ESPNowComponent::write(ESPNowPacket *packet) {
|
||||||
uint8_t *mac = packet->peer_as_bytes();
|
uint8_t *mac = packet->peer_as_bytes();
|
||||||
|
show_packet("Write", packet);
|
||||||
ESP_LOGVV(TAG, "Write: H:%02x%02x%02x P:%02x%02x%02x%02x T:%02x C:%02x%02x S:%02d", packet->content_at(0),
|
|
||||||
packet->content_at(1), packet->content_at(2), packet->content_at(3), packet->content_at(4),
|
|
||||||
packet->content_at(5), packet->content_at(6), packet->content_at(7), packet->content_at(8),
|
|
||||||
packet->content_at(9), packet->get_size());
|
|
||||||
if (this->is_failed()) {
|
if (this->is_failed()) {
|
||||||
ESP_LOGE(TAG, "Cannot send espnow packet, espnow failed to setup");
|
ESP_LOGE(TAG, "Cannot send espnow packet, espnow failed to setup");
|
||||||
} else if (this->send_queue_full()) {
|
} else if (this->send_queue_full()) {
|
||||||
|
|
|
@ -107,7 +107,7 @@ struct ESPNowPacket {
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t crc() {
|
uint8_t crc() {
|
||||||
this->update_payload_();
|
// this->update_payload_();
|
||||||
return this->content.payload[this->size];
|
return this->content.payload[this->size];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,19 +175,17 @@ class ESPNowDefaultProtocol : public ESPNowProtocol {
|
||||||
void add_on_receive_callback(std::function<void(ESPNowPacket *)> &&callback) {
|
void add_on_receive_callback(std::function<void(ESPNowPacket *)> &&callback) {
|
||||||
this->on_receive_.add(std::move(callback));
|
this->on_receive_.add(std::move(callback));
|
||||||
}
|
}
|
||||||
void on_receive(ESPNowPacket *data_packet) override { this->on_receive_.call(std::move(data_packet)); };
|
void on_receive(ESPNowPacket *data_packet) override { this->on_receive_.call(packet); };
|
||||||
|
|
||||||
void add_on_sent_callback(std::function<void(ESPNowPacket *, bool status)> &&callback) {
|
void add_on_sent_callback(std::function<void(ESPNowPacket *, bool status)> &&callback) {
|
||||||
this->on_sent_.add(std::move(callback));
|
this->on_sent_.add(std::move(callback));
|
||||||
}
|
}
|
||||||
void on_sent(ESPNowPacket *data_packet, bool status) override {
|
void on_sent(ESPNowPacket *data_packet, bool status) override { this->on_sent_.call(packet, status); };
|
||||||
this->on_sent_.call(std::move(data_packet), status);
|
|
||||||
};
|
|
||||||
|
|
||||||
void add_on_peer_callback(std::function<void(ESPNowPacket *)> &&callback) {
|
void add_on_peer_callback(std::function<void(ESPNowPacket *)> &&callback) {
|
||||||
this->on_new_peer_.add(std::move(callback));
|
this->on_new_peer_.add(std::move(callback));
|
||||||
}
|
}
|
||||||
void on_new_peer(ESPNowPacket *data_packet) override { this->on_new_peer_.call(std::move(data_packet)); };
|
void on_new_peer(ESPNowPacket *data_packet) override { this->on_new_peer_.call(packet); };
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
CallbackManager<void(ESPNowPacket *, bool)> on_sent_;
|
CallbackManager<void(ESPNowPacket *, bool)> on_sent_;
|
||||||
|
|
Loading…
Reference in a new issue