Skip to content

Commit 9f73c6a

Browse files
authored
Fix: always create port/List.1.0 publisher. (#221)
If Publishers/Subscriptions/etc. are created as global static objects the order of initialisation is not clear. Hence it could happen that Publisher IDs are not probably registered.
1 parent 6487c9c commit 9f73c6a

File tree

3 files changed

+2
-11
lines changed

3 files changed

+2
-11
lines changed

examples/host-example-01-opencyphal-basic-node/host-example-01-opencyphal-basic-node.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ int main(int argc, char ** argv)
5858
Node node_hdl(node_heap.data(), node_heap.size(), micros, [socket_can_fd] (CanardFrame const & frame) { return (socketcanPush(socket_can_fd, &frame, 1000*1000UL) > 0); });
5959
std::mutex node_mtx;
6060

61-
PortListPublisher port_list_pub = node_hdl.create_port_list_publisher();
62-
6361
Publisher<uavcan::node::Heartbeat_1_0> heartbeat_pub = node_hdl.create_publisher<uavcan::node::Heartbeat_1_0>
6462
(1*1000*1000UL /* = 1 sec in usecs. */);
6563

src/Node.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,14 @@ Node::Node(uint8_t * heap_ptr,
4040
{
4141
_canard_hdl.node_id = node_id;
4242
_canard_hdl.user_reference = static_cast<void *>(_o1heap_ins);
43+
44+
_opt_port_list_pub = std::make_shared<impl::PortListPublisher>(*this, _micros_func);
4345
}
4446

4547
/**************************************************************************************
4648
* PUBLIC MEMBER FUNCTIONS
4749
**************************************************************************************/
4850

49-
PortListPublisher Node::create_port_list_publisher()
50-
{
51-
_opt_port_list_pub = std::make_shared<impl::PortListPublisher>(*this, _micros_func);
52-
return _opt_port_list_pub.value();
53-
}
54-
5551
#if __GNUC__ >= 11
5652
Registry Node::create_registry()
5753
{

src/Node.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,6 @@ class Node
7676
inline CanardNodeID getNodeId() const { return _canard_hdl.node_id; }
7777

7878

79-
PortListPublisher create_port_list_publisher();
80-
81-
8279
template <typename T>
8380
Publisher<T> create_publisher(CanardMicrosecond const tx_timeout_usec);
8481
template <typename T>

0 commit comments

Comments
 (0)