Files
ESP32-S3-Touch-LCD-5B/src/modules/espnow_link.h
T

49 lines
1.6 KiB
C++

/*
* ESP-NOW Link Module (Controller A side)
*
* Second transport for the A -> B link: every frame the UART manager builds
* is also broadcast over ESP-NOW, so B keeps receiving if the wire is lost.
* B dedupes on packet_id, so both paths may be live at once.
*
* Since 2026-09-27 the radio also listens: B unicasts STATUS frames back and
* A unicasts SECURE frames to B (LinkPeer). Frames received are handed to the
* handler set with setReceiveHandler(); sendTo() unicasts to one MAC.
*
* Radio policy: the Wi-Fi radio stays in STA mode permanently (the WiFi
* manager's "off" only stops scanning). A transmits on ESPNOW_CHANNEL unless
* associated to an access point, in which case the AP's channel is used and
* B hops until it finds us.
*/
#pragma once
#include <Arduino.h>
namespace EspNowLink {
/**
* Bring the radio up in STA mode on ESPNOW_CHANNEL and register the
* broadcast peer. Safe to call after WiFiManager::init().
* @return true if ESP-NOW is ready
*/
bool init();
/**
* Broadcast one complete frame (start..end bytes).
* @return true if queued for transmission
*/
bool send(const uint8_t* frame, size_t len);
bool isReady();
uint32_t sentCount();
uint32_t failCount();
/** Frames received from any sender (runs in the Wi-Fi task - copy and return). */
typedef void (*receive_handler_t)(const uint8_t mac[6], const uint8_t* frame, size_t len);
void setReceiveHandler(receive_handler_t handler);
/** Unicast one complete frame to a MAC (peer added on first use, unencrypted). */
bool sendTo(const uint8_t mac[6], const uint8_t* frame, size_t len);
} // namespace EspNowLink