diff options
| author | Julian Arnold <julian.arnold@ettus.com> | 2015-01-30 15:11:15 -0800 | 
|---|---|---|
| committer | Martin Braun <martin.braun@ettus.com> | 2015-03-09 17:39:32 -0700 | 
| commit | a55b5a097da01606f23209713bf1ce754be5b7d3 (patch) | |
| tree | 93ea4476976b88dc1551b6a0be32ff86eda544c4 /host/lib | |
| parent | c646177e54fed77a9508369ed3f7fc20f1d88a8f (diff) | |
| download | uhd-a55b5a097da01606f23209713bf1ce754be5b7d3.tar.gz uhd-a55b5a097da01606f23209713bf1ce754be5b7d3.tar.bz2 uhd-a55b5a097da01606f23209713bf1ce754be5b7d3.zip | |
uhd: Introduced filter API.
This is a unified API to access filters on USRP devices. Filters
can be accessed through the property tree, or multi_usrp.
Diffstat (limited to 'host/lib')
| -rw-r--r-- | host/lib/types/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | host/lib/types/filters.cpp | 74 | ||||
| -rw-r--r-- | host/lib/usrp/multi_usrp.cpp | 83 | 
3 files changed, 158 insertions, 0 deletions
| diff --git a/host/lib/types/CMakeLists.txt b/host/lib/types/CMakeLists.txt index 853da3fe2..821754386 100644 --- a/host/lib/types/CMakeLists.txt +++ b/host/lib/types/CMakeLists.txt @@ -91,4 +91,5 @@ LIBUHD_APPEND_SOURCES(      ${CMAKE_CURRENT_SOURCE_DIR}/tune.cpp      ${CMAKE_CURRENT_SOURCE_DIR}/types.cpp      ${CMAKE_CURRENT_SOURCE_DIR}/wb_iface.cpp +    ${CMAKE_CURRENT_SOURCE_DIR}/filters.cpp  ) diff --git a/host/lib/types/filters.cpp b/host/lib/types/filters.cpp new file mode 100644 index 000000000..4ee06491f --- /dev/null +++ b/host/lib/types/filters.cpp @@ -0,0 +1,74 @@ +// +// Copyright 2015 Ettus Research LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program.  If not, see <http://www.gnu.org/licenses/>. +// + +#include <uhd/types/filters.hpp> + +using namespace uhd; + +std::ostream& uhd::operator<<(std::ostream& os, filter_info_base& f) +{ +    return os << f.to_pp_string(); +} + +std::string filter_info_base::to_pp_string() +{ +    std::ostringstream os; +    os << "[filter_info_base]" << std::endl; +    switch(_type){ +        case ANALOG_LOW_PASS: +            os << "type: " << "Analog Low-pass" << std::endl; +            break; +        case ANALOG_BAND_PASS: +            os << "type: " << "Analog Band-pass" << std::endl; +            break; +        case DIGITAL_I16: +            os << "type: " << "Digital (i16)" << std::endl; +            break; +        case DIGITAL_FIR_I16: +            os << "type: " << "Digital FIR (i16)" << std::endl; +            break; +        default: +            os << "type: " << "Unknown type!" << std::endl; +            break; +        } + +    os << "bypass enable: " << _bypass << std::endl +        <<"position index: " << _position_index << std::endl; + +    std::string str =  os.str(); +    return str; +} + +std::string analog_filter_base::to_pp_string() +{ +    std::ostringstream os; +    os << filter_info_base::to_pp_string() << +        "\t[analog_filter_base]" << std::endl << +        "\tdesc: " << _analog_type << std::endl; +    return std::string(os.str()); + +} + +std::string analog_filter_lp::to_pp_string() +{ +    std::ostringstream os; +    os << analog_filter_base::to_pp_string() << +        "\t\t[analog_filter_lp]" << std::endl << +        "\t\tcutoff: " << _cutoff << std::endl << +        "\t\trolloff: " << _rolloff << std::endl; +    return std::string(os.str()); +} diff --git a/host/lib/usrp/multi_usrp.cpp b/host/lib/usrp/multi_usrp.cpp index bc6e121d0..570c67875 100644 --- a/host/lib/usrp/multi_usrp.cpp +++ b/host/lib/usrp/multi_usrp.cpp @@ -30,6 +30,8 @@  #include <boost/thread.hpp>  #include <boost/foreach.hpp>  #include <boost/format.hpp> +#include <boost/algorithm/string.hpp> +#include <algorithm>  #include <cmath>  using namespace uhd; @@ -1007,6 +1009,87 @@ public:          }      } +    std::vector<std::string> get_filter_names(const std::string &search_mask) +    { +        std::vector<std::string> ret; + +        for (size_t chan = 0; chan < get_rx_num_channels(); chan++){ + +            if (_tree->exists(rx_rf_fe_root(chan) / "filters")) { +                std::vector<std::string> names = _tree->list(rx_rf_fe_root(chan) / "filters"); +                for(size_t i = 0; i < names.size(); i++) +                { +                    std::string name = rx_rf_fe_root(chan) / "filters" / names[i]; +                    if((search_mask.empty()) or boost::contains(name, search_mask)) { +                        ret.push_back(name); +                    } +                } +            } +            if (_tree->exists(rx_dsp_root(chan) / "filters")) { +                std::vector<std::string> names = _tree->list(rx_dsp_root(chan) / "filters"); +                for(size_t i = 0; i < names.size(); i++) +                { +                    std::string name = rx_dsp_root(chan) / "filters" / names[i]; +                    if((search_mask.empty()) or (boost::contains(name, search_mask))) { +                        ret.push_back(name); +                    } +                } +            } + +        } + +        for (size_t chan = 0; chan < get_tx_num_channels(); chan++){ + +            if (_tree->exists(tx_rf_fe_root(chan) / "filters")) { +                std::vector<std::string> names = _tree->list(tx_rf_fe_root(chan) / "filters"); +                for(size_t i = 0; i < names.size(); i++) +                { +                    std::string name = tx_rf_fe_root(chan) / "filters" / names[i]; +                    if((search_mask.empty()) or (boost::contains(name, search_mask))) { +                        ret.push_back(name); +                    } +                } +            } +            if (_tree->exists(rx_dsp_root(chan) / "filters")) { +                std::vector<std::string> names = _tree->list(tx_dsp_root(chan) / "filters"); +                for(size_t i = 0; i < names.size(); i++) +                { +                    std::string name = tx_dsp_root(chan) / "filters" / names[i]; +                    if((search_mask.empty()) or (boost::contains(name, search_mask))) { +                        ret.push_back(name); +                    } +                } +            } + +        } + +        return ret; +    } + +    filter_info_base::sptr get_filter(const std::string &path) +    { +        std::vector<std::string> possible_names = get_filter_names(""); +        std::vector<std::string>::iterator it; +        it = find(possible_names.begin(), possible_names.end(), path); +        if (it == possible_names.end()) { +            throw uhd::runtime_error("Attempting to get non-existing filter: "+path); +        } + +        return _tree->access<filter_info_base::sptr>(path / "value").get(); +    } + +    void set_filter(const std::string &path, filter_info_base::sptr filter) +    { +        std::vector<std::string> possible_names = get_filter_names(""); +        std::vector<std::string>::iterator it; +        it = find(possible_names.begin(), possible_names.end(), path); +        if (it == possible_names.end()) { +            throw uhd::runtime_error("Attempting to set non-existing filter: "+path); +        } + +        _tree->access<filter_info_base::sptr>(path / "value").set(filter); +    } +      /*******************************************************************       * TX methods       ******************************************************************/ | 
