diff --git a/libuavcan/include/uavcan/node/abstract_node.hpp b/libuavcan/include/uavcan/node/abstract_node.hpp index c9e4a4c919..82dff8762e 100644 --- a/libuavcan/include/uavcan/node/abstract_node.hpp +++ b/libuavcan/include/uavcan/node/abstract_node.hpp @@ -41,8 +41,9 @@ public: /** * Sets the Node ID of this node. * Node ID can be assigned only once. This method returns true if the Node ID was successfully assigned, otherwise - * it returns false (e.g. the argument does not represent a valid Node ID, or it was already assigned earlier). + * it returns false. * As long as a valid Node ID is not set, the node will remain in passive mode. + * Using a non-unicast Node ID puts the node into passive mode (as default). */ bool setNodeID(NodeID nid) { diff --git a/libuavcan/include/uavcan/transport/dispatcher.hpp b/libuavcan/include/uavcan/transport/dispatcher.hpp index 50cc703ca3..c9cbbfc63b 100644 --- a/libuavcan/include/uavcan/transport/dispatcher.hpp +++ b/libuavcan/include/uavcan/transport/dispatcher.hpp @@ -102,6 +102,7 @@ class UAVCAN_EXPORT Dispatcher : Noncopyable LoopbackFrameListenerRegistry loopback_listeners_; NodeID self_node_id_; + bool self_node_id_is_set_; void handleFrame(const CanRxFrame& can_frame); void handleLoopbackFrame(const CanRxFrame& can_frame); @@ -111,6 +112,7 @@ public: : canio_(driver, allocator, sysclock) , sysclock_(sysclock) , outgoing_transfer_reg_(otr) + , self_node_id_is_set_(false) { } int spin(MonotonicTime deadline); @@ -143,6 +145,10 @@ public: LoopbackFrameListenerRegistry& getLoopbackFrameListenerRegistry() { return loopback_listeners_; } + /** + * Node ID can be set only once. + * Non-unicast Node ID puts the node into passive mode. + */ NodeID getNodeID() const { return self_node_id_; } bool setNodeID(NodeID nid); diff --git a/libuavcan/src/transport/uc_dispatcher.cpp b/libuavcan/src/transport/uc_dispatcher.cpp index 4ce9bb3453..b0ece03a7a 100644 --- a/libuavcan/src/transport/uc_dispatcher.cpp +++ b/libuavcan/src/transport/uc_dispatcher.cpp @@ -319,9 +319,10 @@ bool Dispatcher::hasServer(DataTypeID dtid) const bool Dispatcher::setNodeID(NodeID nid) { - if (nid.isUnicast() && !self_node_id_.isValid()) + if (!self_node_id_is_set_) { self_node_id_ = nid; + self_node_id_is_set_ = true; return true; } return false;