diff options
23 files changed, 284 insertions, 143 deletions
diff --git a/config/grc_gr_uhd.m4 b/config/grc_gr_uhd.m4 index 80052bb50..e94747c1a 100644 --- a/config/grc_gr_uhd.m4 +++ b/config/grc_gr_uhd.m4 @@ -26,8 +26,8 @@ AC_DEFUN([GRC_GR_UHD],[ if test $passed = yes; then dnl Don't do gr-uhd if the 'uhd' package is not installed PKG_CHECK_MODULES( - [UHD], [uhd >= 1.0.0 uhd < 2.0.0], [], - [passed=no; AC_MSG_RESULT([gr-uhd requires libuhd 1.x.x])] + [UHD], [uhd >= 2.0.0 uhd < 3.0.0], [], + [passed=no; AC_MSG_RESULT([gr-uhd requires libuhd 2.x.x])] ) UHD_CPPFLAGS="${UHD_CPPFLAGS} -I\${abs_top_srcdir}/gr-uhd/lib" AC_SUBST(UHD_CPPFLAGS) diff --git a/config/grc_grc.m4 b/config/grc_grc.m4 index 446bba3c5..c21acccff 100644 --- a/config/grc_grc.m4 +++ b/config/grc_grc.m4 @@ -1,4 +1,4 @@ -dnl Copyright 2008, 2009 Free Software Foundation, Inc. +dnl Copyright 2008, 2009, 2011 Free Software Foundation, Inc. dnl dnl This file is part of GNU Radio dnl @@ -20,8 +20,6 @@ dnl Boston, MA 02110-1301, USA. AC_DEFUN([GRC_GRC],[ GRC_ENABLE(grc) -dnl GRC_CHECK_DEPENDENCY(grc, gr-wxgui) - AC_CHECK_PROG(XDG_UTILS, xdg-mime, true, false) AM_CONDITIONAL(XDG_UTILS, $XDG_UTILS) @@ -33,6 +31,7 @@ dnl GRC_CHECK_DEPENDENCY(grc, gr-wxgui) PYTHON_CHECK_MODULE([Cheetah],[Python Cheetah templates >= 2.0.0],[],[passed=no],[Cheetah.Version >= "2.0.0"]) PYTHON_CHECK_MODULE([lxml.etree],[Python lxml wrappers >= 1.3.6],[],[passed=no],[lxml.etree.LXML_VERSION >= (1, 3, 6, 0)]) PYTHON_CHECK_MODULE([gtk],[Python gtk wrappers >= 2.10.0],[],[passed=no],[gtk.pygtk_version >= (2, 10, 0)]) + PYTHON_CHECK_MODULE([numpy],[NumPy],[],[passed=no],[True]) fi dnl ######################################## diff --git a/gr-qtgui/src/lib/FrequencyDisplayPlot.h b/gr-qtgui/src/lib/FrequencyDisplayPlot.h index c78e1667e..3c22c1397 100644 --- a/gr-qtgui/src/lib/FrequencyDisplayPlot.h +++ b/gr-qtgui/src/lib/FrequencyDisplayPlot.h @@ -1,6 +1,7 @@ #ifndef FREQUENCY_DISPLAY_PLOT_HPP #define FREQUENCY_DISPLAY_PLOT_HPP +#include <stdint.h> #include <cstdio> #include <qwt_plot.h> #include <qwt_painter.h> diff --git a/gr-qtgui/src/lib/SpectrumGUIClass.cc b/gr-qtgui/src/lib/SpectrumGUIClass.cc index 563ed34ba..052730fc2 100644 --- a/gr-qtgui/src/lib/SpectrumGUIClass.cc +++ b/gr-qtgui/src/lib/SpectrumGUIClass.cc @@ -6,8 +6,8 @@ #include <QEvent> #include <QCustomEvent> -const long SpectrumGUIClass::MAX_FFT_SIZE; -const long SpectrumGUIClass::MIN_FFT_SIZE; +const long SpectrumGUIClass::MAX_FFT_SIZE = 32768; +const long SpectrumGUIClass::MIN_FFT_SIZE = 1024; SpectrumGUIClass::SpectrumGUIClass(const uint64_t maxDataSize, const uint64_t fftSize, diff --git a/gr-qtgui/src/lib/SpectrumGUIClass.h b/gr-qtgui/src/lib/SpectrumGUIClass.h index 63a340c34..57a749a6a 100644 --- a/gr-qtgui/src/lib/SpectrumGUIClass.h +++ b/gr-qtgui/src/lib/SpectrumGUIClass.h @@ -67,8 +67,8 @@ public: void DecrementPendingGUIUpdateEvents(); void ResetPendingGUIUpdateEvents(); - static const long MAX_FFT_SIZE = /*1048576*/32768; - static const long MIN_FFT_SIZE = 1024; + static const long MAX_FFT_SIZE; + static const long MIN_FFT_SIZE; QWidget* qwidget(); diff --git a/gr-qtgui/src/lib/TimeDomainDisplayPlot.h b/gr-qtgui/src/lib/TimeDomainDisplayPlot.h index 5525bbabe..952b5c8cf 100644 --- a/gr-qtgui/src/lib/TimeDomainDisplayPlot.h +++ b/gr-qtgui/src/lib/TimeDomainDisplayPlot.h @@ -1,6 +1,7 @@ #ifndef TIME_DOMAIN_DISPLAY_PLOT_HPP #define TIME_DOMAIN_DISPLAY_PLOT_HPP +#include <stdint.h> #include <cstdio> #include <qwt_plot.h> #include <qwt_painter.h> diff --git a/gr-qtgui/src/lib/WaterfallDisplayPlot.cc b/gr-qtgui/src/lib/WaterfallDisplayPlot.cc index 680c44756..805af1d8d 100644 --- a/gr-qtgui/src/lib/WaterfallDisplayPlot.cc +++ b/gr-qtgui/src/lib/WaterfallDisplayPlot.cc @@ -210,12 +210,6 @@ private: }; -const int WaterfallDisplayPlot::INTENSITY_COLOR_MAP_TYPE_MULTI_COLOR; -const int WaterfallDisplayPlot::INTENSITY_COLOR_MAP_TYPE_WHITE_HOT; -const int WaterfallDisplayPlot::INTENSITY_COLOR_MAP_TYPE_BLACK_HOT; -const int WaterfallDisplayPlot::INTENSITY_COLOR_MAP_TYPE_INCANDESCENT; -const int WaterfallDisplayPlot::INTENSITY_COLOR_MAP_TYPE_USER_DEFINED; - WaterfallDisplayPlot::WaterfallDisplayPlot(QWidget* parent) : QwtPlot(parent) { diff --git a/gr-qtgui/src/lib/WaterfallDisplayPlot.h b/gr-qtgui/src/lib/WaterfallDisplayPlot.h index a5ccaec40..6b4e978bb 100644 --- a/gr-qtgui/src/lib/WaterfallDisplayPlot.h +++ b/gr-qtgui/src/lib/WaterfallDisplayPlot.h @@ -1,6 +1,7 @@ #ifndef WATERFALL_DISPLAY_PLOT_HPP #define WATERFALL_DISPLAY_PLOT_HPP +#include <stdint.h> #include <cstdio> #include <qwt_plot.h> #include <qwt_plot_zoomer.h> @@ -39,11 +40,13 @@ public: const QColor GetUserDefinedLowIntensityColor()const; const QColor GetUserDefinedHighIntensityColor()const; - static const int INTENSITY_COLOR_MAP_TYPE_MULTI_COLOR = 0; - static const int INTENSITY_COLOR_MAP_TYPE_WHITE_HOT = 1; - static const int INTENSITY_COLOR_MAP_TYPE_BLACK_HOT = 2; - static const int INTENSITY_COLOR_MAP_TYPE_INCANDESCENT = 3; - static const int INTENSITY_COLOR_MAP_TYPE_USER_DEFINED = 4; + enum{ + INTENSITY_COLOR_MAP_TYPE_MULTI_COLOR = 0, + INTENSITY_COLOR_MAP_TYPE_WHITE_HOT = 1, + INTENSITY_COLOR_MAP_TYPE_BLACK_HOT = 2, + INTENSITY_COLOR_MAP_TYPE_INCANDESCENT = 3, + INTENSITY_COLOR_MAP_TYPE_USER_DEFINED = 4 + }; public slots: void resizeSlot( QSize *s ); diff --git a/gr-qtgui/src/lib/plot_waterfall.h b/gr-qtgui/src/lib/plot_waterfall.h index 91746e3f3..a11461611 100644 --- a/gr-qtgui/src/lib/plot_waterfall.h +++ b/gr-qtgui/src/lib/plot_waterfall.h @@ -19,7 +19,7 @@ class QwtColorMap; \sa QwtRasterData, QwtColorMap */ -class QWT_EXPORT PlotWaterfall: public QwtPlotRasterItem +class PlotWaterfall: public QwtPlotRasterItem { public: explicit PlotWaterfall(WaterfallData* data, const QString &title = QString::null); diff --git a/gr-uhd/grc/gen_uhd_multi_usrp_blocks_xml.py b/gr-uhd/grc/gen_uhd_multi_usrp_blocks_xml.py index 5902fa855..9f413f2a8 100755 --- a/gr-uhd/grc/gen_uhd_multi_usrp_blocks_xml.py +++ b/gr-uhd/grc/gen_uhd_multi_usrp_blocks_xml.py @@ -1,6 +1,6 @@ #!/usr/bin/env python """ -Copyright 2010 Free Software Foundation, Inc. +Copyright 2010-2011 Free Software Foundation, Inc. This file is part of GNU Radio @@ -27,16 +27,12 @@ MAIN_TMPL = """\ <import>from gnuradio import uhd</import> <make>uhd.multi_usrp_$(sourk)( device_addr=\$dev_addr, - io_type=uhd.io_type_t.\$type.type, + io_type=uhd.io_type.\$type.type, num_channels=\$nchan, ) \#if \$sync() -_clk_cfg = uhd.clock_config_t() -_clk_cfg.ref_source = uhd.clock_config_t.REF_SMA -_clk_cfg.pps_source = uhd.clock_config_t.PPS_SMA -_clk_cfg.pps_polarity = uhd.clock_config_t.PPS_POS -self.\$(id).set_clock_config(_clk_cfg, uhd.ALL_MBOARDS); -self.\$(id).set_time_unknown_pps(uhd.time_spec_t()) +self.\$(id).set_clock_config(uhd.clock_config.external(), uhd.ALL_MBOARDS); +self.\$(id).setime_unknown_pps(uhd.time_spec()) \#end if #for $m in range($max_mboards) \#if \$num_mboards() > $m and \$sd_spec$(m)() @@ -201,8 +197,8 @@ If the requested rate is not possible, the UHD block will print an error at runt Center frequency: The center frequency is the overall frequency of the RF chain. \\ For greater control of how the UHD tunes elements in the RF chain, \\ -pass a tune_request_t object rather than a simple target frequency. -Tuning with an LO offset example: uhd.tune_request_t(freq, lo_off) +pass a tune_request object rather than a simple target frequency. +Tuning with an LO offset example: uhd.tune_request(freq, lo_off) Antenna: For subdevices with only one antenna, this may be left blank. \\ diff --git a/gr-uhd/grc/gen_uhd_single_usrp_blocks_xml.py b/gr-uhd/grc/gen_uhd_single_usrp_blocks_xml.py index 66728fe28..4de21c989 100755 --- a/gr-uhd/grc/gen_uhd_single_usrp_blocks_xml.py +++ b/gr-uhd/grc/gen_uhd_single_usrp_blocks_xml.py @@ -1,6 +1,6 @@ #!/usr/bin/env python """ -Copyright 2010 Free Software Foundation, Inc. +Copyright 2010-2011 Free Software Foundation, Inc. This file is part of GNU Radio @@ -27,15 +27,11 @@ MAIN_TMPL = """\ <import>from gnuradio import uhd</import> <make>uhd.single_usrp_$(sourk)( device_addr=\$dev_addr, - io_type=uhd.io_type_t.\$type.type, + io_type=uhd.io_type.\$type.type, num_channels=\$nchan, ) \#if \$ref_clk() -_clk_cfg = uhd.clock_config_t() -_clk_cfg.ref_source = uhd.clock_config_t.REF_SMA -_clk_cfg.pps_source = uhd.clock_config_t.PPS_SMA -_clk_cfg.pps_polarity = uhd.clock_config_t.PPS_POS -self.\$(id).set_clock_config(_clk_cfg); +self.\$(id).set_clock_config(uhd.clock_config.external()); \#end if \#if \$sd_spec() self.\$(id).set_subdev_spec(\$sd_spec) @@ -180,8 +176,8 @@ If the requested rate is not possible, the UHD block will print an error at runt Center frequency: The center frequency is the overall frequency of the RF chain. \\ For greater control of how the UHD tunes elements in the RF chain, \\ -pass a tune_request_t object rather than a simple target frequency. -Tuning with an LO offset example: uhd.tune_request_t(freq, lo_off) +pass a tune_request object rather than a simple target frequency. +Tuning with an LO offset example: uhd.tune_request(freq, lo_off) Antenna: For subdevices with only one antenna, this may be left blank. \\ diff --git a/gr-uhd/lib/Makefile.am b/gr-uhd/lib/Makefile.am index 1bcfbbbdc..7ddb45cb3 100644 --- a/gr-uhd/lib/Makefile.am +++ b/gr-uhd/lib/Makefile.am @@ -1,5 +1,5 @@ # -# Copyright 2010 Free Software Foundation, Inc. +# Copyright 2010-2011 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -41,6 +41,7 @@ libgnuradio_uhd_la_LIBADD = \ libgnuradio_uhd_la_LDFLAGS = $(LTVERSIONFLAGS) grinclude_HEADERS = \ + gr_uhd_api.h \ uhd_multi_usrp_source.h \ uhd_multi_usrp_sink.h \ uhd_single_usrp_source.h \ diff --git a/gr-uhd/lib/gr_uhd_api.h b/gr-uhd/lib/gr_uhd_api.h new file mode 100644 index 000000000..a9b99fd87 --- /dev/null +++ b/gr-uhd/lib/gr_uhd_api.h @@ -0,0 +1,33 @@ +/* + * Copyright 2011 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_GR_UHD_API_H +#define INCLUDED_GR_UHD_API_H + +#include <uhd/config.hpp> + +#ifdef gnuradio_uhd_EXPORTS +# define GR_UHD_API UHD_EXPORT +#else +# define GR_UHD_API UHD_EXPORT +#endif + +#endif /* INCLUDED_GR_UHD_API_H */ diff --git a/gr-uhd/lib/uhd_multi_usrp_sink.cc b/gr-uhd/lib/uhd_multi_usrp_sink.cc index ee16e2928..32039e44a 100644 --- a/gr-uhd/lib/uhd_multi_usrp_sink.cc +++ b/gr-uhd/lib/uhd_multi_usrp_sink.cc @@ -1,5 +1,5 @@ /* - * Copyright 2010 Free Software Foundation, Inc. + * Copyright 2010-2011 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -37,7 +37,7 @@ uhd_multi_usrp_sink::uhd_multi_usrp_sink(gr_io_signature_sptr sig) class uhd_multi_usrp_sink_impl : public uhd_multi_usrp_sink{ public: uhd_multi_usrp_sink_impl( - const std::string &device_addr, + const uhd::device_addr_t &device_addr, const uhd::io_type_t &io_type, size_t num_channels ): @@ -56,6 +56,7 @@ public: void set_samp_rate(double rate){ _dev->set_tx_rate(rate); + _sample_rate = this->get_samp_rate(); } double get_samp_rate(void){ @@ -72,11 +73,11 @@ public: return _dev->get_tx_freq_range(chan); } - void set_gain(float gain, size_t chan){ + void set_gain(double gain, size_t chan){ return _dev->set_tx_gain(gain, chan); } - float get_gain(size_t chan){ + double get_gain(size_t chan){ return _dev->get_tx_gain(chan); } @@ -128,28 +129,31 @@ public: gr_vector_const_void_star &input_items, gr_vector_void_star &output_items ){ - uhd::tx_metadata_t metadata; - metadata.start_of_burst = true; + //send a mid-burst packet with time spec + _metadata.start_of_burst = false; + _metadata.end_of_burst = false; + _metadata.has_time_spec = true; - return _dev->get_device()->send( - input_items, noutput_items, metadata, + size_t num_sent = _dev->get_device()->send( + input_items, noutput_items, _metadata, _type, uhd::device::SEND_MODE_FULL_BUFF, 1.0 ); + + //increment the timespec by the number of samples sent + _metadata.time_spec += uhd::time_spec_t(0, num_sent, _sample_rate); + return num_sent; } //Send an empty start-of-burst packet to begin streaming. - //Set at a time in the near future so data will be sync'd. + //Set at a time in the near future to avoid late packets. bool start(void){ - uhd::tx_metadata_t metadata; - metadata.start_of_burst = true; - metadata.has_time_spec = true; - //TODO: Time in the near future, must be less than source time in future - //because ethernet pause frames with throttle stream commands. - //It will be fixed with the invention of host-based flow control. - metadata.time_spec = get_time_now() + uhd::time_spec_t(0.05); + _metadata.start_of_burst = true; + _metadata.end_of_burst = false; + _metadata.has_time_spec = true; + _metadata.time_spec = get_time_now() + uhd::time_spec_t(0.01); _dev->get_device()->send( - gr_vector_const_void_star(_nchan), 0, metadata, + gr_vector_const_void_star(_nchan), 0, _metadata, _type, uhd::device::SEND_MODE_ONE_PACKET, 1.0 ); return true; @@ -158,11 +162,12 @@ public: //Send an empty end-of-burst packet to end streaming. //Ending the burst avoids an underflow error on stop. bool stop(void){ - uhd::tx_metadata_t metadata; - metadata.end_of_burst = true; + _metadata.start_of_burst = false; + _metadata.end_of_burst = true; + _metadata.has_time_spec = false; _dev->get_device()->send( - gr_vector_const_void_star(_nchan), 0, metadata, + gr_vector_const_void_star(_nchan), 0, _metadata, _type, uhd::device::SEND_MODE_ONE_PACKET, 1.0 ); return true; @@ -172,14 +177,16 @@ protected: uhd::usrp::multi_usrp::sptr _dev; const uhd::io_type_t _type; size_t _nchan; + uhd::tx_metadata_t _metadata; + double _sample_rate; }; /*********************************************************************** * Make UHD Multi USRP Sink **********************************************************************/ boost::shared_ptr<uhd_multi_usrp_sink> uhd_make_multi_usrp_sink( - const std::string &device_addr, - const uhd::io_type_t::tid_t &io_type, + const uhd::device_addr_t &device_addr, + const uhd::io_type_t &io_type, size_t num_channels ){ return boost::shared_ptr<uhd_multi_usrp_sink>( diff --git a/gr-uhd/lib/uhd_multi_usrp_sink.h b/gr-uhd/lib/uhd_multi_usrp_sink.h index 370e59d0e..4866f2cbb 100644 --- a/gr-uhd/lib/uhd_multi_usrp_sink.h +++ b/gr-uhd/lib/uhd_multi_usrp_sink.h @@ -1,5 +1,5 @@ /* - * Copyright 2010 Free Software Foundation, Inc. + * Copyright 2010-2011 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -22,18 +22,19 @@ #ifndef INCLUDED_UHD_MULTI_USRP_SINK_H #define INCLUDED_UHD_MULTI_USRP_SINK_H +#include <gr_uhd_api.h> #include <gr_sync_block.h> #include <uhd/usrp/multi_usrp.hpp> class uhd_multi_usrp_sink; -boost::shared_ptr<uhd_multi_usrp_sink> uhd_make_multi_usrp_sink( - const std::string &device_addr, - const uhd::io_type_t::tid_t &io_type, +GR_UHD_API boost::shared_ptr<uhd_multi_usrp_sink> uhd_make_multi_usrp_sink( + const uhd::device_addr_t &device_addr, + const uhd::io_type_t &io_type, size_t num_channels ); -class uhd_multi_usrp_sink : public gr_sync_block{ +class GR_UHD_API uhd_multi_usrp_sink : public gr_sync_block{ public: /*! @@ -96,14 +97,14 @@ public: * \param gain the gain in dB * \param chan the channel index 0 to N-1 */ - virtual void set_gain(float gain, size_t chan) = 0; + virtual void set_gain(double gain, size_t chan) = 0; /*! * Get the actual dboard gain setting. * \param chan the channel index 0 to N-1 * \return the actual gain in dB */ - virtual float get_gain(size_t chan) = 0; + virtual double get_gain(size_t chan) = 0; /*! * Get the settable gain range. diff --git a/gr-uhd/lib/uhd_multi_usrp_source.cc b/gr-uhd/lib/uhd_multi_usrp_source.cc index 029a763e3..181cf1eb4 100644 --- a/gr-uhd/lib/uhd_multi_usrp_source.cc +++ b/gr-uhd/lib/uhd_multi_usrp_source.cc @@ -1,5 +1,5 @@ /* - * Copyright 2010 Free Software Foundation, Inc. + * Copyright 2010-2011 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -39,7 +39,7 @@ uhd_multi_usrp_source::uhd_multi_usrp_source(gr_io_signature_sptr sig) class uhd_multi_usrp_source_impl : public uhd_multi_usrp_source{ public: uhd_multi_usrp_source_impl( - const std::string &device_addr, + const uhd::device_addr_t &device_addr, const uhd::io_type_t &io_type, size_t num_channels ): @@ -73,11 +73,11 @@ public: return _dev->get_rx_freq_range(chan); } - void set_gain(float gain, size_t chan){ + void set_gain(double gain, size_t chan){ return _dev->set_rx_gain(gain, chan); } - float get_gain(size_t chan){ + double get_gain(size_t chan){ return _dev->get_rx_gain(chan); } @@ -177,8 +177,8 @@ private: * Make UHD Multi USRP Source **********************************************************************/ boost::shared_ptr<uhd_multi_usrp_source> uhd_make_multi_usrp_source( - const std::string &device_addr, - const uhd::io_type_t::tid_t &io_type, + const uhd::device_addr_t &device_addr, + const uhd::io_type_t &io_type, size_t num_channels ){ return boost::shared_ptr<uhd_multi_usrp_source>( diff --git a/gr-uhd/lib/uhd_multi_usrp_source.h b/gr-uhd/lib/uhd_multi_usrp_source.h index b3cbdae1f..9cbec52aa 100644 --- a/gr-uhd/lib/uhd_multi_usrp_source.h +++ b/gr-uhd/lib/uhd_multi_usrp_source.h @@ -1,5 +1,5 @@ /* - * Copyright 2010 Free Software Foundation, Inc. + * Copyright 2010-2011 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -22,18 +22,19 @@ #ifndef INCLUDED_UHD_MULTI_USRP_SOURCE_H #define INCLUDED_UHD_MULTI_USRP_SOURCE_H +#include <gr_uhd_api.h> #include <gr_sync_block.h> #include <uhd/usrp/multi_usrp.hpp> class uhd_multi_usrp_source; -boost::shared_ptr<uhd_multi_usrp_source> uhd_make_multi_usrp_source( - const std::string &device_addr, - const uhd::io_type_t::tid_t &io_type, +GR_UHD_API boost::shared_ptr<uhd_multi_usrp_source> uhd_make_multi_usrp_source( + const uhd::device_addr_t &device_addr, + const uhd::io_type_t &io_type, size_t num_channels ); -class uhd_multi_usrp_source : public gr_sync_block{ +class GR_UHD_API uhd_multi_usrp_source : public gr_sync_block{ public: /*! @@ -96,14 +97,14 @@ public: * \param gain the gain in dB * \param chan the channel index 0 to N-1 */ - virtual void set_gain(float gain, size_t chan) = 0; + virtual void set_gain(double gain, size_t chan) = 0; /*! * Get the actual dboard gain setting. * \param chan the channel index 0 to N-1 * \return the actual gain in dB */ - virtual float get_gain(size_t chan) = 0; + virtual double get_gain(size_t chan) = 0; /*! * Get the settable gain range. diff --git a/gr-uhd/lib/uhd_single_usrp_sink.cc b/gr-uhd/lib/uhd_single_usrp_sink.cc index 622f506b5..d9aaac893 100644 --- a/gr-uhd/lib/uhd_single_usrp_sink.cc +++ b/gr-uhd/lib/uhd_single_usrp_sink.cc @@ -1,5 +1,5 @@ /* - * Copyright 2010 Free Software Foundation, Inc. + * Copyright 2010-2011 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -37,7 +37,7 @@ uhd_single_usrp_sink::uhd_single_usrp_sink(gr_io_signature_sptr sig) class uhd_single_usrp_sink_impl : public uhd_single_usrp_sink{ public: uhd_single_usrp_sink_impl( - const std::string &device_addr, + const uhd::device_addr_t &device_addr, const uhd::io_type_t &io_type, size_t num_channels ): @@ -72,11 +72,11 @@ public: return _dev->get_tx_freq_range(chan); } - void set_gain(float gain, size_t chan){ + void set_gain(double gain, size_t chan){ return _dev->set_tx_gain(gain, chan); } - float get_gain(size_t chan){ + double get_gain(size_t chan){ return _dev->get_tx_gain(chan); } @@ -128,8 +128,7 @@ public: gr_vector_const_void_star &input_items, gr_vector_void_star &output_items ){ - uhd::tx_metadata_t metadata; - metadata.start_of_burst = true; + uhd::tx_metadata_t metadata; //send a mid-burst packet return _dev->get_device()->send( input_items, noutput_items, metadata, @@ -173,8 +172,8 @@ protected: * Make UHD Single USRP Sink **********************************************************************/ boost::shared_ptr<uhd_single_usrp_sink> uhd_make_single_usrp_sink( - const std::string &device_addr, - const uhd::io_type_t::tid_t &io_type, + const uhd::device_addr_t &device_addr, + const uhd::io_type_t &io_type, size_t num_channels ){ return boost::shared_ptr<uhd_single_usrp_sink>( diff --git a/gr-uhd/lib/uhd_single_usrp_sink.h b/gr-uhd/lib/uhd_single_usrp_sink.h index a4c4e6452..4929d0f13 100644 --- a/gr-uhd/lib/uhd_single_usrp_sink.h +++ b/gr-uhd/lib/uhd_single_usrp_sink.h @@ -1,5 +1,5 @@ /* - * Copyright 2010 Free Software Foundation, Inc. + * Copyright 2010-2011 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -22,18 +22,19 @@ #ifndef INCLUDED_UHD_SINGLE_USRP_SINK_H #define INCLUDED_UHD_SINGLE_USRP_SINK_H +#include <gr_uhd_api.h> #include <gr_sync_block.h> #include <uhd/usrp/single_usrp.hpp> class uhd_single_usrp_sink; -boost::shared_ptr<uhd_single_usrp_sink> uhd_make_single_usrp_sink( - const std::string &device_addr, - const uhd::io_type_t::tid_t &io_type, +GR_UHD_API boost::shared_ptr<uhd_single_usrp_sink> uhd_make_single_usrp_sink( + const uhd::device_addr_t &device_addr, + const uhd::io_type_t &io_type, size_t num_channels = 1 ); -class uhd_single_usrp_sink : public gr_sync_block{ +class GR_UHD_API uhd_single_usrp_sink : public gr_sync_block{ public: /*! @@ -95,14 +96,14 @@ public: * \param gain the gain in dB * \param chan the channel index 0 to N-1 */ - virtual void set_gain(float gain, size_t chan = 0) = 0; + virtual void set_gain(double gain, size_t chan = 0) = 0; /*! * Get the actual dboard gain setting. * \param chan the channel index 0 to N-1 * \return the actual gain in dB */ - virtual float get_gain(size_t chan = 0) = 0; + virtual double get_gain(size_t chan = 0) = 0; /*! * Get the settable gain range. diff --git a/gr-uhd/lib/uhd_single_usrp_source.cc b/gr-uhd/lib/uhd_single_usrp_source.cc index 45f852a3e..5a26d44b1 100644 --- a/gr-uhd/lib/uhd_single_usrp_source.cc +++ b/gr-uhd/lib/uhd_single_usrp_source.cc @@ -1,5 +1,5 @@ /* - * Copyright 2010 Free Software Foundation, Inc. + * Copyright 2010-2011 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -39,7 +39,7 @@ uhd_single_usrp_source::uhd_single_usrp_source(gr_io_signature_sptr sig) class uhd_single_usrp_source_impl : public uhd_single_usrp_source{ public: uhd_single_usrp_source_impl( - const std::string &device_addr, + const uhd::device_addr_t &device_addr, const uhd::io_type_t &io_type, size_t num_channels ): @@ -49,7 +49,6 @@ public: _type(io_type) { _dev = uhd::usrp::single_usrp::make(device_addr); - d_tag_srcid = pmt::mp("uhd_single_usrp_source"); } void set_subdev_spec(const std::string &spec){ @@ -74,11 +73,11 @@ public: return _dev->get_rx_freq_range(chan); } - void set_gain(float gain, size_t chan){ + void set_gain(double gain, size_t chan){ return _dev->set_rx_gain(gain, chan); } - float get_gain(size_t chan){ + double get_gain(size_t chan){ return _dev->get_rx_gain(chan); } @@ -125,7 +124,7 @@ public: /*********************************************************************** * Work **********************************************************************/ - int work( + virtual int work( int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items @@ -139,16 +138,7 @@ public: switch(metadata.error_code){ case uhd::rx_metadata_t::ERROR_CODE_NONE: - if(metadata.has_time_spec) { - d_tstamp_pair = pmt::mp(pmt::mp(metadata.time_spec.get_full_secs()), - pmt::mp(metadata.time_spec.get_frac_secs())); - add_item_tag(0, nitems_written(0), - //gr_tags::key_time, - pmt::pmt_string_to_symbol("time"), - d_tstamp_pair, - d_tag_srcid); - } - return num_samps; + return num_samps; case uhd::rx_metadata_t::ERROR_CODE_OVERFLOW: //ignore overflows and try work again @@ -172,9 +162,68 @@ public: return true; } -private: +protected: uhd::usrp::single_usrp::sptr _dev; const uhd::io_type_t _type; +}; + +/*********************************************************************** + * UHD Single USRP Source Impl with Tags + **********************************************************************/ +class uhd_single_usrp_source_impl_with_tags : public uhd_single_usrp_source_impl{ +public: + uhd_single_usrp_source_impl_with_tags( + const uhd::device_addr_t &device_addr, + const uhd::io_type_t &io_type, + size_t num_channels + ): + uhd_single_usrp_source_impl(device_addr, io_type, num_channels) + { + d_tag_srcid = pmt::mp("uhd_single_usrp_source"); + } + + int work( + int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items + ){ + uhd::rx_metadata_t metadata; //not passed out of this block + + size_t num_samps = _dev->get_device()->recv( + output_items, noutput_items, metadata, + _type, uhd::device::RECV_MODE_FULL_BUFF + ); + + switch(metadata.error_code){ + case uhd::rx_metadata_t::ERROR_CODE_NONE: + //FIXME in RECV_MODE_FULL_BUFF we are probably get remainders, + //there is no guarantee of has_time_spec, its random + if(metadata.has_time_spec) { + d_tstamp_pair = pmt::mp(pmt::mp(metadata.time_spec.get_full_secs()), + pmt::mp(metadata.time_spec.get_frac_secs())); + add_item_tag(0, nitems_written(0), + //gr_tags::key_time, + pmt::pmt_string_to_symbol("time"), + d_tstamp_pair, + d_tag_srcid); + } + return num_samps; + + case uhd::rx_metadata_t::ERROR_CODE_OVERFLOW: + //ignore overflows and try work again + return work(noutput_items, input_items, output_items); + + default: + std::cout << boost::format( + "UHD source block got error code 0x%x" + ) % metadata.error_code << std::endl; + return num_samps; + } + } + +private: + size_t d_num_packet_samps; + pmt::pmt_t d_tstamp_pair; pmt::pmt_t d_tag_srcid; }; @@ -182,11 +231,18 @@ private: /*********************************************************************** * Make UHD Single USRP Source **********************************************************************/ +#include <gr_prefs.h> boost::shared_ptr<uhd_single_usrp_source> uhd_make_single_usrp_source( - const std::string &device_addr, - const uhd::io_type_t::tid_t &io_type, + const uhd::device_addr_t &device_addr, + const uhd::io_type_t &io_type, size_t num_channels ){ + //use the tags constructor if tags is set to on + bool tags_enabled = (gr_prefs().get_string("gr-uhd", "tags", "off") == "on"); + if (tags_enabled) return boost::shared_ptr<uhd_single_usrp_source>( + new uhd_single_usrp_source_impl_with_tags(device_addr, io_type, num_channels) + ); + return boost::shared_ptr<uhd_single_usrp_source>( new uhd_single_usrp_source_impl(device_addr, io_type, num_channels) ); diff --git a/gr-uhd/lib/uhd_single_usrp_source.h b/gr-uhd/lib/uhd_single_usrp_source.h index 2a011b2b3..262f6696c 100644 --- a/gr-uhd/lib/uhd_single_usrp_source.h +++ b/gr-uhd/lib/uhd_single_usrp_source.h @@ -1,5 +1,5 @@ /* - * Copyright 2010 Free Software Foundation, Inc. + * Copyright 2010-2011 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -22,18 +22,19 @@ #ifndef INCLUDED_UHD_SINGLE_USRP_SOURCE_H #define INCLUDED_UHD_SINGLE_USRP_SOURCE_H +#include <gr_uhd_api.h> #include <gr_sync_block.h> #include <uhd/usrp/single_usrp.hpp> class uhd_single_usrp_source; -boost::shared_ptr<uhd_single_usrp_source> uhd_make_single_usrp_source( - const std::string &device_addr, - const uhd::io_type_t::tid_t &io_type, +GR_UHD_API boost::shared_ptr<uhd_single_usrp_source> uhd_make_single_usrp_source( + const uhd::device_addr_t &device_addr, + const uhd::io_type_t &io_type, size_t num_channels = 1 ); -class uhd_single_usrp_source : public gr_sync_block{ +class GR_UHD_API uhd_single_usrp_source : public gr_sync_block{ public: /*! @@ -95,14 +96,14 @@ public: * \param gain the gain in dB * \param chan the channel index 0 to N-1 */ - virtual void set_gain(float gain, size_t chan = 0) = 0; + virtual void set_gain(double gain, size_t chan = 0) = 0; /*! * Get the actual dboard gain setting. * \param chan the channel index 0 to N-1 * \return the actual gain in dB */ - virtual float get_gain(size_t chan = 0) = 0; + virtual double get_gain(size_t chan = 0) = 0; /*! * Get the settable gain range. @@ -168,10 +169,6 @@ public: * \return the single usrp device object */ virtual uhd::usrp::single_usrp::sptr get_device(void) = 0; - - protected: - size_t d_num_packet_samps; - pmt::pmt_t d_tstamp_pair; }; #endif /* INCLUDED_UHD_SINGLE_USRP_SOURCE_H */ diff --git a/gr-uhd/swig/__init__.py b/gr-uhd/swig/__init__.py index 0fdacb796..1a9f8358d 100644 --- a/gr-uhd/swig/__init__.py +++ b/gr-uhd/swig/__init__.py @@ -1,5 +1,5 @@ # -# Copyright 2010 Free Software Foundation, Inc. +# Copyright 2010-2011 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -22,6 +22,17 @@ # The presence of this file turns this directory into a Python package ######################################################################## +# Create aliases for uhd swig attributes to avoid the "_t" +# Install the __str__ and __repr__ handlers if applicable +######################################################################## +import uhd_swig +for attr in dir(uhd_swig): + myobj = getattr(uhd_swig, attr) + if hasattr(myobj, 'to_string'): myobj.__repr__ = lambda s: s.to_string().strip() + if hasattr(myobj, 'to_pp_string'): myobj.__str__ = lambda s: s.to_pp_string().strip() + if attr.endswith('_t'): setattr(uhd_swig, attr[:-2], myobj) + +######################################################################## # Add SWIG generated code to this namespace ######################################################################## from uhd_swig import * @@ -29,6 +40,8 @@ from uhd_swig import * ######################################################################## # Add other content from pure-Python modules here ######################################################################## +class freq_range_t(meta_range_t): pass #a typedef for the user +class gain_range_t(meta_range_t): pass #a typedef for the user class tune_request_t(tune_request_t, float): """ @@ -38,3 +51,36 @@ class tune_request_t(tune_request_t, float): """ def __new__(self, *args): return float.__new__(self) def __float__(self): return self.target_freq + +class device_addr_t(device_addr_t, str): + """ + Make the python tune request object inherit from string + so that it can be passed in GRC as a string parameter. + The type checking in GRC will accept the device address. + Define the set/get item special methods for dict access. + """ + def __new__(self, *args): return str.__new__(self) + def __getitem__(self, key): return self.get(key) + def __setitem__(self, key, val): self.set(key, val) + +######################################################################## +# Cast constructor args (FIXME swig handle overloads?) +######################################################################## +for attr in ( + 'single_usrp_source', 'single_usrp_sink', + 'multi_usrp_source', 'multi_usrp_sink' +): + def constructor_factory(old_constructor): + def constructor_interceptor(*args, **kwargs): + args = list(args) + kwargs = dict(kwargs) + for index, key, cast in ( + (0, 'device_addr', device_addr), + (1, 'io_type', io_type), + ): + if len(args) > index: args[index] = cast(args[index]) + if kwargs.has_key(key): kwargs[key] = cast(kwargs[key]) + return old_constructor(*args, **kwargs) + return constructor_interceptor + import uhd_swig + globals()[attr] = constructor_factory(getattr(uhd_swig, attr)) diff --git a/gr-uhd/swig/uhd_swig.i b/gr-uhd/swig/uhd_swig.i index 76f44a491..3c317beb4 100644 --- a/gr-uhd/swig/uhd_swig.i +++ b/gr-uhd/swig/uhd_swig.i @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2010 Free Software Foundation, Inc. + * Copyright 2010-2011 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -24,6 +24,8 @@ // header files if UHD was not installed. #ifdef GR_HAVE_UHD +#define GR_UHD_API + //////////////////////////////////////////////////////////////////////// // Language independent exception handler //////////////////////////////////////////////////////////////////////// @@ -47,10 +49,6 @@ //////////////////////////////////////////////////////////////////////// %include "gnuradio.i" -namespace std { - %template(StringVector) vector<string>; -} - //////////////////////////////////////////////////////////////////////// // block headers //////////////////////////////////////////////////////////////////////// @@ -64,25 +62,36 @@ namespace std { //////////////////////////////////////////////////////////////////////// // used types //////////////////////////////////////////////////////////////////////// +%template(string_vector_t) std::vector<std::string>; + %include <uhd/config.hpp> + %include <uhd/utils/pimpl.hpp> + +%include <uhd/types/dict.hpp> +%template(string_string_dict_t) uhd::dict<std::string, std::string>; //define after dict + +%include <uhd/types/device_addr.hpp> + +%include <uhd/types/io_type.hpp> + +%template(range_vector_t) std::vector<uhd::range_t>; //define before range %include <uhd/types/ranges.hpp> + %include <uhd/types/tune_request.hpp> + %include <uhd/types/tune_result.hpp> + %include <uhd/types/io_type.hpp> + %include <uhd/types/time_spec.hpp> -%include <uhd/types/clock_config.hpp> -//Re-create range typedefs here with %template as they are not imported. -//Replicate all the levels of templated inheritance so swig understands. +%include <uhd/types/clock_config.hpp> -%template(float_range_t) uhd::range_t<float>; -%template(_float_range_vector_t) std::vector<uhd::range_t<float> >; -%template(gain_range_t) uhd::meta_range_t<float>; +%include <uhd/types/metadata.hpp> -%template(double_range_t) uhd::range_t<double>; -%template(_double_range_vector_t) std::vector<uhd::range_t<double> >; -%template(freq_range_t) uhd::meta_range_t<double>; +%include <uhd/device.hpp> +%template(device_addr_vector_t) std::vector<uhd::device_addr_t>; //////////////////////////////////////////////////////////////////////// // block magic |