mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-11 04:33:34 +08:00
NodeIDSelector: allocating only in the range [1, 125], unless the node explicitly requested higher node ID
This commit is contained in:
@@ -35,12 +35,12 @@ public:
|
||||
/**
|
||||
* Reutrns a default-constructed (invalid) node ID if a free one could not be found.
|
||||
*/
|
||||
NodeID findFreeNodeID(const NodeID preferred_node_id) const
|
||||
NodeID findFreeNodeID(const NodeID preferred) const
|
||||
{
|
||||
uint8_t candidate = preferred_node_id.isUnicast() ? preferred_node_id.get() : NodeID::Max;
|
||||
uint8_t candidate = preferred.isUnicast() ? preferred.get() : NodeID::MaxRecommendedForRegularNodes;
|
||||
|
||||
// Up
|
||||
while (candidate <= NodeID::Max)
|
||||
while (candidate <= NodeID::MaxRecommendedForRegularNodes)
|
||||
{
|
||||
if (!(owner_->*is_node_id_taken_)(candidate))
|
||||
{
|
||||
@@ -49,7 +49,7 @@ public:
|
||||
candidate++;
|
||||
}
|
||||
|
||||
candidate = preferred_node_id.isUnicast() ? preferred_node_id.get() : NodeID::Max;
|
||||
candidate = preferred.isUnicast() ? preferred.get() : NodeID::MaxRecommendedForRegularNodes;
|
||||
candidate--; // This has been tested already
|
||||
|
||||
// Down
|
||||
|
||||
@@ -129,6 +129,7 @@ class UAVCAN_EXPORT NodeID
|
||||
public:
|
||||
static const uint8_t BitLen = 7U;
|
||||
static const uint8_t Max = (1U << BitLen) - 1U;
|
||||
static const uint8_t MaxRecommendedForRegularNodes = Max - 2;
|
||||
static const NodeID Broadcast;
|
||||
|
||||
NodeID() : value_(ValueInvalid) { }
|
||||
|
||||
@@ -21,6 +21,7 @@ const uint8_t NodeID::ValueBroadcast;
|
||||
const uint8_t NodeID::ValueInvalid;
|
||||
const uint8_t NodeID::BitLen;
|
||||
const uint8_t NodeID::Max;
|
||||
const uint8_t NodeID::MaxRecommendedForRegularNodes;
|
||||
const NodeID NodeID::Broadcast(ValueBroadcast);
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user