USRP Hardware Driver and USRP Manual  Version: 3.11.0.HEAD-0-g13c32cef
UHD and USRP Manual
device3.hpp
Go to the documentation of this file.
1 //
2 // Copyright 2014-2016 Ettus Research LLC
3 // Copyright 2018 Ettus Research, a National Instruments Company
4 //
5 // SPDX-License-Identifier: GPL-3.0-or-later
6 //
7 
8 #ifndef INCLUDED_UHD_DEVICE3_HPP
9 #define INCLUDED_UHD_DEVICE3_HPP
10 
11 #include <uhd/device.hpp>
12 #include <uhd/rfnoc/graph.hpp>
13 #include <uhd/rfnoc/block_ctrl_base.hpp>
14 #include <boost/units/detail/utility.hpp>
15 #include <boost/thread/mutex.hpp>
16 #include <vector>
17 
18 namespace uhd {
19 
27 class UHD_API device3 : public uhd::device {
28 
29  public:
30  typedef boost::shared_ptr<device3> sptr;
31 
33  static sptr make(const device_addr_t &hint, const size_t which = 0);
34 
35  virtual rfnoc::graph::sptr create_graph(const std::string &name="") = 0;
36 
41  void clear();
42 
49  bool has_block(const rfnoc::block_id_t &block_id) const;
50 
56  template <typename T>
57  bool has_block(const rfnoc::block_id_t &block_id) const
58  {
59  if (has_block(block_id)) {
60  return bool(boost::dynamic_pointer_cast<T>(get_block_ctrl(block_id)));
61  } else {
62  return false;
63  }
64  }
65 
74  rfnoc::block_ctrl_base::sptr get_block_ctrl(const rfnoc::block_id_t &block_id) const;
75 
90  template <typename T>
91  boost::shared_ptr<T> get_block_ctrl(const rfnoc::block_id_t &block_id) const
92  {
93  boost::shared_ptr<T> blk = boost::dynamic_pointer_cast<T>(get_block_ctrl(block_id));
94  if (blk) {
95  return blk;
96  } else {
97  throw uhd::lookup_error(str(boost::format("This device does not have a block of type %s with ID: %s")
98  % boost::units::detail::demangle(typeid(T).name())
99  % block_id.to_string()));
100  }
101  }
102 
115  std::vector<rfnoc::block_id_t> find_blocks(const std::string &block_id_hint) const;
116 
119  template <typename T>
120  std::vector<rfnoc::block_id_t> find_blocks(const std::string &block_id_hint) const
121  {
122  std::vector<rfnoc::block_id_t> all_block_ids = find_blocks(block_id_hint);
123  std::vector<rfnoc::block_id_t> filt_block_ids;
124  for (size_t i = 0; i < all_block_ids.size(); i++) {
125  if (has_block<T>(all_block_ids[i])) {
126  filt_block_ids.push_back(all_block_ids[i]);
127  }
128  }
129  return filt_block_ids;
130  }
131 
132  protected:
134  // It is the responsibility of the deriving class to make
135  // sure this gets correctly populated.
136  std::vector< rfnoc::block_ctrl_base::sptr > _rfnoc_block_ctrl;
138  boost::mutex _block_ctrl_mutex;
139 };
140 
141 } //namespace uhd
142 
143 #endif /* INCLUDED_UHD_DEVICE3_HPP */
144 // vim: sw=4 et:
Definition: exception.hpp:49
std::vector< rfnoc::block_id_t > find_blocks(const std::string &block_id_hint) const
Definition: device3.hpp:120
Extends uhd::device for third-generation USRP devices.
Definition: device3.hpp:27
Definition: build_info.hpp:14
boost::mutex _block_ctrl_mutex
Mutex to protect access to members.
Definition: device3.hpp:138
std::vector< rfnoc::block_ctrl_base::sptr > _rfnoc_block_ctrl
List of all RFNoC blocks available on this device.
Definition: device3.hpp:136
#define UHD_API
Definition: config.h:63
bool has_block(const rfnoc::block_id_t &block_id) const
Definition: device3.hpp:57
boost::shared_ptr< T > get_block_ctrl(const rfnoc::block_id_t &block_id) const
Definition: device3.hpp:91
Definition: device.hpp:28
boost::shared_ptr< device3 > sptr
Definition: device3.hpp:30
Definition: device_addr.hpp:37