From d2374c6ad67f94fa577d28d5660f32579f4775cc Mon Sep 17 00:00:00 2001
From: Lane Kolbly <lane.kolbly@ni.com>
Date: Mon, 31 Jan 2022 16:10:42 -0600
Subject: host: zbx: Expose tuning table on property tree

This allows viewing or, conceivably, customizing the tuning table that
ZBX uses, depending on the particular needs of the end user.
---
 host/lib/usrp/dboard/zbx/zbx_dboard_init.cpp | 14 ++++++++++++++
 host/lib/usrp/dboard/zbx/zbx_expert.cpp      |  9 ++++-----
 2 files changed, 18 insertions(+), 5 deletions(-)

(limited to 'host/lib/usrp/dboard')

diff --git a/host/lib/usrp/dboard/zbx/zbx_dboard_init.cpp b/host/lib/usrp/dboard/zbx/zbx_dboard_init.cpp
index 6871080ff..18fb9bbe1 100644
--- a/host/lib/usrp/dboard/zbx/zbx_dboard_init.cpp
+++ b/host/lib/usrp/dboard/zbx/zbx_dboard_init.cpp
@@ -66,6 +66,13 @@ std::ostream& operator<<(
     }
 }
 
+std::ostream& operator<<(
+    std::ostream& os, const std::vector<::uhd::usrp::zbx::tune_map_item_t>& tune_map)
+{
+    os << "Tune map with " << tune_map.size() << " entries";
+    return os;
+}
+
 void zbx_dboard_impl::_init_cpld()
 {
     // CPLD
@@ -573,6 +580,13 @@ void zbx_dboard_impl::_init_lo_prop_tree(uhd::property_tree::sptr subtree,
     const size_t chan_idx,
     const fs_path fe_path)
 {
+    // Tuning table
+    expert_factory::add_prop_node<std::vector<tune_map_item_t>>(expert,
+        subtree,
+        fe_path / "tune_table",
+        trx == RX_DIRECTION ? rx_tune_map : tx_tune_map,
+        AUTO_RESOLVE_ON_WRITE);
+
     // Analog LO Specific
     for (const std::string lo : {ZBX_LO1, ZBX_LO2}) {
         expert_factory::add_prop_node<zbx_lo_source_t>(expert,
diff --git a/host/lib/usrp/dboard/zbx/zbx_expert.cpp b/host/lib/usrp/dboard/zbx/zbx_expert.cpp
index ae39814ff..02b4873d9 100644
--- a/host/lib/usrp/dboard/zbx/zbx_expert.cpp
+++ b/host/lib/usrp/dboard/zbx/zbx_expert.cpp
@@ -28,11 +28,10 @@ bool _is_band_highband(const tune_map_item_t tune_setting)
     return tune_setting.rf_fir == 0;
 }
 
-tune_map_item_t _get_tune_settings(const double freq, const uhd::direction_t trx)
+tune_map_item_t _get_tune_settings(const double freq, const std::vector<tune_map_item_t>& tune_map)
 {
-    auto tune_setting = trx == RX_DIRECTION ? rx_tune_map.begin() : tx_tune_map.begin();
-
-    auto tune_settings_end = trx == RX_DIRECTION ? rx_tune_map.end() : tx_tune_map.end();
+    auto tune_setting = tune_map.begin();
+    auto tune_settings_end = tune_map.end();
 
     for (; tune_setting != tune_settings_end; ++tune_setting) {
         if (tune_setting->max_band_freq >= freq) {
@@ -147,7 +146,7 @@ void zbx_scheduling_expert::resolve()
 void zbx_freq_fe_expert::resolve()
 {
     const double tune_freq = ZBX_FREQ_RANGE.clip(_desired_frequency);
-    _tune_settings         = _get_tune_settings(tune_freq, _trx);
+    _tune_settings         = _get_tune_settings(tune_freq, _tune_table.get());
 
     // Set mixer values so the backend expert knows how to calculate final frequency
     _mixer1_m  = _tune_settings.mix1_m;
-- 
cgit v1.2.3