From 73273ab06dcce4898a401d2a0d0b865447f24080 Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Sun, 24 May 2015 17:21:26 +0300 Subject: [PATCH] Optimized NodeDiscoverer - picking any node to query, without any preference --- .../node_discoverer.hpp | 31 ++----------------- 1 file changed, 3 insertions(+), 28 deletions(-) diff --git a/libuavcan/include/uavcan/protocol/dynamic_node_id_server/node_discoverer.hpp b/libuavcan/include/uavcan/protocol/dynamic_node_id_server/node_discoverer.hpp index ef7f901749..827551250c 100644 --- a/libuavcan/include/uavcan/protocol/dynamic_node_id_server/node_discoverer.hpp +++ b/libuavcan/include/uavcan/protocol/dynamic_node_id_server/node_discoverer.hpp @@ -86,27 +86,6 @@ class NodeDiscoverer : TimerBase typedef Map NodeMap; - class HighestUptimeSearcher : ::uavcan::Noncopyable - { - uint32_t highest_uptime_sec_; - NodeID node_id_; - - public: - HighestUptimeSearcher() : highest_uptime_sec_(0) { } - - bool operator()(const NodeID& key, const NodeData& value) - { - if (value.last_seen_uptime >= highest_uptime_sec_) - { - highest_uptime_sec_ = value.last_seen_uptime; - node_id_ = key; - } - return false; - } - - NodeID getNodeWithHighestUptime() const { return node_id_; } - }; - /** * When this number of attempts has been made, the discoverer will give up and assume that the node * does not implement this service. @@ -144,13 +123,9 @@ class NodeDiscoverer : TimerBase NodeID pickNextNodeToQuery() const { - HighestUptimeSearcher searcher; - - const NodeID* const out = node_map_.find(searcher); - (void)out; - UAVCAN_ASSERT(out == NULL); - - return searcher.getNodeWithHighestUptime(); + // This essentially means that we pick first available node. Remember that the map is unordered. + const NodeMap::KVPair* const pair = node_map_.getByIndex(0); + return (pair == NULL) ? NodeID() : pair->key; } bool needToQuery(NodeID node_id)