summaryrefslogtreecommitdiff
path: root/gr-vrt/src
diff options
context:
space:
mode:
Diffstat (limited to 'gr-vrt/src')
-rw-r--r--gr-vrt/src/.gitignore8
-rw-r--r--gr-vrt/src/Makefile.am122
-rw-r--r--gr-vrt/src/Makefile.swig.gen259
-rw-r--r--gr-vrt/src/missing_pkt_checker.cc47
-rw-r--r--gr-vrt/src/missing_pkt_checker.h57
-rwxr-xr-xgr-vrt/src/qa_vrt.py40
-rw-r--r--gr-vrt/src/run_tests.in17
-rw-r--r--gr-vrt/src/vrt.i64
-rw-r--r--gr-vrt/src/vrt_quadradio_source_32fc.cc212
-rw-r--r--gr-vrt/src/vrt_quadradio_source_32fc.h116
-rw-r--r--gr-vrt/src/vrt_sink_16sc.cc73
-rw-r--r--gr-vrt/src/vrt_sink_16sc.h56
-rw-r--r--gr-vrt/src/vrt_sink_32fc.cc73
-rw-r--r--gr-vrt/src/vrt_sink_32fc.h56
-rw-r--r--gr-vrt/src/vrt_sink_base.cc151
-rw-r--r--gr-vrt/src/vrt_sink_base.h139
-rw-r--r--gr-vrt/src/vrt_source_16sc.cc69
-rw-r--r--gr-vrt/src/vrt_source_16sc.h54
-rw-r--r--gr-vrt/src/vrt_source_32fc.cc144
-rw-r--r--gr-vrt/src/vrt_source_32fc.h48
-rw-r--r--gr-vrt/src/vrt_source_base.cc41
-rw-r--r--gr-vrt/src/vrt_source_base.h45
22 files changed, 1891 insertions, 0 deletions
diff --git a/gr-vrt/src/.gitignore b/gr-vrt/src/.gitignore
new file mode 100644
index 000000000..9ae817ed4
--- /dev/null
+++ b/gr-vrt/src/.gitignore
@@ -0,0 +1,8 @@
+Makefile
+Makefile.in
+.deps
+.libs
+run_tests
+vrt.py
+vrt.pyc
+vrt.cc
diff --git a/gr-vrt/src/Makefile.am b/gr-vrt/src/Makefile.am
new file mode 100644
index 000000000..671c10274
--- /dev/null
+++ b/gr-vrt/src/Makefile.am
@@ -0,0 +1,122 @@
+#
+# Copyright 2004,2005,2006,2008,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.
+#
+
+include $(top_srcdir)/Makefile.common
+
+# ----------------------------------------------------------------------
+# Local Python files, not installed
+#
+# qa_vrt.py
+# ----------------------------------------------------------------------
+
+noinst_PYTHON = qa_vrt.py
+
+# ----------------------------------------------------------------------
+# Miscellaneous build operations
+# ----------------------------------------------------------------------
+
+EXTRA_DIST = run_tests.in
+TESTS = run_tests
+DISTCLEANFILES = run_tests
+
+# ----------------------------------------------------------------------
+# C++ block API interface librar(ies)
+#
+# libgnuradio_vrt.so
+# ----------------------------------------------------------------------
+AM_CPPFLAGS = \
+ $(STD_DEFINES_AND_INCLUDES) \
+ $(GRUEL_INCLUDES) \
+ $(PYTHON_CPPFLAGS) \
+ $(VRT_INCLUDES) \
+ $(WITH_INCLUDES)
+
+lib_LTLIBRARIES = libgnuradio-vrt.la
+
+libgnuradio_vrt_la_SOURCES = \
+ missing_pkt_checker.cc \
+ vrt_source_base.cc \
+ vrt_source_32fc.cc \
+ vrt_quadradio_source_32fc.cc
+
+
+#libgnuradio_vrt_la_SOURCES = \
+# rx_16sc_handler.cc \
+# rx_32fc_handler.cc \
+# vrt_base.cc \
+# vrt_source_base.cc \
+# vrt_source_16sc.cc \
+# vrt_source_32fc.cc
+
+# vrt_sink_base.cc \
+# vrt_sink_16sc.cc \
+# vrt_sink_32fc.cc
+
+libgnuradio_vrt_la_LIBADD = \
+ $(VRT_LA) \
+ $(GNURADIO_CORE_LA)
+
+grinclude_HEADERS = \
+ vrt_source_base.h \
+ vrt_source_32fc.h \
+ vrt_quadradio_source_32fc.h
+
+# vrt_source_16sc.h \
+# vrt_sink_base.h \
+# vrt_sink_16sc.h \
+# vrt_sink_32fc.h
+
+noinst_HEADERS = \
+ missing_pkt_checker.h
+
+
+# ----------------------------------------------------------------------
+# Python SWIG wrapper around C++ library
+#
+# vrt.py
+# _vrt.so
+# ----------------------------------------------------------------------
+
+TOP_SWIG_IFILES = \
+ vrt.i
+
+# Install so that they end up available as:
+# import gnuradio.vrt
+# This ends up at:
+# ${prefix}/lib/python${python_version}/site-packages/gnuradio
+vrt_pythondir_category = \
+ gnuradio
+
+# additional arguments to the SWIG command
+vrt_swig_args = \
+ $(VRT_INCLUDES)
+
+# additional libraries for linking with the SWIG-generated library
+vrt_la_swig_libadd = \
+ libgnuradio-vrt.la
+
+include $(top_srcdir)/Makefile.swig
+
+# 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)
diff --git a/gr-vrt/src/Makefile.swig.gen b/gr-vrt/src/Makefile.swig.gen
new file mode 100644
index 000000000..b0a4a22fa
--- /dev/null
+++ b/gr-vrt/src/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 vrt.i
+
+## Default install locations for these files:
+##
+## Default location for the Python directory is:
+## ${prefix}/lib/python${python_version}/site-packages/[category]/vrt
+## Default location for the Python exec directory is:
+## ${exec_prefix}/lib/python${python_version}/site-packages/[category]/vrt
+##
+## 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.
+
+vrt_pythondir_category ?= gnuradio/vrt
+vrt_pylibdir_category ?= $(vrt_pythondir_category)
+vrt_pythondir = $(pythondir)/$(vrt_pythondir_category)
+vrt_pylibdir = $(pyexecdir)/$(vrt_pylibdir_category)
+
+## SWIG headers are always installed into the same directory.
+
+vrt_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)/vrt-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 += vrt.py vrt.cc
+
+## Various SWIG variables. These can be overloaded in the including
+## Makefile.am by setting the variable value there, then including
+## Makefile.swig .
+
+vrt_swiginclude_HEADERS = \
+ vrt.i \
+ $(vrt_swiginclude_headers)
+
+vrt_pylib_LTLIBRARIES = \
+ _vrt.la
+
+_vrt_la_SOURCES = \
+ vrt.cc \
+ $(vrt_la_swig_sources)
+
+_vrt_la_LIBADD = \
+ $(STD_SWIG_LA_LIB_ADD) \
+ $(vrt_la_swig_libadd)
+
+_vrt_la_LDFLAGS = \
+ $(STD_SWIG_LA_LD_FLAGS) \
+ $(vrt_la_swig_ldflags)
+
+_vrt_la_CXXFLAGS = \
+ $(STD_SWIG_CXX_FLAGS) \
+ $(vrt_la_swig_cxxflags)
+
+vrt_python_PYTHON = \
+ vrt.py \
+ $(vrt_python)
+
+## Entry rule for running SWIG
+
+vrt.h vrt.py vrt.cc: vrt.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)/vrt-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)/vrt-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)/vrt-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)/vrt-generate-stamp; \
+##
+## Tell MAKE to run the rule for creating this stamp.
+##
+ $(MAKE) $(AM_MAKEFLAGS) $(DEPDIR)/vrt-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)/vrt-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)/vrt-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)/vrt-generate-stamp; \
+ exit $$?; \
+ fi;
+
+$(DEPDIR)/vrt-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) $(vrt_swig_args) \
+ -MD -MF $(DEPDIR)/vrt.Std \
+ -module vrt -o vrt.cc $(WHAT); then \
+ if test $(host_os) = mingw32; then \
+ $(RM) $(DEPDIR)/vrt.Sd; \
+ $(SED) 's,\\\\,/,g' < $(DEPDIR)/vrt.Std \
+ > $(DEPDIR)/vrt.Sd; \
+ $(RM) $(DEPDIR)/vrt.Std; \
+ $(MV) $(DEPDIR)/vrt.Sd $(DEPDIR)/vrt.Std; \
+ fi; \
+ else \
+ $(RM) $(DEPDIR)/vrt.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)/vrt.d
+##
+## (2) Copy the whole SWIG file:
+##
+ cp $(DEPDIR)/vrt.Std $(DEPDIR)/vrt.d
+##
+## (3) all a carriage return to the end of the dependency file.
+##
+ echo "" >> $(DEPDIR)/vrt.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)/vrt.Std | \
+ awk '{ printf "%s:\n\n", $$0 }' >> $(DEPDIR)/vrt.d
+##
+## (5) remove the SWIG-generated file
+##
+ $(RM) $(DEPDIR)/vrt.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)/vrt-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)/vrt.d@am__quote@
+
diff --git a/gr-vrt/src/missing_pkt_checker.cc b/gr-vrt/src/missing_pkt_checker.cc
new file mode 100644
index 000000000..09b70fe2c
--- /dev/null
+++ b/gr-vrt/src/missing_pkt_checker.cc
@@ -0,0 +1,47 @@
+/* -*- c++ -*- */
+/*
+ * 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 this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <missing_pkt_checker.h>
+
+int
+missing_pkt_checker::check(const vrt::expanded_header *hdr)
+{
+ // FIXME assumes we're inspecting only a single stream
+
+ int nmissing = 0;
+ int actual = hdr->pkt_cnt();
+ int expected = (d_last_pkt_cnt + 1) & 0xf;
+ if (actual != expected && !d_resync){
+ d_nwrong_pkt_cnt++;
+ if (actual > expected)
+ nmissing = actual - expected;
+ else
+ nmissing = actual + 16 - expected;
+ d_nmissing_pkt_est += nmissing;
+ }
+ d_last_pkt_cnt = actual;
+ d_npackets++;
+ d_resync = false;
+ return nmissing;
+}
diff --git a/gr-vrt/src/missing_pkt_checker.h b/gr-vrt/src/missing_pkt_checker.h
new file mode 100644
index 000000000..ab171ffa3
--- /dev/null
+++ b/gr-vrt/src/missing_pkt_checker.h
@@ -0,0 +1,57 @@
+/* -*- c++ -*- */
+/*
+ * 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 this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#ifndef INCLUDED_MISSING_PKT_CHECKER_H
+#define INCLUDED_MISSING_PKT_CHECKER_H
+
+#include <vrt/expanded_header.h>
+#include <stdint.h>
+
+/*!
+ * \brief Check for missing packets
+ */
+class missing_pkt_checker
+{
+ // FIXME assumes we're inspecting only a single stream
+
+ bool d_resync;
+ uint64_t d_npackets; //< total number of packets
+ int d_last_pkt_cnt; //< the last pkt_cnt we saw
+ uint64_t d_nwrong_pkt_cnt; //< number of incorrect pkt_cnt
+ uint64_t d_nmissing_pkt_est; //< estimate of total number of missing pkts
+
+public:
+ missing_pkt_checker()
+ : d_resync(true), d_npackets(0), d_last_pkt_cnt(0xf), d_nwrong_pkt_cnt(0),
+ d_nmissing_pkt_est(0) {}
+
+ /*!
+ * \brief check header pkt_cnt and return 0 if OK, else estimate of number of missing packets.
+ */
+ int check(const vrt::expanded_header *hdr);
+
+ void resync() { d_resync = true; }
+ uint64_t npackets() const { return d_npackets; }
+ uint64_t nwrong_pkt_cnt() const { return d_nwrong_pkt_cnt; }
+ uint64_t nmissing_pkt_est() const { return d_nmissing_pkt_est; }
+};
+
+
+#endif /* INCLUDED_MISSING_PKT_CHECKER_H */
diff --git a/gr-vrt/src/qa_vrt.py b/gr-vrt/src/qa_vrt.py
new file mode 100755
index 000000000..9df1edd92
--- /dev/null
+++ b/gr-vrt/src/qa_vrt.py
@@ -0,0 +1,40 @@
+#!/usr/bin/env python
+#
+# Copyright 2005,2008,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.
+#
+
+from gnuradio import gr, gr_unittest
+import vrt
+
+class qa_vrt(gr_unittest.TestCase):
+
+ def setUp(self):
+ self.tb = gr.top_block()
+
+ def tearDown(self):
+ self.tb = None
+
+ def test_000_nop (self):
+ """Just see if we can import the module...
+ They may not have a VRT connected, etc. Don't try to run anything"""
+ pass
+
+if __name__ == '__main__':
+ gr_unittest.main ()
diff --git a/gr-vrt/src/run_tests.in b/gr-vrt/src/run_tests.in
new file mode 100644
index 000000000..5c56c4674
--- /dev/null
+++ b/gr-vrt/src/run_tests.in
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+# 1st parameter is absolute path to component source directory
+# 2nd parameter is absolute path to component build directory
+# 3rd parameter is path to Python QA directory
+
+# For OS/X
+DYLD_LIBRARY_PATH=@abs_top_builddir@/vrt/host/lib/legacy:@abs_top_builddir@/vrt/host/lib/legacy/.libs:$DYLD_LIBRARY_PATH
+export DYLD_LIBRARY_PATH
+
+# For Win32
+PATH=@abs_top_builddir@/vrt/host/lib/legacy:@abs_top_builddir@/vrt/host/lib/legacy/.libs:$PATH
+
+@top_builddir@/run_tests.sh \
+ @abs_top_srcdir@/gr-vrt \
+ @abs_top_builddir@/gr-vrt \
+ @srcdir@
diff --git a/gr-vrt/src/vrt.i b/gr-vrt/src/vrt.i
new file mode 100644
index 000000000..9016dc33e
--- /dev/null
+++ b/gr-vrt/src/vrt.i
@@ -0,0 +1,64 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008,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.
+ */
+
+%include "gnuradio.i" // the common stuff
+%import <stdint.i>
+
+%{
+#include "vrt_quadradio_source_32fc.h"
+#include <vrt/quadradio.h>
+//#include "vrt_quadradio_source_16sc.h"
+//#include "vrt_sink_32fc.h"
+//#include "vrt_sink_16sc.h"
+%}
+
+%template(uint32_t_vector) std::vector<uint32_t>;
+
+// ----------------------------------------------------------------
+
+class vrt_source_base : public gr_sync_block
+{
+protected:
+ vrt_source_base() throw (std::runtime_error);
+
+public:
+ ~vrt_source_base();
+
+};
+
+class vrt_source_32fc : public vrt_source_base
+{
+protected:
+ vrt_source_32fc() throw (std::runtime_error);
+
+public:
+ ~vrt_source_32fc();
+ void reset();
+};
+
+// ----------------------------------------------------------------
+
+GR_SWIG_BLOCK_MAGIC(vrt,quadradio_source_32fc)
+
+%include "vrt_quadradio_source_32fc.h"
+
+%include <vrt/quadradio.h>
diff --git a/gr-vrt/src/vrt_quadradio_source_32fc.cc b/gr-vrt/src/vrt_quadradio_source_32fc.cc
new file mode 100644
index 000000000..0321062aa
--- /dev/null
+++ b/gr-vrt/src/vrt_quadradio_source_32fc.cc
@@ -0,0 +1,212 @@
+/* -*- c++ -*- */
+/*
+ * 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 this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <vrt_quadradio_source_32fc.h>
+#include <vrt/quadradio.h>
+#include <vrt/rx_packet_handler.h>
+#include <cstdio>
+
+vrt_quadradio_source_32fc_sptr
+vrt_make_quadradio_source_32fc(const std::string &ip,
+ size_t rx_bufsize,
+ size_t samples_per_pkt)
+{
+ return gnuradio::get_initial_sptr(new vrt_quadradio_source_32fc(ip,
+ rx_bufsize,
+ samples_per_pkt));
+}
+
+vrt_quadradio_source_32fc::vrt_quadradio_source_32fc(const std::string &ip,
+ size_t rx_bufsize,
+ size_t samples_per_pkt)
+ : vrt_source_32fc("quadradio_source_32fc"),
+ d_samples_per_pkt(samples_per_pkt == 0 ? 800 : samples_per_pkt),
+ d_qr(vrt::quadradio::sptr(new vrt::quadradio(ip, rx_bufsize)))
+{
+}
+
+vrt_quadradio_source_32fc::~vrt_quadradio_source_32fc()
+{
+ d_qr->stop_streaming();
+}
+
+vrt::rx::sptr
+vrt_quadradio_source_32fc::vrt_rx() const
+{
+ return d_qr->vrt_rx();
+}
+
+bool
+vrt_quadradio_source_32fc::start()
+{
+ // throw away any stale packets before starting
+ vrt::rx_packet_handler nop;
+ vrt_rx()->rx_packets(&nop, true);
+ d_checker.resync();
+
+ return d_qr->start_streaming(d_samples_per_pkt);
+}
+
+bool
+vrt_quadradio_source_32fc::stop()
+{
+ return d_qr->stop_streaming();
+}
+
+bool
+vrt_quadradio_source_32fc::set_dboard_pins(int which_dboard, int v)
+{
+ return d_qr->set_dboard_pins(which_dboard, v);
+}
+
+bool
+vrt_quadradio_source_32fc::set_center_freq(double target_freq)
+{
+ return d_qr->set_center_freq(target_freq);
+}
+
+bool
+vrt_quadradio_source_32fc::set_band_select(const std::string &band)
+{
+ return d_qr->set_band_select(band);
+}
+
+//void
+//vrt_quadradio_source_32fc::set_10dB_atten(bool on)
+//{
+// return d_qr->set_10dB_atten(on);
+//}
+
+bool
+vrt_quadradio_source_32fc::select_rx_antenna(const std::string &ant)
+{
+ return d_qr->select_rx_antenna(ant);
+}
+
+bool
+vrt_quadradio_source_32fc::set_attenuation0(int attenuation)
+{
+ return d_qr->set_attenuation0(attenuation);
+}
+
+bool
+vrt_quadradio_source_32fc::set_attenuation1(int attenuation)
+{
+ return d_qr->set_attenuation1(attenuation);
+}
+
+void
+vrt_quadradio_source_32fc::set_adc_gain(bool on){
+ d_qr->set_adc_gain(on);
+}
+
+void
+vrt_quadradio_source_32fc::set_dc_offset_comp(bool on){
+ d_qr->set_dc_offset_comp(on);
+}
+
+void
+vrt_quadradio_source_32fc::set_digital_gain(float gain){
+ d_qr->set_digital_gain(gain);
+}
+
+void
+vrt_quadradio_source_32fc::set_test_signal(int type){
+ d_qr->set_test_signal(static_cast<vrt_test_sig_t>(type));
+}
+
+bool
+vrt_quadradio_source_32fc::set_setting_reg(int regno, int value)
+{
+ return d_qr->set_setting_reg(regno, value);
+}
+
+bool
+vrt_quadradio_source_32fc::set_hsadc_conf(int which_dboard, int regno, int value)
+{
+ return d_qr->set_hsadc_conf(which_dboard, regno, value);
+}
+
+bool
+vrt_quadradio_source_32fc::set_lsdac(int which_dboard, int which_dac, int value)
+{
+ return d_qr->set_lsdac(which_dboard, which_dac, value);
+}
+
+bool
+vrt_quadradio_source_32fc::set_mem32(int addr, int value)
+{
+ return d_qr->set_mem32(addr, value);
+}
+
+bool
+vrt_quadradio_source_32fc::set_lo_freq(double freq)
+{
+ return d_qr->set_lo_freq(freq);
+}
+
+bool
+vrt_quadradio_source_32fc::set_cal_freq(double freq)
+{
+ return d_qr->set_cal_freq(freq);
+}
+
+/*--------------------------------------------------------------------*/
+#define IQ_IMBAL_NUM_TAPS 30
+#define IQ_IMBAL_REG_NO 162
+
+//helper function to set the iq imbalance register with a tap
+static int get_iq_imbal_reg(bool real, bool init, float tap){
+ int val = int(round(tap));
+ val &= 0x1ffffff; //lower 25 bits for tap
+ val |= (real?0:1) << 30; //30th bit for filter type
+ val |= (init?1:0) << 31; //31st bit for initialization
+ printf("Reg %d Val %x\n", IQ_IMBAL_REG_NO, val);
+ return val;
+}
+
+void
+vrt_quadradio_source_32fc::set_iq_imbal_taps(const std::vector<gr_complex> taps){
+ int i = 0;
+ /* set the real part of the taps */
+ get_iq_imbal_reg(true, true, 0);
+ for (i = 0; i < IQ_IMBAL_NUM_TAPS; i++){
+ set_setting_reg(IQ_IMBAL_REG_NO, get_iq_imbal_reg(true, false, taps[IQ_IMBAL_NUM_TAPS-i-1].real()));
+ }
+ get_iq_imbal_reg(false, true, 0);
+ /* set the imaginary part of the taps */
+ for (i = 0; i < IQ_IMBAL_NUM_TAPS; i++){
+ set_setting_reg(IQ_IMBAL_REG_NO, get_iq_imbal_reg(false, false, taps[IQ_IMBAL_NUM_TAPS-i-1].imag()));
+ }
+}
+
+bool
+vrt_quadradio_source_32fc::set_beamforming(std::vector<gr_complex> gains){
+ int32_t gains_ints[8];
+ for (int i = 0; i < 4; i++){
+ gains_ints[2*i] = int32_t(gains[i].real());
+ gains_ints[2*i+1] = int32_t(gains[i].imag());
+ }
+ return d_qr->set_beamforming(gains_ints);
+}
+
diff --git a/gr-vrt/src/vrt_quadradio_source_32fc.h b/gr-vrt/src/vrt_quadradio_source_32fc.h
new file mode 100644
index 000000000..6ad63f7be
--- /dev/null
+++ b/gr-vrt/src/vrt_quadradio_source_32fc.h
@@ -0,0 +1,116 @@
+/* -*- c++ -*- */
+/*
+ * 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 this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#ifndef INCLUDED_VRT_QUADRADIO_SOURCE_32FC_H
+#define INCLUDED_VRT_QUADRADIO_SOURCE_32FC_H
+
+#include <vrt_source_32fc.h>
+
+namespace vrt {
+ class quadradio;
+};
+
+class vrt_quadradio_source_32fc;
+typedef boost::shared_ptr<vrt_quadradio_source_32fc> vrt_quadradio_source_32fc_sptr;
+
+vrt_quadradio_source_32fc_sptr
+vrt_make_quadradio_source_32fc(const std::string &ip,
+ size_t rx_bufsize = 0,
+ size_t samples_per_pkt = 0);
+
+class vrt_quadradio_source_32fc : public vrt_source_32fc
+{
+ size_t d_samples_per_pkt;
+ boost::shared_ptr<vrt::quadradio> d_qr;
+
+ vrt_quadradio_source_32fc(const std::string &ip, size_t rx_bufsize,
+ size_t samples_per_pkt);
+
+ friend vrt_quadradio_source_32fc_sptr
+ vrt_make_quadradio_source_32fc(const std::string &ip, size_t rx_bufsize,
+ size_t samples_per_pkt);
+
+public:
+ virtual ~vrt_quadradio_source_32fc();
+ virtual vrt::rx::sptr vrt_rx() const;
+
+ /*!
+ * \brief Called by scheduler when starting flowgraph
+ */
+ virtual bool start();
+
+ /*!
+ * \brief Called by scheduler when stopping flowgraph
+ */
+ virtual bool stop();
+
+ /*!
+ * \brief Set the LO frequency (actually just sets the band select for now).
+ */
+ bool set_center_freq(double target_freq);
+
+ /*!
+ * \brief Set the band select dboard bits.
+ * \param band "A", "B", "C", "D"
+ */
+ bool set_band_select(const std::string &band);
+
+ /*!
+ * \brief Turn the 10 dB attenuation on/off.
+ */
+ //void set_10dB_atten(bool on);
+
+ /*!
+ * \brief Set the antenna type to the main rf or calibrator.
+ * \param ant "rf" or "cal"
+ */
+ bool select_rx_antenna(const std::string &ant);
+
+ /*!
+ * \brief Set the attenuation.
+ * \param attenuation 0 to 31 in dB
+ */
+ bool set_attenuation0(int attenuation);
+ bool set_attenuation1(int attenuation);
+
+ void set_iq_imbal_taps(const std::vector<gr_complex> taps);
+
+ void set_adc_gain(bool on);
+ void set_dc_offset_comp(bool on);
+ void set_digital_gain(float gain);
+ void set_test_signal(int type);
+
+ bool set_setting_reg(int regno, int value);
+
+ /*!
+ * \brief write \p v to daugherboard control setting register
+ */
+ bool set_dboard_pins(int which_dboard, int v);
+ bool set_hsadc_conf(int which_dboard, int regno, int value);
+ bool set_lsdac(int which_dboard, int which_dac, int value);
+ bool set_mem32(int addr, int value);
+ bool set_lo_freq(double freq);
+ bool set_cal_freq(double freq);
+ bool set_beamforming(std::vector<gr_complex> gains);
+};
+
+
+
+#endif /* INCLUDED_VRT_QUADRADIO_SOURCE_32FC_H */
diff --git a/gr-vrt/src/vrt_sink_16sc.cc b/gr-vrt/src/vrt_sink_16sc.cc
new file mode 100644
index 000000000..09abe29ee
--- /dev/null
+++ b/gr-vrt/src/vrt_sink_16sc.cc
@@ -0,0 +1,73 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <vrt_sink_16sc.h>
+#include <vrt/metadata.h>
+#include <gr_io_signature.h>
+#include <iostream>
+
+vrt_sink_16sc_sptr
+vrt_make_sink_16sc(const std::string &ifc, const std::string &mac_addr)
+ throw (std::runtime_error)
+{
+ return gnuradio::get_initial_sptr(new vrt_sink_16sc(ifc, mac_addr));
+}
+
+vrt_sink_16sc::vrt_sink_16sc(const std::string &ifc, const std::string &mac_addr)
+ throw (std::runtime_error)
+ : vrt_sink_base("vrt_sink_16sc",
+ gr_make_io_signature(1, 1, sizeof(std::complex<int16_t>)),
+ ifc, mac_addr)
+{
+ // NOP
+}
+
+vrt_sink_16sc::~vrt_sink_16sc()
+{
+ // NOP
+}
+
+int
+vrt_sink_16sc::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+{
+ std::complex<int16_t> *in = (std::complex<int16_t> *)input_items[0];
+
+ vrt::tx_metadata metadata;
+ metadata.timestamp = -1;
+ metadata.send_now = 1;
+ metadata.start_of_burst = 1;
+
+ bool ok = d_u2->tx_16sc(0, // FIXME: someday, streams will have channel numbers
+ in, noutput_items, &metadata);
+ if (!ok){
+ std::cerr << "vrt_sink_16sc: tx_16sc failed" << std::endl;
+ return -1; // say we're done
+ }
+
+ return noutput_items;
+}
diff --git a/gr-vrt/src/vrt_sink_16sc.h b/gr-vrt/src/vrt_sink_16sc.h
new file mode 100644
index 000000000..ba6e673be
--- /dev/null
+++ b/gr-vrt/src/vrt_sink_16sc.h
@@ -0,0 +1,56 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef INCLUDED_USRP2_SINK_16SC_H
+#define INCLUDED_USRP2_SINK_16SC_H
+
+#include <vrt_sink_base.h>
+
+class vrt_sink_16sc;
+typedef boost::shared_ptr<vrt_sink_16sc> vrt_sink_16sc_sptr;
+
+vrt_sink_16sc_sptr
+vrt_make_sink_16sc(const std::string &ifc="eth0",
+ const std::string &mac="")
+ throw (std::runtime_error);
+
+class vrt_sink_16sc : public vrt_sink_base
+{
+private:
+ friend vrt_sink_16sc_sptr
+ vrt_make_sink_16sc(const std::string &ifc,
+ const std::string &mac)
+ throw (std::runtime_error);
+
+protected:
+ vrt_sink_16sc(const std::string &ifc, const std::string &mac)
+ throw (std::runtime_error);
+
+public:
+ ~vrt_sink_16sc();
+
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+};
+
+#endif /* INCLUDED_USRP2_SINK_16SC_H */
diff --git a/gr-vrt/src/vrt_sink_32fc.cc b/gr-vrt/src/vrt_sink_32fc.cc
new file mode 100644
index 000000000..a9987a361
--- /dev/null
+++ b/gr-vrt/src/vrt_sink_32fc.cc
@@ -0,0 +1,73 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <vrt_sink_32fc.h>
+#include <vrt/metadata.h>
+#include <gr_io_signature.h>
+#include <iostream>
+
+vrt_sink_32fc_sptr
+vrt_make_sink_32fc(const std::string &ifc, const std::string &mac_addr)
+ throw (std::runtime_error)
+{
+ return gnuradio::get_initial_sptr(new vrt_sink_32fc(ifc, mac_addr));
+}
+
+vrt_sink_32fc::vrt_sink_32fc(const std::string &ifc, const std::string &mac_addr)
+ throw (std::runtime_error)
+ : vrt_sink_base("vrt_sink_32fc",
+ gr_make_io_signature(1, 1, sizeof(gr_complex)),
+ ifc, mac_addr)
+{
+ // NOP
+}
+
+vrt_sink_32fc::~vrt_sink_32fc()
+{
+ // NOP
+}
+
+int
+vrt_sink_32fc::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+{
+ gr_complex *in = (gr_complex *)input_items[0];
+
+ vrt::tx_metadata metadata;
+ metadata.timestamp = -1;
+ metadata.send_now = 1;
+ metadata.start_of_burst = 1;
+
+ bool ok = d_u2->tx_32fc(0, // FIXME: someday, streams will have channel numbers
+ in, noutput_items, &metadata);
+ if (!ok){
+ std::cerr << "vrt_sink_32fc: tx_32fc failed" << std::endl;
+ return -1; // say we're done
+ }
+
+ return noutput_items;
+}
diff --git a/gr-vrt/src/vrt_sink_32fc.h b/gr-vrt/src/vrt_sink_32fc.h
new file mode 100644
index 000000000..55a6512f0
--- /dev/null
+++ b/gr-vrt/src/vrt_sink_32fc.h
@@ -0,0 +1,56 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef INCLUDED_USRP2_SINK_32FC_H
+#define INCLUDED_USRP2_SINK_32FC_H
+
+#include <vrt_sink_base.h>
+
+class vrt_sink_32fc;
+typedef boost::shared_ptr<vrt_sink_32fc> vrt_sink_32fc_sptr;
+
+vrt_sink_32fc_sptr
+vrt_make_sink_32fc(const std::string &ifc="eth0",
+ const std::string &mac="")
+ throw (std::runtime_error);
+
+class vrt_sink_32fc : public vrt_sink_base
+{
+private:
+ friend vrt_sink_32fc_sptr
+ vrt_make_sink_32fc(const std::string &ifc,
+ const std::string &mac)
+ throw (std::runtime_error);
+
+protected:
+ vrt_sink_32fc(const std::string &ifc, const std::string &mac)
+ throw (std::runtime_error);
+
+public:
+ ~vrt_sink_32fc();
+
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+};
+
+#endif /* INCLUDED_USRP2_SINK_32FC_H */
diff --git a/gr-vrt/src/vrt_sink_base.cc b/gr-vrt/src/vrt_sink_base.cc
new file mode 100644
index 000000000..a75024dcc
--- /dev/null
+++ b/gr-vrt/src/vrt_sink_base.cc
@@ -0,0 +1,151 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <vrt_sink_base.h>
+#include <gr_io_signature.h>
+#include <iostream>
+
+vrt_sink_base::vrt_sink_base(const char *name,
+ gr_io_signature_sptr input_signature,
+ const std::string &ifc,
+ const std::string &mac)
+ throw (std::runtime_error)
+ : vrt_base(name,
+ input_signature,
+ gr_make_io_signature(0, 0, 0),
+ ifc, mac)
+{
+ // NOP
+}
+
+vrt_sink_base::~vrt_sink_base ()
+{
+ // NOP
+}
+
+bool
+vrt_sink_base::set_gain(double gain)
+{
+ return d_u2->set_tx_gain(gain);
+}
+
+bool
+vrt_sink_base::set_lo_offset(double frequency)
+{
+ return d_u2->set_tx_lo_offset(frequency);
+}
+
+bool
+vrt_sink_base::set_center_freq(double frequency, vrt::tune_result *tr)
+{
+ return d_u2->set_tx_center_freq(frequency, tr);
+}
+
+bool
+vrt_sink_base::set_interp(int interp_factor)
+{
+ return d_u2->set_tx_interp(interp_factor);
+}
+
+void
+vrt_sink_base::default_scale_iq(int interp_factor, int *scale_i, int *scale_q)
+{
+ return d_u2->default_tx_scale_iq(interp_factor, scale_i, scale_q);
+}
+
+bool
+vrt_sink_base::set_scale_iq(int scale_i, int scale_q)
+{
+ return d_u2->set_tx_scale_iq(scale_i, scale_q);
+}
+
+int
+vrt_sink_base::interp()
+{
+ return d_u2->tx_interp();
+}
+
+bool
+vrt_sink_base::dac_rate(long *rate)
+{
+ return d_u2->dac_rate(rate);
+}
+
+double
+vrt_sink_base::gain_min()
+{
+ return d_u2->tx_gain_min();
+}
+
+double
+vrt_sink_base::gain_max()
+{
+ return d_u2->tx_gain_max();
+}
+
+double
+vrt_sink_base::gain_db_per_step()
+{
+ return d_u2->tx_gain_db_per_step();
+}
+
+double
+vrt_sink_base::freq_min()
+{
+ return d_u2->tx_freq_min();
+}
+
+double
+vrt_sink_base::freq_max()
+{
+ return d_u2->tx_freq_max();
+}
+
+bool
+vrt_sink_base::daughterboard_id(int *dbid)
+{
+ return d_u2->tx_daughterboard_id(dbid);
+}
+
+bool vrt_sink_base::set_gpio_ddr(uint16_t value, uint16_t mask)
+{
+ return d_u2->set_gpio_ddr(vrt::GPIO_TX_BANK, value, mask);
+}
+
+bool vrt_sink_base::set_gpio_sels(std::string sels)
+{
+ return d_u2->set_gpio_sels(vrt::GPIO_TX_BANK, sels);
+}
+
+bool vrt_sink_base::write_gpio(uint16_t value, uint16_t mask)
+{
+ return d_u2->write_gpio(vrt::GPIO_TX_BANK, value, mask);
+}
+
+bool vrt_sink_base::read_gpio(uint16_t *value)
+{
+ return d_u2->read_gpio(vrt::GPIO_TX_BANK, value);
+}
diff --git a/gr-vrt/src/vrt_sink_base.h b/gr-vrt/src/vrt_sink_base.h
new file mode 100644
index 000000000..5f0532d8e
--- /dev/null
+++ b/gr-vrt/src/vrt_sink_base.h
@@ -0,0 +1,139 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef INCLUDED_USRP2_SINK_BASE_H
+#define INCLUDED_USRP2_SINK_BASE_H
+
+#include <vrt_base.h>
+
+/*!
+ * Base class for all USRP2 transmit blocks
+ */
+class vrt_sink_base : public vrt_base
+{
+protected:
+ vrt_sink_base(const char *name,
+ gr_io_signature_sptr input_signature,
+ const std::string &ifc,
+ const std::string &mac)
+ throw (std::runtime_error);
+
+public:
+ ~vrt_sink_base();
+
+ /*!
+ * \brief Set transmitter gain
+ */
+ bool set_gain(double gain);
+
+ /*!
+ * \brief Set transmitter LO offset frequency
+ */
+ bool set_lo_offset(double frequency);
+
+ /*!
+ * \brief Set transmitter center frequency
+ */
+ bool set_center_freq(double frequency, vrt::tune_result *tr);
+
+ /*!
+ * \brief Set transmit interpolation rate
+ */
+ bool set_interp(int interp_factor);
+
+ /*!
+ * \brief Calculate default scale_iq for given interpolation factor
+ */
+ void default_scale_iq(int interpolation_factor, int *scale_i, int *scale_q);
+
+ /*!
+ * \brief Set transmit IQ scale factors
+ */
+ bool set_scale_iq(int scale_i, int scale_q);
+
+ /*!
+ * \brief Get transmit interpolation rate
+ */
+ int interp();
+
+ /*!
+ * \brief Get DAC sample rate in Hz
+ */
+ bool dac_rate(long *rate);
+
+ /*!
+ * \brief Returns minimum Tx gain
+ */
+ double gain_min();
+
+ /*!
+ * \brief Returns maximum Tx gain
+ */
+ double gain_max();
+
+ /*!
+ * \brief Returns Tx gain db_per_step
+ */
+ double gain_db_per_step();
+
+ /*!
+ * \brief Returns minimum Tx center frequency
+ */
+ double freq_min();
+
+ /*!
+ * \brief Returns maximum Tx center frequency
+ */
+ double freq_max();
+
+ /*!
+ * \brief Get Tx daughterboard ID
+ *
+ * \param[out] dbid returns the daughterboard id.
+ *
+ * daughterboard id >= 0 if successful, -1 if no daugherboard installed,
+ * -2 if invalid EEPROM on daughterboard.
+ */
+ bool daughterboard_id(int *dbid);
+
+ /*!
+ * \brief Set daughterboard GPIO data direction register.
+ */
+ bool set_gpio_ddr(uint16_t value, uint16_t mask);
+
+ /*!
+ * \brief Set daughterboard GPIO output selection register.
+ */
+ bool set_gpio_sels(std::string sels);
+
+ /*!
+ * \brief Set daughterboard GPIO pin values.
+ */
+ bool write_gpio(uint16_t value, uint16_t mask);
+
+ /*!
+ * \brief Read daughterboard GPIO pin values
+ */
+ bool read_gpio(uint16_t *value);
+};
+
+#endif /* INCLUDED_USRP2_SINK_BASE_H */
diff --git a/gr-vrt/src/vrt_source_16sc.cc b/gr-vrt/src/vrt_source_16sc.cc
new file mode 100644
index 000000000..f0ea35bb3
--- /dev/null
+++ b/gr-vrt/src/vrt_source_16sc.cc
@@ -0,0 +1,69 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <vrt_source_16sc.h>
+#include <rx_16sc_handler.h>
+#include <gr_io_signature.h>
+#include <iostream>
+
+vrt_source_16sc_sptr
+vrt_make_source_16sc(const std::string &ifc, const std::string &mac_addr)
+ throw (std::runtime_error)
+{
+ return gnuradio::get_initial_sptr(new vrt_source_16sc(ifc, mac_addr));
+}
+
+vrt_source_16sc::vrt_source_16sc(const std::string &ifc, const std::string &mac_addr)
+ throw (std::runtime_error)
+ : vrt_source_base("vrt_source_16sc",
+ gr_make_io_signature(1, 1, sizeof(std::complex<int16_t>)),
+ ifc, mac_addr)
+{
+ set_output_multiple(USRP2_MIN_RX_SAMPLES);
+}
+
+vrt_source_16sc::~vrt_source_16sc()
+{
+ // NOP
+}
+
+int
+vrt_source_16sc::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+{
+ std::complex<int16_t> *out = (std::complex<int16_t> *)output_items[0];
+
+ rx_16sc_handler::sptr handler = rx_16sc_handler::make(noutput_items, USRP2_MIN_RX_SAMPLES, out);
+
+ bool ok = d_u2->rx_samples(0, handler.get()); // FIXME: channel number instead of 0
+ if (!ok){
+ std::cerr << "vrt::rx_samples() failed" << std::endl;
+ return -1; // say we're done
+ }
+
+ return handler->nsamples();
+}
diff --git a/gr-vrt/src/vrt_source_16sc.h b/gr-vrt/src/vrt_source_16sc.h
new file mode 100644
index 000000000..34175b3ca
--- /dev/null
+++ b/gr-vrt/src/vrt_source_16sc.h
@@ -0,0 +1,54 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef INCLUDED_USRP2_SOURCE_16SC_H
+#define INCLUDED_USRP2_SOURCE_16SC_H
+
+#include <vrt_source_base.h>
+
+class vrt_source_16sc;
+typedef boost::shared_ptr<vrt_source_16sc> vrt_source_16sc_sptr;
+
+vrt_source_16sc_sptr
+vrt_make_source_16sc(const std::string &ifc="eth0",
+ const std::string &mac="")
+ throw (std::runtime_error);
+
+class vrt_source_16sc : public vrt_source_base
+{
+private:
+ friend vrt_source_16sc_sptr
+ vrt_make_source_16sc(const std::string &ifc,
+ const std::string &mac) throw (std::runtime_error);
+
+protected:
+ vrt_source_16sc(const std::string &ifc, const std::string &mac) throw (std::runtime_error);
+
+public:
+ ~vrt_source_16sc();
+
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+};
+
+#endif /* INCLUDED_USRP2_SOURCE_16SC_H */
diff --git a/gr-vrt/src/vrt_source_32fc.cc b/gr-vrt/src/vrt_source_32fc.cc
new file mode 100644
index 000000000..beb5ef26d
--- /dev/null
+++ b/gr-vrt/src/vrt_source_32fc.cc
@@ -0,0 +1,144 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008,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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <vrt_source_32fc.h>
+#include <vrt/expanded_header.h>
+#include <vrt/copiers.h>
+#include <gr_io_signature.h>
+#include <missing_pkt_checker.h>
+#include <iostream>
+
+#define VERBOSE 1 // define to 0 or 1
+
+
+class rx_32fc_handler : public vrt::rx_packet_handler
+{
+ int d_noutput_items;
+ std::complex<float> *d_out;
+ int *d_oo; // output index
+ std::vector< std::complex<float> > &d_remainder;
+ missing_pkt_checker &d_checker;
+
+
+public:
+
+ rx_32fc_handler(int noutput_items, std::complex<float> *out,
+ int *oo, std::vector< std::complex<float> > &remainder,
+ missing_pkt_checker &checker)
+ : d_noutput_items(noutput_items), d_out(out),
+ d_oo(oo), d_remainder(remainder), d_checker(checker) {}
+
+ ~rx_32fc_handler();
+
+ bool operator()(const uint32_t *payload,
+ size_t n32_bit_words,
+ const vrt::expanded_header *hdr);
+};
+
+rx_32fc_handler::~rx_32fc_handler()
+{
+}
+
+bool
+rx_32fc_handler::operator()(const uint32_t *payload,
+ size_t n32_bit_words,
+ const vrt::expanded_header *hdr)
+{
+ int nmissing = d_checker.check(hdr);
+ if (VERBOSE && nmissing != 0){
+ std::cerr << "S" << nmissing;
+ }
+
+ // copy as many as will fit into the output buffer.
+
+ size_t n = std::min(n32_bit_words, (size_t)(d_noutput_items - *d_oo));
+ vrt::copy_net_16sc_to_host_32fc(n, payload, &d_out[*d_oo]);
+ *d_oo += n;
+
+ // if there are any left over, copy them into remainder and tell
+ // our caller we're had enough for now.
+
+ size_t r = n32_bit_words - n;
+ if (r > 0){
+ assert(d_remainder.size() == 0);
+ d_remainder.resize(r);
+ vrt::copy_net_16sc_to_host_32fc(r, &payload[n], &d_remainder[0]);
+ return false; // Stop calling us.
+ }
+
+ return true; // Keep calling us, we've got more room
+}
+
+
+// ------------------------------------------------------------------------
+
+vrt_source_32fc::vrt_source_32fc(const char *name)
+
+ : vrt_source_base(name,
+ gr_make_io_signature(1, 1, sizeof(gr_complex)))
+{
+}
+
+vrt_source_32fc::~vrt_source_32fc()
+{
+ if (VERBOSE){
+ std::cerr << "\nvrt_source_32fc: npackets = " << d_checker.npackets()
+ << " nwrong_pkt_cnt = " << d_checker.nwrong_pkt_cnt()
+ << " nmissing_pkt_est = " << d_checker.nmissing_pkt_est()
+ << std::endl;
+ }
+}
+
+int
+vrt_source_32fc::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+{
+ gr_complex *out = (gr_complex *)output_items[0];
+ int oo = 0;
+
+ // Handle any samples left over from the last call.
+ int t = std::min(noutput_items, (int)d_remainder.size());
+ if (t != 0){
+ for (int i = 0; i < t; i++)
+ out[i] = d_remainder[i];
+ d_remainder.erase(d_remainder.begin(), d_remainder.begin()+t);
+ oo = t;
+ }
+ if (noutput_items - oo == 0)
+ return oo;
+
+ // While we've got room, and there are packets, handle them
+ rx_32fc_handler h(noutput_items, out, &oo, d_remainder, d_checker);
+ bool ok = vrt_rx()->rx_packets(&h);
+
+ if (!ok){
+ std::cerr << "vrt_source_32fc: vrt::rx_packets() failed" << std::endl;
+ return -1; // say we're done
+ }
+
+ return oo;
+}
diff --git a/gr-vrt/src/vrt_source_32fc.h b/gr-vrt/src/vrt_source_32fc.h
new file mode 100644
index 000000000..7ca3e5fe2
--- /dev/null
+++ b/gr-vrt/src/vrt_source_32fc.h
@@ -0,0 +1,48 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008,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.
+ */
+
+#ifndef INCLUDED_VRT_SOURCE_32FC_H
+#define INCLUDED_VRT_SOURCE_32FC_H
+
+#include <vrt_source_base.h>
+#include <missing_pkt_checker.h>
+
+class vrt_source_32fc : public vrt_source_base
+{
+protected:
+ vrt_source_32fc(const char *name);
+
+ std::vector< std::complex<float> > d_remainder;
+ missing_pkt_checker d_checker;
+
+public:
+ ~vrt_source_32fc();
+
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+
+ void reset() { d_remainder.clear(); }
+
+};
+
+#endif /* INCLUDED_VRT_SOURCE_32FC_H */
diff --git a/gr-vrt/src/vrt_source_base.cc b/gr-vrt/src/vrt_source_base.cc
new file mode 100644
index 000000000..40e871653
--- /dev/null
+++ b/gr-vrt/src/vrt_source_base.cc
@@ -0,0 +1,41 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008,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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <vrt_source_base.h>
+#include <gr_io_signature.h>
+#include <iostream>
+
+vrt_source_base::vrt_source_base(const char *name,
+ gr_io_signature_sptr output_signature)
+ : gr_sync_block(name,
+ gr_make_io_signature(0, 0, 0),
+ output_signature)
+{
+}
+
+vrt_source_base::~vrt_source_base()
+{
+}
diff --git a/gr-vrt/src/vrt_source_base.h b/gr-vrt/src/vrt_source_base.h
new file mode 100644
index 000000000..e67778860
--- /dev/null
+++ b/gr-vrt/src/vrt_source_base.h
@@ -0,0 +1,45 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008,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.
+ */
+
+#ifndef INCLUDED_VRT_SOURCE_BASE_H
+#define INCLUDED_VRT_SOURCE_BASE_H
+
+#include <gr_sync_block.h>
+#include <vrt/rx.h>
+#include <gr_io_signature.h>
+
+/*!
+ * Base class for all VRT source blocks
+ */
+class vrt_source_base : public gr_sync_block
+{
+protected:
+ vrt_source_base(const char *name,
+ gr_io_signature_sptr output_signature);
+
+public:
+ ~vrt_source_base();
+
+ virtual vrt::rx::sptr vrt_rx() const = 0;
+};
+
+#endif /* INCLUDED_VRT_SOURCE_BASE_H */