From 9a77d27d81a586d65efda1a785a94b44c725050a Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Mon, 15 Jun 2015 15:44:58 +0300 Subject: [PATCH] Build config UAVCAN_MAX_NETWORK_SIZE_HINT (#33) --- libuavcan/include/uavcan/build_config.hpp | 15 +++++++++++++++ .../dynamic_node_id_server/node_discoverer.hpp | 4 +--- .../uavcan/protocol/node_status_monitor.hpp | 7 +------ 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/libuavcan/include/uavcan/build_config.hpp b/libuavcan/include/uavcan/build_config.hpp index 0ce6575bf1..e176eadec4 100644 --- a/libuavcan/include/uavcan/build_config.hpp +++ b/libuavcan/include/uavcan/build_config.hpp @@ -228,6 +228,21 @@ static const unsigned FloatComparisonEpsilonMult = UAVCAN_FLOAT_COMPARISON_EPSIL static const unsigned FloatComparisonEpsilonMult = 10; #endif +/** + * This constant defines how many receiver objects will be statically pre-allocated by classes that listen to messages + * of type uavcan.protocol.NodeStatus from other nodes. If the number of publishers exceeds this value, extra + * listeners will be allocated in the dynamic memory (one block per listener). + * + * The default value is safe to use in any application (since extra memory can always be retrieved from the pool). + * Applications that are extremely memory sensitive and are not expected to operate in large networks can override + * the default with a lower value. + */ +#ifdef UAVCAN_MAX_NETWORK_SIZE_HINT +static const unsigned MaxNetworkSizeHint = UAVCAN_MAX_NETWORK_SIZE_HINT; +#else +static const unsigned MaxNetworkSizeHint = 64; ///< Rest will go into the dynamic memory +#endif + } #endif // UAVCAN_BUILD_CONFIG_HPP_INCLUDED 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 e5e4da5e1f..e9c58c12d8 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 @@ -94,8 +94,6 @@ class NodeDiscoverer : TimerBase enum { TimerPollIntervalMs = 170 }; // ~ ceil(500 ms service timeout / 3) - enum { NumNodeStatusStaticReceivers = 64 }; - /* * States */ @@ -106,7 +104,7 @@ class NodeDiscoverer : TimerBase NodeMap node_map_; ///< Will not work in UAVCAN_TINY ServiceClient get_node_info_client_; - Subscriber node_status_sub_; + Subscriber node_status_sub_; /* * Methods diff --git a/libuavcan/include/uavcan/protocol/node_status_monitor.hpp b/libuavcan/include/uavcan/protocol/node_status_monitor.hpp index 06f7bb7605..86a1348b31 100644 --- a/libuavcan/include/uavcan/protocol/node_status_monitor.hpp +++ b/libuavcan/include/uavcan/protocol/node_status_monitor.hpp @@ -51,12 +51,7 @@ private: typedef MethodBinder TimerCallback; - /* - * We'll be able to handle this many nodes in the network without any dynamic memory. - */ - enum { NumStaticReceivers = 64 }; - - Subscriber sub_; + Subscriber sub_; TimerEventForwarder timer_;