Skip to content

Commit

Permalink
Fix: always create port/List.1.0 publisher.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
aentinger committed Mar 28, 2023
1 parent 6487c9c commit 7f9b89f
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ int main(int argc, char ** argv)
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); });
std::mutex node_mtx;

PortListPublisher port_list_pub = node_hdl.create_port_list_publisher();

Publisher<uavcan::node::Heartbeat_1_0> heartbeat_pub = node_hdl.create_publisher<uavcan::node::Heartbeat_1_0>
(1*1000*1000UL /* = 1 sec in usecs. */);

Expand Down
8 changes: 2 additions & 6 deletions src/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,14 @@ Node::Node(uint8_t * heap_ptr,
{
_canard_hdl.node_id = node_id;
_canard_hdl.user_reference = static_cast<void *>(_o1heap_ins);

_opt_port_list_pub = std::make_shared<impl::PortListPublisher>(*this, _micros_func);
}

/**************************************************************************************
* PUBLIC MEMBER FUNCTIONS
**************************************************************************************/

PortListPublisher Node::create_port_list_publisher()
{
_opt_port_list_pub = std::make_shared<impl::PortListPublisher>(*this, _micros_func);
return _opt_port_list_pub.value();
}

#if __GNUC__ >= 11
Registry Node::create_registry()
{
Expand Down
3 changes: 0 additions & 3 deletions src/Node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@ class Node
inline CanardNodeID getNodeId() const { return _canard_hdl.node_id; }


PortListPublisher create_port_list_publisher();


template <typename T>
Publisher<T> create_publisher(CanardMicrosecond const tx_timeout_usec);
template <typename T>
Expand Down

0 comments on commit 7f9b89f

Please sign in to comment.