Adds usrp2.sink_32fc, usrp2.sink_16sc, refactoring, cleanup
authorjcorgan <jcorgan@221aa14e-8319-0410-a670-987f0aec2ac5>
Tue, 23 Sep 2008 02:17:38 +0000 (02:17 +0000)
committerjcorgan <jcorgan@221aa14e-8319-0410-a670-987f0aec2ac5>
Tue, 23 Sep 2008 02:17:38 +0000 (02:17 +0000)
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@9641 221aa14e-8319-0410-a670-987f0aec2ac5

17 files changed:
gr-usrp2/src/Makefile.am
gr-usrp2/src/usrp2.i
gr-usrp2/src/usrp2_base.cc [new file with mode: 0644]
gr-usrp2/src/usrp2_base.h [new file with mode: 0644]
gr-usrp2/src/usrp2_sink_16sc.cc [new file with mode: 0644]
gr-usrp2/src/usrp2_sink_16sc.h [new file with mode: 0644]
gr-usrp2/src/usrp2_sink_32fc.cc
gr-usrp2/src/usrp2_sink_32fc.h
gr-usrp2/src/usrp2_sink_base.cc
gr-usrp2/src/usrp2_sink_base.h
gr-usrp2/src/usrp2_source_16sc.cc
gr-usrp2/src/usrp2_source_16sc.h
gr-usrp2/src/usrp2_source_32fc.cc
gr-usrp2/src/usrp2_source_32fc.h
gr-usrp2/src/usrp2_source_base.cc
gr-usrp2/src/usrp2_source_base.h
usrp2/host/include/usrp2/usrp2.h

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