some CI linting fixes

This commit is contained in:
NP v/d Spek 2024-09-23 16:19:07 +02:00
parent 9f5643f75e
commit ecb3920564
2 changed files with 28 additions and 26 deletions

View file

@ -39,7 +39,7 @@ 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]); sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
return buf; return buf;
} }
void show_packet(std::string title, ESPNowPacketPtr packet) { void show_packet(std::string title, const ESPNowPacketPtr &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", 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), 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(2), packet->content_at(3), packet->content_at(4), packet->content_at(5),
@ -215,21 +215,21 @@ ESPNowProtocol *ESPNowComponent::get_protocol_(uint32_t protocol) {
return this->protocols_[protocol]; return this->protocols_[protocol];
} }
void ESPNowComponent::on_receive_(ESPNowPacketPtr packet) { void ESPNowComponent::on_receive_(const ESPNowPacketPtr &packet) {
ESPNowProtocol *protocol = this->get_protocol_(packet->get_protocol()); ESPNowProtocol *protocol = this->get_protocol_(packet->get_protocol());
if (protocol != nullptr) { if (protocol != nullptr) {
protocol->on_receive(packet); protocol->on_receive(packet);
} }
} }
void ESPNowComponent::on_sent_(ESPNowPacketPtr packet, bool status) { void ESPNowComponent::on_sent_(const ESPNowPacketPtr &packet, bool status) {
ESPNowProtocol *protocol = this->get_protocol_(packet->get_protocol()); ESPNowProtocol *protocol = this->get_protocol_(packet->get_protocol());
if (protocol != nullptr) { if (protocol != nullptr) {
protocol->on_sent(packet, status); protocol->on_sent(packet, status);
} }
} }
void ESPNowComponent::on_new_peer_(ESPNowPacketPtr packet) { void ESPNowComponent::on_new_peer_(const ESPNowPacketPtr &packet) {
ESPNowProtocol *protocol = this->get_protocol_(packet->get_protocol()); ESPNowProtocol *protocol = this->get_protocol_(packet->get_protocol());
if (protocol != nullptr) { if (protocol != nullptr) {
protocol->on_new_peer(packet); protocol->on_new_peer(packet);
@ -272,7 +272,7 @@ void ESPNowComponent::on_data_received(const uint8_t *addr, const uint8_t *data,
} }
} }
bool ESPNowComponent::write(ESPNowPacketPtr packet) { bool ESPNowComponent::write(const ESPNowPacketPtr &packet) {
uint8_t *mac = packet->peer_as_bytes(); uint8_t *mac = packet->peer_as_bytes();
show_packet("Write", packet); show_packet("Write", packet);
if (this->is_failed()) { if (this->is_failed()) {
@ -293,7 +293,7 @@ bool ESPNowComponent::write(ESPNowPacketPtr packet) {
esp_err_t err = esp_now_send((uint8_t *) &mac, packet->content_bytes(), packet->get_size()); esp_err_t err = esp_now_send((uint8_t *) &mac, packet->content_bytes(), packet->get_size());
ESP_LOGVV(TAG, "S: 0x%04x.%d B: %d%s.", packet->get_sequents(), packet->attempts, this->send_queue_used(), ESP_LOGVV(TAG, "S: 0x%04x.%d B: %d%s.", packet->get_sequents(), packet->attempts, this->send_queue_used(),
(err == ESP_OK) ? "" : " FAILED"); (err == ESP_OK) ? "" : " FAILED");
this->defer([this, packet, err]() { this->on_sent_(packet, err == ESP_OK); }); this->defer([this, packet, err]() { this->on_sent_(std::move(packet), err == ESP_OK); });
return true; return true;
} }
@ -310,13 +310,13 @@ void ESPNowComponent::runner() {
if (!esp_now_is_peer_exist(mac)) { if (!esp_now_is_peer_exist(mac)) {
if (!this->auto_add_peer_) { if (!this->auto_add_peer_) {
this->defer([this, packet]() { this->on_new_peer_(packet); }); this->defer([this, packet]() { this->on_new_peer_(std::move(packet)); });
continue; continue;
} else { } else {
this->add_peer(packet->peer); this->add_peer(packet->peer);
} }
} }
this->defer([this, packet]() { this->on_receive_(packet); }); this->defer([this, packet]() { this->on_receive_(std::move(packet)); });
} }
packet = std::make_shared<ESPNowPacket>(); packet = std::make_shared<ESPNowPacket>();
if (xQueueReceive(this->send_queue_, packet.get(), (TickType_t) 1) == pdTRUE) { if (xQueueReceive(this->send_queue_, packet.get(), (TickType_t) 1) == pdTRUE) {
@ -366,7 +366,7 @@ void ESPNowComponent::on_data_sent(const uint8_t *mac_addr, esp_now_send_status_
ESP_LOGV(TAG, "Confirm sent (0x%04x.%d)", packet->get_sequents(), packet->attempts); ESP_LOGV(TAG, "Confirm sent (0x%04x.%d)", packet->get_sequents(), packet->attempts);
global_esp_now->defer([packet]() { global_esp_now->defer([packet]() {
packet->reload(); packet->reload();
global_esp_now->on_sent_(packet, true); global_esp_now->on_sent_(std::move(packet), true);
auto tmp = std::make_shared<ESPNowPacket>(); auto tmp = std::make_shared<ESPNowPacket>();
xQueueReceive(global_esp_now->send_queue_, tmp.get(), 10 / portTICK_PERIOD_MS); xQueueReceive(global_esp_now->send_queue_, tmp.get(), 10 / portTICK_PERIOD_MS);
@ -376,7 +376,7 @@ void ESPNowComponent::on_data_sent(const uint8_t *mac_addr, esp_now_send_status_
return; return;
} }
global_esp_now->defer([packet]() { global_esp_now->defer([packet]() {
global_esp_now->on_sent_(packet, false); global_esp_now->on_sent_(std::move(packet), false);
auto tmp = std::make_shared<ESPNowPacket>(); auto tmp = std::make_shared<ESPNowPacket>();
xQueueReceive(global_esp_now->send_queue_, tmp.get(), 10 / portTICK_PERIOD_MS); xQueueReceive(global_esp_now->send_queue_, tmp.get(), 10 / portTICK_PERIOD_MS);
xQueueSendToFront(global_esp_now->send_queue_, tmp.get(), 10 / portTICK_PERIOD_MS); xQueueSendToFront(global_esp_now->send_queue_, tmp.get(), 10 / portTICK_PERIOD_MS);

View file

@ -147,9 +147,9 @@ class ESPNowProtocol : public Parented<ESPNowComponent> {
public: public:
ESPNowProtocol(){}; ESPNowProtocol(){};
virtual void on_receive(ESPNowPacketPtr packet){}; virtual void on_receive(const ESPNowPacketPtr &packet){};
virtual void on_sent(ESPNowPacketPtr packet, bool status){}; virtual void on_sent(const ESPNowPacketPtr &packet, bool status){};
virtual void on_new_peer(ESPNowPacketPtr packet){}; virtual void on_new_peer(const ESPNowPacketPtr &packet){};
virtual uint32_t get_protocol_id() = 0; virtual uint32_t get_protocol_id() = 0;
uint8_t get_next_sequents() { uint8_t get_next_sequents() {
@ -181,20 +181,20 @@ class ESPNowDefaultProtocol : public ESPNowProtocol {
public: public:
uint32_t get_protocol_id() override { return ESPNOW_MAIN_PROTOCOL_ID; }; uint32_t get_protocol_id() override { return ESPNOW_MAIN_PROTOCOL_ID; };
void add_on_receive_callback(std::function<void(ESPNowPacketPtr)> &&callback) { void add_on_receive_callback(std::function<void(const ESPNowPacketPtr &)> &&callback) {
this->on_receive_.add(std::move(callback)); this->on_receive_.add(std::move(callback));
} }
void on_receive(ESPNowPacketPtr packet) override { this->on_receive_.call(packet); }; void on_receive(const ESPNowPacketPtr &packet) override { this->on_receive_.call(std::move(packet)); };
void add_on_sent_callback(std::function<void(ESPNowPacketPtr, bool status)> &&callback) { void add_on_sent_callback(std::function<void(const ESPNowPacketPtr &, bool status)> &&callback) {
this->on_sent_.add(std::move(callback)); this->on_sent_.add(std::move(callback));
} }
void on_sent(ESPNowPacketPtr packet, bool status) override { this->on_sent_.call(packet, status); }; void on_sent(const ESPNowPacketPtr &packet, bool status) override { this->on_sent_.call(std::move(packet), status); };
void add_on_peer_callback(std::function<void(ESPNowPacketPtr)> &&callback) { void add_on_peer_callback(std::function<void(const ESPNowPacketPtr &)> &&callback) {
this->on_new_peer_.add(std::move(callback)); this->on_new_peer_.add(std::move(callback));
} }
void on_new_peer(ESPNowPacketPtr packet) override { this->on_new_peer_.call(packet); }; void on_new_peer(const ESPNowPacketPtr &packet) override { this->on_new_peer_.call(std::move(packet)); };
protected: protected:
CallbackManager<void(ESPNowPacketPtr, bool)> on_sent_; CallbackManager<void(ESPNowPacketPtr, bool)> on_sent_;
@ -226,7 +226,7 @@ class ESPNowComponent : public Component {
void runner(); void runner();
bool write(ESPNowPacketPtr packet); bool write(const ESPNowPacketPtr &packet);
void register_protocol(ESPNowProtocol *protocol) { void register_protocol(ESPNowProtocol *protocol) {
protocol->set_parent(this); protocol->set_parent(this);
@ -257,9 +257,9 @@ class ESPNowComponent : public Component {
bool use_sent_check_{true}; bool use_sent_check_{true};
bool lock_{false}; bool lock_{false};
void on_receive_(ESPNowPacketPtr packet); void on_receive_(const ESPNowPacketPtr &packet);
void on_sent_(ESPNowPacketPtr packet, bool status); void on_sent_(const ESPNowPacketPtr &packet, bool status);
void on_new_peer_(ESPNowPacketPtr packet); void on_new_peer_(const ESPNowPacketPtr &packet);
QueueHandle_t receive_queue_{}; QueueHandle_t receive_queue_{};
QueueHandle_t send_queue_{}; QueueHandle_t send_queue_{};
@ -328,21 +328,23 @@ class ESPNowSentTrigger : public Trigger<ESPNowPacketPtr, bool> {
public: public:
explicit ESPNowSentTrigger(ESPNowComponent *parent) { explicit ESPNowSentTrigger(ESPNowComponent *parent) {
parent->get_default_protocol()->add_on_sent_callback( parent->get_default_protocol()->add_on_sent_callback(
[this](ESPNowPacketPtr packet, bool status) { this->trigger(packet, status); }); [this](ESPNowPacketPtr packet, bool status) { this->trigger(std::move(packet), status); });
} }
}; };
class ESPNowReceiveTrigger : public Trigger<ESPNowPacketPtr> { class ESPNowReceiveTrigger : public Trigger<ESPNowPacketPtr> {
public: public:
explicit ESPNowReceiveTrigger(ESPNowComponent *parent) { explicit ESPNowReceiveTrigger(ESPNowComponent *parent) {
parent->get_default_protocol()->add_on_receive_callback([this](ESPNowPacketPtr packet) { this->trigger(packet); }); parent->get_default_protocol()->add_on_receive_callback(
[this](ESPNowPacketPtr packet) { this->trigger(std::move(packet)); });
} }
}; };
class ESPNowNewPeerTrigger : public Trigger<ESPNowPacketPtr> { class ESPNowNewPeerTrigger : public Trigger<ESPNowPacketPtr> {
public: public:
explicit ESPNowNewPeerTrigger(ESPNowComponent *parent) { explicit ESPNowNewPeerTrigger(ESPNowComponent *parent) {
parent->get_default_protocol()->add_on_peer_callback([this](ESPNowPacketPtr packet) { this->trigger(packet); }); parent->get_default_protocol()->add_on_peer_callback(
[this](ESPNowPacketPtr packet) { this->trigger(std::move(packet)); });
} }
}; };