GNU Radio Manual and C++ API Reference 3.10.5.1
The Free & Open Software Radio Ecosystem
rfnoc_block.h
Go to the documentation of this file.
1/* -*- c++ -*- */
2/*
3 * Copyright 2020 Free Software Foundation, Inc.
4 * Copyright 2020 Ettus Research, A National Instruments Brand.
5 *
6 * SPDX-License-Identifier: GPL-3.0-or-later
7 */
8
9#ifndef INCLUDED_UHD_RFNOC_BLOCK_H
10#define INCLUDED_UHD_RFNOC_BLOCK_H
11
12#include <gnuradio/block.h>
14#include <uhd/rfnoc/noc_block_base.hpp>
15#include <string>
16
17namespace gr {
18namespace uhd {
19
20/*! Base class for RFNoC blocks controlled by GNU Radio
21 *
22 * Any GNU Radio block that is meant to control an RFNoC block
23 * should be derived from this class.
24 */
26{
27protected:
28 // \param block_ref A reference to the underlying block controller
29 rfnoc_block(::uhd::rfnoc::noc_block_base::sptr block_ref);
30
31 rfnoc_block() {} // For virtual subclassing
32
33public:
34 using sptr = std::shared_ptr<rfnoc_block>;
35
36 //! Factory function to create a UHD block controller reference
37 //
38 // \param graph Reference to the flowgraph's RFNoC graph
39 // \param block_args Block args
40 // \param block_name Block name (e.g. "DDC")
41 // \param device_select Device index (motherboard index)
42 // \param block_select Block index
43 // \param max_ref_count Maximum number of references this block can have in
44 // the GNU Radio flow graph
45 static ::uhd::rfnoc::noc_block_base::sptr
47 const ::uhd::device_addr_t& block_args,
48 const std::string& block_name,
49 const int device_select = -1,
50 const int block_select = -1,
51 const size_t max_ref_count = 1);
52
53 //! Return a type-cast block reference, or throw if the cast failed.
54 //
55 // \throws std::runtime_error if there is no valid block reference
56 template <typename block_type>
57 std::shared_ptr<block_type> get_block_ref()
58 {
59 auto cast_block_ref = std::dynamic_pointer_cast<block_type>(d_block_ref);
60 if (!cast_block_ref) {
61 throw std::runtime_error(
62 std::string(
63 "Unable to cast the following block into its desired type: ") +
64 d_block_ref->get_unique_id());
65 }
66 return cast_block_ref;
67 }
68
69 /*! Return the unique ID of the underlying block
70 */
71 std::string get_unique_id() const;
72
73 // GNU Radio-specific overrides
74
75 //! This method should never be called by RFNoC blocks, they do the work
76 // in the FPGA.
77 int general_work(int noutput_items,
78 gr_vector_int& ninput_items,
79 gr_vector_const_void_star& input_items,
80 gr_vector_void_star& output_items) override;
81
82 /*! Set multiple properties coming from a dictionary
83 *
84 * See the [UHD
85 * manual](https://uhd.readthedocs.io/en/latest/classuhd_1_1rfnoc_1_1node__t.html#abf34d4be8fe7a602b27927194195f1f6)
86 * for details.
87 *
88 * This function allows the client to override the \p instance parameter
89 * for each property key/value pair passed in via the \p props parameter.
90 * If the key consists of the property name, followed by a colon (':') and
91 * then a number, the number following the colon is used to determine
92 * which instance of the property this set pertains to, and the \p
93 * instance parameter is ignored for that property. (Note that if the key
94 * does not have the colon and instance number override syntax, then
95 * \p instance is still used to determine which instance of the property
96 * to set. For example, in the following call:
97 *
98 * node->set_properties("dog=10,cat:2=5,bird:0=0.5", 1)
99 *
100 * instance 1 of node's 'dog' property is set to 10, the 1 coming from the
101 * instance parameter, instance 2 of the node's 'cat' property is set to
102 * 5 due to the override syntax provided in the string, and instance 0 of
103 * the node's 'bird' property is set to 0.5 due to its override.
104 *
105 * If the instance override is malformed, that is, there is no
106 * number following the colon, or the number cannot be parsed as an
107 * integer, a value_error is thrown.
108 *
109 * If a key in \p props is not a valid property of this block, a warning is
110 * logged, but no error is raised.
111 */
112 void set_properties(const ::uhd::device_addr_t& props, const size_t instance = 0)
113 {
114 d_block_ref->set_properties(props, instance);
115 }
116
117 /*! Set a specific user property that belongs to this block.
118 *
119 * Setting a user property will trigger a property resolution. This means
120 * that changing this block can have effects on other RFNoC blocks or nodes
121 * (like streamers).
122 *
123 * \param name The name of the property.
124 * \param value The new value of the property.
125 * \param port The port of the property.
126 */
127 template <typename T>
128 void set_property(const std::string& name, const T& value, const size_t port = 0)
129 {
130 d_block_ref->set_property<T>(name, value, port);
131 }
132
133 /*! Get the value of a specific block argument. \p The type of an argument
134 * must be known at compile time.
135 *
136 * Note: Despite this being a "getter", this function is not declared const.
137 * This is because internally, it can resolve properties, which may cause
138 * changes within the object.
139 *
140 * \param name The name of the property.
141 * \param port The port of the property.
142 * \return The value of the property.
143 */
144 template <typename T>
145 const T get_property(const std::string& name, const size_t port = 0)
146 {
147 return d_block_ref->get_property<T>(name, port);
148 }
149
150 std::vector<std::string> get_property_ids();
151
152private:
153 //! Reference to the underlying RFNoC block
154 ::uhd::rfnoc::noc_block_base::sptr d_block_ref;
155};
156
157} // namespace uhd
158} // namespace gr
159
160#endif /* INCLUDED_UHD_RFNOC_BLOCK_H */
The abstract base class for all 'terminal' processing blocks.
Definition: gnuradio-runtime/include/gnuradio/block.h:63
Definition: rfnoc_block.h:26
std::shared_ptr< block_type > get_block_ref()
Return a type-cast block reference, or throw if the cast failed.
Definition: rfnoc_block.h:57
::uhd::rfnoc::noc_block_base::sptr make_block_ref(rfnoc_graph::sptr graph, const ::uhd::device_addr_t &block_args, const std::string &block_name, const int device_select=-1, const int block_select=-1, const size_t max_ref_count=1)
Factory function to create a UHD block controller reference.
rfnoc_block(::uhd::rfnoc::noc_block_base::sptr block_ref)
void set_property(const std::string &name, const T &value, const size_t port=0)
Definition: rfnoc_block.h:128
void set_properties(const ::uhd::device_addr_t &props, const size_t instance=0)
Definition: rfnoc_block.h:112
std::vector< std::string > get_property_ids()
int general_work(int noutput_items, gr_vector_int &ninput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) override
This method should never be called by RFNoC blocks, they do the work.
std::string get_unique_id() const
std::shared_ptr< rfnoc_block > sptr
Definition: rfnoc_block.h:34
const T get_property(const std::string &name, const size_t port=0)
Definition: rfnoc_block.h:145
rfnoc_block()
Definition: rfnoc_block.h:31
std::shared_ptr< rfnoc_graph > sptr
Definition: rfnoc_graph.h:32
#define GR_UHD_API
Definition: gr-uhd/include/gnuradio/uhd/api.h:18
GNU Radio logging wrapper.
Definition: basic_block.h:29
std::vector< const void * > gr_vector_const_void_star
Definition: types.h:28
std::vector< void * > gr_vector_void_star
Definition: types.h:27
std::vector< int > gr_vector_int
Definition: types.h:23