From a5fe0b071d7041f0539804cd16ada27d920bc96d Mon Sep 17 00:00:00 2001 From: Aaron Rossetto Date: Wed, 22 Jul 2020 12:51:21 -0500 Subject: rfnoc: Support instance overrides in set_properties() This commit adds an enhancement to node_t::set_properties() in which the instance argument provided to the function (which normally applies to all properties in the key/value list) can be overridden on a per-property basis using a special syntax. If the key consists of the property name followed by a colon (':') and then a number, the number following the colon is used to determine which instance of the property this set pertains to, and the value passed via the instance parameter is ignored for that property. For example, in the following call: node->set_properties("dog=10,cat:2=5,bird:0=0.5", 1) instance 1 of node's 'dog' property is set to 10, the 1 coming from the instance parameter, instance 2 of the node's 'cat' property is set to 5 due to the override syntax provided in the string, and instance 0 of the node's 'bird' property is set to 0.5 due to its override. If the name/instance pair is malformed, e.g. 'value:=10' or 'value:foobar=10', a runtime error is thrown. --- host/lib/rfnoc/node.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'host/lib') diff --git a/host/lib/rfnoc/node.cpp b/host/lib/rfnoc/node.cpp index 0abbb0d3b..062645b93 100644 --- a/host/lib/rfnoc/node.cpp +++ b/host/lib/rfnoc/node.cpp @@ -48,11 +48,28 @@ std::vector node_t::get_property_ids() const void node_t::set_properties(const uhd::device_addr_t& props, const size_t instance) { for (const auto& key : props.keys()) { + std::string local_key = key; + size_t local_instance = instance; + const size_t colon_pos = key.find(':'); + if (colon_pos != std::string::npos) { + // Extract the property ID and instance + local_key = key.substr(0, colon_pos); + std::string instance_part = key.substr(colon_pos + 1); + try { + local_instance = std::stoi(instance_part); + } catch (...) { + // If no number, or an invalid number is specified after the + // colon, throw a value_error. + throw uhd::value_error("Property id `" + local_key + + "' contains a malformed instance override!"); + } + } + property_base_t* prop_ref = - _find_property({res_source_info::USER, instance}, key); + _find_property({res_source_info::USER, local_instance}, local_key); if (!prop_ref) { RFNOC_LOG_WARNING("set_properties() cannot set property `" - << key << "': No such property."); + << local_key << "': No such property."); continue; } auto prop_access = _request_property_access(prop_ref, property_base_t::RW); -- cgit v1.2.3