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 
59  started_at_ = node_.getMonotonicTime();
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  {
73  const MonotonicTime ts = node_.getMonotonicTime();
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  */
87  if (node_discoverer_.hasUnknownNodes())
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 =
96  ts - allocation_request_manager_.getTimeOfLastAllocationActivity();
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
int init(const UniqueID &own_unique_id, const TransferPriority priority)
AbstractServer(INode &node, IEventTracer &tracer)
UAVCAN_EXPORT const T & max(const T &a, const T &b)
Definition: templates.hpp:291
protocol::dynamic_node_id::server::Entry::FieldTypes::unique_id UniqueID
const NodeDiscoverer & getNodeDiscoverer() const
bool guessIfAllDynamicNodesAreAllocated(const MonotonicDuration &allocation_activity_timeout=MonotonicDuration::fromMSec(Allocation::MAX_REQUEST_PERIOD_MS *2), const MonotonicDuration &min_uptime=MonotonicDuration::fromMSec(6000)) const
int init(const TransferPriority priority)
static MonotonicDuration fromMSec(int64_t ms)
Definition: time.hpp:41
MonotonicTime getMonotonicTime() const


uavcan_communicator
Author(s):
autogenerated on Wed Jan 11 2023 03:59:39