AlteriomPainlessMesh v2.1.1
Easy ESP32/ESP8266 mesh networking with Alteriom IoT extensions
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
painlessmesh::ack::AckTracker Class Reference

#include <ack.hpp>

Public Member Functions

void seed (uint32_t value)
 
uint32_t nextMessageId ()
 
bool full () const
 
bool track (uint32_t msgId, const std::list< uint32_t > &destinations, deliveryCallback_t callback, uint32_t timeoutMs, uint32_t now)
 
bool handleAck (uint32_t msgId, uint32_t fromNode, uint32_t now)
 
bool collectAck (uint32_t msgId, uint32_t fromNode, uint32_t now, std::list< DeliveryResult > &results)
 
size_t expire (uint32_t now)
 
size_t collectExpired (uint32_t now, std::list< DeliveryResult > &results)
 
size_t pending () const
 
void clear ()
 

Protected Attributes

std::map< uint32_t, PendingAck > entries
 
uint32_t counter = 0
 

Detailed Description

AckTracker - tracks outgoing messages awaiting acknowledgment

Time is passed in explicitly (millis() on device) so the tracker stays platform independent and unit testable. All time comparisons are uint32 wraparound safe.

Member Function Documentation

◆ clear()

void painlessmesh::ack::AckTracker::clear ( )
inline

Drop all pending messages without firing callbacks

◆ collectAck()

bool painlessmesh::ack::AckTracker::collectAck ( uint32_t  msgId,
uint32_t  fromNode,
uint32_t  now,
std::list< DeliveryResult > &  results 
)
inline

Match an acknowledgment without invoking user code.

Mesh receive dispatch uses this form so callbacks can be scheduled after the connection read task has unwound. Tracker state is still updated synchronously and exactly once.

◆ collectExpired()

size_t painlessmesh::ack::AckTracker::collectExpired ( uint32_t  now,
std::list< DeliveryResult > &  results 
)
inline

Collect timeout results without invoking user callbacks

Mesh uses this form to defer callbacks until receive dispatch has unwound. Direct AckTracker users retain the synchronous expire() API.

◆ expire()

size_t painlessmesh::ack::AckTracker::expire ( uint32_t  now)
inline

Fire timeout callbacks for expired messages

Parameters
nowCurrent time (millis())
Returns
Number of messages still awaiting acknowledgment

◆ full()

bool painlessmesh::ack::AckTracker::full ( ) const
inline

Whether the tracker is at its pending-message limit

◆ handleAck()

bool painlessmesh::ack::AckTracker::handleAck ( uint32_t  msgId,
uint32_t  fromNode,
uint32_t  now 
)
inline

Process an incoming acknowledgment

Fires the callback with delivered = true and the measured latency.

Returns
true when the ack matched a pending message/destination

◆ nextMessageId()

uint32_t painlessmesh::ack::AckTracker::nextMessageId ( )
inline

Generate the next unique, non-zero message id

◆ pending()

size_t painlessmesh::ack::AckTracker::pending ( ) const
inline

Number of messages awaiting acknowledgment

◆ seed()

void painlessmesh::ack::AckTracker::seed ( uint32_t  value)
inline

Seed the message-id counter

Called once at mesh init with a random value so ids do not restart at 1 after a reboot — a delayed ACK for a pre-reboot message could otherwise match a fresh message's id and report a false delivered = true.

◆ track()

bool painlessmesh::ack::AckTracker::track ( uint32_t  msgId,
const std::list< uint32_t > &  destinations,
deliveryCallback_t  callback,
uint32_t  timeoutMs,
uint32_t  now 
)
inline

Start tracking a message

Parameters
msgIdUnique id from nextMessageId()
destinationsNodes expected to acknowledge
callbackFired once per destination (ack or timeout)
timeoutMsTime to wait for acknowledgments
nowCurrent time (millis())
Returns
false when the callback/destinations are empty or the tracker is full (PAINLESSMESH_MAX_PENDING_ACKS)

Member Data Documentation

◆ counter

uint32_t painlessmesh::ack::AckTracker::counter = 0
protected

◆ entries

std::map<uint32_t, PendingAck> painlessmesh::ack::AckTracker::entries
protected

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