diff options
-rw-r--r-- | gr-usrp2/src/Makefile.am | 19 | ||||
-rw-r--r-- | gr-usrp2/src/usrp2.i | 118 | ||||
-rw-r--r-- | gr-usrp2/src/usrp2_base.cc | 70 | ||||
-rw-r--r-- | gr-usrp2/src/usrp2_base.h | 74 | ||||
-rw-r--r-- | gr-usrp2/src/usrp2_sink_16sc.cc | 71 | ||||
-rw-r--r-- | gr-usrp2/src/usrp2_sink_16sc.h | 56 | ||||
-rw-r--r-- | gr-usrp2/src/usrp2_sink_32fc.cc | 37 | ||||
-rw-r--r-- | gr-usrp2/src/usrp2_sink_32fc.h | 21 | ||||
-rw-r--r-- | gr-usrp2/src/usrp2_sink_base.cc | 38 | ||||
-rw-r--r-- | gr-usrp2/src/usrp2_sink_base.h | 39 | ||||
-rw-r--r-- | gr-usrp2/src/usrp2_source_16sc.cc | 13 | ||||
-rw-r--r-- | gr-usrp2/src/usrp2_source_16sc.h | 4 | ||||
-rw-r--r-- | gr-usrp2/src/usrp2_source_32fc.cc | 13 | ||||
-rw-r--r-- | gr-usrp2/src/usrp2_source_32fc.h | 4 | ||||
-rw-r--r-- | gr-usrp2/src/usrp2_source_base.cc | 27 | ||||
-rw-r--r-- | gr-usrp2/src/usrp2_source_base.h | 32 | ||||
-rw-r--r-- | usrp2/host/include/usrp2/usrp2.h | 2 |
17 files changed, 475 insertions, 163 deletions
diff --git a/gr-usrp2/src/Makefile.am b/gr-usrp2/src/Makefile.am index da626d594..a4269f354 100644 --- a/gr-usrp2/src/Makefile.am +++ b/gr-usrp2/src/Makefile.am @@ -38,25 +38,26 @@ lib_LTLIBRARIES = libgr-usrp2.la libgr_usrp2_la_SOURCES = \ rx_16sc_handler.cc \ rx_32fc_handler.cc \ + usrp2_base.cc \ usrp2_source_base.cc \ usrp2_source_16sc.cc \ - usrp2_source_32fc.cc -# usrp2_source_16sc.cc -# usrp2_sink_base.cc -# usrp2_sink_32fc.cc -# usrp2_sink_16sc.cc + usrp2_source_32fc.cc \ + usrp2_sink_base.cc \ + usrp2_sink_16sc.cc \ + usrp2_sink_32fc.cc libgr_usrp2_la_LIBADD = \ $(USRP2_LA) \ $(GNURADIO_CORE_LA) grinclude_HEADERS = \ + usrp2_base.h \ usrp2_source_base.h \ usrp2_source_32fc.h \ - usrp2_source_16sc.h -# usrp2_sink_base.h \ -# usrp2_sink_32fc.h \ -# usrp2_sink_16sc.h + usrp2_source_16sc.h \ + usrp2_sink_base.h \ + usrp2_sink_16sc.h \ + usrp2_sink_32fc.h noinst_HEADERS = \ rx_16sc_handler.h \ diff --git a/gr-usrp2/src/usrp2.i b/gr-usrp2/src/usrp2.i index fba6c18e3..ae13ab25b 100644 --- a/gr-usrp2/src/usrp2.i +++ b/gr-usrp2/src/usrp2.i @@ -23,109 +23,135 @@ %feature("autodoc", "1"); // generate python docstrings %include "exception.i" -%import "gnuradio.i" // the common stuff +%import "gnuradio.i" // the common stuff %{ #include <gnuradio_swig_bug_workaround.h> -//#include "usrp2_sink_32fc.h" #include "usrp2_source_16sc.h" #include "usrp2_source_32fc.h" +#include "usrp2_sink_16sc.h" +#include "usrp2_sink_32fc.h" %} %include <usrp2/tune_result.h> -#if 0 // ---------------------------------------------------------------- -class usrp2_sink_base : public gr_sync_block { - +class usrp2_base : public gr_sync_block +{ protected: - usrp2_sink_base(const std::string &name, - gr_io_signature_sptr input_signature) - throw (std::runtime_error); + usrp2_base() throw (std::runtime_error); public: - ~usrp2_sink_base(); + ~usrp2_base(); + std::string mac_addr() const; }; // ---------------------------------------------------------------- -GR_SWIG_BLOCK_MAGIC(usrp2,sink_32fc) - -usrp2_sink_32fc_sptr -usrp2_make_sink_32fc() throw (std::runtime_error); - -class usrp2_sink_32fc : public usrp2_sink_base { - +class usrp2_source_base : public usrp2_base +{ protected: - usrp2_sink_32fc(); + usrp2_source_base() throw (std::runtime_error); public: - ~usrp2_sink_32fc(); + ~usrp2_source_base(); + bool set_gain(double gain); + %rename(_real_set_center_freq) set_center_freq; + bool set_center_freq(double frequency, usrp2::tune_result *r); + bool set_decim(int decimation_factor); }; -#endif // ---------------------------------------------------------------- -class usrp2_source_base : public gr_sync_block { +GR_SWIG_BLOCK_MAGIC(usrp2,source_32fc) +usrp2_source_32fc_sptr +usrp2_make_source_32fc(const std::string ifc="eth0", + const std::string mac="") + throw (std::runtime_error); + +class usrp2_source_32fc : public usrp2_source_base +{ protected: - usrp2_source_base(const char *name, - gr_io_signature_sptr output_signature) - throw (std::runtime_error); + usrp2_source_32fc(const std::string &ifc, const std::string &mac); public: - ~usrp2_source_base(); + ~usrp2_source_32fc(); }; // ---------------------------------------------------------------- -GR_SWIG_BLOCK_MAGIC(usrp2,source_32fc) +GR_SWIG_BLOCK_MAGIC(usrp2,source_16sc) -usrp2_source_32fc_sptr -usrp2_make_source_32fc(const std::string ifc, const std::string mac) +usrp2_source_16sc_sptr +usrp2_make_source_16sc(const std::string ifc="eth0", + const std::string mac="") throw (std::runtime_error); -class usrp2_source_32fc : public usrp2_source_base { +class usrp2_source_16sc : public usrp2_source_base +{ +protected: + usrp2_source_16sc(const std::string &ifc, const std::string &mac); +public: + ~usrp2_source_16sc(); + + std::string mac_addr(); +}; + +// ---------------------------------------------------------------- + +class usrp2_sink_base : public usrp2_base +{ protected: - usrp2_source_32fc(const std::string &ifc, const std::string &mac); + usrp2_sink_base() throw (std::runtime_error); public: - ~usrp2_source_32fc(); + ~usrp2_sink_base(); bool set_gain(double gain); %rename(_real_set_center_freq) set_center_freq; bool set_center_freq(double frequency, usrp2::tune_result *r); - bool set_decim(int decimation_factor); - - std::string mac_addr(); + bool set_interp(int interp_factor); }; // ---------------------------------------------------------------- -GR_SWIG_BLOCK_MAGIC(usrp2,source_16sc) +GR_SWIG_BLOCK_MAGIC(usrp2,sink_32fc) -usrp2_source_16sc_sptr -usrp2_make_source_16sc(const std::string ifc, const std::string mac) +usrp2_sink_32fc_sptr +usrp2_make_sink_32fc(const std::string ifc="eth0", + const std::string mac="") throw (std::runtime_error); -class usrp2_source_16sc : public usrp2_source_base { - +class usrp2_sink_32fc : public usrp2_sink_base +{ protected: - usrp2_source_16sc(const std::string &ifc, const std::string &mac); + usrp2_sink_32fc(const std::string &ifc, const std::string &mac); public: - ~usrp2_source_16sc(); + ~usrp2_sink_32fc(); +}; - bool set_gain(double gain); - %rename(_real_set_center_freq) set_center_freq; - bool set_center_freq(double frequency, usrp2::tune_result *r); - bool set_decim(int decimation_factor); +// ---------------------------------------------------------------- - std::string mac_addr(); +GR_SWIG_BLOCK_MAGIC(usrp2,sink_16sc) + +usrp2_sink_16sc_sptr +usrp2_make_sink_16sc(const std::string ifc="eth0", + const std::string mac="") + throw (std::runtime_error); + +class usrp2_sink_16sc : public usrp2_sink_base +{ +protected: + usrp2_sink_16sc(const std::string &ifc, const std::string &mac); + +public: + ~usrp2_sink_16sc(); }; // ---------------------------------------------------------------- @@ -143,4 +169,6 @@ def __set_center_freq(self, freq): usrp2_source_32fc_sptr.set_center_freq = __set_center_freq usrp2_source_16sc_sptr.set_center_freq = __set_center_freq +usrp2_sink_32fc_sptr.set_center_freq = __set_center_freq +usrp2_sink_16sc_sptr.set_center_freq = __set_center_freq %} diff --git a/gr-usrp2/src/usrp2_base.cc b/gr-usrp2/src/usrp2_base.cc new file mode 100644 index 000000000..19b977edb --- /dev/null +++ b/gr-usrp2/src/usrp2_base.cc @@ -0,0 +1,70 @@ +/* -*- c++ -*- */ +/* + * Copyright 2008 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <usrp2_base.h> +#include <gr_io_signature.h> +#include <iostream> + +usrp2_base::usrp2_base(const char *name, + gr_io_signature_sptr input_signature, + gr_io_signature_sptr output_signature, + const std::string &ifc, + const std::string &mac) + throw (std::runtime_error) + : gr_sync_block(name, + input_signature, + output_signature), + d_u2(usrp2::usrp2::sptr()) +{ + d_u2 = usrp2::usrp2::make(ifc, mac); + if (!d_u2) + throw std::runtime_error("Unable to initialize USRP2!"); +} + +usrp2_base::~usrp2_base () +{ + // NOP +} + +std::string +usrp2_base::mac_addr() const +{ + return d_u2->mac_addr(); +} + +bool +usrp2_base::start() +{ + // Default implementation is NOP + return true; +} + +bool +usrp2_base::stop() +{ + // Default implementation is NOP + return true; +} diff --git a/gr-usrp2/src/usrp2_base.h b/gr-usrp2/src/usrp2_base.h new file mode 100644 index 000000000..ad99b4eda --- /dev/null +++ b/gr-usrp2/src/usrp2_base.h @@ -0,0 +1,74 @@ +/* -*- c++ -*- */ +/* + * Copyright 2008 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_USRP2_BASE_H +#define INCLUDED_USRP2_BASE_H + +#include <gr_sync_block.h> +#include <usrp2/usrp2.h> +#include <stdexcept> + +// BIG ASS FIXME: get from lower layer MTU calculation +#define USRP2_MIN_RX_SAMPLES 371 + +/*! + * Base class for all USRP2 blocks + */ +class usrp2_base : public gr_sync_block +{ +protected: + usrp2_base(const char *name, + gr_io_signature_sptr input_signature, + gr_io_signature_sptr output_signature, + const std::string &ifc, + const std::string &mac) + throw (std::runtime_error); + + usrp2::usrp2::sptr d_u2; + +public: + ~usrp2_base(); + + /*! + * \brief Get USRP2 hardware MAC address + */ + std::string mac_addr() const; + + /*! + * \brief Called by scheduler when starting flowgraph + */ + virtual bool start(); + + /*! + * \brief Called by scheduler when stopping flowgraph + */ + virtual bool stop(); + + /*! + * \brief Derived class must override this + */ + virtual int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) = 0; +}; + +#endif /* INCLUDED_USRP2_BASE_H */ diff --git a/gr-usrp2/src/usrp2_sink_16sc.cc b/gr-usrp2/src/usrp2_sink_16sc.cc new file mode 100644 index 000000000..fd87ea868 --- /dev/null +++ b/gr-usrp2/src/usrp2_sink_16sc.cc @@ -0,0 +1,71 @@ +/* -*- c++ -*- */ +/* + * Copyright 2008 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <usrp2_sink_16sc.h> +#include <usrp2/metadata.h> +#include <gr_io_signature.h> +#include <iostream> + +usrp2_sink_16sc_sptr +usrp2_make_sink_16sc(const std::string &ifc, const std::string &mac_addr) + throw (std::runtime_error) +{ + return usrp2_sink_16sc_sptr(new usrp2_sink_16sc(ifc, mac_addr)); +} + +usrp2_sink_16sc::usrp2_sink_16sc(const std::string &ifc, const std::string &mac_addr) + throw (std::runtime_error) + : usrp2_sink_base("usrp2_sink_16sc", + gr_make_io_signature(1, 1, sizeof(std::complex<int16_t>)), + ifc, mac_addr) +{ + // NOP +} + +usrp2_sink_16sc::~usrp2_sink_16sc() +{ + // NOP +} + +int +usrp2_sink_16sc::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + std::complex<int16_t> *in = (std::complex<int16_t> *)input_items[0]; + + usrp2::tx_metadata metadata; + metadata.timestamp = -1; + metadata.send_now = 1; + metadata.start_of_burst = 1; + + bool ok = d_u2->tx_complex_int16(0, // FIXME: someday, streams will have channel numbers + in, noutput_items, &metadata); + if (!ok) + std::cerr << "usrp2_sink_16sc: tx_complex_int16 failed" << std::endl; + + return noutput_items; +} diff --git a/gr-usrp2/src/usrp2_sink_16sc.h b/gr-usrp2/src/usrp2_sink_16sc.h new file mode 100644 index 000000000..489d15295 --- /dev/null +++ b/gr-usrp2/src/usrp2_sink_16sc.h @@ -0,0 +1,56 @@ +/* -*- c++ -*- */ +/* + * Copyright 2008 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_USRP2_SINK_16SC_H +#define INCLUDED_USRP2_SINK_16SC_H + +#include <usrp2_sink_base.h> + +class usrp2_sink_16sc; +typedef boost::shared_ptr<usrp2_sink_16sc> usrp2_sink_16sc_sptr; + +usrp2_sink_16sc_sptr +usrp2_make_sink_16sc(const std::string &ifc="eth0", + const std::string &mac="") + throw (std::runtime_error); + +class usrp2_sink_16sc : public usrp2_sink_base +{ +private: + friend usrp2_sink_16sc_sptr + usrp2_make_sink_16sc(const std::string &ifc, + const std::string &mac) + throw (std::runtime_error); + +protected: + usrp2_sink_16sc(const std::string &ifc, const std::string &mac) + throw (std::runtime_error); + +public: + ~usrp2_sink_16sc(); + + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); +}; + +#endif /* INCLUDED_USRP2_SINK_16SC_H */ diff --git a/gr-usrp2/src/usrp2_sink_32fc.cc b/gr-usrp2/src/usrp2_sink_32fc.cc index 56cde6ba7..acbba7aba 100644 --- a/gr-usrp2/src/usrp2_sink_32fc.cc +++ b/gr-usrp2/src/usrp2_sink_32fc.cc @@ -25,22 +25,47 @@ #endif #include <usrp2_sink_32fc.h> +#include <usrp2/metadata.h> #include <gr_io_signature.h> -#include <usrp_standard.h> -#include <usrp_bytesex.h> +#include <iostream> usrp2_sink_32fc_sptr -usrp2_make_sink_32fc() throw (std::runtime_error) +usrp2_make_sink_32fc(const std::string &ifc, const std::string &mac_addr) + throw (std::runtime_error) { - return usrp2_sink_32fc_sptr(new usrp2_sink_32fc()); + return usrp2_sink_32fc_sptr(new usrp2_sink_32fc(ifc, mac_addr)); } -usrp2_sink_32fc::usrp2_sink_32fc() throw (std::runtime_error) +usrp2_sink_32fc::usrp2_sink_32fc(const std::string &ifc, const std::string &mac_addr) + throw (std::runtime_error) : usrp2_sink_base("usrp2_sink_32fc", - gr_make_io_signature(1, 1, sizeof(gr_complex))) + gr_make_io_signature(1, 1, sizeof(gr_complex)), + ifc, mac_addr) { + // NOP } usrp2_sink_32fc::~usrp2_sink_32fc() { + // NOP +} + +int +usrp2_sink_32fc::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + gr_complex *in = (gr_complex *)input_items[0]; + + usrp2::tx_metadata metadata; + metadata.timestamp = -1; + metadata.send_now = 1; + metadata.start_of_burst = 1; + + bool ok = d_u2->tx_complex_float(0, // FIXME: someday, streams will have channel numbers + in, noutput_items, &metadata); + if (!ok) + std::cerr << "usrp2_sink_32fc: tx_complex_float failed" << std::endl; + + return noutput_items; } diff --git a/gr-usrp2/src/usrp2_sink_32fc.h b/gr-usrp2/src/usrp2_sink_32fc.h index eeb80b19c..4e213abe7 100644 --- a/gr-usrp2/src/usrp2_sink_32fc.h +++ b/gr-usrp2/src/usrp2_sink_32fc.h @@ -29,19 +29,28 @@ class usrp2_sink_32fc; typedef boost::shared_ptr<usrp2_sink_32fc> usrp2_sink_32fc_sptr; usrp2_sink_32fc_sptr -usrp2_make_sink_32fc() throw (std::runtime_error); +usrp2_make_sink_32fc(const std::string &ifc="eth0", + const std::string &mac="") + throw (std::runtime_error); -class usrp2_sink_32fc : public usrp2_sink_base { +class usrp2_sink_32fc : public usrp2_sink_base +{ private: - friend usrp2_sink_32fc_sptr - usrp2_make_sink_32fc() throw (std::runtime_error); - + usrp2_make_sink_32fc(const std::string &ifc, + const std::string &mac) + throw (std::runtime_error); + protected: - usrp2_sink_32fc() throw (std::runtime_error); + usrp2_sink_32fc(const std::string &ifc, const std::string &mac) + throw (std::runtime_error); public: ~usrp2_sink_32fc(); + + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); }; #endif /* INCLUDED_USRP2_SINK_32FC_H */ diff --git a/gr-usrp2/src/usrp2_sink_base.cc b/gr-usrp2/src/usrp2_sink_base.cc index ebef93902..8a622d65f 100644 --- a/gr-usrp2/src/usrp2_sink_base.cc +++ b/gr-usrp2/src/usrp2_sink_base.cc @@ -26,24 +26,42 @@ #include <usrp2_sink_base.h> #include <gr_io_signature.h> +#include <iostream> -usrp2_sink_base::usrp2_sink_base(const std::string &name, - gr_io_signature_sptr input_signature) +#define USRP2_SINK_BASE_DEBUG 0 + +usrp2_sink_base::usrp2_sink_base(const char *name, + gr_io_signature_sptr input_signature, + const std::string &ifc, + const std::string &mac) throw (std::runtime_error) - : gr_sync_block(name, - input_signature, - gr_make_io_signature(0, 0, 0)) + : usrp2_base(name, + input_signature, + gr_make_io_signature(0, 0, 0), + ifc, mac) { + // NOP } usrp2_sink_base::~usrp2_sink_base () { + // NOP +} + +bool +usrp2_sink_base::set_gain(double gain) +{ + return d_u2->set_tx_gain(gain); +} + +bool +usrp2_sink_base::set_center_freq(double frequency, usrp2::tune_result *tr) +{ + return d_u2->set_tx_center_freq(frequency, tr); } -int -usrp2_sink_base::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) +bool +usrp2_sink_base::set_interp(int interp_factor) { - return noutput_items; + return d_u2->set_tx_interp(interp_factor); } diff --git a/gr-usrp2/src/usrp2_sink_base.h b/gr-usrp2/src/usrp2_sink_base.h index a999a6cac..8396c08f7 100644 --- a/gr-usrp2/src/usrp2_sink_base.h +++ b/gr-usrp2/src/usrp2_sink_base.h @@ -23,24 +23,37 @@ #ifndef INCLUDED_USRP2_SINK_BASE_H #define INCLUDED_USRP2_SINK_BASE_H -#include <gr_sync_block.h> -#include <stdexcept> - -class usrp2_sink_base : public gr_sync_block { - -private: +#include <usrp2_base.h> +/*! + * Base class for all USRP2 transmit blocks + */ +class usrp2_sink_base : public usrp2_base +{ protected: - usrp2_sink_base(const std::string &name, - gr_io_signature_sptr input_signature) + usrp2_sink_base(const char *name, + gr_io_signature_sptr input_signature, + const std::string &ifc, + const std::string &mac) throw (std::runtime_error); - + public: ~usrp2_sink_base(); - - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); + + /*! + * \brief Set transmitter gain + */ + bool set_gain(double gain); + + /*! + * \brief Set transmitter center frequency + */ + bool set_center_freq(double frequency, usrp2::tune_result *tr); + + /*! + * \brief Set transmit interpolation rate + */ + bool set_interp(int interp_factor); }; #endif /* INCLUDED_USRP2_SINK_BASE_H */ diff --git a/gr-usrp2/src/usrp2_source_16sc.cc b/gr-usrp2/src/usrp2_source_16sc.cc index b60b61c1b..b12a6eece 100644 --- a/gr-usrp2/src/usrp2_source_16sc.cc +++ b/gr-usrp2/src/usrp2_source_16sc.cc @@ -29,8 +29,6 @@ #include <gr_io_signature.h> #include <iostream> -#define USRP2_SOURCE_16SC_DEBUG 0 - usrp2_source_16sc_sptr usrp2_make_source_16sc(const std::string &ifc, const std::string &mac_addr) throw (std::runtime_error) @@ -56,9 +54,6 @@ usrp2_source_16sc::work(int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) { - if (USRP2_SOURCE_16SC_DEBUG) - printf("work: noutput_items=%i\n", noutput_items); - std::complex<int16_t> *out = (std::complex<int16_t> *)output_items[0]; rx_16sc_handler::sptr handler = rx_16sc_handler::make(noutput_items, USRP2_MIN_RX_SAMPLES, out); @@ -67,11 +62,5 @@ usrp2_source_16sc::work(int noutput_items, if (!ok) std::cerr << "usrp2::rx_samples() failed" << std::endl; - int j = handler->nsamples(); - int f = handler->nframes(); - - if (USRP2_SOURCE_16SC_DEBUG) - printf("work: produced=%i items from %i frames\n\n", j, f); - - return j; + return handler->nsamples(); } diff --git a/gr-usrp2/src/usrp2_source_16sc.h b/gr-usrp2/src/usrp2_source_16sc.h index fa277f733..7a6b8e596 100644 --- a/gr-usrp2/src/usrp2_source_16sc.h +++ b/gr-usrp2/src/usrp2_source_16sc.h @@ -33,8 +33,8 @@ usrp2_make_source_16sc(const std::string &ifc="eth0", const std::string &mac="") throw (std::runtime_error); -class usrp2_source_16sc : public usrp2_source_base { - +class usrp2_source_16sc : public usrp2_source_base +{ private: friend usrp2_source_16sc_sptr usrp2_make_source_16sc(const std::string &ifc, diff --git a/gr-usrp2/src/usrp2_source_32fc.cc b/gr-usrp2/src/usrp2_source_32fc.cc index 0d34931a5..0d2418518 100644 --- a/gr-usrp2/src/usrp2_source_32fc.cc +++ b/gr-usrp2/src/usrp2_source_32fc.cc @@ -29,8 +29,6 @@ #include <gr_io_signature.h> #include <iostream> -#define USRP2_SOURCE_32FC_DEBUG 0 - usrp2_source_32fc_sptr usrp2_make_source_32fc(const std::string &ifc, const std::string &mac_addr) throw (std::runtime_error) @@ -56,9 +54,6 @@ usrp2_source_32fc::work(int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) { - if (USRP2_SOURCE_32FC_DEBUG) - printf("work: noutput_items=%i\n", noutput_items); - gr_complex *out = (gr_complex *)output_items[0]; rx_32fc_handler::sptr handler = rx_32fc_handler::make(noutput_items, USRP2_MIN_RX_SAMPLES, out); @@ -67,11 +62,5 @@ usrp2_source_32fc::work(int noutput_items, if (!ok) std::cerr << "usrp2::rx_samples() failed" << std::endl; - int j = handler->nsamples(); - int f = handler->nframes(); - - if (USRP2_SOURCE_32FC_DEBUG) - printf("work: produced=%i items from %i frames\n\n", j, f); - - return j; + return handler->nsamples(); } diff --git a/gr-usrp2/src/usrp2_source_32fc.h b/gr-usrp2/src/usrp2_source_32fc.h index c60910918..26b40ad3f 100644 --- a/gr-usrp2/src/usrp2_source_32fc.h +++ b/gr-usrp2/src/usrp2_source_32fc.h @@ -33,8 +33,8 @@ usrp2_make_source_32fc(const std::string &ifc="eth0", const std::string &mac="") throw (std::runtime_error); -class usrp2_source_32fc : public usrp2_source_base { - +class usrp2_source_32fc : public usrp2_source_base +{ private: friend usrp2_source_32fc_sptr usrp2_make_source_32fc(const std::string &ifc, diff --git a/gr-usrp2/src/usrp2_source_base.cc b/gr-usrp2/src/usrp2_source_base.cc index 631b50c14..e83014308 100644 --- a/gr-usrp2/src/usrp2_source_base.cc +++ b/gr-usrp2/src/usrp2_source_base.cc @@ -28,25 +28,22 @@ #include <gr_io_signature.h> #include <iostream> -#define USRP2_SOURCE_BASE_DEBUG 0 - usrp2_source_base::usrp2_source_base(const char *name, gr_io_signature_sptr output_signature, const std::string &ifc, const std::string &mac) throw (std::runtime_error) - : gr_sync_block(name, - gr_make_io_signature(0, 0, 0), - output_signature), - d_u2(usrp2::usrp2::sptr()) + : usrp2_base(name, + gr_make_io_signature(0, 0, 0), + output_signature, + ifc, mac) { - d_u2 = usrp2::usrp2::make(ifc, mac); - if (!d_u2) - throw std::runtime_error("Unable to initialize USRP2!"); + // NOP } usrp2_source_base::~usrp2_source_base () { + // NOP } bool @@ -67,26 +64,14 @@ usrp2_source_base::set_decim(int decimation_factor) return d_u2->set_rx_decim(decimation_factor); } -std::string -usrp2_source_base::mac_addr() -{ - return d_u2->mac_addr(); -} - bool usrp2_source_base::start() { - if (USRP2_SOURCE_BASE_DEBUG) - printf("usrp2_source_base::start()\n"); - return d_u2->start_rx_streaming(0); // FIXME: someday sources will have channel #s } bool usrp2_source_base::stop() { - if (USRP2_SOURCE_BASE_DEBUG) - printf("usrp2_source_base::stop()\n"); - return d_u2->stop_rx_streaming(0); // FIXME: someday sources will have channel #s } diff --git a/gr-usrp2/src/usrp2_source_base.h b/gr-usrp2/src/usrp2_source_base.h index 34d9fea0b..f6bf10059 100644 --- a/gr-usrp2/src/usrp2_source_base.h +++ b/gr-usrp2/src/usrp2_source_base.h @@ -23,15 +23,13 @@ #ifndef INCLUDED_USRP2_SOURCE_BASE_H #define INCLUDED_USRP2_SOURCE_BASE_H -#include <gr_sync_block.h> -#include <usrp2/usrp2.h> -#include <stdexcept> +#include <usrp2_base.h> -// BIG ASS FIXME: get from lower layer MTU calculation -#define USRP2_MIN_RX_SAMPLES 371 - -class usrp2_source_base : public gr_sync_block { - +/*! + * Base class for all USRP2 source blocks + */ +class usrp2_source_base : public usrp2_base +{ protected: usrp2_source_base(const char *name, gr_io_signature_sptr output_signature, @@ -39,8 +37,6 @@ protected: const std::string &mac) throw (std::runtime_error); - usrp2::usrp2::sptr d_u2; - public: ~usrp2_source_base(); @@ -60,26 +56,14 @@ public: bool set_decim(int decimation_factor); /*! - * \brief Get USRP2 hardware MAC address - */ - std::string mac_addr(); - - /*! * \brief Called by scheduler when starting flowgraph */ - bool start(); + virtual bool start(); /*! * \brief Called by scheduler when stopping flowgraph */ - bool stop(); - - /*! - * \brief Derived class must override this - */ - virtual int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) = 0; + virtual bool stop(); }; #endif /* INCLUDED_USRP2_SOURCE_BASE_H */ diff --git a/usrp2/host/include/usrp2/usrp2.h b/usrp2/host/include/usrp2/usrp2.h index 874337911..4e875d343 100644 --- a/usrp2/host/include/usrp2/usrp2.h +++ b/usrp2/host/include/usrp2/usrp2.h @@ -171,7 +171,7 @@ namespace usrp2 { */ /*! - * Set receiver gain + * Set transmitter gain */ bool set_tx_gain(double gain); |