Classes | Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
uavcan::NodeInfoRetriever Class Reference

#include <node_info_retriever.hpp>

Inheritance diagram for uavcan::NodeInfoRetriever:
Inheritance graph
[legend]

Classes

struct  Entry
 
struct  GenericHandlerCaller
 
struct  NodeInfoRetrievedHandlerCaller
 

Public Types

enum  { MaxNumRequestAttempts = 254 }
 
enum  { UnlimitedRequestAttempts = 0 }
 

Public Member Functions

int addListener (INodeInfoListener *listener)
 
unsigned getNumListeners () const
 
uint8_t getNumPendingRequests () const
 
uint8_t getNumRequestAttempts () const
 
MonotonicDuration getRequestInterval () const
 
void invalidateAll ()
 
bool isRetrievingInProgress () const
 
 NodeInfoRetriever (INode &node)
 
void removeListener (INodeInfoListener *listener)
 
void setNumRequestAttempts (const uint8_t num)
 
void setRequestInterval (const MonotonicDuration interval)
 
int start (const TransferPriority priority=TransferPriority::OneHigherThanLowest)
 
- Public Member Functions inherited from uavcan::NodeStatusMonitor
NodeID findNodeWithWorstHealth () const
 
template<typename Operator >
void forEachNode (Operator op) const
 
void forgetAllNodes ()
 
void forgetNode (NodeID node_id)
 
NodeStatus getNodeStatus (NodeID node_id) const
 
bool isNodeKnown (NodeID node_id) const
 
 NodeStatusMonitor (INode &node)
 
int start ()
 
virtual ~NodeStatusMonitor ()
 

Private Types

enum  { DefaultNumRequestAttempts = 16 }
 
enum  { DefaultTimerIntervalMSec = 40 }
 
typedef MethodBinder< NodeInfoRetriever *, void(NodeInfoRetriever::*)(const ServiceCallResult< protocol::GetNodeInfo > &)> GetNodeInfoResponseCallback
 

Private Member Functions

EntrygetEntry (NodeID node_id)
 
const EntrygetEntry (NodeID node_id) const
 
void handleGetNodeInfoResponse (const ServiceCallResult< protocol::GetNodeInfo > &result)
 
virtual void handleNodeStatusChange (const NodeStatusChangeEvent &event)
 
virtual void handleNodeStatusMessage (const ReceivedDataStructure< protocol::NodeStatus > &msg)
 
virtual void handleTimerEvent (const TimerEvent &)
 
NodeID pickNextNodeToQuery (bool &out_at_least_one_request_needed) const
 
void startTimerIfNotRunning ()
 
- Private Member Functions inherited from uavcan::TimerBase
MonotonicTime getDeadline () const
 
MonotonicDuration getPeriod () const
 
SchedulergetScheduler () const
 
bool isRunning () const
 
void startOneShotWithDeadline (MonotonicTime deadline)
 
void startOneShotWithDelay (MonotonicDuration delay)
 
void startPeriodic (MonotonicDuration period)
 
void stop ()
 
 TimerBase (INode &node)
 

Private Attributes

Entry entries_ [NodeID::Max]
 
ServiceClient< protocol::GetNodeInfo, GetNodeInfoResponseCallbackget_node_info_client_
 
uint8_t last_picked_node_
 
Multiset< INodeInfoListener * > listeners_
 
uint8_t num_attempts_
 
MonotonicDuration request_interval_
 

Additional Inherited Members

Detailed Description

This class automatically retrieves a response to GetNodeInfo once a node appears online or restarts. It does a number of attempts in case if there's a communication failure before assuming that the node does not implement the GetNodeInfo service. All parameters are pre-configured with sensible default values that should fit virtually any use case, but they can be overriden if needed - refer to the setter methods below for details.

Defaults are pre-configured so that the class is able to query 123 nodes (node ID 1..125, where 1 is our local node and 1 is one node that implements GetNodeInfo service, hence 123) of which none implements GetNodeInfo service in under 5 seconds. The 5 second limitation is imposed by UAVCAN-compatible bootloaders, which are unlikely to wait for more than that before continuing to boot. In case if this default value is not appropriate for the end application, the request interval can be overriden via setRequestInterval().

Following the above explained requirements, the default request interval is defined as follows: request interval [ms] = floor(5000 [ms] bootloader timeout / 123 nodes) Which yields 40 ms.

Given default service timeout 1000 ms and the defined above request frequency 40 ms, the maximum number of concurrent requests will be: max concurrent requests = ceil(1000 [ms] timeout / 40 [ms] request interval) Which yields 25 requests.

Keep the above equations in mind when changing the default request interval.

Obviously, if all calls are completing in under (request interval), the number of concurrent requests will never exceed one. This is actually the most likely scenario.

Note that all nodes are queried in a round-robin fashion, regardless of their uptime, number of requests made, etc.

Events from this class can be routed to many listeners, INodeInfoListener.

Definition at line 91 of file node_info_retriever.hpp.

Member Typedef Documentation

◆ GetNodeInfoResponseCallback

typedef MethodBinder<NodeInfoRetriever*, void (NodeInfoRetriever::*)(const ServiceCallResult<protocol::GetNodeInfo>&)> uavcan::NodeInfoRetriever::GetNodeInfoResponseCallback
private

Definition at line 101 of file node_info_retriever.hpp.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
MaxNumRequestAttempts 

Definition at line 95 of file node_info_retriever.hpp.

◆ anonymous enum

anonymous enum
Enumerator
UnlimitedRequestAttempts 

Definition at line 96 of file node_info_retriever.hpp.

◆ anonymous enum

anonymous enum
private
Enumerator
DefaultNumRequestAttempts 

Definition at line 159 of file node_info_retriever.hpp.

◆ anonymous enum

anonymous enum
private
Enumerator
DefaultTimerIntervalMSec 

Definition at line 160 of file node_info_retriever.hpp.

Constructor & Destructor Documentation

◆ NodeInfoRetriever()

uavcan::NodeInfoRetriever::NodeInfoRetriever ( INode node)
inline

Definition at line 332 of file node_info_retriever.hpp.

Member Function Documentation

◆ addListener()

int uavcan::NodeInfoRetriever::addListener ( INodeInfoListener listener)
inline

Adds one listener. Does nothing if such listener already exists. May return -ErrMemory if there's no space to add the listener.

Definition at line 386 of file node_info_retriever.hpp.

◆ getEntry() [1/2]

Entry& uavcan::NodeInfoRetriever::getEntry ( NodeID  node_id)
inlineprivate

Definition at line 181 of file node_info_retriever.hpp.

◆ getEntry() [2/2]

const Entry& uavcan::NodeInfoRetriever::getEntry ( NodeID  node_id) const
inlineprivate

Definition at line 180 of file node_info_retriever.hpp.

◆ getNumListeners()

unsigned uavcan::NodeInfoRetriever::getNumListeners ( ) const
inline

Definition at line 415 of file node_info_retriever.hpp.

◆ getNumPendingRequests()

uint8_t uavcan::NodeInfoRetriever::getNumPendingRequests ( ) const
inline

Definition at line 454 of file node_info_retriever.hpp.

◆ getNumRequestAttempts()

uint8_t uavcan::NodeInfoRetriever::getNumRequestAttempts ( ) const
inline

Number of attempts to retrieve GetNodeInfo response before giving up on the assumption that the service is not implemented. Zero is a special value that can be used to set unlimited number of attempts, UnlimitedRequestAttempts.

Definition at line 422 of file node_info_retriever.hpp.

◆ getRequestInterval()

MonotonicDuration uavcan::NodeInfoRetriever::getRequestInterval ( ) const
inline

Request interval also implicitly defines the maximum number of concurrent requests. Read the class documentation for details.

Definition at line 432 of file node_info_retriever.hpp.

◆ handleGetNodeInfoResponse()

void uavcan::NodeInfoRetriever::handleGetNodeInfoResponse ( const ServiceCallResult< protocol::GetNodeInfo > &  result)
inlineprivate

Definition at line 301 of file node_info_retriever.hpp.

◆ handleNodeStatusChange()

virtual void uavcan::NodeInfoRetriever::handleNodeStatusChange ( const NodeStatusChangeEvent event)
inlineprivatevirtual

Called when a node becomes online, changes status or goes offline. Refer to uavcan.protocol.NodeStatus for the offline timeout value. Overriding is not required.

Reimplemented from uavcan::NodeStatusMonitor.

Definition at line 256 of file node_info_retriever.hpp.

◆ handleNodeStatusMessage()

virtual void uavcan::NodeInfoRetriever::handleNodeStatusMessage ( const ReceivedDataStructure< protocol::NodeStatus > &  msg)
inlineprivatevirtual

Called for every received message uavcan.protocol.NodeStatus after handleNodeStatusChange(), even if the status code did not change. Overriding is not required.

Reimplemented from uavcan::NodeStatusMonitor.

Definition at line 283 of file node_info_retriever.hpp.

◆ handleTimerEvent()

virtual void uavcan::NodeInfoRetriever::handleTimerEvent ( const TimerEvent event)
inlineprivatevirtual

Implement this method in your class to receive callbacks.

Implements uavcan::TimerBase.

Definition at line 231 of file node_info_retriever.hpp.

◆ invalidateAll()

void uavcan::NodeInfoRetriever::invalidateAll ( )
inline

This method forces the class to re-request uavcan.protocol.GetNodeInfo from all nodes as if they have just appeared in the network.

Definition at line 370 of file node_info_retriever.hpp.

◆ isRetrievingInProgress()

bool uavcan::NodeInfoRetriever::isRetrievingInProgress ( ) const
inline

These methods are needed mostly for testing.

Definition at line 452 of file node_info_retriever.hpp.

◆ pickNextNodeToQuery()

NodeID uavcan::NodeInfoRetriever::pickNextNodeToQuery ( bool &  out_at_least_one_request_needed) const
inlineprivate

Definition at line 199 of file node_info_retriever.hpp.

◆ removeListener()

void uavcan::NodeInfoRetriever::removeListener ( INodeInfoListener listener)
inline

Removes the listener. If the listener was not registered, nothing will be done.

Definition at line 403 of file node_info_retriever.hpp.

◆ setNumRequestAttempts()

void uavcan::NodeInfoRetriever::setNumRequestAttempts ( const uint8_t  num)
inline

Definition at line 423 of file node_info_retriever.hpp.

◆ setRequestInterval()

void uavcan::NodeInfoRetriever::setRequestInterval ( const MonotonicDuration  interval)
inline

Definition at line 433 of file node_info_retriever.hpp.

◆ start()

int uavcan::NodeInfoRetriever::start ( const TransferPriority  priority = TransferPriority::OneHigherThanLowest)
inline

Starts the retriever. Destroy the object to stop it. Returns negative error code.

Definition at line 347 of file node_info_retriever.hpp.

◆ startTimerIfNotRunning()

void uavcan::NodeInfoRetriever::startTimerIfNotRunning ( )
inlineprivate

Definition at line 190 of file node_info_retriever.hpp.

Member Data Documentation

◆ entries_

Entry uavcan::NodeInfoRetriever::entries_[NodeID::Max]
private

Definition at line 165 of file node_info_retriever.hpp.

◆ get_node_info_client_

ServiceClient<protocol::GetNodeInfo, GetNodeInfoResponseCallback> uavcan::NodeInfoRetriever::get_node_info_client_
private

Definition at line 169 of file node_info_retriever.hpp.

◆ last_picked_node_

uint8_t uavcan::NodeInfoRetriever::last_picked_node_
mutableprivate

Definition at line 173 of file node_info_retriever.hpp.

◆ listeners_

Multiset<INodeInfoListener*> uavcan::NodeInfoRetriever::listeners_
private

Definition at line 167 of file node_info_retriever.hpp.

◆ num_attempts_

uint8_t uavcan::NodeInfoRetriever::num_attempts_
private

Definition at line 175 of file node_info_retriever.hpp.

◆ request_interval_

MonotonicDuration uavcan::NodeInfoRetriever::request_interval_
private

Definition at line 171 of file node_info_retriever.hpp.


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


uavcan_communicator
Author(s):
autogenerated on Fri Dec 13 2024 03:10:05