From 47e3be21e3509c554682ad72a1a426f19beb0e47 Mon Sep 17 00:00:00 2001 From: NP v/d Spek Date: Thu, 5 Dec 2024 21:36:19 +0100 Subject: [PATCH] fixing reboot issue --- esphome/components/espnow/espnow.cpp | 3 +-- esphome/components/espnow/espnow.h | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/esphome/components/espnow/espnow.cpp b/esphome/components/espnow/espnow.cpp index 30c7b97a2a..0da0bc3186 100644 --- a/esphome/components/espnow/espnow.cpp +++ b/esphome/components/espnow/espnow.cpp @@ -24,6 +24,7 @@ namespace esphome { namespace espnow { static const char *const TAG = "espnow"; +const char *const ESPNowTAG::TAG = "espnow"; static const size_t SEND_BUFFER_SIZE = 200; @@ -564,8 +565,6 @@ bool ESPNowProtocol::send(uint64_t peer, const uint8_t *data, uint8_t len, uint8 return this->parent_->send(packet); } -const char *const SetChannel::TAG = "espnow.changechannel"; - } // namespace espnow } // namespace esphome diff --git a/esphome/components/espnow/espnow.h b/esphome/components/espnow/espnow.h index 601148067d..c9b7b7532c 100644 --- a/esphome/components/espnow/espnow.h +++ b/esphome/components/espnow/espnow.h @@ -38,6 +38,12 @@ static const uint64_t FAILED = 0; struct ESPNowPacket; +class ESPNowTAG { + public: + // could be made inline with C++17 + static const char *const TAG; +}; + template std::string espnow_i2h(T i) { return sprintf("%04x", i); } std::string espnow_rdm(std::string::size_type length); @@ -103,7 +109,10 @@ struct ESPNowPacket { inline uint8_t *get_content() const { return (uint8_t *) &(this->content); } inline uint8_t *get_payload() const { return (uint8_t *) &(this->content.payload); } inline uint8_t at(uint8_t pos) const { - assert(pos < this->size); + if (pos >= this->content_size()) { + esph_log_e(ESPNowTAG::TAG, "Trying to read out of space (%d of %d).", pos, this->content_size()); + return 0; + } return *(((uint8_t *) &this->content) + pos); } @@ -354,18 +363,12 @@ template class DelPeerAction : public Action, public Pare } }; -class SetChannel { - public: - // could be made inline with C++17 - static const char *const TAG; -}; - template class SetChannelAction : public Action, public Parented { public: TEMPLATABLE_VALUE(int8_t, channel); void play(Ts... x) override { #ifdef USE_WIFI - esph_log_e(SetChannel::TAG, "Manual changing the channel is not possible with WIFI enabled."); + esph_log_e(ESPNowTAG::TAG, "Manual changing the channel is not possible with WIFI enabled."); #else int8_t value = this->channel_.value(x...); parent_->set_wifi_channel(value);