Files
OptoTest/OpticalChannelTester/Radio.h
2026-08-05 16:49:05 +03:00

25 lines
661 B
C++

#pragma once
#include <Arduino.h>
#include <esp_now.h>
#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]);
static Radio *instance_;
QueueHandle_t queue_ = nullptr;
bool active_ = false;
};