From 54179f7f860dcf8bc986fd90a22a5be8322b5fdf Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 24 Feb 2010 14:42:25 -0800 Subject: Created gr uhd skeleton build. Checks uhd pkg config and gens the makefiles. --- config/grc_gr_uhd.m4 | 44 ++++++++++++++++++++++++++++++++++++++++++++ configure.ac | 1 + gr-uhd/.gitignore | 2 ++ gr-uhd/Makefile.am | 29 +++++++++++++++++++++++++++++ gr-uhd/apps/.gitignore | 2 ++ gr-uhd/apps/Makefile.am | 22 ++++++++++++++++++++++ gr-uhd/grc/.gitignore | 2 ++ gr-uhd/grc/Makefile.am | 22 ++++++++++++++++++++++ gr-uhd/lib/.gitignore | 2 ++ gr-uhd/lib/Makefile.am | 22 ++++++++++++++++++++++ gr-uhd/swig/.gitignore | 2 ++ gr-uhd/swig/Makefile.am | 22 ++++++++++++++++++++++ 12 files changed, 172 insertions(+) create mode 100644 config/grc_gr_uhd.m4 create mode 100644 gr-uhd/.gitignore create mode 100644 gr-uhd/Makefile.am create mode 100644 gr-uhd/apps/.gitignore create mode 100644 gr-uhd/apps/Makefile.am create mode 100644 gr-uhd/grc/.gitignore create mode 100644 gr-uhd/grc/Makefile.am create mode 100644 gr-uhd/lib/.gitignore create mode 100644 gr-uhd/lib/Makefile.am create mode 100644 gr-uhd/swig/.gitignore create mode 100644 gr-uhd/swig/Makefile.am diff --git a/config/grc_gr_uhd.m4 b/config/grc_gr_uhd.m4 new file mode 100644 index 000000000..c3c701dbd --- /dev/null +++ b/config/grc_gr_uhd.m4 @@ -0,0 +1,44 @@ +dnl Copyright 2010 Free Software Foundation, Inc. +dnl +dnl This file is part of GNU Radio +dnl +dnl GNU Radio is free software; you can redistribute it and/or modify +dnl it under the terms of the GNU General Public License as published by +dnl the Free Software Foundation; either version 3, or (at your option) +dnl any later version. +dnl +dnl GNU Radio is distributed in the hope that it will be useful, +dnl but WITHOUT ANY WARRANTY; without even the implied warranty of +dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +dnl GNU General Public License for more details. +dnl +dnl You should have received a copy of the GNU General Public License +dnl along with GNU Radio; see the file COPYING. If not, write to +dnl the Free Software Foundation, Inc., 51 Franklin Street, +dnl Boston, MA 02110-1301, USA. + +AC_DEFUN([GRC_GR_UHD],[ + GRC_ENABLE(gr-uhd) + + dnl Dont do gr-uhd if gnuradio-core skipped + GRC_CHECK_DEPENDENCY(gr-uhd, gnuradio-core) + + if test $passed = yes; then + PKG_CHECK_MODULES( + [UHD], [uhd], [], + [passed=no; AC_MSG_RESULT([gr-uhd requires libuhd])] + ) + AC_SUBST(UHD_CFLAGS) + AC_SUBST(UHD_LIBS) + fi + + AC_CONFIG_FILES([ \ + gr-uhd/Makefile \ + gr-uhd/apps/Makefile \ + gr-uhd/grc/Makefile \ + gr-uhd/lib/Makefile \ + gr-uhd/swig/Makefile \ + ]) + + GRC_BUILD_CONDITIONAL(gr-uhd) +]) diff --git a/configure.ac b/configure.ac index 3ba5bb387..f1e56efee 100644 --- a/configure.ac +++ b/configure.ac @@ -364,6 +364,7 @@ GRC_GR_SOUNDER dnl this must come after GRC_USRP GRC_GR_UTILS dnl this must come after GRC_GR_WXGUI GRC_GNURADIO_EXAMPLES dnl must come after all GRC_GR_* GRC_GRC +GRC_GR_UHD GRC_DOCS dnl must be last # Each component is now either to be built, was skipped, will be diff --git a/gr-uhd/.gitignore b/gr-uhd/.gitignore new file mode 100644 index 000000000..b336cc7ce --- /dev/null +++ b/gr-uhd/.gitignore @@ -0,0 +1,2 @@ +/Makefile +/Makefile.in diff --git a/gr-uhd/Makefile.am b/gr-uhd/Makefile.am new file mode 100644 index 000000000..83190a1d0 --- /dev/null +++ b/gr-uhd/Makefile.am @@ -0,0 +1,29 @@ +# +# Copyright 2010 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. +# + +include $(top_srcdir)/Makefile.common + +SUBDIRS = lib apps + +if PYTHON +SUBDIRS += swig grc +endif + diff --git a/gr-uhd/apps/.gitignore b/gr-uhd/apps/.gitignore new file mode 100644 index 000000000..b336cc7ce --- /dev/null +++ b/gr-uhd/apps/.gitignore @@ -0,0 +1,2 @@ +/Makefile +/Makefile.in diff --git a/gr-uhd/apps/Makefile.am b/gr-uhd/apps/Makefile.am new file mode 100644 index 000000000..b78d07ee8 --- /dev/null +++ b/gr-uhd/apps/Makefile.am @@ -0,0 +1,22 @@ +# +# Copyright 2010 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. +# + +include $(top_srcdir)/Makefile.common diff --git a/gr-uhd/grc/.gitignore b/gr-uhd/grc/.gitignore new file mode 100644 index 000000000..b336cc7ce --- /dev/null +++ b/gr-uhd/grc/.gitignore @@ -0,0 +1,2 @@ +/Makefile +/Makefile.in diff --git a/gr-uhd/grc/Makefile.am b/gr-uhd/grc/Makefile.am new file mode 100644 index 000000000..b78d07ee8 --- /dev/null +++ b/gr-uhd/grc/Makefile.am @@ -0,0 +1,22 @@ +# +# Copyright 2010 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. +# + +include $(top_srcdir)/Makefile.common diff --git a/gr-uhd/lib/.gitignore b/gr-uhd/lib/.gitignore new file mode 100644 index 000000000..b336cc7ce --- /dev/null +++ b/gr-uhd/lib/.gitignore @@ -0,0 +1,2 @@ +/Makefile +/Makefile.in diff --git a/gr-uhd/lib/Makefile.am b/gr-uhd/lib/Makefile.am new file mode 100644 index 000000000..b78d07ee8 --- /dev/null +++ b/gr-uhd/lib/Makefile.am @@ -0,0 +1,22 @@ +# +# Copyright 2010 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. +# + +include $(top_srcdir)/Makefile.common diff --git a/gr-uhd/swig/.gitignore b/gr-uhd/swig/.gitignore new file mode 100644 index 000000000..b336cc7ce --- /dev/null +++ b/gr-uhd/swig/.gitignore @@ -0,0 +1,2 @@ +/Makefile +/Makefile.in diff --git a/gr-uhd/swig/Makefile.am b/gr-uhd/swig/Makefile.am new file mode 100644 index 000000000..b78d07ee8 --- /dev/null +++ b/gr-uhd/swig/Makefile.am @@ -0,0 +1,22 @@ +# +# Copyright 2010 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. +# + +include $(top_srcdir)/Makefile.common -- cgit From 7c23fd43214e8a729b3022db281dc85040f0e749 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 26 Feb 2010 15:17:38 -0800 Subject: Created simple source (with nothing in it) and some swig build stuff. Seems to work and compile --- gr-uhd/lib/Makefile.am | 19 +++ gr-uhd/lib/uhd_simple_source.cc | 81 +++++++++++++ gr-uhd/lib/uhd_simple_source.h | 50 ++++++++ gr-uhd/swig/.gitignore | 2 + gr-uhd/swig/Makefile.am | 44 +++++++ gr-uhd/swig/Makefile.swig.gen | 259 ++++++++++++++++++++++++++++++++++++++++ gr-uhd/swig/__init__.py | 28 +++++ gr-uhd/swig/uhd_swig.i | 31 +++++ 8 files changed, 514 insertions(+) create mode 100644 gr-uhd/lib/uhd_simple_source.cc create mode 100644 gr-uhd/lib/uhd_simple_source.h create mode 100644 gr-uhd/swig/Makefile.swig.gen create mode 100644 gr-uhd/swig/__init__.py create mode 100644 gr-uhd/swig/uhd_swig.i diff --git a/gr-uhd/lib/Makefile.am b/gr-uhd/lib/Makefile.am index b78d07ee8..2f49ed2d6 100644 --- a/gr-uhd/lib/Makefile.am +++ b/gr-uhd/lib/Makefile.am @@ -20,3 +20,22 @@ # include $(top_srcdir)/Makefile.common + +AM_CPPFLAGS = \ + $(STD_DEFINES_AND_INCLUDES) \ + $(WITH_INCLUDES) \ + $(UHD_CFLAGS) + +lib_LTLIBRARIES = libgnuradio-uhd.la + +libgnuradio_uhd_la_SOURCES = \ + uhd_simple_source.cc + +libgnuradio_uhd_la_LIBADD = \ + $(GNURADIO_CORE_LA) \ + $(UHD_LIBS) + +grinclude_HEADERS = \ + uhd_simple_source.h + +noinst_HEADERS = diff --git a/gr-uhd/lib/uhd_simple_source.cc b/gr-uhd/lib/uhd_simple_source.cc new file mode 100644 index 000000000..588b27627 --- /dev/null +++ b/gr-uhd/lib/uhd_simple_source.cc @@ -0,0 +1,81 @@ +/* -*- c++ -*- */ +/* + * Copyright 2010 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. + */ + +#include +#include +#include + +/*********************************************************************** + * Helper Functions + **********************************************************************/ +static gr_io_signature_sptr make_io_sig(const std::string &type){ + if(type == "32fc"){ + return gr_make_io_signature(1, 1, sizeof(std::complex)); + } + if(type == "16sc"){ + return gr_make_io_signature(1, 1, sizeof(std::complex)); + } + throw std::runtime_error("unknown type"); +} + +/*********************************************************************** + * Make UHD Source + **********************************************************************/ +boost::shared_ptr uhd_make_simple_source( + const uhd::device_addr_t &addr, + const std::string &type +){ + return boost::shared_ptr( + new uhd_simple_source(addr, type) + ); +} + +/*********************************************************************** + * UHD Source + **********************************************************************/ +uhd_simple_source::uhd_simple_source( + const uhd::device_addr_t &addr, + const std::string &type +) : gr_sync_block( + "uhd source", + gr_make_io_signature(0, 0, 0), + make_io_sig(type) +){ + _type = type; + _dev = uhd::device::make(addr); +} + +uhd_simple_source::~uhd_simple_source(void){ + /* NOP */ +} + +/*********************************************************************** + * Work + **********************************************************************/ +int uhd_simple_source::work( + int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items +){ + uhd::metadata_t metadata; + return _dev->recv(boost::asio::buffer(output_items[0], noutput_items), metadata, _type); +} diff --git a/gr-uhd/lib/uhd_simple_source.h b/gr-uhd/lib/uhd_simple_source.h new file mode 100644 index 000000000..156b9f357 --- /dev/null +++ b/gr-uhd/lib/uhd_simple_source.h @@ -0,0 +1,50 @@ +/* -*- c++ -*- */ +/* + * Copyright 2010 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_UHD_SIMPLE_SOURCE_H +#define INCLUDED_UHD_SIMPLE_SOURCE_H + +#include +#include + +class uhd_simple_source; + +boost::shared_ptr +uhd_make_simple_source(const uhd::device_addr_t &addr, const std::string &type); + +class uhd_simple_source : public gr_sync_block{ +public: + uhd_simple_source(const uhd::device_addr_t &addr, const std::string &type); + ~uhd_simple_source(void); + + int work( + int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items + ); + +protected: + uhd::device::sptr _dev; + std::string _type; +}; + +#endif /* INCLUDED_UHD_SIMPLE_SOURCE_H */ diff --git a/gr-uhd/swig/.gitignore b/gr-uhd/swig/.gitignore index b336cc7ce..02d25cc00 100644 --- a/gr-uhd/swig/.gitignore +++ b/gr-uhd/swig/.gitignore @@ -1,2 +1,4 @@ +/uhd_swig.cc +/uhd_swig.py /Makefile /Makefile.in diff --git a/gr-uhd/swig/Makefile.am b/gr-uhd/swig/Makefile.am index b78d07ee8..3b1fd20f8 100644 --- a/gr-uhd/swig/Makefile.am +++ b/gr-uhd/swig/Makefile.am @@ -20,3 +20,47 @@ # include $(top_srcdir)/Makefile.common + +AM_CPPFLAGS = \ + $(STD_DEFINES_AND_INCLUDES) \ + $(PYTHON_CPPFLAGS) \ + $(WITH_INCLUDES) \ + -I$(top_srcdir)/gr-uhd/lib + +if PYTHON +# ---------------------------------------------------------------- +# The SWIG library +# TESTS = run_tests + +TOP_SWIG_IFILES = \ + uhd_swig.i + +# Install so that they end up available as: +# import gnuradio.uhd +# This ends up at: +# ${prefix}/lib/python${python_version}/site-packages/gnuradio/uhd +uhd_swig_pythondir_category = \ + gnuradio/uhd + +# additional libraries for linking with the SWIG-generated library +uhd_swig_la_swig_libadd = \ + $(top_builddir)/gr-uhd/lib/libgnuradio-uhd.la + +# additional Python files to be installed along with the SWIG-generated one +uhd_swig_python = \ + __init__.py + +# additional SWIG files to be installed +uhd_swig_swiginclude_headers = + +include $(top_srcdir)/Makefile.swig + +# FIXME better way to set this? +STD_SWIG_PYTHON_ARGS += -I$(top_srcdir)/gr-uhd/lib + +# add some of the variables generated inside the Makefile.swig.gen +BUILT_SOURCES = $(swig_built_sources) + +# Do not distribute the output of SWIG +no_dist_files = $(swig_built_sources) +endif diff --git a/gr-uhd/swig/Makefile.swig.gen b/gr-uhd/swig/Makefile.swig.gen new file mode 100644 index 000000000..3804461a4 --- /dev/null +++ b/gr-uhd/swig/Makefile.swig.gen @@ -0,0 +1,259 @@ +# -*- Makefile -*- +# +# Copyright 2009 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. +# + +# Makefile.swig.gen for uhd_swig.i + +## Default install locations for these files: +## +## Default location for the Python directory is: +## ${prefix}/lib/python${python_version}/site-packages/[category]/uhd_swig +## Default location for the Python exec directory is: +## ${exec_prefix}/lib/python${python_version}/site-packages/[category]/uhd_swig +## +## The following can be overloaded to change the install location, but +## this has to be done in the including Makefile.am -before- +## Makefile.swig is included. + +uhd_swig_pythondir_category ?= gnuradio/uhd_swig +uhd_swig_pylibdir_category ?= $(uhd_swig_pythondir_category) +uhd_swig_pythondir = $(pythondir)/$(uhd_swig_pythondir_category) +uhd_swig_pylibdir = $(pyexecdir)/$(uhd_swig_pylibdir_category) + +## SWIG headers are always installed into the same directory. + +uhd_swig_swigincludedir = $(swigincludedir) + +## This is a template file for a "generated" Makefile addition (in +## this case, "Makefile.swig.gen"). By including the top-level +## Makefile.swig, this file will be used to generate the SWIG +## dependencies. Assign the variable TOP_SWIG_FILES to be the list of +## SWIG .i files to generated wrappings for; there can be more than 1 +## so long as the names are unique (no sorting is done on the +## TOP_SWIG_FILES list). This file explicitly assumes that a SWIG .i +## file will generate .cc, .py, and possibly .h files -- meaning that +## all of these files will have the same base name (that provided for +## the SWIG .i file). +## +## This code is setup to ensure parallel MAKE ("-j" or "-jN") does the +## right thing. For more info, see < +## http://sources.redhat.com/automake/automake.html#Multiple-Outputs > + +## Stamps used to ensure parallel make does the right thing. These +## are removed by "make clean", but otherwise unused except during the +## parallel built. These will not be included in a tarball, because +## the SWIG-generated files will be removed from the distribution. + +STAMPS += $(DEPDIR)/uhd_swig-generate-* + +## Other cleaned files: dependency files generated by SWIG or this Makefile + +MOSTLYCLEANFILES += $(DEPDIR)/*.S* + +## Add the .py and .cc files to the list of SWIG built sources. The +## .h file is sometimes built, but not always ... so that one has to +## be added manually by the including Makefile.am . + +swig_built_sources += uhd_swig.py uhd_swig.cc + +## Various SWIG variables. These can be overloaded in the including +## Makefile.am by setting the variable value there, then including +## Makefile.swig . + +uhd_swig_swiginclude_HEADERS = \ + uhd_swig.i \ + $(uhd_swig_swiginclude_headers) + +uhd_swig_pylib_LTLIBRARIES = \ + _uhd_swig.la + +_uhd_swig_la_SOURCES = \ + uhd_swig.cc \ + $(uhd_swig_la_swig_sources) + +_uhd_swig_la_LIBADD = \ + $(STD_SWIG_LA_LIB_ADD) \ + $(uhd_swig_la_swig_libadd) + +_uhd_swig_la_LDFLAGS = \ + $(STD_SWIG_LA_LD_FLAGS) \ + $(uhd_swig_la_swig_ldflags) + +_uhd_swig_la_CXXFLAGS = \ + $(STD_SWIG_CXX_FLAGS) \ + $(uhd_swig_la_swig_cxxflags) + +uhd_swig_python_PYTHON = \ + uhd_swig.py \ + $(uhd_swig_python) + +## Entry rule for running SWIG + +uhd_swig.h uhd_swig.py uhd_swig.cc: uhd_swig.i +## This rule will get called only when MAKE decides that one of the +## targets needs to be created or re-created, because: +## +## * The .i file is newer than any or all of the generated files; +## +## * Any or all of the .cc, .h, or .py files does not exist and is +## needed (in the case this file is not needed, the rule for it is +## ignored); or +## +## * Some SWIG-based dependecy of the .cc file isn't met and hence the +## .cc file needs be be regenerated. Explanation: Because MAKE +## knows how to handle dependencies for .cc files (regardless of +## their name or extension), then the .cc file is used as a target +## instead of the .i file -- but with the dependencies of the .i +## file. It is this last reason why the line: +## +## if test -f $@; then :; else +## +## cannot be used in this case: If a .i file dependecy is not met, +## then the .cc file needs to be rebuilt. But if the stamp is newer +## than the .cc file, and the .cc file exists, then in the original +## version (with the 'test' above) the internal MAKE call will not +## be issued and hence the .cc file will not be rebuilt. +## +## Once execution gets to here, it should always proceed no matter the +## state of a stamp (as discussed in link above). The +## $(DEPDIR)/uhd_swig-generate stuff is used to allow for parallel +## builds to "do the right thing". The stamp has no relationship with +## either the target files or dependency file; it is used solely for +## the protection of multiple builds during a given call to MAKE. +## +## Catch signals SIGHUP (1), SIGINT (2), SIGPIPE (13), and SIGTERM +## (15). At a caught signal, the quoted command will be issued before +## exiting. In this case, remove any stamp, whether temporary of not. +## The trap is valid until the process exits; the process includes all +## commands appended via "\"s. +## + trap 'rm -rf $(DEPDIR)/uhd_swig-generate-*' 1 2 13 15; \ +## +## Create a temporary directory, which acts as a lock. The first +## process to create the directory will succeed and issue the MAKE +## command to do the actual work, while all subsequent processes will +## fail -- leading them to wait for the first process to finish. +## + if mkdir $(DEPDIR)/uhd_swig-generate-lock 2>/dev/null; then \ +## +## This code is being executed by the first process to succeed in +## creating the directory lock. +## +## Remove the stamp associated with this filename. +## + rm -f $(DEPDIR)/uhd_swig-generate-stamp; \ +## +## Tell MAKE to run the rule for creating this stamp. +## + $(MAKE) $(AM_MAKEFLAGS) $(DEPDIR)/uhd_swig-generate-stamp WHAT=$<; \ +## +## Now that the .cc, .h, and .py files have been (re)created from the +## .i file, future checking of this rule during the same MAKE +## execution will come back that the rule doesn't need to be executed +## because none of the conditions mentioned at the start of this rule +## will be positive. Remove the the directory lock, which frees up +## any waiting process(es) to continue. +## + rmdir $(DEPDIR)/uhd_swig-generate-lock; \ + else \ +## +## This code is being executed by any follower processes while the +## directory lock is in place. +## +## Wait until the first process is done, testing once per second. +## + while test -d $(DEPDIR)/uhd_swig-generate-lock; do \ + sleep 1; \ + done; \ +## +## Succeed if and only if the first process succeeded; exit this +## process returning the status of the generated stamp. +## + test -f $(DEPDIR)/uhd_swig-generate-stamp; \ + exit $$?; \ + fi; + +$(DEPDIR)/uhd_swig-generate-stamp: +## This rule will be called only by the first process issuing the +## above rule to succeed in creating the lock directory, after +## removing the actual stamp file in order to guarantee that MAKE will +## execute this rule. +## +## Call SWIG to generate the various output files; special +## post-processing on 'mingw32' host OS for the dependency file. +## + if $(SWIG) $(STD_SWIG_PYTHON_ARGS) $(uhd_swig_swig_args) \ + -MD -MF $(DEPDIR)/uhd_swig.Std \ + -module uhd_swig -o uhd_swig.cc $(WHAT); then \ + if test $(host_os) = mingw32; then \ + $(RM) $(DEPDIR)/uhd_swig.Sd; \ + $(SED) 's,\\\\,/,g' < $(DEPDIR)/uhd_swig.Std \ + > $(DEPDIR)/uhd_swig.Sd; \ + $(RM) $(DEPDIR)/uhd_swig.Std; \ + $(MV) $(DEPDIR)/uhd_swig.Sd $(DEPDIR)/uhd_swig.Std; \ + fi; \ + else \ + $(RM) $(DEPDIR)/uhd_swig.S*; exit 1; \ + fi; +## +## Mess with the SWIG output .Std dependency file, to create a +## dependecy file valid for the input .i file: Basically, simulate the +## dependency file created for libraries by GNU's libtool for C++, +## where all of the dependencies for the target are first listed, then +## each individual dependency is listed as a target with no further +## dependencies. +## +## (1) remove the current dependency file +## + $(RM) $(DEPDIR)/uhd_swig.d +## +## (2) Copy the whole SWIG file: +## + cp $(DEPDIR)/uhd_swig.Std $(DEPDIR)/uhd_swig.d +## +## (3) all a carriage return to the end of the dependency file. +## + echo "" >> $(DEPDIR)/uhd_swig.d +## +## (4) from the SWIG file, remove the first line (the target); remove +## trailing " \" and " " from each line. Append ":" to each line, +## followed by 2 carriage returns, then append this to the end of +## the dependency file. +## + $(SED) -e '1d;s, \\,,g;s, ,,g' < $(DEPDIR)/uhd_swig.Std | \ + awk '{ printf "%s:\n\n", $$0 }' >> $(DEPDIR)/uhd_swig.d +## +## (5) remove the SWIG-generated file +## + $(RM) $(DEPDIR)/uhd_swig.Std +## +## Create the stamp for this filename generation, to signal success in +## executing this rule; allows other threads waiting on this process +## to continue. +## + touch $(DEPDIR)/uhd_swig-generate-stamp + +# KLUDGE: Force runtime include of a SWIG dependency file. This is +# not guaranteed to be portable, but will probably work. If it works, +# we have accurate dependencies for our swig stuff, which is good. + +@am__include@ @am__quote@./$(DEPDIR)/uhd_swig.d@am__quote@ + diff --git a/gr-uhd/swig/__init__.py b/gr-uhd/swig/__init__.py new file mode 100644 index 000000000..2fed17e57 --- /dev/null +++ b/gr-uhd/swig/__init__.py @@ -0,0 +1,28 @@ +# +# Copyright 2010 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. +# + +# The presence of this file turns this directory into a Python package + +# Add SWIG generated code to this namespace +from uhd_swig import * + +# Add other content from pure-Python modules here + diff --git a/gr-uhd/swig/uhd_swig.i b/gr-uhd/swig/uhd_swig.i new file mode 100644 index 000000000..e20d22a26 --- /dev/null +++ b/gr-uhd/swig/uhd_swig.i @@ -0,0 +1,31 @@ +/* -*- c++ -*- */ +/* + * Copyright 2010 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. + */ + +%include "gnuradio.i" + +%{ +#include +%} + +GR_SWIG_BLOCK_MAGIC(uhd,simple_source) + +%include -- cgit From 00f9ccaa50ed26d71a66d19f8f1518874004c5de Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 1 Mar 2010 11:50:09 -0800 Subject: recv noise with uhd --- gr-uhd/grc/Makefile.am | 5 ++++ gr-uhd/lib/Makefile.am | 4 ++- gr-uhd/lib/uhd_simple_source.cc | 56 +++++++++++++++++++++++++++++++++++------ gr-uhd/lib/uhd_simple_source.h | 5 +++- 4 files changed, 60 insertions(+), 10 deletions(-) diff --git a/gr-uhd/grc/Makefile.am b/gr-uhd/grc/Makefile.am index b78d07ee8..a46146272 100644 --- a/gr-uhd/grc/Makefile.am +++ b/gr-uhd/grc/Makefile.am @@ -20,3 +20,8 @@ # include $(top_srcdir)/Makefile.common + +grcblocksdir = $(grc_blocksdir) + +dist_grcblocks_DATA = \ + uhd_simple_source.xml diff --git a/gr-uhd/lib/Makefile.am b/gr-uhd/lib/Makefile.am index 2f49ed2d6..73424ae8e 100644 --- a/gr-uhd/lib/Makefile.am +++ b/gr-uhd/lib/Makefile.am @@ -29,6 +29,7 @@ AM_CPPFLAGS = \ lib_LTLIBRARIES = libgnuradio-uhd.la libgnuradio_uhd_la_SOURCES = \ + utils.cc \ uhd_simple_source.cc libgnuradio_uhd_la_LIBADD = \ @@ -38,4 +39,5 @@ libgnuradio_uhd_la_LIBADD = \ grinclude_HEADERS = \ uhd_simple_source.h -noinst_HEADERS = +noinst_HEADERS = \ + utils.h diff --git a/gr-uhd/lib/uhd_simple_source.cc b/gr-uhd/lib/uhd_simple_source.cc index 588b27627..4bd3622f3 100644 --- a/gr-uhd/lib/uhd_simple_source.cc +++ b/gr-uhd/lib/uhd_simple_source.cc @@ -22,17 +22,19 @@ #include #include +#include #include +#include "utils.h" /*********************************************************************** * Helper Functions **********************************************************************/ -static gr_io_signature_sptr make_io_sig(const std::string &type){ +static size_t get_size(const std::string &type){ if(type == "32fc"){ - return gr_make_io_signature(1, 1, sizeof(std::complex)); + return sizeof(std::complex); } if(type == "16sc"){ - return gr_make_io_signature(1, 1, sizeof(std::complex)); + return sizeof(std::complex); } throw std::runtime_error("unknown type"); } @@ -41,11 +43,11 @@ static gr_io_signature_sptr make_io_sig(const std::string &type){ * Make UHD Source **********************************************************************/ boost::shared_ptr uhd_make_simple_source( - const uhd::device_addr_t &addr, + const std::string &args, const std::string &type ){ return boost::shared_ptr( - new uhd_simple_source(addr, type) + new uhd_simple_source(args_to_device_addr(args), type) ); } @@ -58,14 +60,27 @@ uhd_simple_source::uhd_simple_source( ) : gr_sync_block( "uhd source", gr_make_io_signature(0, 0, 0), - make_io_sig(type) + gr_make_io_signature(1, 1, get_size(type)) ){ _type = type; _dev = uhd::device::make(addr); + _sizeof_samp = get_size(type); + + set_streaming(true); } uhd_simple_source::~uhd_simple_source(void){ - /* NOP */ + set_streaming(false); +} + +/*********************************************************************** + * DDC Control + **********************************************************************/ +void uhd_simple_source::set_streaming(bool enb){ + wax::obj ddc = (*_dev) + [uhd::DEVICE_PROP_MBOARD] + [uhd::named_prop_t(uhd::MBOARD_PROP_RX_DSP, "ddc0")]; + ddc[std::string("enabled")] = enb; } /*********************************************************************** @@ -76,6 +91,31 @@ int uhd_simple_source::work( gr_vector_const_void_star &input_items, gr_vector_void_star &output_items ){ + + size_t total_items_read = 0; + size_t count = 0; uhd::metadata_t metadata; - return _dev->recv(boost::asio::buffer(output_items[0], noutput_items), metadata, _type); + while(total_items_read == 0 or total_items_read + 1500/_sizeof_samp < size_t(noutput_items)){ + size_t items_read = _dev->recv( + boost::asio::buffer( + (uint8_t *)output_items[0]+(total_items_read*_sizeof_samp), + (noutput_items-total_items_read)*_sizeof_samp + ), metadata, _type + ); + + //record items read and recv again + if (items_read > 0){ + total_items_read += items_read; + continue; + } + + //if we have read at least once, but not this time, get out + if (total_items_read > 0) break; + + //the timeout part + boost::this_thread::sleep(boost::posix_time::milliseconds(1)); + count++; if (count > 50) break; + } + + return total_items_read; } diff --git a/gr-uhd/lib/uhd_simple_source.h b/gr-uhd/lib/uhd_simple_source.h index 156b9f357..43c4a647a 100644 --- a/gr-uhd/lib/uhd_simple_source.h +++ b/gr-uhd/lib/uhd_simple_source.h @@ -29,7 +29,7 @@ class uhd_simple_source; boost::shared_ptr -uhd_make_simple_source(const uhd::device_addr_t &addr, const std::string &type); +uhd_make_simple_source(const std::string &args, const std::string &type); class uhd_simple_source : public gr_sync_block{ public: @@ -43,8 +43,11 @@ public: ); protected: + void set_streaming(bool enb); + uhd::device::sptr _dev; std::string _type; + size_t _sizeof_samp; }; #endif /* INCLUDED_UHD_SIMPLE_SOURCE_H */ -- cgit From c85606eaaf5a73387d4423bdeb2f63483394137e Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 1 Mar 2010 16:16:16 -0800 Subject: using samples prop, added unchecked in files for utils and grc rx wrapper --- gr-uhd/grc/uhd_simple_source.xml | 43 +++++++++++++++++++++++++++++++++++ gr-uhd/lib/uhd_simple_source.cc | 6 +++-- gr-uhd/lib/utils.cc | 49 ++++++++++++++++++++++++++++++++++++++++ gr-uhd/lib/utils.h | 30 ++++++++++++++++++++++++ 4 files changed, 126 insertions(+), 2 deletions(-) create mode 100644 gr-uhd/grc/uhd_simple_source.xml create mode 100644 gr-uhd/lib/utils.cc create mode 100644 gr-uhd/lib/utils.h diff --git a/gr-uhd/grc/uhd_simple_source.xml b/gr-uhd/grc/uhd_simple_source.xml new file mode 100644 index 000000000..90bde1cd3 --- /dev/null +++ b/gr-uhd/grc/uhd_simple_source.xml @@ -0,0 +1,43 @@ + + + + UHD Simple Source + uhd_simple_source + UHD + from gnuradio import uhd + uhd.simple_source($args, "$type.type") + + Output Type + type + enum + + + + + Args + args + + string + + + out + $type + $type.vlen + + + + diff --git a/gr-uhd/lib/uhd_simple_source.cc b/gr-uhd/lib/uhd_simple_source.cc index 4bd3622f3..360b91434 100644 --- a/gr-uhd/lib/uhd_simple_source.cc +++ b/gr-uhd/lib/uhd_simple_source.cc @@ -92,10 +92,12 @@ int uhd_simple_source::work( gr_vector_void_star &output_items ){ + const size_t max_samples = wax::cast((*_dev)[uhd::DEVICE_PROP_MAX_RX_SAMPLES]); + size_t total_items_read = 0; size_t count = 0; uhd::metadata_t metadata; - while(total_items_read == 0 or total_items_read + 1500/_sizeof_samp < size_t(noutput_items)){ + while(total_items_read == 0 or total_items_read + max_samples < size_t(noutput_items)){ size_t items_read = _dev->recv( boost::asio::buffer( (uint8_t *)output_items[0]+(total_items_read*_sizeof_samp), @@ -114,7 +116,7 @@ int uhd_simple_source::work( //the timeout part boost::this_thread::sleep(boost::posix_time::milliseconds(1)); - count++; if (count > 50) break; + if (++count > 50) break; } return total_items_read; diff --git a/gr-uhd/lib/utils.cc b/gr-uhd/lib/utils.cc new file mode 100644 index 000000000..6b2121064 --- /dev/null +++ b/gr-uhd/lib/utils.cc @@ -0,0 +1,49 @@ +/* -*- c++ -*- */ +/* + * Copyright 2010 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. + */ + +#include "utils.h" +#include +#include +#include + +static std::string trim(const std::string &in){ + return boost::algorithm::trim_copy(in); +} + +uhd::device_addr_t args_to_device_addr(const std::string &args){ + uhd::device_addr_t addr; + + //split the args at the semi-colons + std::vector pairs; + boost::split(pairs, args, boost::is_any_of(";")); + BOOST_FOREACH(std::string pair, pairs){ + if (trim(pair) == "") continue; + + //split the key value pairs at the equals + std::vector key_val; + boost::split(key_val, pair, boost::is_any_of("=")); + if (key_val.size() != 2) throw std::runtime_error("invalid args string: "+args); + addr[trim(key_val[0])] = trim(key_val[1]); + } + + return addr; +} diff --git a/gr-uhd/lib/utils.h b/gr-uhd/lib/utils.h new file mode 100644 index 000000000..7530faba2 --- /dev/null +++ b/gr-uhd/lib/utils.h @@ -0,0 +1,30 @@ +/* -*- c++ -*- */ +/* + * Copyright 2010 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_NOINST_UTILS_H +#define INCLUDED_NOINST_UTILS_H + +#include + +uhd::device_addr_t args_to_device_addr(const std::string &args); + +#endif /* INCLUDED_NOINST_UTILS_H */ -- cgit From 6d71414a0a467dc37fc903b327be22f8d0ddeade Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 2 Mar 2010 14:43:20 -0800 Subject: Added the uhd simple sink lib block, swig wrapper, grc wrapper. It seems to work, but still getting the kinks out of tx->usrp2 --- gr-uhd/grc/Makefile.am | 3 +- gr-uhd/grc/uhd_simple_sink.xml | 43 ++++++++++++++++++++ gr-uhd/lib/Makefile.am | 6 ++- gr-uhd/lib/uhd_simple_sink.cc | 87 +++++++++++++++++++++++++++++++++++++++++ gr-uhd/lib/uhd_simple_sink.h | 52 ++++++++++++++++++++++++ gr-uhd/lib/uhd_simple_source.cc | 21 ++-------- gr-uhd/lib/utils.cc | 11 ++++++ gr-uhd/lib/utils.h | 2 + gr-uhd/swig/uhd_swig.i | 5 ++- 9 files changed, 209 insertions(+), 21 deletions(-) create mode 100644 gr-uhd/grc/uhd_simple_sink.xml create mode 100644 gr-uhd/lib/uhd_simple_sink.cc create mode 100644 gr-uhd/lib/uhd_simple_sink.h diff --git a/gr-uhd/grc/Makefile.am b/gr-uhd/grc/Makefile.am index a46146272..61eb32770 100644 --- a/gr-uhd/grc/Makefile.am +++ b/gr-uhd/grc/Makefile.am @@ -24,4 +24,5 @@ include $(top_srcdir)/Makefile.common grcblocksdir = $(grc_blocksdir) dist_grcblocks_DATA = \ - uhd_simple_source.xml + uhd_simple_source.xml \ + uhd_simple_sink.xml diff --git a/gr-uhd/grc/uhd_simple_sink.xml b/gr-uhd/grc/uhd_simple_sink.xml new file mode 100644 index 000000000..1259c38c0 --- /dev/null +++ b/gr-uhd/grc/uhd_simple_sink.xml @@ -0,0 +1,43 @@ + + + + UHD Simple Sink + uhd_simple_sink + UHD + from gnuradio import uhd + uhd.simple_sink($args, "$type.type") + + Input Type + type + enum + + + + + Args + args + + string + + + out + $type + $type.vlen + + + + diff --git a/gr-uhd/lib/Makefile.am b/gr-uhd/lib/Makefile.am index 73424ae8e..d4363406b 100644 --- a/gr-uhd/lib/Makefile.am +++ b/gr-uhd/lib/Makefile.am @@ -30,14 +30,16 @@ lib_LTLIBRARIES = libgnuradio-uhd.la libgnuradio_uhd_la_SOURCES = \ utils.cc \ - uhd_simple_source.cc + uhd_simple_source.cc \ + uhd_simple_sink.cc libgnuradio_uhd_la_LIBADD = \ $(GNURADIO_CORE_LA) \ $(UHD_LIBS) grinclude_HEADERS = \ - uhd_simple_source.h + uhd_simple_source.h \ + uhd_simple_sink.h noinst_HEADERS = \ utils.h diff --git a/gr-uhd/lib/uhd_simple_sink.cc b/gr-uhd/lib/uhd_simple_sink.cc new file mode 100644 index 000000000..269487f0e --- /dev/null +++ b/gr-uhd/lib/uhd_simple_sink.cc @@ -0,0 +1,87 @@ +/* -*- c++ -*- */ +/* + * Copyright 2010 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. + */ + +#include +#include +#include +#include +#include "utils.h" + +/*********************************************************************** + * Make UHD Sink + **********************************************************************/ +boost::shared_ptr uhd_make_simple_sink( + const std::string &args, + const std::string &type +){ + return boost::shared_ptr( + new uhd_simple_sink(args_to_device_addr(args), type) + ); +} + +/*********************************************************************** + * UHD Sink + **********************************************************************/ +uhd_simple_sink::uhd_simple_sink( + const uhd::device_addr_t &addr, + const std::string &type +) : gr_sync_block( + "uhd sink", + gr_make_io_signature(1, 1, get_size(type)), + gr_make_io_signature(0, 0, 0) +){ + _type = type; + _dev = uhd::device::make(addr); + _sizeof_samp = get_size(type); +} + +uhd_simple_sink::~uhd_simple_sink(void){ + //NOP +} + +/*********************************************************************** + * Work + **********************************************************************/ +int uhd_simple_sink::work( + int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items +){ + + const size_t max_samples = wax::cast((*_dev)[uhd::DEVICE_PROP_MAX_TX_SAMPLES]); + size_t total_items_sent = 0; + uhd::metadata_t metadata; + metadata.start_of_burst = true; + + //handles fragmentation + while(total_items_sent < size_t(noutput_items)){ + size_t items_sent = _dev->send( + boost::asio::buffer( + (uint8_t *)input_items[0]+(total_items_sent*_sizeof_samp), + std::min(max_samples, noutput_items-total_items_sent)*_sizeof_samp + ), metadata, _type + ); + total_items_sent += items_sent; + } + + return noutput_items; +} diff --git a/gr-uhd/lib/uhd_simple_sink.h b/gr-uhd/lib/uhd_simple_sink.h new file mode 100644 index 000000000..76b4a26cf --- /dev/null +++ b/gr-uhd/lib/uhd_simple_sink.h @@ -0,0 +1,52 @@ +/* -*- c++ -*- */ +/* + * Copyright 2010 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_UHD_SIMPLE_SINK_H +#define INCLUDED_UHD_SIMPLE_SINK_H + +#include +#include + +class uhd_simple_sink; + +boost::shared_ptr +uhd_make_simple_sink(const std::string &args, const std::string &type); + +class uhd_simple_sink : public gr_sync_block{ +public: + uhd_simple_sink(const uhd::device_addr_t &addr, const std::string &type); + ~uhd_simple_sink(void); + + int work( + int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items + ); + +protected: + + uhd::device::sptr _dev; + std::string _type; + size_t _sizeof_samp; +}; + +#endif /* INCLUDED_UHD_SIMPLE_SINK_H */ diff --git a/gr-uhd/lib/uhd_simple_source.cc b/gr-uhd/lib/uhd_simple_source.cc index 360b91434..f6a783ef9 100644 --- a/gr-uhd/lib/uhd_simple_source.cc +++ b/gr-uhd/lib/uhd_simple_source.cc @@ -26,19 +26,6 @@ #include #include "utils.h" -/*********************************************************************** - * Helper Functions - **********************************************************************/ -static size_t get_size(const std::string &type){ - if(type == "32fc"){ - return sizeof(std::complex); - } - if(type == "16sc"){ - return sizeof(std::complex); - } - throw std::runtime_error("unknown type"); -} - /*********************************************************************** * Make UHD Source **********************************************************************/ @@ -95,9 +82,9 @@ int uhd_simple_source::work( const size_t max_samples = wax::cast((*_dev)[uhd::DEVICE_PROP_MAX_RX_SAMPLES]); size_t total_items_read = 0; - size_t count = 0; + size_t count = 50; uhd::metadata_t metadata; - while(total_items_read == 0 or total_items_read + max_samples < size_t(noutput_items)){ + while(total_items_read < size_t(noutput_items)){ size_t items_read = _dev->recv( boost::asio::buffer( (uint8_t *)output_items[0]+(total_items_read*_sizeof_samp), @@ -116,8 +103,8 @@ int uhd_simple_source::work( //the timeout part boost::this_thread::sleep(boost::posix_time::milliseconds(1)); - if (++count > 50) break; + if (--count == 0) break; } - + return total_items_read; } diff --git a/gr-uhd/lib/utils.cc b/gr-uhd/lib/utils.cc index 6b2121064..c92846dc1 100644 --- a/gr-uhd/lib/utils.cc +++ b/gr-uhd/lib/utils.cc @@ -24,6 +24,7 @@ #include #include #include +#include static std::string trim(const std::string &in){ return boost::algorithm::trim_copy(in); @@ -47,3 +48,13 @@ uhd::device_addr_t args_to_device_addr(const std::string &args){ return addr; } + +size_t get_size(const std::string &type){ + if(type == "32fc"){ + return sizeof(std::complex); + } + if(type == "16sc"){ + return sizeof(std::complex); + } + throw std::runtime_error("unknown type"); +} diff --git a/gr-uhd/lib/utils.h b/gr-uhd/lib/utils.h index 7530faba2..9a6dd604a 100644 --- a/gr-uhd/lib/utils.h +++ b/gr-uhd/lib/utils.h @@ -27,4 +27,6 @@ uhd::device_addr_t args_to_device_addr(const std::string &args); +size_t get_size(const std::string &type); + #endif /* INCLUDED_NOINST_UTILS_H */ diff --git a/gr-uhd/swig/uhd_swig.i b/gr-uhd/swig/uhd_swig.i index e20d22a26..06a1c88ff 100644 --- a/gr-uhd/swig/uhd_swig.i +++ b/gr-uhd/swig/uhd_swig.i @@ -24,8 +24,11 @@ %{ #include +#include %} GR_SWIG_BLOCK_MAGIC(uhd,simple_source) - %include + +GR_SWIG_BLOCK_MAGIC(uhd,simple_sink) +%include -- cgit From 23f6fc0f5f484380fe5f934ec97c4397d3675cb6 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 3 Mar 2010 12:32:18 -0800 Subject: Got the source and sink working with current uhd. --- gr-uhd/lib/uhd_simple_sink.cc | 8 +++----- gr-uhd/lib/uhd_simple_source.cc | 21 ++++++++++++++------- gr-uhd/lib/uhd_simple_source.h | 1 + gr-uhd/lib/utils.cc | 4 ++-- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/gr-uhd/lib/uhd_simple_sink.cc b/gr-uhd/lib/uhd_simple_sink.cc index 269487f0e..01581bb76 100644 --- a/gr-uhd/lib/uhd_simple_sink.cc +++ b/gr-uhd/lib/uhd_simple_sink.cc @@ -66,18 +66,16 @@ int uhd_simple_sink::work( gr_vector_const_void_star &input_items, gr_vector_void_star &output_items ){ - - const size_t max_samples = wax::cast((*_dev)[uhd::DEVICE_PROP_MAX_TX_SAMPLES]); size_t total_items_sent = 0; - uhd::metadata_t metadata; + uhd::tx_metadata_t metadata; metadata.start_of_burst = true; - //handles fragmentation + //call until the input items are all sent while(total_items_sent < size_t(noutput_items)){ size_t items_sent = _dev->send( boost::asio::buffer( (uint8_t *)input_items[0]+(total_items_sent*_sizeof_samp), - std::min(max_samples, noutput_items-total_items_sent)*_sizeof_samp + (noutput_items-total_items_sent)*_sizeof_samp ), metadata, _type ); total_items_sent += items_sent; diff --git a/gr-uhd/lib/uhd_simple_source.cc b/gr-uhd/lib/uhd_simple_source.cc index f6a783ef9..17691c7ae 100644 --- a/gr-uhd/lib/uhd_simple_source.cc +++ b/gr-uhd/lib/uhd_simple_source.cc @@ -53,7 +53,7 @@ uhd_simple_source::uhd_simple_source( _dev = uhd::device::make(addr); _sizeof_samp = get_size(type); - set_streaming(true); + set_streaming(false); } uhd_simple_source::~uhd_simple_source(void){ @@ -68,6 +68,7 @@ void uhd_simple_source::set_streaming(bool enb){ [uhd::DEVICE_PROP_MBOARD] [uhd::named_prop_t(uhd::MBOARD_PROP_RX_DSP, "ddc0")]; ddc[std::string("enabled")] = enb; + _is_streaming = enb; } /*********************************************************************** @@ -78,12 +79,16 @@ int uhd_simple_source::work( gr_vector_const_void_star &input_items, gr_vector_void_star &output_items ){ - - const size_t max_samples = wax::cast((*_dev)[uhd::DEVICE_PROP_MAX_RX_SAMPLES]); + //conditionally start streaming in the work call + //this prevents streaming before the runtime is ready + if (not _is_streaming) set_streaming(true); size_t total_items_read = 0; - size_t count = 50; - uhd::metadata_t metadata; + size_t timeout_count = 50; + uhd::rx_metadata_t metadata; + + //call until the output items are all filled + //or an exit condition below is encountered while(total_items_read < size_t(noutput_items)){ size_t items_read = _dev->recv( boost::asio::buffer( @@ -99,11 +104,13 @@ int uhd_simple_source::work( } //if we have read at least once, but not this time, get out - if (total_items_read > 0) break; + // commented out behaviour: I believe that it would be better to + // fill the buffer entirely to mimimize scheduler context switching + //if (total_items_read > 0) break; //the timeout part boost::this_thread::sleep(boost::posix_time::milliseconds(1)); - if (--count == 0) break; + if (--timeout_count == 0) break; } return total_items_read; diff --git a/gr-uhd/lib/uhd_simple_source.h b/gr-uhd/lib/uhd_simple_source.h index 43c4a647a..5d2dafe49 100644 --- a/gr-uhd/lib/uhd_simple_source.h +++ b/gr-uhd/lib/uhd_simple_source.h @@ -44,6 +44,7 @@ public: protected: void set_streaming(bool enb); + bool _is_streaming; //shadow for the streaming status uhd::device::sptr _dev; std::string _type; diff --git a/gr-uhd/lib/utils.cc b/gr-uhd/lib/utils.cc index c92846dc1..e36320c3c 100644 --- a/gr-uhd/lib/utils.cc +++ b/gr-uhd/lib/utils.cc @@ -20,7 +20,7 @@ * Boston, MA 02110-1301, USA. */ -#include "utils.h" +#include "utils.h" //local include #include #include #include @@ -54,7 +54,7 @@ size_t get_size(const std::string &type){ return sizeof(std::complex); } if(type == "16sc"){ - return sizeof(std::complex); + return sizeof(std::complex); } throw std::runtime_error("unknown type"); } -- cgit From 6c79d5158ace300038937688bb11309736926214 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 4 Mar 2010 18:38:47 -0800 Subject: removed timeout from here --- gr-uhd/lib/uhd_simple_source.cc | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/gr-uhd/lib/uhd_simple_source.cc b/gr-uhd/lib/uhd_simple_source.cc index 17691c7ae..a8977abc3 100644 --- a/gr-uhd/lib/uhd_simple_source.cc +++ b/gr-uhd/lib/uhd_simple_source.cc @@ -22,7 +22,6 @@ #include #include -#include #include #include "utils.h" @@ -84,7 +83,6 @@ int uhd_simple_source::work( if (not _is_streaming) set_streaming(true); size_t total_items_read = 0; - size_t timeout_count = 50; uhd::rx_metadata_t metadata; //call until the output items are all filled @@ -96,21 +94,10 @@ int uhd_simple_source::work( (noutput_items-total_items_read)*_sizeof_samp ), metadata, _type ); + total_items_read += items_read; - //record items read and recv again - if (items_read > 0){ - total_items_read += items_read; - continue; - } - - //if we have read at least once, but not this time, get out - // commented out behaviour: I believe that it would be better to - // fill the buffer entirely to mimimize scheduler context switching - //if (total_items_read > 0) break; - - //the timeout part - boost::this_thread::sleep(boost::posix_time::milliseconds(1)); - if (--timeout_count == 0) break; + //we timed out, get out of here + if (items_read == 0) break; } return total_items_read; -- cgit From 19d3c0cab37123f8bfd19fdfc576f44b6069300f Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 10 Mar 2010 14:48:50 -0800 Subject: Added samp rate param and using the simple device from uhd --- gr-uhd/grc/uhd_simple_sink.xml | 10 +++++++++- gr-uhd/grc/uhd_simple_source.xml | 10 +++++++++- gr-uhd/lib/uhd_simple_sink.cc | 16 ++++++++++++---- gr-uhd/lib/uhd_simple_sink.h | 10 ++++++---- gr-uhd/lib/uhd_simple_source.cc | 33 +++++++++++++++++---------------- gr-uhd/lib/uhd_simple_source.h | 13 +++++++------ gr-uhd/lib/utils.cc | 28 ++-------------------------- gr-uhd/lib/utils.h | 5 ++--- 8 files changed, 64 insertions(+), 61 deletions(-) diff --git a/gr-uhd/grc/uhd_simple_sink.xml b/gr-uhd/grc/uhd_simple_sink.xml index 1259c38c0..078288e04 100644 --- a/gr-uhd/grc/uhd_simple_sink.xml +++ b/gr-uhd/grc/uhd_simple_sink.xml @@ -9,7 +9,9 @@ uhd_simple_sink UHD from gnuradio import uhd - uhd.simple_sink($args, "$type.type") + uhd.simple_sink($args, "$type.type") +self.$(id).set_samp_rate($samp_rate) + set_samp_rate($samp_rate) Input Type type @@ -33,6 +35,12 @@ string + + Samp Rate (Sps) + samp_rate + samp_rate + real + out $type diff --git a/gr-uhd/grc/uhd_simple_source.xml b/gr-uhd/grc/uhd_simple_source.xml index 90bde1cd3..45496b098 100644 --- a/gr-uhd/grc/uhd_simple_source.xml +++ b/gr-uhd/grc/uhd_simple_source.xml @@ -9,7 +9,9 @@ uhd_simple_source UHD from gnuradio import uhd - uhd.simple_source($args, "$type.type") + uhd.simple_source($args, "$type.type") +self.$(id).set_samp_rate($samp_rate) + set_samp_rate($samp_rate) Output Type type @@ -33,6 +35,12 @@ string + + Samp Rate (Sps) + samp_rate + samp_rate + real + out $type diff --git a/gr-uhd/lib/uhd_simple_sink.cc b/gr-uhd/lib/uhd_simple_sink.cc index 01581bb76..c1edf29bb 100644 --- a/gr-uhd/lib/uhd_simple_sink.cc +++ b/gr-uhd/lib/uhd_simple_sink.cc @@ -34,7 +34,7 @@ boost::shared_ptr uhd_make_simple_sink( const std::string &type ){ return boost::shared_ptr( - new uhd_simple_sink(args_to_device_addr(args), type) + new uhd_simple_sink(args, type) ); } @@ -42,7 +42,7 @@ boost::shared_ptr uhd_make_simple_sink( * UHD Sink **********************************************************************/ uhd_simple_sink::uhd_simple_sink( - const uhd::device_addr_t &addr, + const std::string &args, const std::string &type ) : gr_sync_block( "uhd sink", @@ -50,7 +50,7 @@ uhd_simple_sink::uhd_simple_sink( gr_make_io_signature(0, 0, 0) ){ _type = type; - _dev = uhd::device::make(addr); + _dev = uhd::simple_device::make(args); _sizeof_samp = get_size(type); } @@ -58,6 +58,14 @@ uhd_simple_sink::~uhd_simple_sink(void){ //NOP } +void uhd_simple_sink::set_samp_rate(double rate){ + return _dev->set_tx_rate(rate); +} + +double uhd_simple_sink::get_samp_rate(void){ + return _dev->get_tx_rate(); +} + /*********************************************************************** * Work **********************************************************************/ @@ -72,7 +80,7 @@ int uhd_simple_sink::work( //call until the input items are all sent while(total_items_sent < size_t(noutput_items)){ - size_t items_sent = _dev->send( + size_t items_sent = _dev->get_device()->send( boost::asio::buffer( (uint8_t *)input_items[0]+(total_items_sent*_sizeof_samp), (noutput_items-total_items_sent)*_sizeof_samp diff --git a/gr-uhd/lib/uhd_simple_sink.h b/gr-uhd/lib/uhd_simple_sink.h index 76b4a26cf..301cdd24f 100644 --- a/gr-uhd/lib/uhd_simple_sink.h +++ b/gr-uhd/lib/uhd_simple_sink.h @@ -24,7 +24,7 @@ #define INCLUDED_UHD_SIMPLE_SINK_H #include -#include +#include class uhd_simple_sink; @@ -33,9 +33,12 @@ uhd_make_simple_sink(const std::string &args, const std::string &type); class uhd_simple_sink : public gr_sync_block{ public: - uhd_simple_sink(const uhd::device_addr_t &addr, const std::string &type); + uhd_simple_sink(const std::string &args, const std::string &type); ~uhd_simple_sink(void); + void set_samp_rate(double rate); + double get_samp_rate(void); + int work( int noutput_items, gr_vector_const_void_star &input_items, @@ -43,8 +46,7 @@ public: ); protected: - - uhd::device::sptr _dev; + uhd::simple_device::sptr _dev; std::string _type; size_t _sizeof_samp; }; diff --git a/gr-uhd/lib/uhd_simple_source.cc b/gr-uhd/lib/uhd_simple_source.cc index a8977abc3..827cad458 100644 --- a/gr-uhd/lib/uhd_simple_source.cc +++ b/gr-uhd/lib/uhd_simple_source.cc @@ -33,7 +33,7 @@ boost::shared_ptr uhd_make_simple_source( const std::string &type ){ return boost::shared_ptr( - new uhd_simple_source(args_to_device_addr(args), type) + new uhd_simple_source(args, type) ); } @@ -41,7 +41,7 @@ boost::shared_ptr uhd_make_simple_source( * UHD Source **********************************************************************/ uhd_simple_source::uhd_simple_source( - const uhd::device_addr_t &addr, + const std::string &args, const std::string &type ) : gr_sync_block( "uhd source", @@ -49,25 +49,23 @@ uhd_simple_source::uhd_simple_source( gr_make_io_signature(1, 1, get_size(type)) ){ _type = type; - _dev = uhd::device::make(addr); + _dev = uhd::simple_device::make(args); _sizeof_samp = get_size(type); - set_streaming(false); + _dev->set_streaming(false); + _is_streaming = false; } uhd_simple_source::~uhd_simple_source(void){ - set_streaming(false); + _dev->set_streaming(false); } -/*********************************************************************** - * DDC Control - **********************************************************************/ -void uhd_simple_source::set_streaming(bool enb){ - wax::obj ddc = (*_dev) - [uhd::DEVICE_PROP_MBOARD] - [uhd::named_prop_t(uhd::MBOARD_PROP_RX_DSP, "ddc0")]; - ddc[std::string("enabled")] = enb; - _is_streaming = enb; +void uhd_simple_source::set_samp_rate(double rate){ + return _dev->set_rx_rate(rate); +} + +double uhd_simple_source::get_samp_rate(void){ + return _dev->get_rx_rate(); } /*********************************************************************** @@ -80,7 +78,10 @@ int uhd_simple_source::work( ){ //conditionally start streaming in the work call //this prevents streaming before the runtime is ready - if (not _is_streaming) set_streaming(true); + if (not _is_streaming){ + _dev->set_streaming(true); + _is_streaming = true; + } size_t total_items_read = 0; uhd::rx_metadata_t metadata; @@ -88,7 +89,7 @@ int uhd_simple_source::work( //call until the output items are all filled //or an exit condition below is encountered while(total_items_read < size_t(noutput_items)){ - size_t items_read = _dev->recv( + size_t items_read = _dev->get_device()->recv( boost::asio::buffer( (uint8_t *)output_items[0]+(total_items_read*_sizeof_samp), (noutput_items-total_items_read)*_sizeof_samp diff --git a/gr-uhd/lib/uhd_simple_source.h b/gr-uhd/lib/uhd_simple_source.h index 5d2dafe49..0ddf9d563 100644 --- a/gr-uhd/lib/uhd_simple_source.h +++ b/gr-uhd/lib/uhd_simple_source.h @@ -24,7 +24,7 @@ #define INCLUDED_UHD_SIMPLE_SOURCE_H #include -#include +#include class uhd_simple_source; @@ -33,9 +33,12 @@ uhd_make_simple_source(const std::string &args, const std::string &type); class uhd_simple_source : public gr_sync_block{ public: - uhd_simple_source(const uhd::device_addr_t &addr, const std::string &type); + uhd_simple_source(const std::string &args, const std::string &type); ~uhd_simple_source(void); + void set_samp_rate(double rate); + double get_samp_rate(void); + int work( int noutput_items, gr_vector_const_void_star &input_items, @@ -43,12 +46,10 @@ public: ); protected: - void set_streaming(bool enb); - bool _is_streaming; //shadow for the streaming status - - uhd::device::sptr _dev; + uhd::simple_device::sptr _dev; std::string _type; size_t _sizeof_samp; + bool _is_streaming; }; #endif /* INCLUDED_UHD_SIMPLE_SOURCE_H */ diff --git a/gr-uhd/lib/utils.cc b/gr-uhd/lib/utils.cc index e36320c3c..0351d6370 100644 --- a/gr-uhd/lib/utils.cc +++ b/gr-uhd/lib/utils.cc @@ -21,33 +21,9 @@ */ #include "utils.h" //local include -#include -#include -#include +#include #include - -static std::string trim(const std::string &in){ - return boost::algorithm::trim_copy(in); -} - -uhd::device_addr_t args_to_device_addr(const std::string &args){ - uhd::device_addr_t addr; - - //split the args at the semi-colons - std::vector pairs; - boost::split(pairs, args, boost::is_any_of(";")); - BOOST_FOREACH(std::string pair, pairs){ - if (trim(pair) == "") continue; - - //split the key value pairs at the equals - std::vector key_val; - boost::split(key_val, pair, boost::is_any_of("=")); - if (key_val.size() != 2) throw std::runtime_error("invalid args string: "+args); - addr[trim(key_val[0])] = trim(key_val[1]); - } - - return addr; -} +#include size_t get_size(const std::string &type){ if(type == "32fc"){ diff --git a/gr-uhd/lib/utils.h b/gr-uhd/lib/utils.h index 9a6dd604a..eb3a133bc 100644 --- a/gr-uhd/lib/utils.h +++ b/gr-uhd/lib/utils.h @@ -23,9 +23,8 @@ #ifndef INCLUDED_NOINST_UTILS_H #define INCLUDED_NOINST_UTILS_H -#include - -uhd::device_addr_t args_to_device_addr(const std::string &args); +#include +#include size_t get_size(const std::string &type); -- cgit From b5c1edfd488ccdd8a2c6ff5a2efb3de35a048d67 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 16 Mar 2010 19:43:08 -0700 Subject: added set center freq call --- gr-uhd/grc/uhd_simple_sink.xml | 9 ++++++++- gr-uhd/grc/uhd_simple_source.xml | 9 ++++++++- gr-uhd/lib/uhd_simple_sink.cc | 4 ++++ gr-uhd/lib/uhd_simple_sink.h | 2 ++ gr-uhd/lib/uhd_simple_source.cc | 4 ++++ gr-uhd/lib/uhd_simple_source.h | 2 ++ 6 files changed, 28 insertions(+), 2 deletions(-) diff --git a/gr-uhd/grc/uhd_simple_sink.xml b/gr-uhd/grc/uhd_simple_sink.xml index 078288e04..cad6194ee 100644 --- a/gr-uhd/grc/uhd_simple_sink.xml +++ b/gr-uhd/grc/uhd_simple_sink.xml @@ -10,8 +10,10 @@ UHD from gnuradio import uhd uhd.simple_sink($args, "$type.type") -self.$(id).set_samp_rate($samp_rate) +self.$(id).set_samp_rate($samp_rate) +self.$(id).set_center_freq($center_freq) set_samp_rate($samp_rate) + set_center_freq($center_freq) Input Type type @@ -41,6 +43,11 @@ self.$(id).set_samp_rate($samp_rate) samp_rate real + + Center Freq (Hz) + center_freq + real + out $type diff --git a/gr-uhd/grc/uhd_simple_source.xml b/gr-uhd/grc/uhd_simple_source.xml index 45496b098..519b7ad6c 100644 --- a/gr-uhd/grc/uhd_simple_source.xml +++ b/gr-uhd/grc/uhd_simple_source.xml @@ -10,8 +10,10 @@ UHD from gnuradio import uhd uhd.simple_source($args, "$type.type") -self.$(id).set_samp_rate($samp_rate) +self.$(id).set_samp_rate($samp_rate) +self.$(id).set_center_freq($center_freq) set_samp_rate($samp_rate) + set_center_freq($center_freq) Output Type type @@ -41,6 +43,11 @@ self.$(id).set_samp_rate($samp_rate) samp_rate real + + Center Freq (Hz) + center_freq + real + out $type diff --git a/gr-uhd/lib/uhd_simple_sink.cc b/gr-uhd/lib/uhd_simple_sink.cc index c1edf29bb..f208bd294 100644 --- a/gr-uhd/lib/uhd_simple_sink.cc +++ b/gr-uhd/lib/uhd_simple_sink.cc @@ -66,6 +66,10 @@ double uhd_simple_sink::get_samp_rate(void){ return _dev->get_tx_rate(); } +void uhd_simple_sink::set_center_freq(double freq){ + _dev->set_tx_freq(freq); +} + /*********************************************************************** * Work **********************************************************************/ diff --git a/gr-uhd/lib/uhd_simple_sink.h b/gr-uhd/lib/uhd_simple_sink.h index 301cdd24f..28965d870 100644 --- a/gr-uhd/lib/uhd_simple_sink.h +++ b/gr-uhd/lib/uhd_simple_sink.h @@ -39,6 +39,8 @@ public: void set_samp_rate(double rate); double get_samp_rate(void); + void set_center_freq(double freq); + int work( int noutput_items, gr_vector_const_void_star &input_items, diff --git a/gr-uhd/lib/uhd_simple_source.cc b/gr-uhd/lib/uhd_simple_source.cc index 827cad458..1a0bb2b61 100644 --- a/gr-uhd/lib/uhd_simple_source.cc +++ b/gr-uhd/lib/uhd_simple_source.cc @@ -68,6 +68,10 @@ double uhd_simple_source::get_samp_rate(void){ return _dev->get_rx_rate(); } +void uhd_simple_source::set_center_freq(double freq){ + _dev->set_rx_freq(freq); +} + /*********************************************************************** * Work **********************************************************************/ diff --git a/gr-uhd/lib/uhd_simple_source.h b/gr-uhd/lib/uhd_simple_source.h index 0ddf9d563..cfab8b7a4 100644 --- a/gr-uhd/lib/uhd_simple_source.h +++ b/gr-uhd/lib/uhd_simple_source.h @@ -39,6 +39,8 @@ public: void set_samp_rate(double rate); double get_samp_rate(void); + void set_center_freq(double freq); + int work( int noutput_items, gr_vector_const_void_star &input_items, -- cgit From 0abfa7d596265a2b7d54da1206979171a0891fb4 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 26 Mar 2010 14:01:27 -0700 Subject: using new streaming api --- gr-uhd/lib/uhd_simple_source.cc | 18 +++++++++++------- gr-uhd/lib/uhd_simple_source.h | 1 + 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/gr-uhd/lib/uhd_simple_source.cc b/gr-uhd/lib/uhd_simple_source.cc index 1a0bb2b61..87b727874 100644 --- a/gr-uhd/lib/uhd_simple_source.cc +++ b/gr-uhd/lib/uhd_simple_source.cc @@ -52,12 +52,19 @@ uhd_simple_source::uhd_simple_source( _dev = uhd::simple_device::make(args); _sizeof_samp = get_size(type); - _dev->set_streaming(false); - _is_streaming = false; + set_streaming(false); } uhd_simple_source::~uhd_simple_source(void){ - _dev->set_streaming(false); + set_streaming(false); +} + +void uhd_simple_source::set_streaming(bool enb){ + uhd::stream_cmd_t stream_cmd; + stream_cmd.stream_now = true; + stream_cmd.continuous = enb; + _dev->issue_stream_cmd(stream_cmd); + _is_streaming = enb; } void uhd_simple_source::set_samp_rate(double rate){ @@ -82,10 +89,7 @@ int uhd_simple_source::work( ){ //conditionally start streaming in the work call //this prevents streaming before the runtime is ready - if (not _is_streaming){ - _dev->set_streaming(true); - _is_streaming = true; - } + if (not _is_streaming) set_streaming(true); size_t total_items_read = 0; uhd::rx_metadata_t metadata; diff --git a/gr-uhd/lib/uhd_simple_source.h b/gr-uhd/lib/uhd_simple_source.h index cfab8b7a4..98378d518 100644 --- a/gr-uhd/lib/uhd_simple_source.h +++ b/gr-uhd/lib/uhd_simple_source.h @@ -52,6 +52,7 @@ protected: std::string _type; size_t _sizeof_samp; bool _is_streaming; + void set_streaming(bool enb); }; #endif /* INCLUDED_UHD_SIMPLE_SOURCE_H */ -- cgit From 6851718b6d9a97a8c9397a1548708c7075de98e4 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 29 Mar 2010 15:30:02 -0700 Subject: added swig includes and tune result return --- gr-uhd/lib/uhd_simple_sink.cc | 4 ++-- gr-uhd/lib/uhd_simple_sink.h | 2 +- gr-uhd/lib/uhd_simple_source.cc | 4 ++-- gr-uhd/lib/uhd_simple_source.h | 2 +- gr-uhd/swig/uhd_swig.i | 3 +++ 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/gr-uhd/lib/uhd_simple_sink.cc b/gr-uhd/lib/uhd_simple_sink.cc index f208bd294..499ae4d6e 100644 --- a/gr-uhd/lib/uhd_simple_sink.cc +++ b/gr-uhd/lib/uhd_simple_sink.cc @@ -66,8 +66,8 @@ double uhd_simple_sink::get_samp_rate(void){ return _dev->get_tx_rate(); } -void uhd_simple_sink::set_center_freq(double freq){ - _dev->set_tx_freq(freq); +uhd::tune_result_t uhd_simple_sink::set_center_freq(double freq){ + return _dev->set_tx_freq(freq); } /*********************************************************************** diff --git a/gr-uhd/lib/uhd_simple_sink.h b/gr-uhd/lib/uhd_simple_sink.h index 28965d870..e57ba4abb 100644 --- a/gr-uhd/lib/uhd_simple_sink.h +++ b/gr-uhd/lib/uhd_simple_sink.h @@ -39,7 +39,7 @@ public: void set_samp_rate(double rate); double get_samp_rate(void); - void set_center_freq(double freq); + uhd::tune_result_t set_center_freq(double freq); int work( int noutput_items, diff --git a/gr-uhd/lib/uhd_simple_source.cc b/gr-uhd/lib/uhd_simple_source.cc index 87b727874..725cb2807 100644 --- a/gr-uhd/lib/uhd_simple_source.cc +++ b/gr-uhd/lib/uhd_simple_source.cc @@ -75,8 +75,8 @@ double uhd_simple_source::get_samp_rate(void){ return _dev->get_rx_rate(); } -void uhd_simple_source::set_center_freq(double freq){ - _dev->set_rx_freq(freq); +uhd::tune_result_t uhd_simple_source::set_center_freq(double freq){ + return _dev->set_rx_freq(freq); } /*********************************************************************** diff --git a/gr-uhd/lib/uhd_simple_source.h b/gr-uhd/lib/uhd_simple_source.h index 98378d518..27fa2c382 100644 --- a/gr-uhd/lib/uhd_simple_source.h +++ b/gr-uhd/lib/uhd_simple_source.h @@ -39,7 +39,7 @@ public: void set_samp_rate(double rate); double get_samp_rate(void); - void set_center_freq(double freq); + uhd::tune_result_t set_center_freq(double freq); int work( int noutput_items, diff --git a/gr-uhd/swig/uhd_swig.i b/gr-uhd/swig/uhd_swig.i index 06a1c88ff..363d9c914 100644 --- a/gr-uhd/swig/uhd_swig.i +++ b/gr-uhd/swig/uhd_swig.i @@ -27,6 +27,9 @@ #include %} +%include +%include + GR_SWIG_BLOCK_MAGIC(uhd,simple_source) %include -- cgit From a87552815119742d98561f9b53ab0da5513514bb Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 30 Mar 2010 14:08:11 -0700 Subject: gr-uhd working with io type --- gr-uhd/grc/uhd_simple_sink.xml | 6 +++--- gr-uhd/grc/uhd_simple_source.xml | 6 +++--- gr-uhd/lib/uhd_simple_sink.cc | 14 ++++++-------- gr-uhd/lib/uhd_simple_sink.h | 7 +++---- gr-uhd/lib/uhd_simple_source.cc | 14 ++++++-------- gr-uhd/lib/uhd_simple_source.h | 7 +++---- gr-uhd/lib/utils.cc | 13 ------------- gr-uhd/lib/utils.h | 5 ----- gr-uhd/swig/Makefile.am | 5 ++++- gr-uhd/swig/uhd_swig.i | 2 ++ 10 files changed, 30 insertions(+), 49 deletions(-) diff --git a/gr-uhd/grc/uhd_simple_sink.xml b/gr-uhd/grc/uhd_simple_sink.xml index cad6194ee..fa9e19be7 100644 --- a/gr-uhd/grc/uhd_simple_sink.xml +++ b/gr-uhd/grc/uhd_simple_sink.xml @@ -9,7 +9,7 @@ uhd_simple_sink UHD from gnuradio import uhd - uhd.simple_sink($args, "$type.type") + uhd.simple_sink($args, uhd.io_type_t.$type.type) self.$(id).set_samp_rate($samp_rate) self.$(id).set_center_freq($center_freq) set_samp_rate($samp_rate) @@ -21,13 +21,13 @@ self.$(id).set_center_freq($center_freq) diff --git a/gr-uhd/grc/uhd_simple_source.xml b/gr-uhd/grc/uhd_simple_source.xml index 519b7ad6c..7deffeeec 100644 --- a/gr-uhd/grc/uhd_simple_source.xml +++ b/gr-uhd/grc/uhd_simple_source.xml @@ -9,7 +9,7 @@ uhd_simple_source UHD from gnuradio import uhd - uhd.simple_source($args, "$type.type") + uhd.simple_source($args, uhd.io_type_t.$type.type) self.$(id).set_samp_rate($samp_rate) self.$(id).set_center_freq($center_freq) set_samp_rate($samp_rate) @@ -21,13 +21,13 @@ self.$(id).set_center_freq($center_freq) diff --git a/gr-uhd/lib/uhd_simple_sink.cc b/gr-uhd/lib/uhd_simple_sink.cc index 499ae4d6e..a22b52421 100644 --- a/gr-uhd/lib/uhd_simple_sink.cc +++ b/gr-uhd/lib/uhd_simple_sink.cc @@ -31,7 +31,7 @@ **********************************************************************/ boost::shared_ptr uhd_make_simple_sink( const std::string &args, - const std::string &type + const uhd::io_type_t::tid_t &type ){ return boost::shared_ptr( new uhd_simple_sink(args, type) @@ -43,15 +43,13 @@ boost::shared_ptr uhd_make_simple_sink( **********************************************************************/ uhd_simple_sink::uhd_simple_sink( const std::string &args, - const std::string &type + const uhd::io_type_t &type ) : gr_sync_block( "uhd sink", - gr_make_io_signature(1, 1, get_size(type)), + gr_make_io_signature(1, 1, type.size), gr_make_io_signature(0, 0, 0) -){ - _type = type; +), _type(type){ _dev = uhd::simple_device::make(args); - _sizeof_samp = get_size(type); } uhd_simple_sink::~uhd_simple_sink(void){ @@ -86,8 +84,8 @@ int uhd_simple_sink::work( while(total_items_sent < size_t(noutput_items)){ size_t items_sent = _dev->get_device()->send( boost::asio::buffer( - (uint8_t *)input_items[0]+(total_items_sent*_sizeof_samp), - (noutput_items-total_items_sent)*_sizeof_samp + (uint8_t *)input_items[0]+(total_items_sent*_type.size), + (noutput_items-total_items_sent)*_type.size ), metadata, _type ); total_items_sent += items_sent; diff --git a/gr-uhd/lib/uhd_simple_sink.h b/gr-uhd/lib/uhd_simple_sink.h index e57ba4abb..aa8d1144c 100644 --- a/gr-uhd/lib/uhd_simple_sink.h +++ b/gr-uhd/lib/uhd_simple_sink.h @@ -29,11 +29,11 @@ class uhd_simple_sink; boost::shared_ptr -uhd_make_simple_sink(const std::string &args, const std::string &type); +uhd_make_simple_sink(const std::string &args, const uhd::io_type_t::tid_t &type); class uhd_simple_sink : public gr_sync_block{ public: - uhd_simple_sink(const std::string &args, const std::string &type); + uhd_simple_sink(const std::string &args, const uhd::io_type_t &type); ~uhd_simple_sink(void); void set_samp_rate(double rate); @@ -49,8 +49,7 @@ public: protected: uhd::simple_device::sptr _dev; - std::string _type; - size_t _sizeof_samp; + const uhd::io_type_t _type; }; #endif /* INCLUDED_UHD_SIMPLE_SINK_H */ diff --git a/gr-uhd/lib/uhd_simple_source.cc b/gr-uhd/lib/uhd_simple_source.cc index 725cb2807..677099f11 100644 --- a/gr-uhd/lib/uhd_simple_source.cc +++ b/gr-uhd/lib/uhd_simple_source.cc @@ -30,7 +30,7 @@ **********************************************************************/ boost::shared_ptr uhd_make_simple_source( const std::string &args, - const std::string &type + const uhd::io_type_t::tid_t &type ){ return boost::shared_ptr( new uhd_simple_source(args, type) @@ -42,15 +42,13 @@ boost::shared_ptr uhd_make_simple_source( **********************************************************************/ uhd_simple_source::uhd_simple_source( const std::string &args, - const std::string &type + const uhd::io_type_t &type ) : gr_sync_block( "uhd source", gr_make_io_signature(0, 0, 0), - gr_make_io_signature(1, 1, get_size(type)) -){ - _type = type; + gr_make_io_signature(1, 1, type.size) +), _type(type){ _dev = uhd::simple_device::make(args); - _sizeof_samp = get_size(type); set_streaming(false); } @@ -99,8 +97,8 @@ int uhd_simple_source::work( while(total_items_read < size_t(noutput_items)){ size_t items_read = _dev->get_device()->recv( boost::asio::buffer( - (uint8_t *)output_items[0]+(total_items_read*_sizeof_samp), - (noutput_items-total_items_read)*_sizeof_samp + (uint8_t *)output_items[0]+(total_items_read*_type.size), + (noutput_items-total_items_read)*_type.size ), metadata, _type ); total_items_read += items_read; diff --git a/gr-uhd/lib/uhd_simple_source.h b/gr-uhd/lib/uhd_simple_source.h index 27fa2c382..50b1c9518 100644 --- a/gr-uhd/lib/uhd_simple_source.h +++ b/gr-uhd/lib/uhd_simple_source.h @@ -29,11 +29,11 @@ class uhd_simple_source; boost::shared_ptr -uhd_make_simple_source(const std::string &args, const std::string &type); +uhd_make_simple_source(const std::string &args, const uhd::io_type_t::tid_t &type); class uhd_simple_source : public gr_sync_block{ public: - uhd_simple_source(const std::string &args, const std::string &type); + uhd_simple_source(const std::string &args, const uhd::io_type_t &type); ~uhd_simple_source(void); void set_samp_rate(double rate); @@ -49,8 +49,7 @@ public: protected: uhd::simple_device::sptr _dev; - std::string _type; - size_t _sizeof_samp; + const uhd::io_type_t _type; bool _is_streaming; void set_streaming(bool enb); }; diff --git a/gr-uhd/lib/utils.cc b/gr-uhd/lib/utils.cc index 0351d6370..e81241303 100644 --- a/gr-uhd/lib/utils.cc +++ b/gr-uhd/lib/utils.cc @@ -21,16 +21,3 @@ */ #include "utils.h" //local include -#include -#include -#include - -size_t get_size(const std::string &type){ - if(type == "32fc"){ - return sizeof(std::complex); - } - if(type == "16sc"){ - return sizeof(std::complex); - } - throw std::runtime_error("unknown type"); -} diff --git a/gr-uhd/lib/utils.h b/gr-uhd/lib/utils.h index eb3a133bc..9e3acf571 100644 --- a/gr-uhd/lib/utils.h +++ b/gr-uhd/lib/utils.h @@ -23,9 +23,4 @@ #ifndef INCLUDED_NOINST_UTILS_H #define INCLUDED_NOINST_UTILS_H -#include -#include - -size_t get_size(const std::string &type); - #endif /* INCLUDED_NOINST_UTILS_H */ diff --git a/gr-uhd/swig/Makefile.am b/gr-uhd/swig/Makefile.am index 3b1fd20f8..183e6b587 100644 --- a/gr-uhd/swig/Makefile.am +++ b/gr-uhd/swig/Makefile.am @@ -25,6 +25,7 @@ AM_CPPFLAGS = \ $(STD_DEFINES_AND_INCLUDES) \ $(PYTHON_CPPFLAGS) \ $(WITH_INCLUDES) \ + $(UHD_CFLAGS) \ -I$(top_srcdir)/gr-uhd/lib if PYTHON @@ -56,7 +57,9 @@ uhd_swig_swiginclude_headers = include $(top_srcdir)/Makefile.swig # FIXME better way to set this? -STD_SWIG_PYTHON_ARGS += -I$(top_srcdir)/gr-uhd/lib +STD_SWIG_PYTHON_ARGS += \ + $(UHD_CFLAGS) \ + -I$(top_srcdir)/gr-uhd/lib # add some of the variables generated inside the Makefile.swig.gen BUILT_SOURCES = $(swig_built_sources) diff --git a/gr-uhd/swig/uhd_swig.i b/gr-uhd/swig/uhd_swig.i index 363d9c914..2642f9450 100644 --- a/gr-uhd/swig/uhd_swig.i +++ b/gr-uhd/swig/uhd_swig.i @@ -27,8 +27,10 @@ #include %} +%include %include %include +%include GR_SWIG_BLOCK_MAGIC(uhd,simple_source) %include -- cgit From e390bcd9a69e13add9ffe3da430ba8ce19e88819 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 1 Apr 2010 16:01:08 -0700 Subject: Use simple usrp from uhd. --- gr-uhd/lib/uhd_simple_sink.cc | 2 +- gr-uhd/lib/uhd_simple_sink.h | 4 ++-- gr-uhd/lib/uhd_simple_source.cc | 2 +- gr-uhd/lib/uhd_simple_source.h | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/gr-uhd/lib/uhd_simple_sink.cc b/gr-uhd/lib/uhd_simple_sink.cc index a22b52421..107a4ef6c 100644 --- a/gr-uhd/lib/uhd_simple_sink.cc +++ b/gr-uhd/lib/uhd_simple_sink.cc @@ -49,7 +49,7 @@ uhd_simple_sink::uhd_simple_sink( gr_make_io_signature(1, 1, type.size), gr_make_io_signature(0, 0, 0) ), _type(type){ - _dev = uhd::simple_device::make(args); + _dev = uhd::usrp::simple_usrp::make(args); } uhd_simple_sink::~uhd_simple_sink(void){ diff --git a/gr-uhd/lib/uhd_simple_sink.h b/gr-uhd/lib/uhd_simple_sink.h index aa8d1144c..735f72bdd 100644 --- a/gr-uhd/lib/uhd_simple_sink.h +++ b/gr-uhd/lib/uhd_simple_sink.h @@ -24,7 +24,7 @@ #define INCLUDED_UHD_SIMPLE_SINK_H #include -#include +#include class uhd_simple_sink; @@ -48,7 +48,7 @@ public: ); protected: - uhd::simple_device::sptr _dev; + uhd::usrp::simple_usrp::sptr _dev; const uhd::io_type_t _type; }; diff --git a/gr-uhd/lib/uhd_simple_source.cc b/gr-uhd/lib/uhd_simple_source.cc index 677099f11..4a40c2cfc 100644 --- a/gr-uhd/lib/uhd_simple_source.cc +++ b/gr-uhd/lib/uhd_simple_source.cc @@ -48,7 +48,7 @@ uhd_simple_source::uhd_simple_source( gr_make_io_signature(0, 0, 0), gr_make_io_signature(1, 1, type.size) ), _type(type){ - _dev = uhd::simple_device::make(args); + _dev = uhd::usrp::simple_usrp::make(args); set_streaming(false); } diff --git a/gr-uhd/lib/uhd_simple_source.h b/gr-uhd/lib/uhd_simple_source.h index 50b1c9518..c498c5715 100644 --- a/gr-uhd/lib/uhd_simple_source.h +++ b/gr-uhd/lib/uhd_simple_source.h @@ -24,7 +24,7 @@ #define INCLUDED_UHD_SIMPLE_SOURCE_H #include -#include +#include class uhd_simple_source; @@ -48,7 +48,7 @@ public: ); protected: - uhd::simple_device::sptr _dev; + uhd::usrp::simple_usrp::sptr _dev; const uhd::io_type_t _type; bool _is_streaming; void set_streaming(bool enb); -- cgit From 8dfa110cf286db709a503adafc296a8b23225645 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 5 Apr 2010 17:25:19 -0700 Subject: fix for paradigm shift --- gr-uhd/lib/uhd_simple_source.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gr-uhd/lib/uhd_simple_source.cc b/gr-uhd/lib/uhd_simple_source.cc index 4a40c2cfc..85e7f8f37 100644 --- a/gr-uhd/lib/uhd_simple_source.cc +++ b/gr-uhd/lib/uhd_simple_source.cc @@ -58,10 +58,10 @@ uhd_simple_source::~uhd_simple_source(void){ } void uhd_simple_source::set_streaming(bool enb){ - uhd::stream_cmd_t stream_cmd; - stream_cmd.stream_now = true; - stream_cmd.continuous = enb; - _dev->issue_stream_cmd(stream_cmd); + if (enb) + _dev->issue_stream_cmd(uhd::stream_cmd_t::STREAM_MODE_START_CONTINUOUS); + else + _dev->issue_stream_cmd(uhd::stream_cmd_t::STREAM_MODE_STOP_CONTINUOUS); _is_streaming = enb; } -- cgit From b89d6edb60a069215d02fb78614c9dbfb46b4899 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 14 Apr 2010 12:16:43 -0700 Subject: added more access methods to uhd source and sink --- gr-uhd/lib/uhd_simple_sink.cc | 31 +++++++++++++++++++++- gr-uhd/lib/uhd_simple_sink.h | 57 +++++++++++++++++++++++++++++++++++++++++ gr-uhd/lib/uhd_simple_source.cc | 31 +++++++++++++++++++++- gr-uhd/lib/uhd_simple_source.h | 57 +++++++++++++++++++++++++++++++++++++++++ gr-uhd/lib/utils.cc | 14 ++++++++++ gr-uhd/lib/utils.h | 2 ++ 6 files changed, 190 insertions(+), 2 deletions(-) diff --git a/gr-uhd/lib/uhd_simple_sink.cc b/gr-uhd/lib/uhd_simple_sink.cc index 107a4ef6c..bf2b02d31 100644 --- a/gr-uhd/lib/uhd_simple_sink.cc +++ b/gr-uhd/lib/uhd_simple_sink.cc @@ -57,7 +57,8 @@ uhd_simple_sink::~uhd_simple_sink(void){ } void uhd_simple_sink::set_samp_rate(double rate){ - return _dev->set_tx_rate(rate); + _dev->set_tx_rate(rate); + do_samp_rate_error_message(rate, get_samp_rate()); } double uhd_simple_sink::get_samp_rate(void){ @@ -68,6 +69,34 @@ uhd::tune_result_t uhd_simple_sink::set_center_freq(double freq){ return _dev->set_tx_freq(freq); } +uhd::freq_range_t uhd_simple_sink::get_freq_range(void){ + return _dev->get_tx_freq_range(); +} + +void uhd_simple_sink::set_gain(float gain){ + return _dev->set_tx_gain(gain); +} + +float uhd_simple_sink::get_gain(void){ + return _dev->get_tx_gain(); +} + +uhd::gain_range_t uhd_simple_sink::get_gain_range(void){ + return _dev->get_tx_gain_range(); +} + +void uhd_simple_sink::set_antenna(const std::string &ant){ + return _dev->set_tx_antenna(ant); +} + +std::string uhd_simple_sink::get_antenna(void){ + return _dev->get_tx_antenna(); +} + +std::vector uhd_simple_sink::get_antennas(void){ + return _dev->get_tx_antennas(); +} + /*********************************************************************** * Work **********************************************************************/ diff --git a/gr-uhd/lib/uhd_simple_sink.h b/gr-uhd/lib/uhd_simple_sink.h index 735f72bdd..0229e38ca 100644 --- a/gr-uhd/lib/uhd_simple_sink.h +++ b/gr-uhd/lib/uhd_simple_sink.h @@ -36,11 +36,68 @@ public: uhd_simple_sink(const std::string &args, const uhd::io_type_t &type); ~uhd_simple_sink(void); + /*! + * Set the sample rate for the usrp device. + * \param rate a new rate in Sps + */ void set_samp_rate(double rate); + + /*! + * Get the sample rate for the usrp device. + * This is the actual sample rate and may differ from the rate set. + * \return the actual rate in Sps + */ double get_samp_rate(void); + /*! + * Tune the usrp device to the desired center frequency. + * \param freq the desired frequency in Hz + * \return a tune result with the actual frequencies + */ uhd::tune_result_t set_center_freq(double freq); + /*! + * Get the tunable frequency range. + * \return the frequency range in Hz + */ + uhd::freq_range_t get_freq_range(void); + + /*! + * Set the gain for the dboard. + * \param gain the gain in dB + */ + void set_gain(float gain); + + /*! + * Get the actual dboard gain setting. + * \return the actual gain in dB + */ + float get_gain(void); + + /*! + * Get the settable gain range. + * \return the gain range in dB + */ + uhd::gain_range_t get_gain_range(void); + + /*! + * Set the antenna to use. + * \param ant the antenna string + */ + void set_antenna(const std::string &ant); + + /*! + * Get the antenna in use. + * \return the antenna string + */ + std::string get_antenna(void); + + /*! + * Get a list of possible antennas. + * \return a vector of antenna strings + */ + std::vector get_antennas(void); + int work( int noutput_items, gr_vector_const_void_star &input_items, diff --git a/gr-uhd/lib/uhd_simple_source.cc b/gr-uhd/lib/uhd_simple_source.cc index 85e7f8f37..e63fe9647 100644 --- a/gr-uhd/lib/uhd_simple_source.cc +++ b/gr-uhd/lib/uhd_simple_source.cc @@ -66,7 +66,8 @@ void uhd_simple_source::set_streaming(bool enb){ } void uhd_simple_source::set_samp_rate(double rate){ - return _dev->set_rx_rate(rate); + _dev->set_rx_rate(rate); + do_samp_rate_error_message(rate, get_samp_rate()); } double uhd_simple_source::get_samp_rate(void){ @@ -77,6 +78,34 @@ uhd::tune_result_t uhd_simple_source::set_center_freq(double freq){ return _dev->set_rx_freq(freq); } +uhd::freq_range_t uhd_simple_source::get_freq_range(void){ + return _dev->get_rx_freq_range(); +} + +void uhd_simple_source::set_gain(float gain){ + return _dev->set_rx_gain(gain); +} + +float uhd_simple_source::get_gain(void){ + return _dev->get_rx_gain(); +} + +uhd::gain_range_t uhd_simple_source::get_gain_range(void){ + return _dev->get_rx_gain_range(); +} + +void uhd_simple_source::set_antenna(const std::string &ant){ + return _dev->set_rx_antenna(ant); +} + +std::string uhd_simple_source::get_antenna(void){ + return _dev->get_rx_antenna(); +} + +std::vector uhd_simple_source::get_antennas(void){ + return _dev->get_rx_antennas(); +} + /*********************************************************************** * Work **********************************************************************/ diff --git a/gr-uhd/lib/uhd_simple_source.h b/gr-uhd/lib/uhd_simple_source.h index c498c5715..7d286f09c 100644 --- a/gr-uhd/lib/uhd_simple_source.h +++ b/gr-uhd/lib/uhd_simple_source.h @@ -36,11 +36,68 @@ public: uhd_simple_source(const std::string &args, const uhd::io_type_t &type); ~uhd_simple_source(void); + /*! + * Set the sample rate for the usrp device. + * \param rate a new rate in Sps + */ void set_samp_rate(double rate); + + /*! + * Get the sample rate for the usrp device. + * This is the actual sample rate and may differ from the rate set. + * \return the actual rate in Sps + */ double get_samp_rate(void); + /*! + * Tune the usrp device to the desired center frequency. + * \param freq the desired frequency in Hz + * \return a tune result with the actual frequencies + */ uhd::tune_result_t set_center_freq(double freq); + /*! + * Get the tunable frequency range. + * \return the frequency range in Hz + */ + uhd::freq_range_t get_freq_range(void); + + /*! + * Set the gain for the dboard. + * \param gain the gain in dB + */ + void set_gain(float gain); + + /*! + * Get the actual dboard gain setting. + * \return the actual gain in dB + */ + float get_gain(void); + + /*! + * Get the settable gain range. + * \return the gain range in dB + */ + uhd::gain_range_t get_gain_range(void); + + /*! + * Set the antenna to use. + * \param ant the antenna string + */ + void set_antenna(const std::string &ant); + + /*! + * Get the antenna in use. + * \return the antenna string + */ + std::string get_antenna(void); + + /*! + * Get a list of possible antennas. + * \return a vector of antenna strings + */ + std::vector get_antennas(void); + int work( int noutput_items, gr_vector_const_void_star &input_items, diff --git a/gr-uhd/lib/utils.cc b/gr-uhd/lib/utils.cc index e81241303..ddc36eb99 100644 --- a/gr-uhd/lib/utils.cc +++ b/gr-uhd/lib/utils.cc @@ -21,3 +21,17 @@ */ #include "utils.h" //local include +#include +#include +#include + +void do_samp_rate_error_message(double target_rate, double actual_rate){ + static const double max_allowed_error = 1.0; //Sps + if (std::abs(target_rate - actual_rate) > max_allowed_error){ + std::cerr << boost::format( + "The hardware does not support the requested sample rate:\n" + " Target sample rate: %f MSps\n" + " Actual sample rate: %f MSps\n" + ) % (target_rate/1e6) % (actual_rate/1e6) << std::endl; + } +} diff --git a/gr-uhd/lib/utils.h b/gr-uhd/lib/utils.h index 9e3acf571..cf349e5aa 100644 --- a/gr-uhd/lib/utils.h +++ b/gr-uhd/lib/utils.h @@ -23,4 +23,6 @@ #ifndef INCLUDED_NOINST_UTILS_H #define INCLUDED_NOINST_UTILS_H +void do_samp_rate_error_message(double target_rate, double actual_rate); + #endif /* INCLUDED_NOINST_UTILS_H */ -- cgit From ec7bdb4c93c8046b7d80bdad9b151c990946b181 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 14 Apr 2010 12:31:19 -0700 Subject: added to uhd grc files, also removed warning for grc generator with uhd blocks --- gr-uhd/grc/uhd_simple_sink.xml | 20 +++++++++++++++++++- gr-uhd/grc/uhd_simple_source.xml | 20 +++++++++++++++++++- grc/python/Generator.py | 2 +- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/gr-uhd/grc/uhd_simple_sink.xml b/gr-uhd/grc/uhd_simple_sink.xml index fa9e19be7..7971a296b 100644 --- a/gr-uhd/grc/uhd_simple_sink.xml +++ b/gr-uhd/grc/uhd_simple_sink.xml @@ -11,9 +11,15 @@ from gnuradio import uhd uhd.simple_sink($args, uhd.io_type_t.$type.type) self.$(id).set_samp_rate($samp_rate) -self.$(id).set_center_freq($center_freq) +self.$(id).set_center_freq($center_freq) +self.$(id).set_gain($gain) +#if $ant() +self.$(id).set_antenna($antenna) +#end if set_samp_rate($samp_rate) set_center_freq($center_freq) + set_gain($gain) + set_antenna($antenna) Input Type type @@ -48,6 +54,18 @@ self.$(id).set_center_freq($center_freq) center_freq real + + Gain (dB) + gain + 0 + real + + + Antenna + ant + string + #if $ant() == '' then 'part' else 'none'# + out $type diff --git a/gr-uhd/grc/uhd_simple_source.xml b/gr-uhd/grc/uhd_simple_source.xml index 7deffeeec..10a2f2c56 100644 --- a/gr-uhd/grc/uhd_simple_source.xml +++ b/gr-uhd/grc/uhd_simple_source.xml @@ -11,9 +11,15 @@ from gnuradio import uhd uhd.simple_source($args, uhd.io_type_t.$type.type) self.$(id).set_samp_rate($samp_rate) -self.$(id).set_center_freq($center_freq) +self.$(id).set_center_freq($center_freq) +self.$(id).set_gain($gain) +#if $ant() +self.$(id).set_antenna($antenna) +#end if set_samp_rate($samp_rate) set_center_freq($center_freq) + set_gain($gain) + set_antenna($antenna) Output Type type @@ -48,6 +54,18 @@ self.$(id).set_center_freq($center_freq) center_freq real + + Gain (dB) + gain + 0 + real + + + Antenna + ant + string + #if $ant() == '' then 'part' else 'none'# + out $type diff --git a/grc/python/Generator.py b/grc/python/Generator.py index acd98ef84..d53802bef 100644 --- a/grc/python/Generator.py +++ b/grc/python/Generator.py @@ -58,7 +58,7 @@ class Generator(object): def write(self): #do throttle warning all_keys = ' '.join(map(lambda b: b.get_key(), self._flow_graph.get_enabled_blocks())) - if ('usrp' not in all_keys) and ('audio' not in all_keys) and ('throttle' not in all_keys) and self._generate_options != 'hb': + if ('usrp' not in all_keys) and ('uhd' not in all_keys) and ('audio' not in all_keys) and ('throttle' not in all_keys) and self._generate_options != 'hb': Messages.send_warning('''\ This flow graph may not have flow control: no audio or usrp blocks found. \ Add a Misc->Throttle block to your flow graph to avoid CPU congestion.''') -- cgit From 001bbc6a303218785337b1df7221a3fdcc47a2cd Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 15 Apr 2010 19:47:36 -0700 Subject: typo fix, called variable ant, not antenna --- gr-uhd/grc/uhd_simple_sink.xml | 4 ++-- gr-uhd/grc/uhd_simple_source.xml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/gr-uhd/grc/uhd_simple_sink.xml b/gr-uhd/grc/uhd_simple_sink.xml index 7971a296b..b6406e80d 100644 --- a/gr-uhd/grc/uhd_simple_sink.xml +++ b/gr-uhd/grc/uhd_simple_sink.xml @@ -14,12 +14,12 @@ self.$(id).set_samp_rate($samp_rate) self.$(id).set_center_freq($center_freq) self.$(id).set_gain($gain) #if $ant() -self.$(id).set_antenna($antenna) +self.$(id).set_antenna($ant) #end if set_samp_rate($samp_rate) set_center_freq($center_freq) set_gain($gain) - set_antenna($antenna) + set_antenna($ant) Input Type type diff --git a/gr-uhd/grc/uhd_simple_source.xml b/gr-uhd/grc/uhd_simple_source.xml index 10a2f2c56..34b6817c9 100644 --- a/gr-uhd/grc/uhd_simple_source.xml +++ b/gr-uhd/grc/uhd_simple_source.xml @@ -14,12 +14,12 @@ self.$(id).set_samp_rate($samp_rate) self.$(id).set_center_freq($center_freq) self.$(id).set_gain($gain) #if $ant() -self.$(id).set_antenna($antenna) +self.$(id).set_antenna($ant) #end if set_samp_rate($samp_rate) set_center_freq($center_freq) set_gain($gain) - set_antenna($antenna) + set_antenna($ant) Output Type type -- cgit From 999bba14d657a11fa9bfc1b9587e1341e2f28e07 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 23 Apr 2010 10:11:53 -0700 Subject: added docs to uhd grc blocks, added pkg config path to make support easier --- config/grc_gr_uhd.m4 | 3 +++ gr-uhd/grc/uhd_simple_sink.xml | 17 +++++++++++++++++ gr-uhd/grc/uhd_simple_source.xml | 17 +++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/config/grc_gr_uhd.m4 b/config/grc_gr_uhd.m4 index c3c701dbd..870a8abc6 100644 --- a/config/grc_gr_uhd.m4 +++ b/config/grc_gr_uhd.m4 @@ -24,6 +24,9 @@ AC_DEFUN([GRC_GR_UHD],[ GRC_CHECK_DEPENDENCY(gr-uhd, gnuradio-core) if test $passed = yes; then + #by default, cmake likes to install the uhd.pc file here + #so lets make life easier for everybody and add this path + export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig PKG_CHECK_MODULES( [UHD], [uhd], [], [passed=no; AC_MSG_RESULT([gr-uhd requires libuhd])] diff --git a/gr-uhd/grc/uhd_simple_sink.xml b/gr-uhd/grc/uhd_simple_sink.xml index b6406e80d..2992f650e 100644 --- a/gr-uhd/grc/uhd_simple_sink.xml +++ b/gr-uhd/grc/uhd_simple_sink.xml @@ -72,5 +72,22 @@ self.$(id).set_antenna($ant) $type.vlen +The UHD Sink Block: + +Args: +Args is a delimited string used to locate UHD devices on your system. \ +If left blank, the first UHD device found will be used. \ +Used args to specify a specfic device. \ +USRP2 Example: addr=192.168.10.2 + +Sample rate: +The sample rate is the number of samples per second input by this block. \ +The UHD device driver will try its best to match the requested sample rate. \ +If the requested rate is not possible, the UHD block will print an error at runtime. + +Antenna: +For subdevices/daughterboards with only one antenna, this may be left blank. \ +Otherwise, the user should specify one of the possible antenna choices. \ +See the daughterboard application notes for the possible antenna choices. diff --git a/gr-uhd/grc/uhd_simple_source.xml b/gr-uhd/grc/uhd_simple_source.xml index 34b6817c9..ecd963928 100644 --- a/gr-uhd/grc/uhd_simple_source.xml +++ b/gr-uhd/grc/uhd_simple_source.xml @@ -72,5 +72,22 @@ self.$(id).set_antenna($ant) $type.vlen +The UHD Source Block: + +Args: +Args is a delimited string used to locate UHD devices on your system. \ +If left blank, the first UHD device found will be used. \ +Used args to specify a specfic device. \ +USRP2 Example: addr=192.168.10.2 + +Sample rate: +The sample rate is the number of samples per second output by this block. \ +The UHD device driver will try its best to match the requested sample rate. \ +If the requested rate is not possible, the UHD block will print an error at runtime. + +Antenna: +For subdevices/daughterboards with only one antenna, this may be left blank. \ +Otherwise, the user should specify one of the possible antenna choices. \ +See the daughterboard application notes for the possible antenna choices. -- cgit From 1e4bf239c1f09a0180585de62746922bcd34b639 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 27 Apr 2010 16:07:34 -0700 Subject: Added call to get access to the underlying uhd simple usrp object. Made the simple uhd source and sink into mostly virtual classes with the implementation within the cc files. --- gr-uhd/lib/uhd_simple_sink.cc | 161 ++++++++++++++++++--------------- gr-uhd/lib/uhd_simple_sink.h | 48 +++++----- gr-uhd/lib/uhd_simple_source.cc | 195 ++++++++++++++++++++++------------------ gr-uhd/lib/uhd_simple_source.h | 52 +++++------ 4 files changed, 245 insertions(+), 211 deletions(-) diff --git a/gr-uhd/lib/uhd_simple_sink.cc b/gr-uhd/lib/uhd_simple_sink.cc index bf2b02d31..889371e91 100644 --- a/gr-uhd/lib/uhd_simple_sink.cc +++ b/gr-uhd/lib/uhd_simple_sink.cc @@ -22,103 +22,118 @@ #include #include -#include #include #include "utils.h" /*********************************************************************** - * Make UHD Sink + * UHD Sink **********************************************************************/ -boost::shared_ptr uhd_make_simple_sink( - const std::string &args, - const uhd::io_type_t::tid_t &type -){ - return boost::shared_ptr( - new uhd_simple_sink(args, type) - ); +uhd_simple_sink::uhd_simple_sink(gr_io_signature_sptr sig) +:gr_sync_block("uhd sink", sig, gr_make_io_signature(0, 0, 0)){ + /* NOP */ } /*********************************************************************** - * UHD Sink + * UHD Sink Impl **********************************************************************/ -uhd_simple_sink::uhd_simple_sink( - const std::string &args, - const uhd::io_type_t &type -) : gr_sync_block( - "uhd sink", - gr_make_io_signature(1, 1, type.size), - gr_make_io_signature(0, 0, 0) -), _type(type){ - _dev = uhd::usrp::simple_usrp::make(args); -} +class uhd_simple_sink_impl : public uhd_simple_sink{ +public: + uhd_simple_sink_impl( + const std::string &args, + const uhd::io_type_t &type + ) : uhd_simple_sink(gr_make_io_signature(1, 1, type.size)), _type(type) + { + _dev = uhd::usrp::simple_usrp::make(args); + } -uhd_simple_sink::~uhd_simple_sink(void){ - //NOP -} + ~uhd_simple_sink_impl(void){ + //NOP + } -void uhd_simple_sink::set_samp_rate(double rate){ - _dev->set_tx_rate(rate); - do_samp_rate_error_message(rate, get_samp_rate()); -} + void set_samp_rate(double rate){ + _dev->set_tx_rate(rate); + do_samp_rate_error_message(rate, get_samp_rate()); + } -double uhd_simple_sink::get_samp_rate(void){ - return _dev->get_tx_rate(); -} + double get_samp_rate(void){ + return _dev->get_tx_rate(); + } -uhd::tune_result_t uhd_simple_sink::set_center_freq(double freq){ - return _dev->set_tx_freq(freq); -} + uhd::tune_result_t set_center_freq(double freq){ + return _dev->set_tx_freq(freq); + } -uhd::freq_range_t uhd_simple_sink::get_freq_range(void){ - return _dev->get_tx_freq_range(); -} + uhd::freq_range_t get_freq_range(void){ + return _dev->get_tx_freq_range(); + } -void uhd_simple_sink::set_gain(float gain){ - return _dev->set_tx_gain(gain); -} + void set_gain(float gain){ + return _dev->set_tx_gain(gain); + } -float uhd_simple_sink::get_gain(void){ - return _dev->get_tx_gain(); -} + float get_gain(void){ + return _dev->get_tx_gain(); + } -uhd::gain_range_t uhd_simple_sink::get_gain_range(void){ - return _dev->get_tx_gain_range(); -} + uhd::gain_range_t get_gain_range(void){ + return _dev->get_tx_gain_range(); + } -void uhd_simple_sink::set_antenna(const std::string &ant){ - return _dev->set_tx_antenna(ant); -} + void set_antenna(const std::string &ant){ + return _dev->set_tx_antenna(ant); + } -std::string uhd_simple_sink::get_antenna(void){ - return _dev->get_tx_antenna(); -} + std::string get_antenna(void){ + return _dev->get_tx_antenna(); + } -std::vector uhd_simple_sink::get_antennas(void){ - return _dev->get_tx_antennas(); -} + std::vector get_antennas(void){ + return _dev->get_tx_antennas(); + } /*********************************************************************** * Work **********************************************************************/ -int uhd_simple_sink::work( - int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items -){ - size_t total_items_sent = 0; - uhd::tx_metadata_t metadata; - metadata.start_of_burst = true; - - //call until the input items are all sent - while(total_items_sent < size_t(noutput_items)){ - size_t items_sent = _dev->get_device()->send( - boost::asio::buffer( - (uint8_t *)input_items[0]+(total_items_sent*_type.size), - (noutput_items-total_items_sent)*_type.size - ), metadata, _type - ); - total_items_sent += items_sent; + int work( + int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items + ){ + size_t total_items_sent = 0; + uhd::tx_metadata_t metadata; + metadata.start_of_burst = true; + + //call until the input items are all sent + while(total_items_sent < size_t(noutput_items)){ + size_t items_sent = _dev->get_device()->send( + boost::asio::buffer( + (uint8_t *)input_items[0]+(total_items_sent*_type.size), + (noutput_items-total_items_sent)*_type.size + ), metadata, _type + ); + total_items_sent += items_sent; + } + + return noutput_items; } - return noutput_items; + uhd::usrp::simple_usrp::sptr get_device(void){ + return _dev; + } + +protected: + uhd::usrp::simple_usrp::sptr _dev; + const uhd::io_type_t _type; +}; + +/*********************************************************************** + * Make UHD Sink + **********************************************************************/ +boost::shared_ptr uhd_make_simple_sink( + const std::string &args, + const uhd::io_type_t::tid_t &type +){ + return boost::shared_ptr( + new uhd_simple_sink_impl(args, type) + ); } diff --git a/gr-uhd/lib/uhd_simple_sink.h b/gr-uhd/lib/uhd_simple_sink.h index 0229e38ca..9ecf51aea 100644 --- a/gr-uhd/lib/uhd_simple_sink.h +++ b/gr-uhd/lib/uhd_simple_sink.h @@ -28,85 +28,87 @@ class uhd_simple_sink; -boost::shared_ptr -uhd_make_simple_sink(const std::string &args, const uhd::io_type_t::tid_t &type); +boost::shared_ptr uhd_make_simple_sink( + const std::string &args, + const uhd::io_type_t::tid_t &type +); class uhd_simple_sink : public gr_sync_block{ public: - uhd_simple_sink(const std::string &args, const uhd::io_type_t &type); - ~uhd_simple_sink(void); + + /*! + * Set the IO signature for this block. + * \param sig the input signature + */ + uhd_simple_sink(gr_io_signature_sptr sig); /*! * Set the sample rate for the usrp device. * \param rate a new rate in Sps */ - void set_samp_rate(double rate); + virtual void set_samp_rate(double rate) = 0; /*! * Get the sample rate for the usrp device. * This is the actual sample rate and may differ from the rate set. * \return the actual rate in Sps */ - double get_samp_rate(void); + virtual double get_samp_rate(void) = 0; /*! * Tune the usrp device to the desired center frequency. * \param freq the desired frequency in Hz * \return a tune result with the actual frequencies */ - uhd::tune_result_t set_center_freq(double freq); + virtual uhd::tune_result_t set_center_freq(double freq) = 0; /*! * Get the tunable frequency range. * \return the frequency range in Hz */ - uhd::freq_range_t get_freq_range(void); + virtual uhd::freq_range_t get_freq_range(void) = 0; /*! * Set the gain for the dboard. * \param gain the gain in dB */ - void set_gain(float gain); + virtual void set_gain(float gain) = 0; /*! * Get the actual dboard gain setting. * \return the actual gain in dB */ - float get_gain(void); + virtual float get_gain(void) = 0; /*! * Get the settable gain range. * \return the gain range in dB */ - uhd::gain_range_t get_gain_range(void); + virtual uhd::gain_range_t get_gain_range(void) = 0; /*! * Set the antenna to use. * \param ant the antenna string */ - void set_antenna(const std::string &ant); + virtual void set_antenna(const std::string &ant) = 0; /*! * Get the antenna in use. * \return the antenna string */ - std::string get_antenna(void); + virtual std::string get_antenna(void) = 0; /*! * Get a list of possible antennas. * \return a vector of antenna strings */ - std::vector get_antennas(void); + virtual std::vector get_antennas(void) = 0; - int work( - int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items - ); - -protected: - uhd::usrp::simple_usrp::sptr _dev; - const uhd::io_type_t _type; + /*! + * Get access to the underlying uhd device object. + * \return the simple usrp device object + */ + virtual uhd::usrp::simple_usrp::sptr get_device(void) = 0; }; #endif /* INCLUDED_UHD_SIMPLE_SINK_H */ diff --git a/gr-uhd/lib/uhd_simple_source.cc b/gr-uhd/lib/uhd_simple_source.cc index e63fe9647..8c3fdeef8 100644 --- a/gr-uhd/lib/uhd_simple_source.cc +++ b/gr-uhd/lib/uhd_simple_source.cc @@ -26,115 +26,132 @@ #include "utils.h" /*********************************************************************** - * Make UHD Source + * UHD Source **********************************************************************/ -boost::shared_ptr uhd_make_simple_source( - const std::string &args, - const uhd::io_type_t::tid_t &type -){ - return boost::shared_ptr( - new uhd_simple_source(args, type) - ); +uhd_simple_source::uhd_simple_source(gr_io_signature_sptr sig) +:gr_sync_block("uhd source", gr_make_io_signature(0, 0, 0), sig){ + /* NOP */ } /*********************************************************************** - * UHD Source + * UHD Source Impl **********************************************************************/ -uhd_simple_source::uhd_simple_source( - const std::string &args, - const uhd::io_type_t &type -) : gr_sync_block( - "uhd source", - gr_make_io_signature(0, 0, 0), - gr_make_io_signature(1, 1, type.size) -), _type(type){ - _dev = uhd::usrp::simple_usrp::make(args); - - set_streaming(false); -} - -uhd_simple_source::~uhd_simple_source(void){ - set_streaming(false); -} +class uhd_simple_source_impl : public uhd_simple_source{ +public: + uhd_simple_source_impl( + const std::string &args, + const uhd::io_type_t &type + ) : uhd_simple_source(gr_make_io_signature(1, 1, type.size)), _type(type) + { + _dev = uhd::usrp::simple_usrp::make(args); + set_streaming(false); + } -void uhd_simple_source::set_streaming(bool enb){ - if (enb) - _dev->issue_stream_cmd(uhd::stream_cmd_t::STREAM_MODE_START_CONTINUOUS); - else - _dev->issue_stream_cmd(uhd::stream_cmd_t::STREAM_MODE_STOP_CONTINUOUS); - _is_streaming = enb; -} + ~uhd_simple_source_impl(void){ + set_streaming(false); + } -void uhd_simple_source::set_samp_rate(double rate){ - _dev->set_rx_rate(rate); - do_samp_rate_error_message(rate, get_samp_rate()); -} + void set_samp_rate(double rate){ + _dev->set_rx_rate(rate); + do_samp_rate_error_message(rate, get_samp_rate()); + } -double uhd_simple_source::get_samp_rate(void){ - return _dev->get_rx_rate(); -} + double get_samp_rate(void){ + return _dev->get_rx_rate(); + } -uhd::tune_result_t uhd_simple_source::set_center_freq(double freq){ - return _dev->set_rx_freq(freq); -} + uhd::tune_result_t set_center_freq(double freq){ + return _dev->set_rx_freq(freq); + } -uhd::freq_range_t uhd_simple_source::get_freq_range(void){ - return _dev->get_rx_freq_range(); -} + uhd::freq_range_t get_freq_range(void){ + return _dev->get_rx_freq_range(); + } -void uhd_simple_source::set_gain(float gain){ - return _dev->set_rx_gain(gain); -} + void set_gain(float gain){ + return _dev->set_rx_gain(gain); + } -float uhd_simple_source::get_gain(void){ - return _dev->get_rx_gain(); -} + float get_gain(void){ + return _dev->get_rx_gain(); + } -uhd::gain_range_t uhd_simple_source::get_gain_range(void){ - return _dev->get_rx_gain_range(); -} + uhd::gain_range_t get_gain_range(void){ + return _dev->get_rx_gain_range(); + } -void uhd_simple_source::set_antenna(const std::string &ant){ - return _dev->set_rx_antenna(ant); -} + void set_antenna(const std::string &ant){ + return _dev->set_rx_antenna(ant); + } -std::string uhd_simple_source::get_antenna(void){ - return _dev->get_rx_antenna(); -} + std::string get_antenna(void){ + return _dev->get_rx_antenna(); + } -std::vector uhd_simple_source::get_antennas(void){ - return _dev->get_rx_antennas(); -} + std::vector get_antennas(void){ + return _dev->get_rx_antennas(); + } /*********************************************************************** * Work **********************************************************************/ -int uhd_simple_source::work( - int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items -){ - //conditionally start streaming in the work call - //this prevents streaming before the runtime is ready - if (not _is_streaming) set_streaming(true); - - size_t total_items_read = 0; - uhd::rx_metadata_t metadata; - - //call until the output items are all filled - //or an exit condition below is encountered - while(total_items_read < size_t(noutput_items)){ - size_t items_read = _dev->get_device()->recv( - boost::asio::buffer( - (uint8_t *)output_items[0]+(total_items_read*_type.size), - (noutput_items-total_items_read)*_type.size - ), metadata, _type - ); - total_items_read += items_read; - - //we timed out, get out of here - if (items_read == 0) break; + int work( + int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items + ){ + //conditionally start streaming in the work call + //this prevents streaming before the runtime is ready + if (not _is_streaming) set_streaming(true); + + size_t total_items_read = 0; + uhd::rx_metadata_t metadata; + + //call until the output items are all filled + //or an exit condition below is encountered + while(total_items_read < size_t(noutput_items)){ + size_t items_read = _dev->get_device()->recv( + boost::asio::buffer( + (uint8_t *)output_items[0]+(total_items_read*_type.size), + (noutput_items-total_items_read)*_type.size + ), metadata, _type + ); + total_items_read += items_read; + + //we timed out, get out of here + if (items_read == 0) break; + } + + return total_items_read; + } + + uhd::usrp::simple_usrp::sptr get_device(void){ + return _dev; } - return total_items_read; +private: + uhd::usrp::simple_usrp::sptr _dev; + const uhd::io_type_t _type; + bool _is_streaming; + + void set_streaming(bool enb){ + if (enb) + _dev->issue_stream_cmd(uhd::stream_cmd_t::STREAM_MODE_START_CONTINUOUS); + else + _dev->issue_stream_cmd(uhd::stream_cmd_t::STREAM_MODE_STOP_CONTINUOUS); + _is_streaming = enb; + } +}; + + +/*********************************************************************** + * Make UHD Source + **********************************************************************/ +boost::shared_ptr uhd_make_simple_source( + const std::string &args, + const uhd::io_type_t::tid_t &type +){ + return boost::shared_ptr( + new uhd_simple_source_impl(args, type) + ); } diff --git a/gr-uhd/lib/uhd_simple_source.h b/gr-uhd/lib/uhd_simple_source.h index 7d286f09c..480bb4d3f 100644 --- a/gr-uhd/lib/uhd_simple_source.h +++ b/gr-uhd/lib/uhd_simple_source.h @@ -28,87 +28,87 @@ class uhd_simple_source; -boost::shared_ptr -uhd_make_simple_source(const std::string &args, const uhd::io_type_t::tid_t &type); +boost::shared_ptr uhd_make_simple_source( + const std::string &args, + const uhd::io_type_t::tid_t &type +); class uhd_simple_source : public gr_sync_block{ public: - uhd_simple_source(const std::string &args, const uhd::io_type_t &type); - ~uhd_simple_source(void); + + /*! + * Set the IO signature for this block. + * \param sig the output signature + */ + uhd_simple_source(gr_io_signature_sptr sig); /*! * Set the sample rate for the usrp device. * \param rate a new rate in Sps */ - void set_samp_rate(double rate); + virtual void set_samp_rate(double rate) = 0; /*! * Get the sample rate for the usrp device. * This is the actual sample rate and may differ from the rate set. * \return the actual rate in Sps */ - double get_samp_rate(void); + virtual double get_samp_rate(void) = 0; /*! * Tune the usrp device to the desired center frequency. * \param freq the desired frequency in Hz * \return a tune result with the actual frequencies */ - uhd::tune_result_t set_center_freq(double freq); + virtual uhd::tune_result_t set_center_freq(double freq) = 0; /*! * Get the tunable frequency range. * \return the frequency range in Hz */ - uhd::freq_range_t get_freq_range(void); + virtual uhd::freq_range_t get_freq_range(void) = 0; /*! * Set the gain for the dboard. * \param gain the gain in dB */ - void set_gain(float gain); + virtual void set_gain(float gain) = 0; /*! * Get the actual dboard gain setting. * \return the actual gain in dB */ - float get_gain(void); + virtual float get_gain(void) = 0; /*! * Get the settable gain range. * \return the gain range in dB */ - uhd::gain_range_t get_gain_range(void); + virtual uhd::gain_range_t get_gain_range(void) = 0; /*! * Set the antenna to use. * \param ant the antenna string */ - void set_antenna(const std::string &ant); + virtual void set_antenna(const std::string &ant) = 0; /*! * Get the antenna in use. * \return the antenna string */ - std::string get_antenna(void); + virtual std::string get_antenna(void) = 0; /*! * Get a list of possible antennas. * \return a vector of antenna strings */ - std::vector get_antennas(void); - - int work( - int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items - ); - -protected: - uhd::usrp::simple_usrp::sptr _dev; - const uhd::io_type_t _type; - bool _is_streaming; - void set_streaming(bool enb); + virtual std::vector get_antennas(void) = 0; + + /*! + * Get access to the underlying uhd device object. + * \return the simple usrp device object + */ + virtual uhd::usrp::simple_usrp::sptr get_device(void) = 0; }; #endif /* INCLUDED_UHD_SIMPLE_SOURCE_H */ -- cgit From 2c4bb0b5ea22ed73f3de6cac8a27083d950879bb Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 18 May 2010 12:25:42 -0700 Subject: using the send and recv full buffer modes, avoids extra loop in implementation --- gr-uhd/lib/uhd_simple_sink.cc | 25 ++++++++----------------- gr-uhd/lib/uhd_simple_source.cc | 31 +++++++++---------------------- 2 files changed, 17 insertions(+), 39 deletions(-) diff --git a/gr-uhd/lib/uhd_simple_sink.cc b/gr-uhd/lib/uhd_simple_sink.cc index 889371e91..ccec0e29c 100644 --- a/gr-uhd/lib/uhd_simple_sink.cc +++ b/gr-uhd/lib/uhd_simple_sink.cc @@ -91,6 +91,10 @@ public: return _dev->get_tx_antennas(); } + uhd::usrp::simple_usrp::sptr get_device(void){ + return _dev; + } + /*********************************************************************** * Work **********************************************************************/ @@ -99,26 +103,13 @@ public: gr_vector_const_void_star &input_items, gr_vector_void_star &output_items ){ - size_t total_items_sent = 0; uhd::tx_metadata_t metadata; metadata.start_of_burst = true; - //call until the input items are all sent - while(total_items_sent < size_t(noutput_items)){ - size_t items_sent = _dev->get_device()->send( - boost::asio::buffer( - (uint8_t *)input_items[0]+(total_items_sent*_type.size), - (noutput_items-total_items_sent)*_type.size - ), metadata, _type - ); - total_items_sent += items_sent; - } - - return noutput_items; - } - - uhd::usrp::simple_usrp::sptr get_device(void){ - return _dev; + return _dev->get_device()->send( + boost::asio::buffer(input_items[0], noutput_items*_type.size), + metadata, _type, uhd::device::SEND_MODE_FULL_BUFF + ); } protected: diff --git a/gr-uhd/lib/uhd_simple_source.cc b/gr-uhd/lib/uhd_simple_source.cc index 8c3fdeef8..76179c326 100644 --- a/gr-uhd/lib/uhd_simple_source.cc +++ b/gr-uhd/lib/uhd_simple_source.cc @@ -92,6 +92,10 @@ public: return _dev->get_rx_antennas(); } + uhd::usrp::simple_usrp::sptr get_device(void){ + return _dev; + } + /*********************************************************************** * Work **********************************************************************/ @@ -104,29 +108,12 @@ public: //this prevents streaming before the runtime is ready if (not _is_streaming) set_streaming(true); - size_t total_items_read = 0; - uhd::rx_metadata_t metadata; - - //call until the output items are all filled - //or an exit condition below is encountered - while(total_items_read < size_t(noutput_items)){ - size_t items_read = _dev->get_device()->recv( - boost::asio::buffer( - (uint8_t *)output_items[0]+(total_items_read*_type.size), - (noutput_items-total_items_read)*_type.size - ), metadata, _type - ); - total_items_read += items_read; - - //we timed out, get out of here - if (items_read == 0) break; - } - - return total_items_read; - } + uhd::rx_metadata_t metadata; //not passed out of this block - uhd::usrp::simple_usrp::sptr get_device(void){ - return _dev; + return _dev->get_device()->recv( + boost::asio::buffer(output_items[0], noutput_items*_type.size), + metadata, _type, uhd::device::RECV_MODE_FULL_BUFF + ); } private: -- cgit