summaryrefslogtreecommitdiff
path: root/gr-usrp2
diff options
context:
space:
mode:
Diffstat (limited to 'gr-usrp2')
-rw-r--r--gr-usrp2/Makefile.am24
-rw-r--r--gr-usrp2/src/Makefile.am136
-rwxr-xr-xgr-usrp2/src/qa_usrp2.py40
-rw-r--r--gr-usrp2/src/run_tests.in17
-rw-r--r--gr-usrp2/src/rx_16sc_handler.cc31
-rw-r--r--gr-usrp2/src/rx_16sc_handler.h75
-rw-r--r--gr-usrp2/src/rx_32fc_handler.cc31
-rw-r--r--gr-usrp2/src/rx_32fc_handler.h76
-rw-r--r--gr-usrp2/src/usrp2.i146
-rw-r--r--gr-usrp2/src/usrp2_sink_32fc.cc46
-rw-r--r--gr-usrp2/src/usrp2_sink_32fc.h47
-rw-r--r--gr-usrp2/src/usrp2_sink_base.cc49
-rw-r--r--gr-usrp2/src/usrp2_sink_base.h46
-rw-r--r--gr-usrp2/src/usrp2_source_16sc.cc77
-rw-r--r--gr-usrp2/src/usrp2_source_16sc.h54
-rw-r--r--gr-usrp2/src/usrp2_source_32fc.cc77
-rw-r--r--gr-usrp2/src/usrp2_source_32fc.h54
-rw-r--r--gr-usrp2/src/usrp2_source_base.cc92
-rw-r--r--gr-usrp2/src/usrp2_source_base.h85
19 files changed, 1203 insertions, 0 deletions
diff --git a/gr-usrp2/Makefile.am b/gr-usrp2/Makefile.am
new file mode 100644
index 000000000..a9a7a3a83
--- /dev/null
+++ b/gr-usrp2/Makefile.am
@@ -0,0 +1,24 @@
+#
+# Copyright 2001,2006,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.
+#
+
+include $(top_srcdir)/Makefile.common
+
+SUBDIRS = src
diff --git a/gr-usrp2/src/Makefile.am b/gr-usrp2/src/Makefile.am
new file mode 100644
index 000000000..da626d594
--- /dev/null
+++ b/gr-usrp2/src/Makefile.am
@@ -0,0 +1,136 @@
+#
+# Copyright 2004,2005,2006,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.
+#
+
+include $(top_srcdir)/Makefile.common
+
+# ----------------------------------------------------------------------
+# C++ block API interface librar(ies)
+#
+# libgr-usrp.so
+# ----------------------------------------------------------------------
+AM_CPPFLAGS = \
+ $(STD_DEFINES_AND_INCLUDES) \
+ $(GRUEL_INCLUDES) \
+ $(PYTHON_CPPFLAGS) \
+ $(USRP2_INCLUDES) \
+ $(WITH_INCLUDES)
+
+lib_LTLIBRARIES = libgr-usrp2.la
+
+libgr_usrp2_la_SOURCES = \
+ rx_16sc_handler.cc \
+ rx_32fc_handler.cc \
+ usrp2_source_base.cc \
+ usrp2_source_16sc.cc \
+ usrp2_source_32fc.cc
+# usrp2_source_16sc.cc
+# usrp2_sink_base.cc
+# usrp2_sink_32fc.cc
+# usrp2_sink_16sc.cc
+
+libgr_usrp2_la_LIBADD = \
+ $(USRP2_LA) \
+ $(GNURADIO_CORE_LA)
+
+grinclude_HEADERS = \
+ usrp2_source_base.h \
+ usrp2_source_32fc.h \
+ usrp2_source_16sc.h
+# usrp2_sink_base.h \
+# usrp2_sink_32fc.h \
+# usrp2_sink_16sc.h
+
+noinst_HEADERS = \
+ rx_16sc_handler.h \
+ rx_32fc_handler.h
+
+# ----------------------------------------------------------------------
+# Python SWIG wrapper around C++ library
+#
+# usrp2.py
+# _usrp2.so
+# ----------------------------------------------------------------------
+
+# Python installation locations
+ourpythondir = $(grpythondir)
+ourlibdir = $(grpyexecdir)
+
+# SWIG interface files
+LOCAL_IFILES = $(srcdir)/usrp2.i
+NON_LOCAL_IFILES = $(GNURADIO_I)
+ALL_IFILES = $(LOCAL_IFILES) $(NON_LOCAL_IFILES)
+
+# Install the SWIG interface files
+swiginclude_HEADERS = $(LOCAL_IFILES)
+
+# Generated by SWIG wrapper generator
+BUILT_SOURCES = usrp2.cc usrp2.py
+
+# Install the SWIG python output
+ourpython_PYTHON = usrp2.py
+
+# Arguments to the swig wrapper generator
+SWIGPYTHONARGS = \
+ $(STD_DEFINES_AND_INCLUDES) \
+ $(SWIGPYTHONFLAGS) \
+ $(USRP2_INCLUDES) \
+ $(WITH_INCLUDES) \
+ $(WITH_SWIG_INCLUDES)
+
+# Invoke SWIG wrapper generator
+usrp2.cc usrp2.py: $(ALL_IFILES)
+ $(SWIG) $(SWIGPYTHONARGS) -module usrp2 -o usrp2.cc $(LOCAL_IFILES)
+
+# Create the Python shared library
+ourlib_LTLIBRARIES = _usrp2.la
+_usrp2_la_SOURCES = usrp2.cc
+_usrp2_la_CXXFLAGS = @swig_CXXFLAGS@
+_usrp2_la_LDFLAGS = $(swig_CXXFLAGS) $(NO_UNDEFINED) -module -avoid-version
+
+# Link the library as needed
+_usrp2_la_LIBADD = \
+ $(PYTHON_LDFLAGS) \
+ libgr-usrp2.la \
+ $(GNURADIO_CORE_LA) \
+ $(USRP2_LIBS) \
+ -lstdc++
+
+# Don't distribute output of swig
+dist-hook:
+ @for file in $(BUILT_SOURCES); do echo $(RM) $(distdir)/$$file; done
+ @for file in $(BUILT_SOURCES); do $(RM) $(distdir)/$$file; done
+
+# ----------------------------------------------------------------------
+# Local Python files, not installed
+#
+# qa_usrp2.py
+# ----------------------------------------------------------------------
+
+noinst_PYTHON = qa_usrp2.py
+
+
+# ----------------------------------------------------------------------
+# Miscellaneous build operations
+# ----------------------------------------------------------------------
+
+EXTRA_DIST = run_tests.in
+TESTS = run_tests
+MOSTLYCLEANFILES = $(BUILT_SOURCES) *.pyc
diff --git a/gr-usrp2/src/qa_usrp2.py b/gr-usrp2/src/qa_usrp2.py
new file mode 100755
index 000000000..bc6664a1b
--- /dev/null
+++ b/gr-usrp2/src/qa_usrp2.py
@@ -0,0 +1,40 @@
+#!/usr/bin/env python
+#
+# Copyright 2005,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.
+#
+
+from gnuradio import gr, gr_unittest
+import usrp2
+
+class qa_usrp2(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 USRP2 connected, etc. Don't try to run anything"""
+ pass
+
+if __name__ == '__main__':
+ gr_unittest.main ()
diff --git a/gr-usrp2/src/run_tests.in b/gr-usrp2/src/run_tests.in
new file mode 100644
index 000000000..99190b81b
--- /dev/null
+++ b/gr-usrp2/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@/usrp2/host/lib/legacy:@abs_top_builddir@/usrp2/host/lib/legacy/.libs:$DYLD_LIBRARY_PATH
+export DYLD_LIBRARY_PATH
+
+# For Win32
+PATH=@abs_top_builddir@/usrp2/host/lib/legacy:@abs_top_builddir@/usrp2/host/lib/legacy/.libs:$PATH
+
+@top_builddir@/run_tests.sh \
+ @abs_top_srcdir@/gr-usrp2 \
+ @abs_top_builddir@/gr-usrp2 \
+ @srcdir@
diff --git a/gr-usrp2/src/rx_16sc_handler.cc b/gr-usrp2/src/rx_16sc_handler.cc
new file mode 100644
index 000000000..a3ab2a2b2
--- /dev/null
+++ b/gr-usrp2/src/rx_16sc_handler.cc
@@ -0,0 +1,31 @@
+/* -*- 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 <rx_16sc_handler.h>
+
+rx_16sc_handler::~rx_16sc_handler()
+{
+}
diff --git a/gr-usrp2/src/rx_16sc_handler.h b/gr-usrp2/src/rx_16sc_handler.h
new file mode 100644
index 000000000..cb83d860f
--- /dev/null
+++ b/gr-usrp2/src/rx_16sc_handler.h
@@ -0,0 +1,75 @@
+/* -*- 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_RX_16SC_HANDLER_H
+#define INCLUDED_RX_16SC_HANDLER_H
+
+#include <usrp2/rx_nop_handler.h>
+#include <usrp2/copiers.h>
+
+#define RX_16SC_HANDLER_DEBUG 0
+
+class rx_16sc_handler : public usrp2::rx_nop_handler
+{
+ std::complex<int16_t> *d_dest;
+
+ // Private constructor
+ rx_16sc_handler(uint64_t max_samples, uint64_t max_quantum, std::complex<int16_t> *dest)
+ : rx_nop_handler(max_samples, max_quantum), d_dest(dest) {}
+
+public:
+ // Shared pointer to one of these
+ typedef boost::shared_ptr<rx_16sc_handler> sptr;
+
+ // Factory function to return a shared pointer to a new instance
+ static sptr make(uint64_t max_samples, uint64_t max_quantum, std::complex<int16_t> *dest)
+ {
+ if (RX_16SC_HANDLER_DEBUG)
+ printf("rx_16sc_handler: max_samples=%li max_quantum=%li\n", max_samples, max_quantum);
+
+ return sptr(new rx_16sc_handler(max_samples, max_quantum, dest));
+ }
+
+ // Invoked by USRP2 API when samples are available
+ bool operator()(const uint32_t *items, size_t nitems, const usrp2::rx_metadata *metadata)
+ {
+ if (RX_16SC_HANDLER_DEBUG)
+ printf("rx_16sc_handler: called with items=%zu ", nitems);
+
+ // Copy/reformat/endian swap USRP2 data to destination buffer
+ usrp2::copy_u2_complex_16_to_host_complex_16(nitems, items, d_dest);
+ d_dest += nitems;
+
+ // FIXME: do something with metadata
+
+ // Determine if there is room to be called again
+ bool ok = rx_nop_handler::operator()(items, nitems, metadata);
+ if (RX_16SC_HANDLER_DEBUG)
+ printf("ok to call again=%i\n", ok);
+
+ return ok;
+ }
+
+ ~rx_16sc_handler();
+};
+
+#endif /* INCLUDED_RX_16SC_HANDLER_H */
diff --git a/gr-usrp2/src/rx_32fc_handler.cc b/gr-usrp2/src/rx_32fc_handler.cc
new file mode 100644
index 000000000..f8347633b
--- /dev/null
+++ b/gr-usrp2/src/rx_32fc_handler.cc
@@ -0,0 +1,31 @@
+/* -*- 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 <rx_32fc_handler.h>
+
+rx_32fc_handler::~rx_32fc_handler()
+{
+}
diff --git a/gr-usrp2/src/rx_32fc_handler.h b/gr-usrp2/src/rx_32fc_handler.h
new file mode 100644
index 000000000..875027968
--- /dev/null
+++ b/gr-usrp2/src/rx_32fc_handler.h
@@ -0,0 +1,76 @@
+/* -*- 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_RX_32FC_HANDLER_H
+#define INCLUDED_RX_32FC_HANDLER_H
+
+#include <usrp2/rx_nop_handler.h>
+#include <usrp2/copiers.h>
+#include <gr_complex.h>
+
+#define RX_32FC_HANDLER_DEBUG 0
+
+class rx_32fc_handler : public usrp2::rx_nop_handler
+{
+ gr_complex *d_dest;
+
+ // Private constructor
+ rx_32fc_handler(uint64_t max_samples, uint64_t max_quantum, gr_complex *dest)
+ : rx_nop_handler(max_samples, max_quantum), d_dest(dest) {}
+
+public:
+ // Shared pointer to one of these
+ typedef boost::shared_ptr<rx_32fc_handler> sptr;
+
+ // Factory function to return a shared pointer to a new instance
+ static sptr make(uint64_t max_samples, uint64_t max_quantum, gr_complex *dest)
+ {
+ if (RX_32FC_HANDLER_DEBUG)
+ printf("rx_32fc_handler: max_samples=%li max_quantum=%li\n", max_samples, max_quantum);
+
+ return sptr(new rx_32fc_handler(max_samples, max_quantum, dest));
+ }
+
+ // Invoked by USRP2 API when samples are available
+ bool operator()(const uint32_t *items, size_t nitems, const usrp2::rx_metadata *metadata)
+ {
+ if (RX_32FC_HANDLER_DEBUG)
+ printf("rx_32fc_handler: called with items=%zu ", nitems);
+
+ // Copy/reformat/endian swap USRP2 data to destination buffer
+ usrp2::copy_u2_complex_16_to_host_complex_float(nitems, items, d_dest);
+ d_dest += nitems;
+
+ // FIXME: do something with metadata
+
+ // Determine if there is room to be called again
+ bool ok = rx_nop_handler::operator()(items, nitems, metadata);
+ if (RX_32FC_HANDLER_DEBUG)
+ printf("ok to call again=%i\n", ok);
+
+ return ok;
+ }
+
+ ~rx_32fc_handler();
+};
+
+#endif /* INCLUDED_RX_32FC_HANDLER_H */
diff --git a/gr-usrp2/src/usrp2.i b/gr-usrp2/src/usrp2.i
new file mode 100644
index 000000000..fba6c18e3
--- /dev/null
+++ b/gr-usrp2/src/usrp2.i
@@ -0,0 +1,146 @@
+/* -*- 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.
+ */
+
+%feature("autodoc", "1"); // generate python docstrings
+
+%include "exception.i"
+%import "gnuradio.i" // the common stuff
+
+%{
+#include <gnuradio_swig_bug_workaround.h>
+//#include "usrp2_sink_32fc.h"
+#include "usrp2_source_16sc.h"
+#include "usrp2_source_32fc.h"
+%}
+
+%include <usrp2/tune_result.h>
+
+#if 0
+// ----------------------------------------------------------------
+
+class usrp2_sink_base : public gr_sync_block {
+
+protected:
+ usrp2_sink_base(const std::string &name,
+ gr_io_signature_sptr input_signature)
+ throw (std::runtime_error);
+
+public:
+ ~usrp2_sink_base();
+
+};
+
+// ----------------------------------------------------------------
+
+GR_SWIG_BLOCK_MAGIC(usrp2,sink_32fc)
+
+usrp2_sink_32fc_sptr
+usrp2_make_sink_32fc() throw (std::runtime_error);
+
+class usrp2_sink_32fc : public usrp2_sink_base {
+
+protected:
+ usrp2_sink_32fc();
+
+public:
+ ~usrp2_sink_32fc();
+
+};
+#endif
+
+// ----------------------------------------------------------------
+
+class usrp2_source_base : public gr_sync_block {
+
+protected:
+ usrp2_source_base(const char *name,
+ gr_io_signature_sptr output_signature)
+ throw (std::runtime_error);
+
+public:
+ ~usrp2_source_base();
+};
+
+// ----------------------------------------------------------------
+
+GR_SWIG_BLOCK_MAGIC(usrp2,source_32fc)
+
+usrp2_source_32fc_sptr
+usrp2_make_source_32fc(const std::string ifc, const std::string mac)
+ throw (std::runtime_error);
+
+class usrp2_source_32fc : public usrp2_source_base {
+
+protected:
+ usrp2_source_32fc(const std::string &ifc, const std::string &mac);
+
+public:
+ ~usrp2_source_32fc();
+
+ bool set_gain(double gain);
+ %rename(_real_set_center_freq) set_center_freq;
+ bool set_center_freq(double frequency, usrp2::tune_result *r);
+ bool set_decim(int decimation_factor);
+
+ std::string mac_addr();
+};
+
+// ----------------------------------------------------------------
+
+GR_SWIG_BLOCK_MAGIC(usrp2,source_16sc)
+
+usrp2_source_16sc_sptr
+usrp2_make_source_16sc(const std::string ifc, const std::string mac)
+ throw (std::runtime_error);
+
+class usrp2_source_16sc : public usrp2_source_base {
+
+protected:
+ usrp2_source_16sc(const std::string &ifc, const std::string &mac);
+
+public:
+ ~usrp2_source_16sc();
+
+ bool set_gain(double gain);
+ %rename(_real_set_center_freq) set_center_freq;
+ bool set_center_freq(double frequency, usrp2::tune_result *r);
+ bool set_decim(int decimation_factor);
+
+ std::string mac_addr();
+};
+
+// ----------------------------------------------------------------
+
+// create a more pythonic interface
+%pythoncode %{
+
+def __set_center_freq(self, freq):
+ tr = tune_result()
+ r = self._real_set_center_freq(freq, tr)
+ if r:
+ return tr
+ else:
+ return None
+
+usrp2_source_32fc_sptr.set_center_freq = __set_center_freq
+usrp2_source_16sc_sptr.set_center_freq = __set_center_freq
+%}
diff --git a/gr-usrp2/src/usrp2_sink_32fc.cc b/gr-usrp2/src/usrp2_sink_32fc.cc
new file mode 100644
index 000000000..56cde6ba7
--- /dev/null
+++ b/gr-usrp2/src/usrp2_sink_32fc.cc
@@ -0,0 +1,46 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <usrp2_sink_32fc.h>
+#include <gr_io_signature.h>
+#include <usrp_standard.h>
+#include <usrp_bytesex.h>
+
+usrp2_sink_32fc_sptr
+usrp2_make_sink_32fc() throw (std::runtime_error)
+{
+ return usrp2_sink_32fc_sptr(new usrp2_sink_32fc());
+}
+
+usrp2_sink_32fc::usrp2_sink_32fc() throw (std::runtime_error)
+ : usrp2_sink_base("usrp2_sink_32fc",
+ gr_make_io_signature(1, 1, sizeof(gr_complex)))
+{
+}
+
+usrp2_sink_32fc::~usrp2_sink_32fc()
+{
+}
diff --git a/gr-usrp2/src/usrp2_sink_32fc.h b/gr-usrp2/src/usrp2_sink_32fc.h
new file mode 100644
index 000000000..eeb80b19c
--- /dev/null
+++ b/gr-usrp2/src/usrp2_sink_32fc.h
@@ -0,0 +1,47 @@
+/* -*- 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 <usrp2_sink_base.h>
+
+class usrp2_sink_32fc;
+typedef boost::shared_ptr<usrp2_sink_32fc> usrp2_sink_32fc_sptr;
+
+usrp2_sink_32fc_sptr
+usrp2_make_sink_32fc() throw (std::runtime_error);
+
+class usrp2_sink_32fc : public usrp2_sink_base {
+private:
+
+ friend usrp2_sink_32fc_sptr
+ usrp2_make_sink_32fc() throw (std::runtime_error);
+
+protected:
+ usrp2_sink_32fc() throw (std::runtime_error);
+
+public:
+ ~usrp2_sink_32fc();
+};
+
+#endif /* INCLUDED_USRP2_SINK_32FC_H */
diff --git a/gr-usrp2/src/usrp2_sink_base.cc b/gr-usrp2/src/usrp2_sink_base.cc
new file mode 100644
index 000000000..ebef93902
--- /dev/null
+++ b/gr-usrp2/src/usrp2_sink_base.cc
@@ -0,0 +1,49 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <usrp2_sink_base.h>
+#include <gr_io_signature.h>
+
+usrp2_sink_base::usrp2_sink_base(const std::string &name,
+ gr_io_signature_sptr input_signature)
+ throw (std::runtime_error)
+ : gr_sync_block(name,
+ input_signature,
+ gr_make_io_signature(0, 0, 0))
+{
+}
+
+usrp2_sink_base::~usrp2_sink_base ()
+{
+}
+
+int
+usrp2_sink_base::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+{
+ return noutput_items;
+}
diff --git a/gr-usrp2/src/usrp2_sink_base.h b/gr-usrp2/src/usrp2_sink_base.h
new file mode 100644
index 000000000..a999a6cac
--- /dev/null
+++ b/gr-usrp2/src/usrp2_sink_base.h
@@ -0,0 +1,46 @@
+/* -*- 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 <gr_sync_block.h>
+#include <stdexcept>
+
+class usrp2_sink_base : public gr_sync_block {
+
+private:
+
+protected:
+ usrp2_sink_base(const std::string &name,
+ gr_io_signature_sptr input_signature)
+ throw (std::runtime_error);
+
+public:
+ ~usrp2_sink_base();
+
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+};
+
+#endif /* INCLUDED_USRP2_SINK_BASE_H */
diff --git a/gr-usrp2/src/usrp2_source_16sc.cc b/gr-usrp2/src/usrp2_source_16sc.cc
new file mode 100644
index 000000000..b60b61c1b
--- /dev/null
+++ b/gr-usrp2/src/usrp2_source_16sc.cc
@@ -0,0 +1,77 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <usrp2_source_16sc.h>
+#include <rx_16sc_handler.h>
+#include <gr_io_signature.h>
+#include <iostream>
+
+#define USRP2_SOURCE_16SC_DEBUG 0
+
+usrp2_source_16sc_sptr
+usrp2_make_source_16sc(const std::string &ifc, const std::string &mac_addr)
+ throw (std::runtime_error)
+{
+ return usrp2_source_16sc_sptr(new usrp2_source_16sc(ifc, mac_addr));
+}
+
+usrp2_source_16sc::usrp2_source_16sc(const std::string &ifc, const std::string &mac_addr)
+ throw (std::runtime_error)
+ : usrp2_source_base("usrp2_source_16sc",
+ gr_make_io_signature(1, 1, sizeof(std::complex<int16_t>)),
+ ifc, mac_addr)
+{
+ set_output_multiple(USRP2_MIN_RX_SAMPLES);
+}
+
+usrp2_source_16sc::~usrp2_source_16sc()
+{
+}
+
+int
+usrp2_source_16sc::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+{
+ if (USRP2_SOURCE_16SC_DEBUG)
+ printf("work: noutput_items=%i\n", noutput_items);
+
+ std::complex<int16_t> *out = (std::complex<int16_t> *)output_items[0];
+
+ rx_16sc_handler::sptr handler = rx_16sc_handler::make(noutput_items, USRP2_MIN_RX_SAMPLES, out);
+
+ bool ok = d_u2->rx_samples(0, handler.get());
+ if (!ok)
+ std::cerr << "usrp2::rx_samples() failed" << std::endl;
+
+ int j = handler->nsamples();
+ int f = handler->nframes();
+
+ if (USRP2_SOURCE_16SC_DEBUG)
+ printf("work: produced=%i items from %i frames\n\n", j, f);
+
+ return j;
+}
diff --git a/gr-usrp2/src/usrp2_source_16sc.h b/gr-usrp2/src/usrp2_source_16sc.h
new file mode 100644
index 000000000..fa277f733
--- /dev/null
+++ b/gr-usrp2/src/usrp2_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_C_H
+#define INCLUDED_USRP2_SOURCE_C_H
+
+#include <usrp2_source_base.h>
+
+class usrp2_source_16sc;
+typedef boost::shared_ptr<usrp2_source_16sc> usrp2_source_16sc_sptr;
+
+usrp2_source_16sc_sptr
+usrp2_make_source_16sc(const std::string &ifc="eth0",
+ const std::string &mac="")
+ throw (std::runtime_error);
+
+class usrp2_source_16sc : public usrp2_source_base {
+
+private:
+ friend usrp2_source_16sc_sptr
+ usrp2_make_source_16sc(const std::string &ifc,
+ const std::string &mac) throw (std::runtime_error);
+
+protected:
+ usrp2_source_16sc(const std::string &ifc, const std::string &mac) throw (std::runtime_error);
+
+public:
+ ~usrp2_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-usrp2/src/usrp2_source_32fc.cc b/gr-usrp2/src/usrp2_source_32fc.cc
new file mode 100644
index 000000000..0d34931a5
--- /dev/null
+++ b/gr-usrp2/src/usrp2_source_32fc.cc
@@ -0,0 +1,77 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <usrp2_source_32fc.h>
+#include <rx_32fc_handler.h>
+#include <gr_io_signature.h>
+#include <iostream>
+
+#define USRP2_SOURCE_32FC_DEBUG 0
+
+usrp2_source_32fc_sptr
+usrp2_make_source_32fc(const std::string &ifc, const std::string &mac_addr)
+ throw (std::runtime_error)
+{
+ return usrp2_source_32fc_sptr(new usrp2_source_32fc(ifc, mac_addr));
+}
+
+usrp2_source_32fc::usrp2_source_32fc(const std::string &ifc, const std::string &mac_addr)
+ throw (std::runtime_error)
+ : usrp2_source_base("usrp2_source_32fc",
+ gr_make_io_signature(1, 1, sizeof(gr_complex)),
+ ifc, mac_addr)
+{
+ set_output_multiple(USRP2_MIN_RX_SAMPLES);
+}
+
+usrp2_source_32fc::~usrp2_source_32fc()
+{
+}
+
+int
+usrp2_source_32fc::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+{
+ if (USRP2_SOURCE_32FC_DEBUG)
+ printf("work: noutput_items=%i\n", noutput_items);
+
+ gr_complex *out = (gr_complex *)output_items[0];
+
+ rx_32fc_handler::sptr handler = rx_32fc_handler::make(noutput_items, USRP2_MIN_RX_SAMPLES, out);
+
+ bool ok = d_u2->rx_samples(0, handler.get());
+ if (!ok)
+ std::cerr << "usrp2::rx_samples() failed" << std::endl;
+
+ int j = handler->nsamples();
+ int f = handler->nframes();
+
+ if (USRP2_SOURCE_32FC_DEBUG)
+ printf("work: produced=%i items from %i frames\n\n", j, f);
+
+ return j;
+}
diff --git a/gr-usrp2/src/usrp2_source_32fc.h b/gr-usrp2/src/usrp2_source_32fc.h
new file mode 100644
index 000000000..c60910918
--- /dev/null
+++ b/gr-usrp2/src/usrp2_source_32fc.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_32FC_H
+#define INCLUDED_USRP2_SOURCE_32FC_H
+
+#include <usrp2_source_base.h>
+
+class usrp2_source_32fc;
+typedef boost::shared_ptr<usrp2_source_32fc> usrp2_source_32fc_sptr;
+
+usrp2_source_32fc_sptr
+usrp2_make_source_32fc(const std::string &ifc="eth0",
+ const std::string &mac="")
+ throw (std::runtime_error);
+
+class usrp2_source_32fc : public usrp2_source_base {
+
+private:
+ friend usrp2_source_32fc_sptr
+ usrp2_make_source_32fc(const std::string &ifc,
+ const std::string &mac) throw (std::runtime_error);
+
+protected:
+ usrp2_source_32fc(const std::string &ifc, const std::string &mac) throw (std::runtime_error);
+
+public:
+ ~usrp2_source_32fc();
+
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+};
+
+#endif /* INCLUDED_USRP2_SOURCE_32FC_H */
diff --git a/gr-usrp2/src/usrp2_source_base.cc b/gr-usrp2/src/usrp2_source_base.cc
new file mode 100644
index 000000000..631b50c14
--- /dev/null
+++ b/gr-usrp2/src/usrp2_source_base.cc
@@ -0,0 +1,92 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <usrp2_source_base.h>
+#include <gr_io_signature.h>
+#include <iostream>
+
+#define USRP2_SOURCE_BASE_DEBUG 0
+
+usrp2_source_base::usrp2_source_base(const char *name,
+ gr_io_signature_sptr output_signature,
+ const std::string &ifc,
+ const std::string &mac)
+ throw (std::runtime_error)
+ : gr_sync_block(name,
+ gr_make_io_signature(0, 0, 0),
+ output_signature),
+ d_u2(usrp2::usrp2::sptr())
+{
+ d_u2 = usrp2::usrp2::make(ifc, mac);
+ if (!d_u2)
+ throw std::runtime_error("Unable to initialize USRP2!");
+}
+
+usrp2_source_base::~usrp2_source_base ()
+{
+}
+
+bool
+usrp2_source_base::set_gain(double gain)
+{
+ return d_u2->set_rx_gain(gain);
+}
+
+bool
+usrp2_source_base::set_center_freq(double frequency, usrp2::tune_result *tr)
+{
+ return d_u2->set_rx_center_freq(frequency, tr);
+}
+
+bool
+usrp2_source_base::set_decim(int decimation_factor)
+{
+ return d_u2->set_rx_decim(decimation_factor);
+}
+
+std::string
+usrp2_source_base::mac_addr()
+{
+ return d_u2->mac_addr();
+}
+
+bool
+usrp2_source_base::start()
+{
+ if (USRP2_SOURCE_BASE_DEBUG)
+ printf("usrp2_source_base::start()\n");
+
+ return d_u2->start_rx_streaming(0); // FIXME: someday sources will have channel #s
+}
+
+bool
+usrp2_source_base::stop()
+{
+ if (USRP2_SOURCE_BASE_DEBUG)
+ printf("usrp2_source_base::stop()\n");
+
+ return d_u2->stop_rx_streaming(0); // FIXME: someday sources will have channel #s
+}
diff --git a/gr-usrp2/src/usrp2_source_base.h b/gr-usrp2/src/usrp2_source_base.h
new file mode 100644
index 000000000..34d9fea0b
--- /dev/null
+++ b/gr-usrp2/src/usrp2_source_base.h
@@ -0,0 +1,85 @@
+/* -*- 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_BASE_H
+#define INCLUDED_USRP2_SOURCE_BASE_H
+
+#include <gr_sync_block.h>
+#include <usrp2/usrp2.h>
+#include <stdexcept>
+
+// BIG ASS FIXME: get from lower layer MTU calculation
+#define USRP2_MIN_RX_SAMPLES 371
+
+class usrp2_source_base : public gr_sync_block {
+
+protected:
+ usrp2_source_base(const char *name,
+ gr_io_signature_sptr output_signature,
+ const std::string &ifc,
+ const std::string &mac)
+ throw (std::runtime_error);
+
+ usrp2::usrp2::sptr d_u2;
+
+public:
+ ~usrp2_source_base();
+
+ /*!
+ * \brief Set receiver gain
+ */
+ bool set_gain(double gain);
+
+ /*!
+ * \brief Set receiver center frequency
+ */
+ bool set_center_freq(double frequency, usrp2::tune_result *tr);
+
+ /*!
+ * \brief Set receive decimation rate
+ */
+ bool set_decim(int decimation_factor);
+
+ /*!
+ * \brief Get USRP2 hardware MAC address
+ */
+ std::string mac_addr();
+
+ /*!
+ * \brief Called by scheduler when starting flowgraph
+ */
+ bool start();
+
+ /*!
+ * \brief Called by scheduler when stopping flowgraph
+ */
+ bool stop();
+
+ /*!
+ * \brief Derived class must override this
+ */
+ virtual int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items) = 0;
+};
+
+#endif /* INCLUDED_USRP2_SOURCE_BASE_H */