abstract_server.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Pavel Kirienko <pavel.kirienko@gmail.com>
3  */
4 
5 #ifndef UAVCAN_PROTOCOL_DYNAMIC_NODE_ID_SERVER_SERVER_HPP_INCLUDED
6 #define UAVCAN_PROTOCOL_DYNAMIC_NODE_ID_SERVER_SERVER_HPP_INCLUDED
7 
9 #include <uavcan/debug.hpp>
13 
14 namespace uavcan
15 {
16 namespace dynamic_node_id_server
17 {
18 
20  , protected INodeDiscoveryHandler
21 {
24 
25 protected:
30 
32  IEventTracer& tracer) :
33  node_(node),
34  tracer_(tracer),
35  allocation_request_manager_(node, tracer, *this),
36  node_discoverer_(node, tracer, *this)
37  { }
38 
39  const UniqueID& getOwnUniqueID() const { return own_unique_id_; }
40 
41  int init(const UniqueID& own_unique_id, const TransferPriority priority)
42  {
43  int res = 0;
44 
45  own_unique_id_ = own_unique_id;
46 
47  res = allocation_request_manager_.init(priority);
48  if (res < 0)
49  {
50  return res;
51  }
52 
53  res = node_discoverer_.init(priority);
54  if (res < 0)
55  {
56  return res;
57  }
58 
60 
61  return 0;
62  }
63 
64 public:
69  const MonotonicDuration& allocation_activity_timeout =
70  MonotonicDuration::fromMSec(Allocation::MAX_REQUEST_PERIOD_MS * 2),
71  const MonotonicDuration& min_uptime = MonotonicDuration::fromMSec(6000)) const
72  {
74 
75  /*
76  * If uptime is not large enough, the allocator may be unaware about some nodes yet.
77  */
78  const MonotonicDuration uptime = ts - started_at_;
79  if (uptime < max(allocation_activity_timeout, min_uptime))
80  {
81  return false;
82  }
83 
84  /*
85  * If there are any undiscovered nodes, assume that allocation is still happening.
86  */
88  {
89  return false;
90  }
91 
92  /*
93  * Lastly, check if there wasn't any allocation messages detected on the bus in the specified amount of time.
94  */
95  const MonotonicDuration since_allocation_activity =
97  if (since_allocation_activity < allocation_activity_timeout)
98  {
99  return false;
100  }
101 
102  return true;
103  }
104 
109 };
110 
111 }
112 }
113 
114 #endif // Include guard
uavcan::dynamic_node_id_server::NodeDiscoverer::init
int init(const TransferPriority priority)
Definition: node_discoverer.hpp:312
uavcan::INode::getMonotonicTime
MonotonicTime getMonotonicTime() const
Definition: abstract_node.hpp:32
uavcan::dynamic_node_id_server::AbstractServer::node_discoverer_
NodeDiscoverer node_discoverer_
Definition: abstract_server.hpp:29
debug.hpp
uavcan::dynamic_node_id_server::AbstractServer::allocation_request_manager_
AllocationRequestManager allocation_request_manager_
Definition: abstract_server.hpp:28
uavcan::dynamic_node_id_server::AbstractServer::AbstractServer
AbstractServer(INode &node, IEventTracer &tracer)
Definition: abstract_server.hpp:31
uavcan::DurationBase< MonotonicDuration >::fromMSec
static MonotonicDuration fromMSec(int64_t ms)
Definition: time.hpp:41
uavcan::dynamic_node_id_server::AbstractServer::started_at_
MonotonicTime started_at_
Definition: abstract_server.hpp:23
event.hpp
uavcan::dynamic_node_id_server::AllocationRequestManager::init
int init(const TransferPriority priority)
Definition: allocation_request_manager.hpp:242
uavcan::dynamic_node_id_server::IAllocationRequestHandler
Definition: allocation_request_manager.hpp:25
uavcan::dynamic_node_id_server::AbstractServer::tracer_
IEventTracer & tracer_
Definition: abstract_server.hpp:27
uavcan::dynamic_node_id_server::AbstractServer::own_unique_id_
UniqueID own_unique_id_
Definition: abstract_server.hpp:22
uavcan::MonotonicDuration
Definition: time.hpp:182
uavcan::dynamic_node_id_server::NodeDiscoverer
Definition: node_discoverer.hpp:68
uavcan::dynamic_node_id_server::AbstractServer::getOwnUniqueID
const UniqueID & getOwnUniqueID() const
Definition: abstract_server.hpp:39
uavcan::max
const UAVCAN_EXPORT T & max(const T &a, const T &b)
Definition: templates.hpp:291
uavcan::dynamic_node_id_server::NodeDiscoverer::hasUnknownNodes
bool hasUnknownNodes() const
Definition: node_discoverer.hpp:336
node_discoverer.hpp
uavcan::dynamic_node_id_server::AbstractServer::init
int init(const UniqueID &own_unique_id, const TransferPriority priority)
Definition: abstract_server.hpp:41
uavcan::INode
Definition: abstract_node.hpp:19
uavcan::TransferPriority
Definition: transfer.hpp:28
build_config.hpp
allocation_request_manager.hpp
uavcan::dynamic_node_id_server::IEventTracer
Definition: event.hpp:90
uavcan::dynamic_node_id_server::AbstractServer::node_
INode & node_
Definition: abstract_server.hpp:26
uavcan::dynamic_node_id_server::AllocationRequestManager::getTimeOfLastAllocationActivity
MonotonicTime getTimeOfLastAllocationActivity() const
Definition: allocation_request_manager.hpp:280
uavcan::dynamic_node_id_server::AbstractServer
Definition: abstract_server.hpp:19
uavcan::dynamic_node_id_server::AbstractServer::getNodeDiscoverer
const NodeDiscoverer & getNodeDiscoverer() const
Definition: abstract_server.hpp:108
pyuavcan_v0.introspect.node
node
Definition: introspect.py:398
uavcan::MonotonicTime
Definition: time.hpp:184
uavcan
Definition: libuavcan/libuavcan/include/uavcan/build_config.hpp:204
uavcan::dynamic_node_id_server::AbstractServer::guessIfAllDynamicNodesAreAllocated
bool guessIfAllDynamicNodesAreAllocated(const MonotonicDuration &allocation_activity_timeout=MonotonicDuration::fromMSec(Allocation::MAX_REQUEST_PERIOD_MS *2), const MonotonicDuration &min_uptime=MonotonicDuration::fromMSec(6000)) const
Definition: abstract_server.hpp:68
uavcan::dynamic_node_id_server::AllocationRequestManager
Definition: allocation_request_manager.hpp:45
uavcan::dynamic_node_id_server::UniqueID
protocol::dynamic_node_id::server::Entry::FieldTypes::unique_id UniqueID
Definition: protocol/dynamic_node_id_server/types.hpp:22
uavcan::dynamic_node_id_server::INodeDiscoveryHandler
Definition: node_discoverer.hpp:29


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