libuavcan: Proper passive mode handling

This commit is contained in:
Pavel Kirienko
2014-07-15 01:03:41 +04:00
parent abaaf8d440
commit c31d41c9c8
3 changed files with 10 additions and 2 deletions
@@ -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)
{
@@ -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);
+2 -1
View File
@@ -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;