ndn-embeds 0.1.0
Lightweight NDN protocol stack for embedded systems
Loading...
Searching...
No Matches
ndn::EspNowFace Class Reference

ESP-NOW Face. More...

#include </home/runner/work/ndn-embeds/ndn-embeds/adapters/espnow_face.hpp>

+ Inheritance diagram for ndn::EspNowFace:

Public Member Functions

 EspNowFace (FaceId faceId=2)
 Constructor.
 
 ~EspNowFace () override
 Destructor.
 
FaceId id () const override
 Get Face ID.
 
Error start () override
 Initialize and start ESP-NOW.
 
void stop () override
 Stop ESP-NOW.
 
Error send (const uint8_t *data, size_t len) override
 Default send (broadcast)
 
Error sendTo (FaceId destFace, const uint8_t *data, size_t len) override
 Unicast send to a specific Face.
 
Error broadcast (const uint8_t *data, size_t len) override
 Broadcast send.
 
size_t maxPayloadSize () const override
 Get maximum payload size.
 
FaceId addPeer (const uint8_t *mac)
 Add a peer.
 
void removePeer (FaceId faceId)
 Remove a peer.
 
bool getMacAddress (FaceId faceId, uint8_t *mac) const
 Get MAC address from FaceId.
 
size_t peerCount () const
 Get number of registered peers.
 
void processReceiveQueue ()
 Process receive events.
 
void setMacFilter (const uint8_t *mac)
 Set MAC address filter (single MAC)
 
void setMacFilters (const uint8_t macs[][6], size_t count)
 Set multiple MAC address filters.
 
void clearMacFilters ()
 Clear MAC address filters.
 
bool hasMacFilter () const
 Check if MAC address filter is enabled.
 
- Public Member Functions inherited from ndn::Face
virtual ~Face ()=default
 Destructor.
 
void setPacketCallback (PacketCallback callback)
 Set the packet receive callback.
 

Static Public Member Functions

static EspNowFaceinstance ()
 Get the static instance (for callbacks)
 

Static Public Attributes

static constexpr size_t MAX_MAC_FILTERS = 4
 Maximum number of filter MACs.
 

Additional Inherited Members

- Protected Member Functions inherited from ndn::Face
void onPacketReceived (FaceId faceId, const uint8_t *data, size_t len)
 Internal handler for packet reception.
 
- Protected Attributes inherited from ndn::Face
PacketCallback packetCallback_
 Packet receive callback.
 

Detailed Description

ESP-NOW Face.

Face implementation that sends/receives NDN packets using ESP-NOW protocol.

Features:

  • Broadcast transmission (broadcast)
  • Unicast transmission (sendTo)
  • Automatic peer discovery and management
  • Maximum 250-byte payload (ESP-NOW v1.0 limit)
face.setPacketCallback([](FaceId id, const uint8_t* data, size_t len) {
// Handle received packet
});
face.start();
face.broadcast(packet, packetLen);
ESP-NOW Face.
Error start() override
Initialize and start ESP-NOW.
Error broadcast(const uint8_t *data, size_t len) override
Broadcast send.
void setPacketCallback(PacketCallback callback)
Set the packet receive callback.
Definition face.hpp:132
uint16_t FaceId
Face identifier.
Definition common.hpp:96

Definition at line 72 of file espnow_face.hpp.

Constructor & Destructor Documentation

◆ EspNowFace()

ndn::EspNowFace::EspNowFace ( FaceId  faceId = 2)
explicit

Constructor.

Parameters
faceIdID of this Face (default: 2)

Definition at line 22 of file espnow_face.cpp.

◆ ~EspNowFace()

ndn::EspNowFace::~EspNowFace ( )
override

Destructor.

Definition at line 34 of file espnow_face.cpp.

References stop().

Member Function Documentation

◆ addPeer()

FaceId ndn::EspNowFace::addPeer ( const uint8_t *  mac)

Add a peer.

Parameters
macMAC address (6 bytes)
Returns
Added FaceId, FACE_ID_INVALID on failure

Definition at line 166 of file espnow_face.cpp.

References ndn::currentTimeMs(), ndn::FACE_ID_INVALID, ndn::PeerInfo::faceId, ndn::PeerInfo::lastSeen, and ndn::macToFaceId().

◆ broadcast()

Error ndn::EspNowFace::broadcast ( const uint8_t *  data,
size_t  len 
)
overridevirtual

Broadcast send.

Parameters
dataData to send
lenData length
Returns
Error::Success: success, Error::SendFailed: send failed

Implements ndn::Face.

Definition at line 148 of file espnow_face.cpp.

References ndn::BROADCAST_MAC, and ndn::ESPNOW_MAX_PAYLOAD.

Referenced by send().

◆ clearMacFilters()

void ndn::EspNowFace::clearMacFilters ( )

Clear MAC address filters.

Definition at line 325 of file espnow_face.cpp.

Referenced by setMacFilter(), and setMacFilters().

◆ getMacAddress()

bool ndn::EspNowFace::getMacAddress ( FaceId  faceId,
uint8_t *  mac 
) const

Get MAC address from FaceId.

Parameters
faceIdFace ID
mac[out] MAC address output (6 bytes)
Returns
true: success, false: peer not registered

Definition at line 212 of file espnow_face.cpp.

References ndn::PeerInfo::mac.

◆ hasMacFilter()

bool ndn::EspNowFace::hasMacFilter ( ) const
inline

Check if MAC address filter is enabled.

Returns
true: filter enabled, false: filter disabled

Definition at line 199 of file espnow_face.hpp.

◆ id()

FaceId ndn::EspNowFace::id ( ) const
inlineoverridevirtual

Get Face ID.

Returns
Face ID

Implements ndn::Face.

Definition at line 89 of file espnow_face.hpp.

◆ instance()

static EspNowFace * ndn::EspNowFace::instance ( )
inlinestatic

Get the static instance (for callbacks)

Definition at line 207 of file espnow_face.hpp.

◆ maxPayloadSize()

size_t ndn::EspNowFace::maxPayloadSize ( ) const
inlineoverridevirtual

Get maximum payload size.

Returns
Maximum payload size (250 bytes)

Implements ndn::Face.

Definition at line 135 of file espnow_face.hpp.

References ndn::ESPNOW_MAX_PAYLOAD.

◆ peerCount()

size_t ndn::EspNowFace::peerCount ( ) const

Get number of registered peers.

Returns
Number of peers

Definition at line 221 of file espnow_face.cpp.

◆ processReceiveQueue()

void ndn::EspNowFace::processReceiveQueue ( )

Process receive events.

Dequeues packets from the receive queue and invokes callbacks. Must be called periodically from the main loop.

Definition at line 231 of file espnow_face.cpp.

◆ removePeer()

void ndn::EspNowFace::removePeer ( FaceId  faceId)

Remove a peer.

Parameters
faceIdFace ID to remove

Definition at line 203 of file espnow_face.cpp.

References ndn::PeerInfo::inUse, and ndn::PeerInfo::mac.

◆ send()

Error ndn::EspNowFace::send ( const uint8_t *  data,
size_t  len 
)
overridevirtual

Default send (broadcast)

Parameters
dataData to send
lenData length
Returns
Error::Success: success, Error::SendFailed: send failed, Error::BufferTooSmall: data too large

Implements ndn::Face.

Definition at line 103 of file espnow_face.cpp.

References broadcast().

◆ sendTo()

Error ndn::EspNowFace::sendTo ( FaceId  destFace,
const uint8_t *  data,
size_t  len 
)
overridevirtual

Unicast send to a specific Face.

Parameters
destFaceDestination Face ID
dataData to send
lenData length
Returns
Error::Success: success, Error::NotFound: peer not registered, Error::SendFailed: send failed

Implements ndn::Face.

Definition at line 108 of file espnow_face.cpp.

References ndn::ESPNOW_MAX_PAYLOAD, and ndn::PeerInfo::mac.

◆ setMacFilter()

void ndn::EspNowFace::setMacFilter ( const uint8_t *  mac)

Set MAC address filter (single MAC)

Parameters
macAllowed MAC address (6 bytes), nullptr to disable filter

When set, only packets from the specified MAC address are received.

Definition at line 297 of file espnow_face.cpp.

References clearMacFilters(), and setMacFilters().

◆ setMacFilters()

void ndn::EspNowFace::setMacFilters ( const uint8_t  macs[][6],
size_t  count 
)

Set multiple MAC address filters.

Parameters
macsArray of allowed MAC addresses (6 bytes each)
countNumber of MAC addresses (max MAX_MAC_FILTERS)

When set, only packets from the specified MAC addresses are received. Used for topology control in multi-hop experiments.

Definition at line 305 of file espnow_face.cpp.

References clearMacFilters(), and MAX_MAC_FILTERS.

Referenced by setMacFilter().

◆ start()

Error ndn::EspNowFace::start ( )
overridevirtual

Initialize and start ESP-NOW.

Returns
Error::Success: success, Error::SendFailed: initialization failed

Wi-Fi must be initialized beforehand.

Implements ndn::Face.

Definition at line 38 of file espnow_face.cpp.

References ndn::BROADCAST_MAC.

◆ stop()

void ndn::EspNowFace::stop ( )
overridevirtual

Stop ESP-NOW.

Implements ndn::Face.

Definition at line 88 of file espnow_face.cpp.

Referenced by ~EspNowFace().

Member Data Documentation

◆ MAX_MAC_FILTERS

constexpr size_t ndn::EspNowFace::MAX_MAC_FILTERS = 4
staticconstexpr

Maximum number of filter MACs.

Definition at line 202 of file espnow_face.hpp.

Referenced by setMacFilters().


The documentation for this class was generated from the following files: