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

NDN Face abstract base class. More...

#include <ndn/face.hpp>

+ Inheritance diagram for ndn::Face:

Public Member Functions

virtual ~Face ()=default
 Destructor.
 
virtual FaceId id () const =0
 Get the Face ID.
 
virtual size_t maxPayloadSize () const =0
 Get the maximum payload size.
 
void setPacketCallback (PacketCallback callback)
 Set the packet receive callback.
 
Lifecycle management
virtual Error start ()=0
 Start the Face.
 
virtual void stop ()=0
 Stop the Face.
 
Packet transmission
virtual Error send (const uint8_t *data, size_t len)=0
 Send a packet.
 
virtual Error sendTo (FaceId destFace, const uint8_t *data, size_t len)=0
 Send a packet to a specific Face.
 
virtual Error broadcast (const uint8_t *data, size_t len)=0
 Broadcast a packet to all nodes.
 

Protected Member Functions

void onPacketReceived (FaceId faceId, const uint8_t *data, size_t len)
 Internal handler for packet reception.
 

Protected Attributes

PacketCallback packetCallback_
 Packet receive callback.
 

Detailed Description

NDN Face abstract base class.

A Face abstracts a network interface. Each transport (ESP-NOW, BLE, etc.) inherits from this class.

// Example using ESP-NOW Face
face.setPacketCallback([](FaceId id, const uint8_t* data, size_t len) {
// Handle received packet
});
face.start();
// Send a packet
face.broadcast(packetData, 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 48 of file face.hpp.

Member Function Documentation

◆ broadcast()

virtual Error ndn::Face::broadcast ( const uint8_t *  data,
size_t  len 
)
pure virtual

Broadcast a packet to all nodes.

Parameters
dataPacket data to send
lenPacket size in bytes
Returns
Error::Success on success, Error::SendFailed on failure

Implemented in ndn::EspNowFace.

◆ id()

virtual FaceId ndn::Face::id ( ) const
pure virtual

Get the Face ID.

Returns
FaceId identifying this Face

Implemented in ndn::EspNowFace.

Referenced by ndn::Forwarder::addFace().

◆ maxPayloadSize()

virtual size_t ndn::Face::maxPayloadSize ( ) const
pure virtual

Get the maximum payload size.

Returns the maximum number of bytes this Face can send at once. ESP-NOW v1: 250 bytes, v2: up to 1470 bytes.

Returns
Maximum payload size (bytes)

Implemented in ndn::EspNowFace.

◆ onPacketReceived()

void ndn::Face::onPacketReceived ( FaceId  faceId,
const uint8_t *  data,
size_t  len 
)
inlineprotected

Internal handler for packet reception.

Derived classes call this method when a packet is received.

Parameters
faceIdID of the Face that received the packet
dataReceived packet data
lenPacket size in bytes

Definition at line 144 of file face.hpp.

References packetCallback_.

◆ send()

virtual Error ndn::Face::send ( const uint8_t *  data,
size_t  len 
)
pure virtual

Send a packet.

Sends a packet to the default destination.

Parameters
dataPacket data to send
lenPacket size in bytes
Returns
Error::Success on success, Error::SendFailed on failure

Implemented in ndn::EspNowFace.

◆ sendTo()

virtual Error ndn::Face::sendTo ( FaceId  destFace,
const uint8_t *  data,
size_t  len 
)
pure virtual

Send a packet to a specific Face.

Parameters
destFaceDestination Face ID
dataPacket data to send
lenPacket size in bytes
Returns
Error::Success on success, Error::SendFailed on failure

Implemented in ndn::EspNowFace.

◆ setPacketCallback()

void ndn::Face::setPacketCallback ( PacketCallback  callback)
inline

Set the packet receive callback.

Parameters
callbackCallback function invoked on packet reception

Definition at line 132 of file face.hpp.

References packetCallback_.

Referenced by ndn::Forwarder::addFace().

◆ start()

virtual Error ndn::Face::start ( )
pure virtual

Start the Face.

Initializes the transport and begins sending/receiving packets.

Returns
Error::Success on success, error code on failure

Implemented in ndn::EspNowFace.

◆ stop()

virtual void ndn::Face::stop ( )
pure virtual

Stop the Face.

Stops sending/receiving packets and releases resources.

Implemented in ndn::EspNowFace.

Member Data Documentation

◆ packetCallback_

PacketCallback ndn::Face::packetCallback_
protected

Packet receive callback.

Definition at line 150 of file face.hpp.

Referenced by onPacketReceived(), and setPacketCallback().


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