Files
ESP32-S3-LCD-1.3/include/modules/espnow_receiver.h
T

47 lines
1.3 KiB
C++

/**
* ESP-NOW Receiver Module (Inst. Cluster)
*
* Wireless leg of the A -> B link. Frames are byte-identical to the UART ones
* and are handed to UARTReceiver::processFrame(), which dedupes on packet_id.
*
* Channel discovery: A transmits on ESPNOW_CHANNEL unless it is associated to
* an access point. B listens on ESPNOW_CHANNEL first and, while it hears
* nothing, hops through channels 1..13 until frames arrive, then locks.
*
* Frames other than DATA/CONFIG (the SECURE envelope from A) are routed to
* LinkPeer, and the sender MAC of A's frames is remembered so LinkPeer can
* unicast STATUS frames back (sendTo).
*/
#ifndef ESPNOW_RECEIVER_H
#define ESPNOW_RECEIVER_H
#include <Arduino.h>
namespace EspNowReceiver {
/**
* Bring the radio up in STA mode and register the receive callback.
* @return true if ESP-NOW is listening
*/
bool init();
/**
* Channel-hopping housekeeping. Call from loop().
*/
void tick();
bool isReady();
uint8_t currentChannel();
uint32_t framesReceived();
/** A's MAC as seen on its last DATA/CONFIG frame. False until A was heard by radio. */
bool peerMac(uint8_t out[6]);
/** 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 EspNowReceiver
#endif // ESPNOW_RECEIVER_H