diff options
author | Martin Braun <martin.braun@ettus.com> | 2014-07-03 20:25:00 +0200 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2014-07-07 23:12:09 +0200 |
commit | fe5853749e0cff54b04bdc06b47e996f1f4ffef2 (patch) | |
tree | f729c85ca94152d8598c3995b718502d6164483f /gr-uhd | |
parent | 350d285a27ee6ea0f448a778551cdd3a5ffcedba (diff) |
uhd: Refactored common stuff from usrp sink and source
Diffstat (limited to 'gr-uhd')
-rw-r--r-- | gr-uhd/lib/usrp_common.h | 73 | ||||
-rw-r--r-- | gr-uhd/lib/usrp_sink_impl.cc | 25 | ||||
-rw-r--r-- | gr-uhd/lib/usrp_sink_impl.h | 10 | ||||
-rw-r--r-- | gr-uhd/lib/usrp_source_impl.cc | 18 | ||||
-rw-r--r-- | gr-uhd/lib/usrp_source_impl.h | 13 |
5 files changed, 74 insertions, 65 deletions
diff --git a/gr-uhd/lib/usrp_common.h b/gr-uhd/lib/usrp_common.h index 26b743a90f..f7fead4f5c 100644 --- a/gr-uhd/lib/usrp_common.h +++ b/gr-uhd/lib/usrp_common.h @@ -25,6 +25,9 @@ #include <pmt/pmt.h> #include <boost/dynamic_bitset.hpp> +#include <boost/make_shared.hpp> +#include <uhd/usrp/multi_usrp.hpp> +#include <uhd/convert.hpp> namespace gr { namespace uhd { @@ -67,32 +70,70 @@ namespace gr { // vector_to_update are set to 1 template <typename T> static boost::dynamic_bitset<> _update_vector_from_cmd_val( - std::vector<T> &vector_to_update, - int chan, - const T cmd_val, - bool minus_one_updates_all = false + std::vector<T> &vector_to_update, + int chan, + const T cmd_val, + bool minus_one_updates_all = false ) { boost::dynamic_bitset<> vals_updated(vector_to_update.size()); if (chan == -1) { - if (minus_one_updates_all) { - for (size_t i = 0; i < vector_to_update.size(); i++) { - if (vector_to_update[i] != cmd_val) { - vals_updated[i] = true; - vector_to_update[i] = cmd_val; - } - } - return vals_updated; - } - chan = 0; + if (minus_one_updates_all) { + for (size_t i = 0; i < vector_to_update.size(); i++) { + if (vector_to_update[i] != cmd_val) { + vals_updated[i] = true; + vector_to_update[i] = cmd_val; + } + } + return vals_updated; + } + chan = 0; } if (vector_to_update[chan] != cmd_val) { - vector_to_update[chan] = cmd_val; - vals_updated[chan] = true; + vector_to_update[chan] = cmd_val; + vals_updated[chan] = true; } return vals_updated; } + /*! \brief Components common to USRP sink and source. + * + */ + class usrp_common_impl + { + public: + usrp_common_impl( + const ::uhd::device_addr_t &device_addr, + const ::uhd::stream_args_t &stream_args, + const std::string &ts_tag_name + ) : + _stream_args(stream_args), + _nchan(stream_args.channels.size()), + _stream_now(_nchan == 1 and ts_tag_name.empty()), + _start_time_set(false) + { + if(stream_args.cpu_format == "fc32") + _type = boost::make_shared< ::uhd::io_type_t >(::uhd::io_type_t::COMPLEX_FLOAT32); + if(stream_args.cpu_format == "sc16") + _type = boost::make_shared< ::uhd::io_type_t >(::uhd::io_type_t::COMPLEX_INT16); + _dev = ::uhd::usrp::multi_usrp::make(device_addr); + }; + + ~usrp_common_impl() {}; + + + protected: + //! Shared pointer to the underlying multi_usrp object + ::uhd::usrp::multi_usrp::sptr _dev; + const ::uhd::stream_args_t _stream_args; + boost::shared_ptr< ::uhd::io_type_t > _type; + //! Number of channels (i.e. number of in- or outputs) + size_t _nchan; + bool _stream_now; + ::uhd::time_spec_t _start_time; + bool _start_time_set; + }; + } /* namespace uhd */ } /* namespace gr */ diff --git a/gr-uhd/lib/usrp_sink_impl.cc b/gr-uhd/lib/usrp_sink_impl.cc index 6942b024ee..42b900e00b 100644 --- a/gr-uhd/lib/usrp_sink_impl.cc +++ b/gr-uhd/lib/usrp_sink_impl.cc @@ -22,11 +22,9 @@ #include <climits> #include <stdexcept> -#include "usrp_common.h" #include "usrp_sink_impl.h" #include "gr_uhd_common.h" #include <gnuradio/io_signature.h> -#include <boost/make_shared.hpp> namespace gr { namespace uhd { @@ -69,27 +67,18 @@ namespace gr { : sync_block("gr uhd usrp sink", args_to_io_sig(stream_args), io_signature::make(0, 0, 0)), - _stream_args(stream_args), - _nchan(stream_args.channels.size()), - _stream_now(_nchan == 1 and length_tag_name.empty()), - _start_time_set(false), + usrp_common_impl(device_addr, stream_args, length_tag_name), _length_tag_key(length_tag_name.empty() ? pmt::PMT_NIL : pmt::string_to_symbol(length_tag_name)), _nitems_to_send(0), - _curr_freq(stream_args.channels.size(), 0.0), - _curr_lo_offset(stream_args.channels.size(), 0.0), - _curr_gain(stream_args.channels.size(), 0.0), - _chans_to_tune(stream_args.channels.size()) + _curr_freq(stream_args.channels.size(), 0.0), + _curr_lo_offset(stream_args.channels.size(), 0.0), + _curr_gain(stream_args.channels.size(), 0.0), + _chans_to_tune(stream_args.channels.size()) { - if(stream_args.cpu_format == "fc32") - _type = boost::make_shared< ::uhd::io_type_t >(::uhd::io_type_t::COMPLEX_FLOAT32); - if(stream_args.cpu_format == "sc16") - _type = boost::make_shared< ::uhd::io_type_t >(::uhd::io_type_t::COMPLEX_INT16); - _dev = ::uhd::usrp::multi_usrp::make(device_addr); - message_port_register_in(pmt::mp("command")); set_msg_handler( - pmt::mp("command"), - boost::bind(&usrp_sink_impl::msg_handler_command, this, _1) + pmt::mp("command"), + boost::bind(&usrp_sink_impl::msg_handler_command, this, _1) ); } diff --git a/gr-uhd/lib/usrp_sink_impl.h b/gr-uhd/lib/usrp_sink_impl.h index 4cfc1091e2..92afb69640 100644 --- a/gr-uhd/lib/usrp_sink_impl.h +++ b/gr-uhd/lib/usrp_sink_impl.h @@ -22,6 +22,7 @@ #include <gnuradio/uhd/usrp_sink.h> #include <uhd/convert.hpp> +#include "usrp_common.h" static const pmt::pmt_t SOB_KEY = pmt::string_to_symbol("tx_sob"); static const pmt::pmt_t EOB_KEY = pmt::string_to_symbol("tx_eob"); @@ -51,7 +52,7 @@ namespace gr { /*********************************************************************** * UHD Multi USRP Sink Impl **********************************************************************/ - class usrp_sink_impl : public usrp_sink + class usrp_sink_impl : public usrp_sink, public usrp_common_impl { public: usrp_sink_impl(const ::uhd::device_addr_t &device_addr, @@ -127,19 +128,12 @@ namespace gr { //! Calls _set_center_freq_from_internals() on all channels void _set_center_freq_from_internals_allchans(); - ::uhd::usrp::multi_usrp::sptr _dev; - const ::uhd::stream_args_t _stream_args; - boost::shared_ptr< ::uhd::io_type_t > _type; #ifdef GR_UHD_USE_STREAM_API ::uhd::tx_streamer::sptr _tx_stream; #endif - size_t _nchan; - bool _stream_now; ::uhd::tx_metadata_t _metadata; double _sample_rate; - ::uhd::time_spec_t _start_time; - bool _start_time_set; //stream tags related stuff std::vector<tag_t> _tags; diff --git a/gr-uhd/lib/usrp_source_impl.cc b/gr-uhd/lib/usrp_source_impl.cc index 278bb3d652..b85b45b16b 100644 --- a/gr-uhd/lib/usrp_source_impl.cc +++ b/gr-uhd/lib/usrp_source_impl.cc @@ -67,25 +67,17 @@ namespace gr { sync_block("gr uhd usrp source", io_signature::make(0, 0, 0), args_to_io_sig(stream_args)), - _stream_args(stream_args), - _nchan(stream_args.channels.size()), - _stream_now(_nchan == 1), - _tag_now(false), - _start_time_set(false) - { - if(stream_args.cpu_format == "fc32") - _type = boost::make_shared< ::uhd::io_type_t >(::uhd::io_type_t::COMPLEX_FLOAT32); - if(stream_args.cpu_format == "sc16") - _type = boost::make_shared< ::uhd::io_type_t >(::uhd::io_type_t::COMPLEX_INT16); + usrp_common_impl(device_addr, stream_args, ""), + _tag_now(false) + { std::stringstream str; str << name() << unique_id(); _id = pmt::string_to_symbol(str.str()); - _dev = ::uhd::usrp::multi_usrp::make(device_addr); message_port_register_in(pmt::mp("command")); set_msg_handler( - pmt::mp("command"), - boost::bind(&usrp_source_impl::msg_handler_command, this, _1) + pmt::mp("command"), + boost::bind(&usrp_source_impl::msg_handler_command, this, _1) ); } diff --git a/gr-uhd/lib/usrp_source_impl.h b/gr-uhd/lib/usrp_source_impl.h index 3f0dd4afde..faceb5a177 100644 --- a/gr-uhd/lib/usrp_source_impl.h +++ b/gr-uhd/lib/usrp_source_impl.h @@ -23,6 +23,7 @@ #include <gnuradio/uhd/usrp_source.h> #include <uhd/convert.hpp> #include <boost/thread/mutex.hpp> +#include "usrp_common.h" static const pmt::pmt_t TIME_KEY = pmt::string_to_symbol("rx_time"); static const pmt::pmt_t RATE_KEY = pmt::string_to_symbol("rx_rate"); @@ -50,7 +51,7 @@ namespace gr { /*********************************************************************** * UHD Multi USRP Source Impl **********************************************************************/ - class usrp_source_impl : public usrp_source + class usrp_source_impl : public usrp_source, public usrp_common_impl { public: usrp_source_impl(const ::uhd::device_addr_t &device_addr, @@ -124,22 +125,14 @@ namespace gr { gr_vector_void_star &output_items); private: - ::uhd::usrp::multi_usrp::sptr _dev; - const ::uhd::stream_args_t _stream_args; - boost::shared_ptr< ::uhd::io_type_t > _type; - #ifdef GR_UHD_USE_STREAM_API ::uhd::rx_streamer::sptr _rx_stream; size_t _samps_per_packet; #endif - size_t _nchan; - bool _stream_now, _tag_now; + bool _tag_now; ::uhd::rx_metadata_t _metadata; pmt::pmt_t _id; - ::uhd::time_spec_t _start_time; - bool _start_time_set; - //tag shadows double _samp_rate; double _center_freq; |