#include <node_info_retriever.hpp>
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) |
![]() | |
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 | |
Entry & | getEntry (NodeID node_id) |
const Entry & | getEntry (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 () |
![]() | |
MonotonicTime | getDeadline () const |
MonotonicDuration | getPeriod () const |
Scheduler & | getScheduler () 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, GetNodeInfoResponseCallback > | get_node_info_client_ |
uint8_t | last_picked_node_ |
Multiset< INodeInfoListener * > | listeners_ |
uint8_t | num_attempts_ |
MonotonicDuration | request_interval_ |
Additional Inherited Members |
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.
|
private |
Definition at line 101 of file node_info_retriever.hpp.
anonymous enum |
Enumerator | |
---|---|
MaxNumRequestAttempts |
Definition at line 95 of file node_info_retriever.hpp.
anonymous enum |
Enumerator | |
---|---|
UnlimitedRequestAttempts |
Definition at line 96 of file node_info_retriever.hpp.
|
private |
Enumerator | |
---|---|
DefaultNumRequestAttempts |
Definition at line 159 of file node_info_retriever.hpp.
|
private |
Enumerator | |
---|---|
DefaultTimerIntervalMSec |
Definition at line 160 of file node_info_retriever.hpp.
|
inline |
Definition at line 332 of file node_info_retriever.hpp.
|
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.
Definition at line 181 of file node_info_retriever.hpp.
Definition at line 180 of file node_info_retriever.hpp.
|
inline |
Definition at line 415 of file node_info_retriever.hpp.
|
inline |
Definition at line 454 of file node_info_retriever.hpp.
|
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.
|
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.
|
inlineprivate |
Definition at line 301 of file node_info_retriever.hpp.
|
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.
|
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.
|
inlineprivatevirtual |
Implement this method in your class to receive callbacks.
Implements uavcan::TimerBase.
Definition at line 231 of file node_info_retriever.hpp.
|
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.
|
inline |
These methods are needed mostly for testing.
Definition at line 452 of file node_info_retriever.hpp.
|
inlineprivate |
Definition at line 199 of file node_info_retriever.hpp.
|
inline |
Removes the listener. If the listener was not registered, nothing will be done.
Definition at line 403 of file node_info_retriever.hpp.
|
inline |
Definition at line 423 of file node_info_retriever.hpp.
|
inline |
Definition at line 433 of file node_info_retriever.hpp.
|
inline |
Starts the retriever. Destroy the object to stop it. Returns negative error code.
Definition at line 347 of file node_info_retriever.hpp.
|
inlineprivate |
Definition at line 190 of file node_info_retriever.hpp.
|
private |
Definition at line 165 of file node_info_retriever.hpp.
|
private |
Definition at line 169 of file node_info_retriever.hpp.
|
mutableprivate |
Definition at line 173 of file node_info_retriever.hpp.
|
private |
Definition at line 167 of file node_info_retriever.hpp.
|
private |
Definition at line 175 of file node_info_retriever.hpp.
|
private |
Definition at line 171 of file node_info_retriever.hpp.