commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r8426 - in usrp2/branches/developers/jcorgan/u2/host:


From: jcorgan
Subject: [Commit-gnuradio] r8426 - in usrp2/branches/developers/jcorgan/u2/host: gr-usrp2 lib
Date: Wed, 14 May 2008 17:36:36 -0600 (MDT)

Author: jcorgan
Date: 2008-05-14 17:36:34 -0600 (Wed, 14 May 2008)
New Revision: 8426

Added:
   usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_source_raw.cc
   usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_source_raw.h
Modified:
   usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/Makefile.am
   usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2.i
   usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_source_base.cc
   usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_source_base.h
   usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_source_c.cc
   usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_source_c.h
   usrp2/branches/developers/jcorgan/u2/host/lib/usrp2_basic.cc
   usrp2/branches/developers/jcorgan/u2/host/lib/usrp2_basic.h
Log:
Added usrp2.source_c and source_raw that use existing half-duplex usrp2_basic 
read code.

Modified: usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/Makefile.am
===================================================================
--- usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/Makefile.am      
2008-05-14 17:48:59 UTC (rev 8425)
+++ usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/Makefile.am      
2008-05-14 23:36:34 UTC (rev 8426)
@@ -27,6 +27,7 @@
        usrp2_sink_c.cc \
        usrp2_source_base.cc \
        usrp2_source_c.cc \
+       usrp2_source_raw.cc \
        usrp2_table.cc
 
 libgr_usrp2_la_LIBADD = \
@@ -36,7 +37,8 @@
        usrp2_sink_base.h \
        usrp2_sink_c.h \
        usrp2_source_base.h \
-       usrp2_source_c.h
+       usrp2_source_c.h \
+       usrp2_source_raw.h
        
 noinst_HEADERS = \
        usrp2_table.h

Modified: usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2.i
===================================================================
--- usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2.i  2008-05-14 
17:48:59 UTC (rev 8425)
+++ usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2.i  2008-05-14 
23:36:34 UTC (rev 8426)
@@ -29,6 +29,7 @@
 #include "gnuradio_swig_bug_workaround.h"      // mandatory bug fix
 #include "usrp2_sink_c.h"
 #include "usrp2_source_c.h"
+#include "usrp2_source_raw.h"
 %}
 
 %include "../lib/usrp2_tune_result.h"
@@ -45,6 +46,10 @@
 public:
   ~usrp2_source_base();
 
+  bool set_gain(double gain);
+  usrp2_tune_result_sptr set_freq(double frequency);
+  bool set_decim(int decimation_factor);
+  bool set_scale_iq(int scale_i, int scale_q);
 };
 
 // ----------------------------------------------------------------
@@ -63,14 +68,28 @@
 public:
   ~usrp2_source_c();
 
-  bool set_gain(double gain);
-  usrp2_tune_result_sptr set_freq(double frequency);
-  bool set_decim(int decimation_factor);
-  bool set_scale_iq(int scale_i, int scale_q);
 };
 
 // ----------------------------------------------------------------
 
+GR_SWIG_BLOCK_MAGIC(usrp2,source_raw)
+
+usrp2_source_raw_sptr
+usrp2_make_source_raw(const std::string &ifc="eth0", const std::string 
&mac="") 
+  throw (std::runtime_error);
+
+class usrp2_source_raw : public usrp2_source_base {
+
+protected:
+  usrp2_source_raw(const std::string &ifc, const std::string &mac);
+
+public:
+  ~usrp2_source_raw();
+
+};
+
+// ----------------------------------------------------------------
+
 class usrp2_sink_base : public gr_sync_block {
 
 protected:

Modified: 
usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_source_base.cc
===================================================================
--- usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_source_base.cc     
2008-05-14 17:48:59 UTC (rev 8425)
+++ usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_source_base.cc     
2008-05-14 23:36:34 UTC (rev 8426)
@@ -29,8 +29,10 @@
 #include <gr_io_signature.h>
 #include <iostream>
 
-#define USRP2_SOURCE_BASE_DEBUG 1
+#define USRP2_SOURCE_BASE_DEBUG 0
 
+#define SAMPLES_PER_PACKET 250
+
 usrp2_source_base::usrp2_source_base(const std::string &name,
                                     gr_io_signature_sptr output_signature,
                                     const std::string &ifc,
@@ -95,7 +97,7 @@
   if (USRP2_SOURCE_BASE_DEBUG)
     std::cout << "usrp2_source_base: start" << std::endl;
 
-  return true;
+  return d_u2->start_rx_streaming(SAMPLES_PER_PACKET);
 }
 
 bool
@@ -104,7 +106,7 @@
   if (USRP2_SOURCE_BASE_DEBUG)
     std::cout << "usrp2_source_base: stop" << std::endl;
 
-  return true;
+  return d_u2->stop_rx();
 }
 
 usrp2_source_base::~usrp2_source_base ()
@@ -116,5 +118,16 @@
                        gr_vector_const_void_star &input_items,
                        gr_vector_void_star &output_items)
 {
-  return noutput_items;
+  int nsamples = std::min(noutput_items, SAMPLES_PER_PACKET);
+  u2_eth_samples_t eth_samples;
+  int n = d_u2->read_samples(&eth_samples, nsamples);
+  if (n < 0)
+    return -1; // we're done
+ 
+  copy_from_usrp2_buffer(&eth_samples.samples[0], output_items[0], n);
+
+  if (USRP2_SOURCE_BASE_DEBUG)
+    printf("noutput_items=%d nsamples=%d n=%d\n", noutput_items, nsamples, n);
+
+  return n;
 }

Modified: usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_source_base.h
===================================================================
--- usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_source_base.h      
2008-05-14 17:48:59 UTC (rev 8425)
+++ usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_source_base.h      
2008-05-14 23:36:34 UTC (rev 8426)
@@ -37,7 +37,7 @@
     throw (std::runtime_error);
 
   usrp2_basic_sptr d_u2;
-
+  
 public:
   ~usrp2_source_base();
   
@@ -52,6 +52,8 @@
   int work(int noutput_items,
           gr_vector_const_void_star &input_items,
           gr_vector_void_star &output_items);
+
+  virtual void copy_from_usrp2_buffer(uint32_t *src, void *dst, int nsamples) 
= 0;
 };
 
 #endif /* INCLUDED_USRP2_SOURCE_BASE_H */

Modified: usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_source_c.cc
===================================================================
--- usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_source_c.cc        
2008-05-14 17:48:59 UTC (rev 8425)
+++ usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_source_c.cc        
2008-05-14 23:36:34 UTC (rev 8426)
@@ -26,7 +26,10 @@
 
 #include <usrp2_source_c.h>
 #include <gr_io_signature.h>
+#include <iostream>
 
+#define USRP2_SOURCE_C_DEBUG 1
+
 usrp2_source_c_sptr
 usrp2_make_source_c(const std::string &ifc,
                    const std::string &mac) 
@@ -47,3 +50,14 @@
 usrp2_source_c::~usrp2_source_c()
 {
 }
+
+void
+usrp2_source_c::copy_from_usrp2_buffer(uint32_t *src, void *dst, int nsamples)
+{
+  gr_complex *out = (gr_complex *)dst;
+  for (int i = 0; i < nsamples; i++) {
+    float re = (signed short int)((src[i] & 0xFFFF0000) >> 16);
+    float im = (signed short int)(src[i] & 0x0000FFFF);
+    *out++ = gr_complex(re, im); 
+  }
+}

Modified: usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_source_c.h
===================================================================
--- usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_source_c.h 
2008-05-14 17:48:59 UTC (rev 8425)
+++ usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_source_c.h 
2008-05-14 23:36:34 UTC (rev 8426)
@@ -46,6 +46,8 @@
 
 public:
   ~usrp2_source_c();
+
+  virtual void copy_from_usrp2_buffer(uint32_t *src, void *dst, int nsamples);
 };
 
 #endif /* INCLUDED_USRP2_SOURCE_C_H */

Added: usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_source_raw.cc
===================================================================
--- usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_source_raw.cc      
                        (rev 0)
+++ usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_source_raw.cc      
2008-05-14 23:36:34 UTC (rev 8426)
@@ -0,0 +1,59 @@
+/* -*- 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_raw.h>
+#include <gr_io_signature.h>
+#include <iostream>
+
+usrp2_source_raw_sptr
+usrp2_make_source_raw(const std::string &ifc,
+                     const std::string &mac) 
+  throw (std::runtime_error)
+{
+  return usrp2_source_raw_sptr(new usrp2_source_raw(ifc, mac));
+}
+
+usrp2_source_raw::usrp2_source_raw(const std::string &ifc,
+                              const std::string &mac) 
+  throw (std::runtime_error)
+  : usrp2_source_base("usrp2_source_raw",
+                     gr_make_io_signature(1, 1, sizeof(uint32_t)),
+                     ifc, mac)
+{
+}
+
+usrp2_source_raw::~usrp2_source_raw()
+{
+}
+
+void
+usrp2_source_raw::copy_from_usrp2_buffer(uint32_t *src, void *dst, int 
nsamples)
+{
+  uint32_t *out = (uint32_t *)dst;
+
+  for (int i = 0; i < nsamples; i++)
+    *out++ = src[i];
+}

Added: usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_source_raw.h
===================================================================
--- usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_source_raw.h       
                        (rev 0)
+++ usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_source_raw.h       
2008-05-14 23:36:34 UTC (rev 8426)
@@ -0,0 +1,53 @@
+/* -*- 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_RAW_H
+#define INCLUDED_USRP2_SOURCE_RAW_H
+
+#include <usrp2_source_base.h>
+
+class usrp2_source_raw;
+typedef boost::shared_ptr<usrp2_source_raw> usrp2_source_raw_sptr;
+
+usrp2_source_raw_sptr
+usrp2_make_source_raw(const std::string &ifc="eth0",
+                     const std::string &mac="") 
+  throw (std::runtime_error);
+
+class usrp2_source_raw : public usrp2_source_base {
+
+private:
+  friend usrp2_source_raw_sptr
+  usrp2_make_source_raw(const std::string &ifc,
+                     const std::string &mac) throw (std::runtime_error);
+
+protected:
+  usrp2_source_raw(const std::string &ifc="eth0",
+                const std::string &mac="") throw (std::runtime_error);
+
+public:
+  ~usrp2_source_raw();
+
+  virtual void copy_from_usrp2_buffer(uint32_t *src, void *dst, int nsamples);
+};
+
+#endif /* INCLUDED_USRP2_SOURCE_RAW_H */

Modified: usrp2/branches/developers/jcorgan/u2/host/lib/usrp2_basic.cc
===================================================================
--- usrp2/branches/developers/jcorgan/u2/host/lib/usrp2_basic.cc        
2008-05-14 17:48:59 UTC (rev 8425)
+++ usrp2/branches/developers/jcorgan/u2/host/lib/usrp2_basic.cc        
2008-05-14 23:36:34 UTC (rev 8426)
@@ -37,7 +37,7 @@
 #include <unistd.h>
 #endif
 
-#define USRP2_BASIC_DEBUG 1
+#define USRP2_BASIC_DEBUG 0
 
 /*
  * Note, this should be considered a first cut at getting
@@ -583,31 +583,33 @@
 }
 
 int
-usrp2_basic::read_raw_samples(u2_eth_samples_t *pkt)
+usrp2_basic::read_raw_samples(u2_eth_samples_t *pkt, int nmax)
 {
-  int len = d_ethernet->read_packet(pkt, sizeof(*pkt));
-  // printf("read_packet = %d\n", len);
+  int nmaxbytes = (nmax == -1) ? sizeof(*pkt) : nmax*sizeof(uint32_t) + 
sizeof(u2_eth_packet_t);
+  int readsize = std::min(int(sizeof(*pkt)), nmaxbytes);
+  int len = d_ethernet->read_packet(pkt, readsize);
 
   if (len <= 0)
     return len;
 
   // FIXME check channel
 
-
-  // shouldn't happen
-  if ((size_t) len < sizeof(u2_eth_packet_t))
+  if ((size_t) len < sizeof(u2_eth_packet_t)) {
+    printf("usrp2_basic::read_raw_samples: short read, len=%d\n", len);
     return 0;
+  }   
 
-  // convert to samples
   int r = (len - sizeof(u2_eth_packet_t)) / sizeof(uint32_t);
-  // printf("read_raw_samples = %d\n", r);
+  if (USRP2_BASIC_DEBUG)
+    printf("usrp2_basic::read_raw_samples: nmax=%d nmaxbytes=%d readsize=%d 
len=%d r=%d\n", 
+           nmax, nmaxbytes, readsize, len, r);
   return r;
 }
 
 int
-usrp2_basic::read_samples(u2_eth_samples_t *pkt)
+usrp2_basic::read_samples(u2_eth_samples_t *pkt, int nmax)
 {
-  int r = read_raw_samples(pkt);
+  int r = read_raw_samples(pkt, nmax);
 
 #ifndef WORDS_BIGENDIAN
   for (int i = 0; i < r; i++)

Modified: usrp2/branches/developers/jcorgan/u2/host/lib/usrp2_basic.h
===================================================================
--- usrp2/branches/developers/jcorgan/u2/host/lib/usrp2_basic.h 2008-05-14 
17:48:59 UTC (rev 8425)
+++ usrp2/branches/developers/jcorgan/u2/host/lib/usrp2_basic.h 2008-05-14 
23:36:34 UTC (rev 8426)
@@ -136,7 +136,7 @@
    * \param pkt contains the raw (non-endian corrected) samples
    * \returns number of valid samples in pkt.
    */
-  int read_raw_samples(u2_eth_samples_t *pkt);
+  int read_raw_samples(u2_eth_samples_t *pkt, int nmax = -1);
 
   /*!
    * \brief Read native-endian samples from USRP2.
@@ -144,7 +144,7 @@
    * \param pkt contains native-endian samples.
    * \returns number of valid samples in pkt.
    */
-  int read_samples(u2_eth_samples_t *pkt);
+  int read_samples(u2_eth_samples_t *pkt, int nmax = -1);
 
   /*!
    * \brief Write raw samples to USRP2.





reply via email to

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