[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] [gnuradio] 06/37: uhd: Refactored common stuff from us
From: |
git |
Subject: |
[Commit-gnuradio] [gnuradio] 06/37: uhd: Refactored common stuff from usrp sink and source |
Date: |
Thu, 17 Jul 2014 20:23:39 +0000 (UTC) |
This is an automated email from the git hooks/post-receive script.
trondeau pushed a commit to branch master
in repository gnuradio.
commit fe5853749e0cff54b04bdc06b47e996f1f4ffef2
Author: Martin Braun <address@hidden>
Date: Thu Jul 3 20:25:00 2014 +0200
uhd: Refactored common stuff from usrp sink and source
---
gr-uhd/lib/usrp_common.h | 73 +++++++++++++++++++++++++++++++++---------
gr-uhd/lib/usrp_sink_impl.cc | 25 ++++-----------
gr-uhd/lib/usrp_sink_impl.h | 10 ++----
gr-uhd/lib/usrp_source_impl.cc | 18 +++--------
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 26b743a..f7fead4 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 6942b02..42b900e 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 4cfc109..92afb69 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 278bb3d..b85b45b 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 3f0dd4a..faceb5a 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;
- [Commit-gnuradio] [gnuradio] 01/37: grc: design time values for object-like variables, (continued)
- [Commit-gnuradio] [gnuradio] 01/37: grc: design time values for object-like variables, git, 2014/07/17
- [Commit-gnuradio] [gnuradio] 04/37: uhd: Updated docs, in particular for the command interface, git, 2014/07/17
- [Commit-gnuradio] [gnuradio] 03/37: grc: allow blocks to dynamically hide some of their ports, git, 2014/07/17
- [Commit-gnuradio] [gnuradio] 10/37: uhd: Added checks for lock sensors., git, 2014/07/17
- [Commit-gnuradio] [gnuradio] 17/37: qtgui: allows users to set title and unit of Y axis for qt time plotter., git, 2014/07/17
- [Commit-gnuradio] [gnuradio] 05/37: uhd: Added command interface to uhd source, modified command syntax, git, 2014/07/17
- [Commit-gnuradio] [gnuradio] 16/37: qtgui: adding ability to set grid on/off from grc properties dialog boxes for all qtgui sinks except the "sink" which doesn't support this., git, 2014/07/17
- [Commit-gnuradio] [gnuradio] 12/37: Merge remote-tracking branch 'gnuradio-wg-grc/grc_variable_blocks', git, 2014/07/17
- [Commit-gnuradio] [gnuradio] 22/37: Merge remote-tracking branch 'gnuradio-wg-grc/grc_port_view_options', git, 2014/07/17
- [Commit-gnuradio] [gnuradio] 09/37: uhd: Added example for re-tuning through messages, git, 2014/07/17
- [Commit-gnuradio] [gnuradio] 06/37: uhd: Refactored common stuff from usrp sink and source,
git <=
- [Commit-gnuradio] [gnuradio] 23/37: qtgui: time raster display updates., git, 2014/07/17
- [Commit-gnuradio] [gnuradio] 11/37: build: missed gnuradio-uhd in static libs build., git, 2014/07/17
- [Commit-gnuradio] [gnuradio] 15/37: grc: fixing some spacing issues in various xml files., git, 2014/07/17
- [Commit-gnuradio] [gnuradio] 13/37: Merge remote-tracking branch 'gnuradio-wg-grc/grc_hide_ports', git, 2014/07/17
- [Commit-gnuradio] [gnuradio] 18/37: Merge branch 'maint', git, 2014/07/17
- [Commit-gnuradio] [gnuradio] 24/37: qtgui: fixes waterfall plots., git, 2014/07/17
- [Commit-gnuradio] [gnuradio] 25/37: qtgui: adding menu item to frequency sink to set y min/max., git, 2014/07/17
- [Commit-gnuradio] [gnuradio] 14/37: grc: fixing xml files of some blocks with message control ports to be able to hide/show them as wanted., git, 2014/07/17
- [Commit-gnuradio] [gnuradio] 21/37: qtgui: updates number sink behavor., git, 2014/07/17
- [Commit-gnuradio] [gnuradio] 20/37: grc: toogle action to disable auto-hiding port labels, git, 2014/07/17