addFilterConfig() added. computeConfiguration() separated from applyConfiguration.

Other small corrections
This commit is contained in:
Ilia
2015-12-16 00:33:00 +00:00
parent a2ed997cb4
commit 5563dbacff
2 changed files with 88 additions and 51 deletions
@@ -21,10 +21,11 @@ namespace uavcan
* preclude reception of irrelevant CAN frames on the hardware level.
*
* Configuration starts by creating an object of class @ref CanAcceptanceFilterConfigurator on the stack.
* Through the method configureFilters() it determines the number of available HW filters and the number
* of listeners. In case the number of listeners is higher than the number of available HW filters, the function
* automatically merges configs in the most efficient way until their number is reduced to the number of
* available HW filters. Subsequently obtained configurations are then loaded into the CAN driver.
* By means of computeConfiguration() method the class determines the number of available HW filters and the number
* of listeners. In case if custom configuration required, it is possible to add it through addFilterConfig().
* Subsequently obtained configurations are then loaded into the CAN driver by calling the applyConfiguration() method.
* If the cumulative number of configurations obtained by computeConfiguration() and addFilterConfig() is higher than
* the number of available HW filters, configurations will be merged automatically in the most efficient way.
*
* The maximum number of CAN acceptance filters is predefined in uavcan/build_config.hpp through a constant
* @ref MaxCanAcceptanceFilters. The algorithm doesn't allow to have higher number of HW filters configurations than
@@ -57,7 +58,7 @@ private:
* HW filters.
* DefaultAnonMsgMask = 00000 00000000 00000000 11111111
* DefaultAnonMsgID = 00000 00000000 00000000 00000000, by default the config is added to accept all anonymous
* frames. In case there are no anonymous messages, invoke configureFilters(IgnoreAnonymousMessages).
* frames. In case there are no anonymous messages, invoke computeConfiguration(IgnoreAnonymousMessages).
*/
static const unsigned DefaultFilterMsgMask = 0xFFFF80;
static const unsigned DefaultFilterServiceMask = 0x7F80;
@@ -72,7 +73,7 @@ private:
uint16_t getNumFilters() const;
/**
* Fills the multiset_configs_ to proceed it with computeConfiguration()
* Fills the multiset_configs_ to proceed it with mergeConfigurations()
*/
int16_t loadInputConfiguration(AnonymousMessages load_mode);
@@ -80,35 +81,44 @@ private:
* This method merges several listeners's filter configurations by predetermined algorithm
* if number of available hardware acceptance filters less than number of listeners
*/
int16_t computeConfiguration();
/**
* This method loads the configuration computed with computeConfiguration() to the CAN driver.
*/
int16_t applyConfiguration();
int16_t mergeConfigurations();
INode& node_; //< Node reference is needed for access to ICanDriver and Dispatcher
MultisetConfigContainer multiset_configs_;
uint16_t filters_number_;
public:
explicit CanAcceptanceFilterConfigurator(INode& node)
explicit CanAcceptanceFilterConfigurator(INode& node, uint16_t filters_number = 0)
: node_(node)
, multiset_configs_(node.getAllocator())
, filters_number_(filters_number)
{ }
/**
* This method invokes loadInputConfiguration(), computeConfiguration() and applyConfiguration() consequently, so
* This method invokes loadInputConfiguration() and mergeConfigurations() consequently, so
* that optimal acceptance filter configuration will be computed and loaded through CanDriver::configureFilters()
*
* @param mode Either: AcceptAnonymousMessages - the filters will accept all anonymous messages (this is default)
* IgnoreAnonymousMessages - anonymous messages will be ignored
* @return 0 = success, negative for error.
*/
int configureFilters(AnonymousMessages mode = AcceptAnonymousMessages);
int computeConfiguration(AnonymousMessages mode = AcceptAnonymousMessages);
/**
* Returns the configuration computed with computeConfiguration().
* If computeConfiguration() has not been called yet, an empty configuration will be returned.
* Add the additional filter configuration to multiset_configs_. This method should be invoked only before
* computeConfiguration() member.
*/
int16_t addFilterConfig(const CanFilterConfig& config);
/**
* This method loads the configuration computed with mergeConfigurations() or explicitly added by addFilterConfig()
* to the CAN driver. Must be called after computeConfiguration() and addFilterConfig().
*/
int16_t applyConfiguration();
/**
* Returns the configuration computed with mergeConfigurations() or added by addFilterConfig().
* If mergeConfigurations() or addFilterConfig() has not been called yet, an empty configuration will be returned.
*/
const MultisetConfigContainer& getConfiguration() const
{