aboutsummaryrefslogtreecommitdiffstats
path: root/host
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2019-08-23 12:11:19 -0700
committerMartin Braun <martin.braun@ettus.com>2019-11-26 11:49:38 -0800
commitaf5b2b5e778ead57b0fe9e72561227f1ebbbfc42 (patch)
tree546aff3823314a2716e7b08911ca1e2a0bdfcdfc /host
parentacc4dab894db1bb6285c3181548af16c1d1091f6 (diff)
downloaduhd-af5b2b5e778ead57b0fe9e72561227f1ebbbfc42.tar.gz
uhd-af5b2b5e778ead57b0fe9e72561227f1ebbbfc42.tar.bz2
uhd-af5b2b5e778ead57b0fe9e72561227f1ebbbfc42.zip
rfnoc: node: Add set_properties()
node_t::set_properties() is a convenience function that lets you set multiple properties at once from a device_addr_t.
Diffstat (limited to 'host')
-rw-r--r--host/include/uhd/rfnoc/node.hpp16
-rw-r--r--host/lib/rfnoc/node.cpp19
-rw-r--r--host/tests/rfnoc_blocks_test.cpp5
3 files changed, 39 insertions, 1 deletions
diff --git a/host/include/uhd/rfnoc/node.hpp b/host/include/uhd/rfnoc/node.hpp
index 59836fbf6..33831a4d7 100644
--- a/host/include/uhd/rfnoc/node.hpp
+++ b/host/include/uhd/rfnoc/node.hpp
@@ -10,9 +10,10 @@
#include <uhd/rfnoc/actions.hpp>
#include <uhd/rfnoc/dirtifier.hpp>
#include <uhd/rfnoc/property.hpp>
+#include <uhd/types/device_addr.hpp>
+#include <uhd/types/time_spec.hpp>
#include <uhd/utils/log.hpp>
#include <uhd/utils/scope_exit.hpp>
-#include <uhd/types/time_spec.hpp>
#include <unordered_map>
#include <unordered_set>
#include <boost/graph/adjacency_list.hpp>
@@ -123,6 +124,19 @@ public:
void set_property(
const std::string& id, const prop_data_t& val, const size_t instance = 0);
+ /*! Set multiple properties coming from a dictionary
+ *
+ * This is equivalent to calling set_property() individually for every
+ * key/value pair of props. However, the type of the property will be
+ * automatically derived using RTTI. Only certain types are supported.
+ *
+ * Property resolution happens after all properties have been updated.
+ *
+ * If a key in \p props is not a valid property of this block, a warning is
+ * logged, but no error is raised.
+ */
+ void set_properties(const uhd::device_addr_t& props, const size_t instance = 0);
+
/*! Get the value of a specific block argument. \p The type of an argument
* must be known at compile time.
*
diff --git a/host/lib/rfnoc/node.cpp b/host/lib/rfnoc/node.cpp
index 8709df9ef..90f0a0a91 100644
--- a/host/lib/rfnoc/node.cpp
+++ b/host/lib/rfnoc/node.cpp
@@ -45,6 +45,25 @@ std::vector<std::string> node_t::get_property_ids() const
return return_value;
}
+void node_t::set_properties(const uhd::device_addr_t& props, const size_t instance)
+{
+ for (const auto& key : props.keys()) {
+ property_base_t* prop_ref =
+ _find_property({res_source_info::USER, instance}, key);
+ if (!prop_ref) {
+ RFNOC_LOG_WARNING("set_properties() cannot set property `"
+ << key << "': No such property.");
+ continue;
+ }
+ auto prop_access = _request_property_access(prop_ref, property_base_t::RW);
+ prop_ref->set_from_str(props.get(key));
+ }
+
+ // Now trigger a property resolution. If other properties depend on modified
+ // properties, they will be updated.
+ resolve_all();
+}
+
void node_t::set_command_time(uhd::time_spec_t time, const size_t instance)
{
if (_cmd_timespecs.size() <= instance) {
diff --git a/host/tests/rfnoc_blocks_test.cpp b/host/tests/rfnoc_blocks_test.cpp
index df08f15ad..ea1f91b6b 100644
--- a/host/tests/rfnoc_blocks_test.cpp
+++ b/host/tests/rfnoc_blocks_test.cpp
@@ -250,6 +250,11 @@ BOOST_AUTO_TEST_CASE(test_ddc_block)
"mtu", NEW_MTU / 2, {res_source_info::OUTPUT_EDGE, 0});
BOOST_CHECK_EQUAL(test_ddc->get_mtu({res_source_info::INPUT_EDGE, 0}), NEW_MTU / 2);
BOOST_CHECK_EQUAL(test_ddc->get_mtu({res_source_info::OUTPUT_EDGE, 0}), NEW_MTU / 2);
+
+ // Now reset the props using set_properties
+ test_ddc->set_properties(uhd::device_addr_t("decim=1,freq=0.0,foo=bar"), 0);
+ BOOST_CHECK_EQUAL(test_ddc->get_property<int>("decim", 0), 1);
+ BOOST_CHECK_EQUAL(test_ddc->get_property<double>("freq", 0), 0.0);
}
BOOST_AUTO_TEST_CASE(test_duc_block)