commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r9641 - in gnuradio/trunk: gr-usrp2/src usrp2/host/inc


From: jcorgan
Subject: [Commit-gnuradio] r9641 - in gnuradio/trunk: gr-usrp2/src usrp2/host/include/usrp2
Date: Mon, 22 Sep 2008 20:17:39 -0600 (MDT)

Author: jcorgan
Date: 2008-09-22 20:17:38 -0600 (Mon, 22 Sep 2008)
New Revision: 9641

Added:
   gnuradio/trunk/gr-usrp2/src/usrp2_base.cc
   gnuradio/trunk/gr-usrp2/src/usrp2_base.h
   gnuradio/trunk/gr-usrp2/src/usrp2_sink_16sc.cc
   gnuradio/trunk/gr-usrp2/src/usrp2_sink_16sc.h
Modified:
   gnuradio/trunk/gr-usrp2/src/Makefile.am
   gnuradio/trunk/gr-usrp2/src/usrp2.i
   gnuradio/trunk/gr-usrp2/src/usrp2_sink_32fc.cc
   gnuradio/trunk/gr-usrp2/src/usrp2_sink_32fc.h
   gnuradio/trunk/gr-usrp2/src/usrp2_sink_base.cc
   gnuradio/trunk/gr-usrp2/src/usrp2_sink_base.h
   gnuradio/trunk/gr-usrp2/src/usrp2_source_16sc.cc
   gnuradio/trunk/gr-usrp2/src/usrp2_source_16sc.h
   gnuradio/trunk/gr-usrp2/src/usrp2_source_32fc.cc
   gnuradio/trunk/gr-usrp2/src/usrp2_source_32fc.h
   gnuradio/trunk/gr-usrp2/src/usrp2_source_base.cc
   gnuradio/trunk/gr-usrp2/src/usrp2_source_base.h
   gnuradio/trunk/usrp2/host/include/usrp2/usrp2.h
Log:
Adds usrp2.sink_32fc, usrp2.sink_16sc, refactoring, cleanup

Modified: gnuradio/trunk/gr-usrp2/src/Makefile.am
===================================================================
--- gnuradio/trunk/gr-usrp2/src/Makefile.am     2008-09-22 23:00:05 UTC (rev 
9640)
+++ gnuradio/trunk/gr-usrp2/src/Makefile.am     2008-09-23 02:17:38 UTC (rev 
9641)
@@ -38,25 +38,26 @@
 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 \

Modified: gnuradio/trunk/gr-usrp2/src/usrp2.i
===================================================================
--- gnuradio/trunk/gr-usrp2/src/usrp2.i 2008-09-22 23:00:05 UTC (rev 9640)
+++ gnuradio/trunk/gr-usrp2/src/usrp2.i 2008-09-23 02:17:38 UTC (rev 9641)
@@ -23,109 +23,135 @@
 %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 @@
 
 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
 %}

Added: gnuradio/trunk/gr-usrp2/src/usrp2_base.cc
===================================================================
--- gnuradio/trunk/gr-usrp2/src/usrp2_base.cc                           (rev 0)
+++ gnuradio/trunk/gr-usrp2/src/usrp2_base.cc   2008-09-23 02:17:38 UTC (rev 
9641)
@@ -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;
+}

Added: gnuradio/trunk/gr-usrp2/src/usrp2_base.h
===================================================================
--- gnuradio/trunk/gr-usrp2/src/usrp2_base.h                            (rev 0)
+++ gnuradio/trunk/gr-usrp2/src/usrp2_base.h    2008-09-23 02:17:38 UTC (rev 
9641)
@@ -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 */

Added: gnuradio/trunk/gr-usrp2/src/usrp2_sink_16sc.cc
===================================================================
--- gnuradio/trunk/gr-usrp2/src/usrp2_sink_16sc.cc                              
(rev 0)
+++ gnuradio/trunk/gr-usrp2/src/usrp2_sink_16sc.cc      2008-09-23 02:17:38 UTC 
(rev 9641)
@@ -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;
+}

Added: gnuradio/trunk/gr-usrp2/src/usrp2_sink_16sc.h
===================================================================
--- gnuradio/trunk/gr-usrp2/src/usrp2_sink_16sc.h                               
(rev 0)
+++ gnuradio/trunk/gr-usrp2/src/usrp2_sink_16sc.h       2008-09-23 02:17:38 UTC 
(rev 9641)
@@ -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 */

Modified: gnuradio/trunk/gr-usrp2/src/usrp2_sink_32fc.cc
===================================================================
--- gnuradio/trunk/gr-usrp2/src/usrp2_sink_32fc.cc      2008-09-22 23:00:05 UTC 
(rev 9640)
+++ gnuradio/trunk/gr-usrp2/src/usrp2_sink_32fc.cc      2008-09-23 02:17:38 UTC 
(rev 9641)
@@ -25,22 +25,47 @@
 #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;
+}

Modified: gnuradio/trunk/gr-usrp2/src/usrp2_sink_32fc.h
===================================================================
--- gnuradio/trunk/gr-usrp2/src/usrp2_sink_32fc.h       2008-09-22 23:00:05 UTC 
(rev 9640)
+++ gnuradio/trunk/gr-usrp2/src/usrp2_sink_32fc.h       2008-09-23 02:17:38 UTC 
(rev 9641)
@@ -29,19 +29,28 @@
 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 */

Modified: gnuradio/trunk/gr-usrp2/src/usrp2_sink_base.cc
===================================================================
--- gnuradio/trunk/gr-usrp2/src/usrp2_sink_base.cc      2008-09-22 23:00:05 UTC 
(rev 9640)
+++ gnuradio/trunk/gr-usrp2/src/usrp2_sink_base.cc      2008-09-23 02:17:38 UTC 
(rev 9641)
@@ -26,24 +26,42 @@
 
 #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
 }
 
-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_gain(double gain)
 {
-  return noutput_items;
+  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);
+}
+
+bool
+usrp2_sink_base::set_interp(int interp_factor)
+{
+  return d_u2->set_tx_interp(interp_factor);
+}

Modified: gnuradio/trunk/gr-usrp2/src/usrp2_sink_base.h
===================================================================
--- gnuradio/trunk/gr-usrp2/src/usrp2_sink_base.h       2008-09-22 23:00:05 UTC 
(rev 9640)
+++ gnuradio/trunk/gr-usrp2/src/usrp2_sink_base.h       2008-09-23 02:17:38 UTC 
(rev 9641)
@@ -23,24 +23,37 @@
 #ifndef INCLUDED_USRP2_SINK_BASE_H
 #define INCLUDED_USRP2_SINK_BASE_H
 
-#include <gr_sync_block.h>
-#include <stdexcept>
+#include <usrp2_base.h>
 
-class usrp2_sink_base : public gr_sync_block {
-
-private:
-
+/*!
+ * 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 */

Modified: gnuradio/trunk/gr-usrp2/src/usrp2_source_16sc.cc
===================================================================
--- gnuradio/trunk/gr-usrp2/src/usrp2_source_16sc.cc    2008-09-22 23:00:05 UTC 
(rev 9640)
+++ gnuradio/trunk/gr-usrp2/src/usrp2_source_16sc.cc    2008-09-23 02:17:38 UTC 
(rev 9641)
@@ -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 @@
                        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 @@
   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();
 }

Modified: gnuradio/trunk/gr-usrp2/src/usrp2_source_16sc.h
===================================================================
--- gnuradio/trunk/gr-usrp2/src/usrp2_source_16sc.h     2008-09-22 23:00:05 UTC 
(rev 9640)
+++ gnuradio/trunk/gr-usrp2/src/usrp2_source_16sc.h     2008-09-23 02:17:38 UTC 
(rev 9641)
@@ -33,8 +33,8 @@
                       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,

Modified: gnuradio/trunk/gr-usrp2/src/usrp2_source_32fc.cc
===================================================================
--- gnuradio/trunk/gr-usrp2/src/usrp2_source_32fc.cc    2008-09-22 23:00:05 UTC 
(rev 9640)
+++ gnuradio/trunk/gr-usrp2/src/usrp2_source_32fc.cc    2008-09-23 02:17:38 UTC 
(rev 9641)
@@ -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 @@
                        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 @@
   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();
 }

Modified: gnuradio/trunk/gr-usrp2/src/usrp2_source_32fc.h
===================================================================
--- gnuradio/trunk/gr-usrp2/src/usrp2_source_32fc.h     2008-09-22 23:00:05 UTC 
(rev 9640)
+++ gnuradio/trunk/gr-usrp2/src/usrp2_source_32fc.h     2008-09-23 02:17:38 UTC 
(rev 9641)
@@ -33,8 +33,8 @@
                       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,

Modified: gnuradio/trunk/gr-usrp2/src/usrp2_source_base.cc
===================================================================
--- gnuradio/trunk/gr-usrp2/src/usrp2_source_base.cc    2008-09-22 23:00:05 UTC 
(rev 9640)
+++ gnuradio/trunk/gr-usrp2/src/usrp2_source_base.cc    2008-09-23 02:17:38 UTC 
(rev 9641)
@@ -28,25 +28,22 @@
 #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 @@
   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
 }

Modified: gnuradio/trunk/gr-usrp2/src/usrp2_source_base.h
===================================================================
--- gnuradio/trunk/gr-usrp2/src/usrp2_source_base.h     2008-09-22 23:00:05 UTC 
(rev 9640)
+++ gnuradio/trunk/gr-usrp2/src/usrp2_source_base.h     2008-09-23 02:17:38 UTC 
(rev 9641)
@@ -23,15 +23,13 @@
 #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 @@
                    const std::string &mac)
     throw (std::runtime_error);
 
-  usrp2::usrp2::sptr d_u2;
-
 public:
   ~usrp2_source_base();
 
@@ -60,26 +56,14 @@
   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 */

Modified: gnuradio/trunk/usrp2/host/include/usrp2/usrp2.h
===================================================================
--- gnuradio/trunk/usrp2/host/include/usrp2/usrp2.h     2008-09-22 23:00:05 UTC 
(rev 9640)
+++ gnuradio/trunk/usrp2/host/include/usrp2/usrp2.h     2008-09-23 02:17:38 UTC 
(rev 9641)
@@ -171,7 +171,7 @@
      */
 
     /*!
-     * Set receiver gain
+     * Set transmitter gain
      */
     bool set_tx_gain(double gain);
 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]