mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-14 02:13:33 +08:00
libuavcan: Proper passive mode handling
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user