From 2581f858ed933c71ecb2907c4840e9ad883fa3e8 Mon Sep 17 00:00:00 2001 From: NP v/d Spek Date: Mon, 23 Sep 2024 01:21:08 +0200 Subject: [PATCH] some CI linting fixes --- esphome/components/espnow/espnow.cpp | 8 ++++---- esphome/components/espnow/espnow.h | 17 +++++++++-------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/esphome/components/espnow/espnow.cpp b/esphome/components/espnow/espnow.cpp index aba9bc6ace..25313e3c46 100644 --- a/esphome/components/espnow/espnow.cpp +++ b/esphome/components/espnow/espnow.cpp @@ -39,8 +39,8 @@ std::string format_mac_addr(const uint8_t *mac) { 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(char *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, +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", "test", 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(), @@ -49,7 +49,7 @@ void show_packet(char *title, ESPNowPacket *packet) { /* 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) : ESPNowPacket() { this->set_peer(peer); this->is_broadcast = @@ -59,7 +59,7 @@ ESPNowPacket::ESPNowPacket(uint64_t peer, const uint8_t *data, uint8_t size, uin this->update_payload_(); } -ESPNowPacket::ESPNowPacket(uint64_t peer, const uint8_t *data, uint8_t size) { +ESPNowPacket::ESPNowPacket(uint64_t peer, const uint8_t *data, uint8_t size) : ESPNowPacket() { this->set_peer(peer); std::memcpy(&(this->content), data, this->prefix_size()); size -= this->prefix_size(); diff --git a/esphome/components/espnow/espnow.h b/esphome/components/espnow/espnow.h index 573d0161e9..6645c35a97 100644 --- a/esphome/components/espnow/espnow.h +++ b/esphome/components/espnow/espnow.h @@ -50,8 +50,7 @@ struct ESPNowPacket { uint8_t payload[MAX_ESPNOW_DATA_SIZE + 2]{0}; } __attribute__((packed)) content; - ESPNowPacket(){}; - ~ESPNowPacket(){}; + ESPNowPacket() { this->payload_buffer_ = make_unique(new ByteBuffer(MAX_ESPNOW_DATA_SIZE)); }; // Create packet to be send. ESPNowPacket(uint64_t peer, const uint8_t *data, uint8_t size, uint32_t protocol); @@ -59,6 +58,8 @@ struct ESPNowPacket { // Load received packet's. ESPNowPacket(uint64_t peer, const uint8_t *data, uint8_t size); + ~ESPNowPacket() { delete this->payload_buffer_; } + uint8_t *peer_as_bytes() { return (uint8_t *) &(this->peer); } void set_peer(uint64_t peer) { if (peer == 0) { @@ -88,7 +89,7 @@ struct ESPNowPacket { } ByteBuffer *payload() { - this->payload_buffer_.set_position(this->payload_buffer_.get_used_space()); + this->payload_buffer_->set_position(this->payload_buffer_->get_used_space()); return this->payload_buffer_; } @@ -117,13 +118,13 @@ struct ESPNowPacket { bool is_valid(); private: - ByteBuffer payload_buffer_(MAX_ESPNOW_DATA_SIZE); + std::unique payload_buffer_{nullptr}; void update_payload_() { - if (this->payload_buffer_.is_changed()) { - this->payload_buffer_.flip(); - this->payload_buffer_.get_bytes((uint8_t *) &(this->content.payload), this->payload_buffer_.get_used_space()); - this->size = this->payload_buffer_.get_used_space() + this->prefix_size(); + if (this->payload_buffer_->is_changed()) { + this->payload_buffer_->flip(); + this->payload_buffer_->get_bytes((uint8_t *) &(this->content.payload), this->payload_buffer_->get_used_space()); + this->size = this->payload_buffer_->get_used_space() + this->prefix_size(); } this->content.payload[this->size] = this->calc_crc(); }