USRP Hardware Driver and USRP Manual  Version: 004.000.000.HEAD-0-g8773fb2c
UHD and USRP Manual
device3.hpp
Go to the documentation of this file.
1 //
2 // Copyright 2014-2016 Ettus Research LLC
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 //
17 
18 #ifndef INCLUDED_UHD_DEVICE3_HPP
19 #define INCLUDED_UHD_DEVICE3_HPP
20 
21 #include <uhd/device.hpp>
22 #include <uhd/rfnoc/graph.hpp>
24 #include <boost/units/detail/utility.hpp>
25 #include <vector>
26 
27 namespace uhd {
28 
36 class UHD_API device3 : public uhd::device {
37 
38  public:
39  typedef boost::shared_ptr<device3> sptr;
40 
42  static sptr make(const device_addr_t &hint, const size_t which = 0);
43 
44  virtual rfnoc::graph::sptr create_graph(const std::string &name="") = 0;
45 
50  void clear();
51 
57  bool has_block(const rfnoc::block_id_t &block_id) const;
58 
63  template <typename T>
64  bool has_block(const rfnoc::block_id_t &block_id) const
65  {
66  if (has_block(block_id)) {
67  return bool(boost::dynamic_pointer_cast<T>(get_block_ctrl(block_id)));
68  } else {
69  return false;
70  }
71  }
72 
80  rfnoc::block_ctrl_base::sptr get_block_ctrl(const rfnoc::block_id_t &block_id) const;
81 
95  template <typename T>
96  boost::shared_ptr<T> get_block_ctrl(const rfnoc::block_id_t &block_id) const
97  {
98  boost::shared_ptr<T> blk = boost::dynamic_pointer_cast<T>(get_block_ctrl(block_id));
99  if (blk) {
100  return blk;
101  } else {
102  throw uhd::lookup_error(str(boost::format("This device does not have a block of type %s with ID: %s")
103  % boost::units::detail::demangle(typeid(T).name())
104  % block_id.to_string()));
105  }
106  }
107 
119  std::vector<rfnoc::block_id_t> find_blocks(const std::string &block_id_hint) const;
120 
123  template <typename T>
124  std::vector<rfnoc::block_id_t> find_blocks(const std::string &block_id_hint) const
125  {
126  std::vector<rfnoc::block_id_t> all_block_ids = find_blocks(block_id_hint);
127  std::vector<rfnoc::block_id_t> filt_block_ids;
128  for (size_t i = 0; i < all_block_ids.size(); i++) {
129  if (has_block<T>(all_block_ids[i])) {
130  filt_block_ids.push_back(all_block_ids[i]);
131  }
132  }
133  return filt_block_ids;
134  }
135 
136  protected:
138  // It is the responsibility of the deriving class to make
139  // sure this gets correctly populated.
140  std::vector< rfnoc::block_ctrl_base::sptr > _rfnoc_block_ctrl;
141 };
142 
143 } //namespace uhd
144 
145 #endif /* INCLUDED_UHD_DEVICE3_HPP */
146 // vim: sw=4 et:
std::string to_string() const
Return a string like this: "0/FFT_1" (includes all components, if set)
Definition: exception.hpp:59
boost::shared_ptr< uhd::rfnoc::graph > sptr
Definition: graph.hpp:29
std::vector< rfnoc::block_id_t > find_blocks(const std::string &block_id_hint) const
Definition: device3.hpp:124
Extends uhd::device for third-generation USRP devices.
Definition: device3.hpp:36
Definition: block_id.hpp:49
Definition: build_info.hpp:25
boost::shared_ptr< block_ctrl_base > sptr
Definition: block_ctrl_base.hpp:112
std::vector< rfnoc::block_ctrl_base::sptr > _rfnoc_block_ctrl
List of all RFNoC blocks available on this device.
Definition: device3.hpp:140
#define UHD_API
Definition: config.h:73
bool has_block(const rfnoc::block_id_t &block_id) const
Definition: device3.hpp:64
boost::shared_ptr< T > get_block_ctrl(const rfnoc::block_id_t &block_id) const
Definition: device3.hpp:96
Definition: device.hpp:38
boost::shared_ptr< device3 > sptr
Definition: device3.hpp:39
Definition: device_addr.hpp:47