From 9efd1ac7aecd34a2f938b2eac1938d1eab4b3825 Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Tue, 12 May 2015 12:59:22 +0300 Subject: [PATCH] NodeIDSelector: allocating only in the range [1, 125], unless the node explicitly requested higher node ID --- .../protocol/dynamic_node_id_server/node_id_selector.hpp | 8 ++++---- libuavcan/include/uavcan/transport/transfer.hpp | 1 + libuavcan/src/transport/uc_transfer.cpp | 1 + 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/libuavcan/include/uavcan/protocol/dynamic_node_id_server/node_id_selector.hpp b/libuavcan/include/uavcan/protocol/dynamic_node_id_server/node_id_selector.hpp index 2af730a67e..97c86ab21b 100644 --- a/libuavcan/include/uavcan/protocol/dynamic_node_id_server/node_id_selector.hpp +++ b/libuavcan/include/uavcan/protocol/dynamic_node_id_server/node_id_selector.hpp @@ -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 diff --git a/libuavcan/include/uavcan/transport/transfer.hpp b/libuavcan/include/uavcan/transport/transfer.hpp index c1cdc38abb..f452c344bc 100644 --- a/libuavcan/include/uavcan/transport/transfer.hpp +++ b/libuavcan/include/uavcan/transport/transfer.hpp @@ -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) { } diff --git a/libuavcan/src/transport/uc_transfer.cpp b/libuavcan/src/transport/uc_transfer.cpp index 51c850ea02..da1897e842 100644 --- a/libuavcan/src/transport/uc_transfer.cpp +++ b/libuavcan/src/transport/uc_transfer.cpp @@ -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); /**