#pragma once #include #include #include "Protocol.h" struct ReceivedPacket { uint8_t mac[6]; ProtocolPacket packet; }; class Radio { public: bool begin(); void end(); bool sendBroadcast(ProtocolPacket packet); bool sendTo(const uint8_t mac[6], ProtocolPacket packet); bool receive(ReceivedPacket &received); void flush(); static void macText(const uint8_t mac[6], char *out, size_t size); private: static void onReceive(const esp_now_recv_info_t *info, const uint8_t *data, int length); bool ensurePeer(const uint8_t mac[6]); void maintainChannel(); static Radio *instance_; QueueHandle_t queue_ = nullptr; bool active_ = false; uint32_t lastChannelCheckMs_ = 0; };