commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r9032 - in usrp2/branches/developers/eb/wip/host-ng: a


From: eb
Subject: [Commit-gnuradio] r9032 - in usrp2/branches/developers/eb/wip/host-ng: apps include/usrp2 lib
Date: Mon, 28 Jul 2008 00:07:13 -0600 (MDT)

Author: eb
Date: 2008-07-28 00:07:13 -0600 (Mon, 28 Jul 2008)
New Revision: 9032

Added:
   usrp2/branches/developers/eb/wip/host-ng/apps/test2_usrp2.cc
   usrp2/branches/developers/eb/wip/host-ng/include/usrp2/metadata.h
   usrp2/branches/developers/eb/wip/host-ng/include/usrp2/rx_sample_handler.h
   usrp2/branches/developers/eb/wip/host-ng/lib/rx_sample_handler.cc
Modified:
   usrp2/branches/developers/eb/wip/host-ng/apps/
   usrp2/branches/developers/eb/wip/host-ng/apps/Makefile.am
   usrp2/branches/developers/eb/wip/host-ng/include/usrp2/usrp2.h
   usrp2/branches/developers/eb/wip/host-ng/lib/Makefile.am
   usrp2/branches/developers/eb/wip/host-ng/lib/eth_buffer.cc
   usrp2/branches/developers/eb/wip/host-ng/lib/usrp2.cc
   usrp2/branches/developers/eb/wip/host-ng/lib/usrp2_impl.cc
   usrp2/branches/developers/eb/wip/host-ng/lib/usrp2_impl.h
Log:
usrp2 work-in-progress


Property changes on: usrp2/branches/developers/eb/wip/host-ng/apps
___________________________________________________________________
Name: svn:ignore
   - Makefile
Makefile.in
.libs
.deps
test_eth
test_usrp2
cerr
*.sh

   + Makefile
Makefile.in
.libs
.deps
test_eth
test_usrp2
test2_usrp2
cerr
*.sh


Modified: usrp2/branches/developers/eb/wip/host-ng/apps/Makefile.am
===================================================================
--- usrp2/branches/developers/eb/wip/host-ng/apps/Makefile.am   2008-07-27 
23:41:30 UTC (rev 9031)
+++ usrp2/branches/developers/eb/wip/host-ng/apps/Makefile.am   2008-07-28 
06:07:13 UTC (rev 9032)
@@ -17,16 +17,16 @@
 
 include $(top_srcdir)/Makefile.common
 
-AM_CPPFLAGS = -Wall -Werror
-INCLUDES = $(STD_DEFINES_AND_INCLUDES) $(CPPUNIT_INCLUDES) $(GRUEL_CFLAGS)
+#AM_CXXFLAGS = -Wall -Werror (handle this with: $ ./configure CXXFLAGS="-Wall 
-Werror -O2 -g")
+AM_CPPFLAGS = $(STD_DEFINES_AND_INCLUDES) $(CPPUNIT_INCLUDES) $(GRUEL_CFLAGS)
 
 LDADD = \
        ../lib/libusrp2ng.la \
        -lgruel
 
 noinst_PROGRAMS = \
-       test_usrp2
+       test2_usrp2
 
-test_usrp2_SOURCES = \
-       test_usrp2.cc
+test2_usrp2_SOURCES = \
+       test2_usrp2.cc
 

Copied: usrp2/branches/developers/eb/wip/host-ng/apps/test2_usrp2.cc (from rev 
9031, usrp2/branches/developers/eb/wip/host-ng/apps/test_usrp2.cc)
===================================================================
--- usrp2/branches/developers/eb/wip/host-ng/apps/test2_usrp2.cc                
                (rev 0)
+++ usrp2/branches/developers/eb/wip/host-ng/apps/test2_usrp2.cc        
2008-07-28 06:07:13 UTC (rev 9032)
@@ -0,0 +1,239 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007,2008 Free Software Foundation, Inc.
+ *
+ * This program 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 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <usrp2/usrp2.h>
+#include <usrp2/tune_result.h>
+#include <usrp2/strtod_si.h>
+#include <usrp2/rx_sample_handler.h>
+#include <gruel/realtime.h>
+#include <sys/time.h>
+#include <iostream>
+#include <string.h>
+#include <boost/scoped_ptr.hpp>
+
+class rx_nop_handler : public usrp2::rx_sample_handler
+{
+  size_t       d_max_samples;
+  size_t       d_nsamples;
+  size_t       d_nframes;
+
+public:
+  
+  rx_nop_handler(size_t max_samples)
+    : d_max_samples(max_samples), d_nsamples(0), d_nframes(0) {}
+      
+  ~rx_nop_handler();
+
+  size_t nframes() const { return d_nframes; }
+  size_t nsamples() const { return d_nsamples; }
+
+  bool 
+  operator()(const uint32_t *items, size_t nitems, const usrp2::rx_metadata 
*metadata)
+  {
+    d_nsamples += nitems;
+    d_nframes++;
+
+    return d_nsamples < d_max_samples;
+  }
+};
+
+rx_nop_handler::~rx_nop_handler()
+{
+  // nop
+}
+
+
+static void
+usage(const char *progname)
+{
+  const char *p = strrchr(progname, '/');      // drop leading directory path
+  if (p)
+    p++;
+
+  if (strncmp(p, "lt-", 3) == 0)               // drop lt- libtool prefix
+    p += 3;
+  
+  fprintf(stderr, "Usage: %s [options]\n\n", p);
+  fprintf(stderr, "Options:\n");
+  fprintf(stderr, "  -h                   show this message and exit\n");
+  fprintf(stderr, "  -e ETH_INTERFACE     specify ethernet interface 
[default=eth0]\n");
+  fprintf(stderr, "  -m MAC_ADDR          mac address of USRP2 HH:HH 
[default=first one found]\n");
+  fprintf(stderr, "  -f FREQUENCY         specify receive center frequency in 
Hz [default=0.0]\n");
+  fprintf(stderr, "  -d DECIM             specify receive decimation rate 
[default=5]\n");
+  fprintf(stderr, "  -g GAIN              specify receive daughterboard gain 
[default=0]\n");
+  fprintf(stderr, "  -n NSAMPLES          specify number of samples to receive 
[default=250e6]\n");
+  fprintf(stderr, "  -b BUFSIZE           specify size of receive buffer 
[default=64k]\n");
+}
+
+int
+main(int argc, char **argv)
+{
+  // options and their defaults
+  const char *interface = "eth0";
+  const char *mac_addr_str = "";
+  double rx_freq = 0.0;
+  int rx_decim = 5;
+  double rx_gain = 0.0;
+  size_t nsamples = static_cast<size_t>(250e6);
+  size_t bufsize = 65536;
+      
+  int ch;
+
+  while ((ch = getopt(argc, argv, "he:m:f:d:g:n:b:")) != EOF){
+    double tmp;
+    switch (ch){
+
+    case 'e':
+      interface = optarg;
+      break;
+      
+    case 'm':
+      mac_addr_str = optarg;
+      break;
+
+    case 'f':
+      if (!strtod_si(optarg, &rx_freq)) {
+        std::cerr << "invalid number: " << optarg << std::endl;
+       usage(argv[0]);
+       exit(1);
+      }
+      break;
+
+    case 'g':
+      if (!strtod_si(optarg, &rx_gain)) {
+        std::cerr << "invalid number: " << optarg << std::endl;
+       usage(argv[0]);
+       exit(1);
+      }
+      break;
+
+    case 'd':
+      rx_decim = strtol(optarg, 0, 0);
+      if (rx_decim < 4 or rx_decim > 512) { 
+        std::cerr << "invalid decimation rate: " << optarg << std::endl;
+       usage(argv[0]);
+       exit(1);
+      }
+      break;
+
+    case 'n':
+      if (!strtod_si(optarg, &tmp)) {
+        std::cerr << "invalid number: " << optarg << std::endl;
+       usage(argv[0]);
+       exit(1);
+      }
+      nsamples = static_cast<size_t>(tmp);
+      break;
+      
+    case 'b':
+      if (!strtod_si(optarg, &tmp)) {
+        std::cerr << "invalid number: " << optarg << std::endl;
+       usage(argv[0]);
+       exit(1);
+      }
+      bufsize = static_cast<size_t>(tmp);
+      break;
+      
+    case 'h':
+    default:
+      usage(argv[0]);
+      exit(1);
+    }
+  }
+
+  gruel::rt_status_t rt = gruel::enable_realtime_scheduling();
+  if (rt != gruel::RT_OK)
+    std::cerr << "Failed to enable realtime scheduling" << std::endl;
+
+  usrp2::usrp2::sptr u2 = usrp2::usrp2::make(interface, mac_addr_str);
+  
+  // FIXME in case it was left running...
+  if (!u2->stop_rx_streaming()){
+    fprintf(stderr, "stop_rx_streaming failed\n");
+  }
+
+  if (!u2->set_rx_gain(rx_gain)){
+    fprintf(stderr, "set_rx_gain(%f) failed\n", rx_gain);
+    exit(1);
+  }
+
+  usrp2::tune_result tr;
+  if (!u2->set_rx_center_freq(rx_freq, &tr)){
+    fprintf(stderr, "set_rx_center_freq(%g) failed\n", rx_freq);
+    exit(1);
+  }
+
+  printf("Daughterboard configuration:\n");
+  printf("  baseband_freq=%f\n", tr.baseband_freq);
+  printf("       ddc_freq=%f\n", tr.dxc_freq);
+  printf("  residual_freq=%f\n", tr.residual_freq);
+  printf("       inverted=%s\n\n", tr.spectrum_inverted ? "yes" : "no");
+  
+  if (!u2->set_rx_decim(rx_decim)) {
+    fprintf(stderr, "set_rx_decim(%d) failed\n", rx_decim);
+    exit(1);
+  }
+
+  printf("USRP2 using decimation rate of %d\n", rx_decim);
+    
+  if (!u2->start_rx_streaming()){
+    fprintf(stderr, "start_rx_streaming failed\n");
+    exit(1);
+  }
+
+  boost::scoped_ptr<unsigned char> buf(new unsigned char[bufsize]);
+
+  // printf("Receiving %li samples into buffer of length %li bytes.\n\n", 
nsamples, bufsize);
+  printf("Receiving %ld samples\n\n", nsamples);
+  
+  struct timeval start, end;
+  gettimeofday(&start, 0);
+
+  // printf("Each '.' is 100 packets:\n");
+
+  rx_nop_handler h(nsamples);
+  bool ok = u2->rx_samples(0, &h);
+  if (!ok){
+    fprintf(stderr, "u2->rx_samples failed\n");
+    return 1;
+  }
+
+
+  gettimeofday(&end, 0);
+  long n_usecs = end.tv_usec-start.tv_usec;
+  long n_secs = end.tv_sec-start.tv_sec;
+  double elapsed = (double)n_secs + (double)n_usecs*1e-6;
+  double mbs = h.nsamples()*sizeof(uint32_t)/elapsed/1e6;
+  double pps = h.nframes()/elapsed;
+  
+  u2->stop_rx_streaming();
+
+  printf("\nCopy handler called %li times.\n", h.nframes());
+  printf("Copy handler called with %li bytes.\n\n", 
h.nsamples()*sizeof(uint32_t));
+  printf("Elapsed time was %5.3f seconds.\n", elapsed);
+  printf("Packet rate was %1.0f pkts/sec.\n", pps);
+  printf("Approximate throughput was %5.2f MB/sec.\n", mbs);
+  printf("Total instances of overruns was %d.\n", u2->rx_overruns());
+  printf("Total missing frames was %d.\n", u2->rx_missing()); 
+
+  return 0;
+}

Added: usrp2/branches/developers/eb/wip/host-ng/include/usrp2/metadata.h
===================================================================
--- usrp2/branches/developers/eb/wip/host-ng/include/usrp2/metadata.h           
                (rev 0)
+++ usrp2/branches/developers/eb/wip/host-ng/include/usrp2/metadata.h   
2008-07-28 06:07:13 UTC (rev 9032)
@@ -0,0 +1,60 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 Free Software Foundation, Inc.
+ *
+ * This program 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 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef INCLUDED_USRP2_METADATA_H
+#define INCLUDED_USRP2_METADATA_H
+
+#include <stdint.h>
+
+namespace usrp2 {
+
+  //! type of the timestamp returned from the USRP2 FPGA
+  typedef uint32_t     fpga_timestamp;
+
+  /*!
+   * \brief metadata associated with received frames
+   */
+  struct rx_metadata {
+    uint32_t           word0;                  //< debugging, extensions
+    fpga_timestamp     timestamp;              //< time that first sample of 
frame was received
+    unsigned int       start_of_burst : 1;     //< this frame is the start of 
a burst
+    unsigned int       end_of_burst   : 1;     //< this frame is the end of a 
burst
+    unsigned int       rx_overrun     : 1;     //< An Rx overrun occurred in 
the FPGA
+    // rssi
+    // agc_mode
+
+    rx_metadata() :
+      word0(0), timestamp(0), start_of_burst(0), end_of_burst(0), 
rx_overrun(0) {}
+  };
+
+  /*!
+   * \brief metadata associated with transmitted frames
+   */
+  struct tx_metadata {
+    fpga_timestamp     timestamp;              //< time to transmit first 
sample of frame
+    unsigned int       send_now       : 1;     //< ignore timestamp, send now
+    unsigned int       start_of_burst : 1;     //< this frame is the start of 
a burst
+    unsigned int       end_of_burst   : 1;     //< this frame is the end of a 
burst
+    // ...
+
+    tx_metadata() :
+      timestamp(0), send_now(0), start_of_burst(0), end_of_burst(0) {}
+  };
+
+}; // usrp2
+
+#endif /* INCLUDED_USRP2_METADATA_H */


Property changes on: 
usrp2/branches/developers/eb/wip/host-ng/include/usrp2/metadata.h
___________________________________________________________________
Name: svn:eol-style
   + native

Added: 
usrp2/branches/developers/eb/wip/host-ng/include/usrp2/rx_sample_handler.h
===================================================================
--- usrp2/branches/developers/eb/wip/host-ng/include/usrp2/rx_sample_handler.h  
                        (rev 0)
+++ usrp2/branches/developers/eb/wip/host-ng/include/usrp2/rx_sample_handler.h  
2008-07-28 06:07:13 UTC (rev 9032)
@@ -0,0 +1,58 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 Free Software Foundation, Inc.
+ *
+ * This program 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 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef INCLUDED_USRP2_RX_SAMPLE_HANDLER_H
+#define INCLUDED_USRP2_RX_SAMPLE_HANDLER_H
+
+#include <usrp2/metadata.h>
+#include <stddef.h>
+
+
+namespace usrp2 {
+
+  /*!
+   * \brief Abstract function object called to handle received data blocks.
+   *
+   * An object derived from this class is passed to usrp2::rx_samples
+   * to process the received frames of samples.
+   */
+  class rx_sample_handler {
+  public:
+    virtual ~rx_sample_handler();
+
+    /*!
+     * \param items points to the first 32-bit word of uninterpreted sample 
data in the frame.
+     * \param nitems is the number of entries in the frame in units of 
uint32_t's.
+     * \param metadata is the additional per frame data provided by the USRP2 
FPGA.
+     *
+     * \p items points to the raw sample data received off of the ethernet.  
The data is
+     * packed into big-endian 32-bit unsigned ints for transport, but the 
actual format
+     * of the data is dependent on the current configuration of the USRP2.  
The most common
+     * format is 16-bit I & Q, with I in the top of the 32-bit word.
+     *
+     * This is the general purpose, low level interface and relies on other 
functions
+     * to handle all required endian-swapping and format conversion.  \sa 
FIXME.
+     *
+     * \returns true if the object wants to be called again with new data;
+     * false if no additional data is wanted.
+     */
+    virtual bool operator()(const uint32_t *items, size_t nitems, const 
rx_metadata *metadata) = 0;
+  };
+
+};
+
+#endif /* INCLUDED_RX_SAMPLE_HANDLER_H */


Property changes on: 
usrp2/branches/developers/eb/wip/host-ng/include/usrp2/rx_sample_handler.h
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: usrp2/branches/developers/eb/wip/host-ng/include/usrp2/usrp2.h
===================================================================
--- usrp2/branches/developers/eb/wip/host-ng/include/usrp2/usrp2.h      
2008-07-27 23:41:30 UTC (rev 9031)
+++ usrp2/branches/developers/eb/wip/host-ng/include/usrp2/usrp2.h      
2008-07-28 06:07:13 UTC (rev 9032)
@@ -22,6 +22,7 @@
 #include <boost/shared_ptr.hpp>
 #include <boost/utility.hpp>
 #include <vector>
+#include <usrp2/rx_sample_handler.h>
 
 namespace usrp2 {
 
@@ -39,10 +40,19 @@
 
   typedef std::vector<props> props_vector_t;
 
-  props_vector_t find(const std::string &ifc, const std::string &addr=""); 
+  /*!
+   * \brief Search the ethernet for all USRP2s or for a specific USRP2.
+   *
+   * \param ifc is the name of the OS ethernet interface (e.g., "eth0")
+   * \param mac_addr is the MAC address of the desired USRP2, or "" to search 
for all.
+   * mac_addr must be either a zero length string, "", or must be of the form
+   * "01:02:03:04:05:06" or "05:06".
+   *
+   * \returns a vector of properties, 1 entry for each matching USRP2 found.
+   */
+  props_vector_t find(const std::string &ifc, const std::string &mac_addr=""); 
 
   class tune_result;
-  class data_handler;
   
   class usrp2 : boost::noncopyable
   {
@@ -57,9 +67,9 @@
     /*! 
      * Static function to return an instance of usrp2 as a shared pointer
      *
-     * \param ifc        Network interface name, e.g., "eth0"
-     * \param addr  Network mac address, e.g., "01:02:03:04:05:06" or "05:06",
-     *              default is auto-select
+     * \param ifc   Network interface name, e.g., "eth0"
+     * \param addr  Network mac address, e.g., "01:02:03:04:05:06", "05:06" or 
"".
+     *              "" will autoselect a USRP2 if there is only a single one 
on the local ethernet.
      */
     static sptr make(const std::string &ifc, const std::string &addr="");
 
@@ -99,9 +109,7 @@
      *      type: floating, fixed point, or raw
      *     depth: bits per sample
      *
-     * Sets format over the wire for samples from USRP2 and determines 
-     * default reader and writer functors   
-     * 
+     * Sets format over the wire for samples from USRP2.
      */
     // bool set_rx_format(...);
 
@@ -115,14 +123,15 @@
     bool start_rx_streaming(unsigned int channel=0, unsigned int 
items_per_frame=0);
   
     /*!
-     * Receive stream data from specified channel
+     * Stop streaming receive mode.
      */
-    bool rx_samples(unsigned int channel, data_handler *handler);
+    bool stop_rx_streaming(unsigned int channel=0);
 
     /*!
-     * Stop streaming receive mode.
+     * \brief Receive data from the specified channel
+     * This method is used to receive all data: streaming or discrete.
      */
-    bool stop_rx_streaming(unsigned int channel=0);
+    bool rx_samples(unsigned int channel, rx_sample_handler *handler);
 
     /*!
      * Returns number of times receive overruns have occurred
@@ -134,8 +143,7 @@
      */
     unsigned int rx_missing();
 
-    /* Ignore :-) */
-    class impl;
+    class impl;                // implementation details
 
   private:
     // Only usrp2::make factory function can instantiate this class

Modified: usrp2/branches/developers/eb/wip/host-ng/lib/Makefile.am
===================================================================
--- usrp2/branches/developers/eb/wip/host-ng/lib/Makefile.am    2008-07-27 
23:41:30 UTC (rev 9031)
+++ usrp2/branches/developers/eb/wip/host-ng/lib/Makefile.am    2008-07-28 
06:07:13 UTC (rev 9032)
@@ -17,8 +17,8 @@
 
 include $(top_srcdir)/Makefile.common
 
-AM_CPPFLAGS = -Wall -Werror
-INCLUDES = $(STD_DEFINES_AND_INCLUDES) $(CPPUNIT_INCLUDES) $(GRUEL_CFLAGS) 
$(BOOST_CFLAGS)
+#AM_CXXFLAGS = -Wall -Werror (handle this with: $ ./configure CXXFLAGS="-Wall 
-Werror -O2 -g")
+AM_CPPFLAGS = $(STD_DEFINES_AND_INCLUDES) $(CPPUNIT_INCLUDES) $(GRUEL_CFLAGS) 
$(BOOST_CFLAGS)
 
 lib_LTLIBRARIES = \
        libusrp2ng.la
@@ -32,6 +32,7 @@
        find.cc \
        pktfilter.cc \
        ring.cc \
+       rx_sample_handler.cc \
        strtod_si.c \
        usrp2.cc \
        usrp2_impl.cc \

Modified: usrp2/branches/developers/eb/wip/host-ng/lib/eth_buffer.cc
===================================================================
--- usrp2/branches/developers/eb/wip/host-ng/lib/eth_buffer.cc  2008-07-27 
23:41:30 UTC (rev 9031)
+++ usrp2/branches/developers/eb/wip/host-ng/lib/eth_buffer.cc  2008-07-28 
06:07:13 UTC (rev 9032)
@@ -208,6 +208,10 @@
       void *base = (uint8_t *)hdr+hdr->tp_mac;
       size_t len = hdr->tp_len;
       
+      if (0)
+       fprintf(stderr, "eth_buffer: base = %p  tp_mac = %3d  tp_net = %3d\n",
+               base, hdr->tp_mac, hdr->tp_net);
+
       // Invoke data handler
       data_handler::result r = (*f)(base, len);
       if (!(r & data_handler::KEEP))

Added: usrp2/branches/developers/eb/wip/host-ng/lib/rx_sample_handler.cc
===================================================================
--- usrp2/branches/developers/eb/wip/host-ng/lib/rx_sample_handler.cc           
                (rev 0)
+++ usrp2/branches/developers/eb/wip/host-ng/lib/rx_sample_handler.cc   
2008-07-28 06:07:13 UTC (rev 9032)
@@ -0,0 +1,27 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 Free Software Foundation, Inc.
+ *
+ * This program 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 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <usrp2/rx_sample_handler.h>
+
+usrp2::rx_sample_handler::~rx_sample_handler()
+{
+  // nop
+}


Property changes on: 
usrp2/branches/developers/eb/wip/host-ng/lib/rx_sample_handler.cc
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: usrp2/branches/developers/eb/wip/host-ng/lib/usrp2.cc
===================================================================
--- usrp2/branches/developers/eb/wip/host-ng/lib/usrp2.cc       2008-07-27 
23:41:30 UTC (rev 9031)
+++ usrp2/branches/developers/eb/wip/host-ng/lib/usrp2.cc       2008-07-28 
06:07:13 UTC (rev 9032)
@@ -76,7 +76,7 @@
   }
   
   bool
-  usrp2::rx_samples(unsigned int channel, data_handler *handler)
+  usrp2::rx_samples(unsigned int channel, rx_sample_handler *handler)
   {
     return d_impl->rx_samples(channel, handler);
   }

Modified: usrp2/branches/developers/eb/wip/host-ng/lib/usrp2_impl.cc
===================================================================
--- usrp2/branches/developers/eb/wip/host-ng/lib/usrp2_impl.cc  2008-07-27 
23:41:30 UTC (rev 9031)
+++ usrp2/branches/developers/eb/wip/host-ng/lib/usrp2_impl.cc  2008-07-28 
06:07:13 UTC (rev 9032)
@@ -34,6 +34,7 @@
 #include <iostream>
 #include <stdio.h>
 #include <stddef.h>
+#include <assert.h>
 
 #define USRP2_IMPL_DEBUG 0
 #if USRP2_IMPL_DEBUG
@@ -76,6 +77,38 @@
   }
 
 
+  /*!
+   * \param p points to fixed header
+   * \param payload_len_in_bytes is length of the fixed hdr and the payload
+   * \param[out] items is set to point to the first uint32 item in the payload
+   * \param[out] nitems is set to the number of uint32 items in the payload
+   * \param[out] md is filled in with the parsed metadata from the frame.
+   */
+  static bool
+  parse_rx_metadata(void *p, size_t payload_len_in_bytes,
+                   uint32_t **items, size_t *nitems_in_uint32s, rx_metadata 
*md)
+  {
+    if (payload_len_in_bytes < sizeof(u2_fixed_hdr_t)) // invalid format
+      return false;
+
+    assert((((uintptr_t) p) % 4) == 0);                // must be 4-byte 
aligned
+
+    u2_fixed_hdr_t *fh = static_cast<u2_fixed_hdr_t *>(p);
+    md->word0 = u2p_word0(fh);
+    md->timestamp = u2p_timestamp(fh);
+    // md->start_of_burst = (md->word0 & XXX) != 0;
+    // md->end_of_burst =   (md->word0 & XXX) != 0;
+    // md->rx_overrun =     (md->word0 & XXX) != 0;
+
+    *items = (uint32_t *)(&fh[1]);
+    size_t nbytes = payload_len_in_bytes - sizeof(u2_fixed_hdr_t);
+    assert((nbytes % sizeof(uint32_t)) == 0);
+    *nitems_in_uint32s = nbytes / sizeof(uint32_t);
+
+    return true;
+  }
+
+
   usrp2::impl::impl(const std::string &ifc, const std::string &addr)
     : d_eth_buf(new eth_buffer()), d_pf(0), d_bg_thread(0), 
d_bg_running(false),
       d_rx_decim(0), d_rx_seqno(-1), d_tx_seqno(0), d_next_rid(0),
@@ -472,6 +505,8 @@
     d_num_rx_frames++;
     d_num_rx_bytes += len;
     
+    /* --- FIXME start of fake transport layer handler --- */
+
     if (d_rx_seqno != -1) {
       int expected_seqno = (d_rx_seqno + 1) & 0xFF;
       int seqno = pkt->hdrs.thdr.seqno; 
@@ -489,14 +524,18 @@
 
     d_rx_seqno = pkt->hdrs.thdr.seqno;
 
+    /* --- end of fake transport layer handler --- */
+
     unsigned int chan = u2p_chan(&pkt->hdrs.fixed);
     if (!d_channel_rings[chan]) {
       DEBUG_LOG("!");
       return data_handler::RELEASE;    // discard packet, no channel handler
     }
 
-    size_t offset = offsetof(u2_eth_samples_t, samples);
-    if (d_channel_rings[chan]->enqueue(&pkt->samples, len-offset)) {
+    // Strip off ethernet header and transport header and enqueue the rest
+
+    size_t offset = offsetof(u2_eth_samples_t, hdrs.fixed);
+    if (d_channel_rings[chan]->enqueue(&pkt->hdrs.fixed, len-offset)) {
       inc_enqueued();
       DEBUG_LOG("+");
       return data_handler::KEEP;       // channel ring runner will mark frame 
done
@@ -509,7 +548,7 @@
   }
 
   bool
-  usrp2::impl::rx_samples(unsigned int channel, data_handler *handler)
+  usrp2::impl::rx_samples(unsigned int channel, rx_sample_handler *handler)
   {
     if (channel > MAX_CHAN) {
       std::cerr << "usrp2: invalid channel (" << channel
@@ -537,20 +576,22 @@
     
     // Iterate through frames and present to user
     void *p;
-    size_t len;
-    while (rp->dequeue(&p, &len)) {
-      result r = (*handler)(p, len);
+    size_t frame_len_in_bytes;
+    while (rp->dequeue(&p, &frame_len_in_bytes)) {
+      uint32_t        *items;                  // points to beginning of data 
items
+      size_t           nitems_in_uint32s;
+      rx_metadata      md;
+      if (!parse_rx_metadata(p, frame_len_in_bytes, &items, 
&nitems_in_uint32s, &md))
+       return false;
 
-      // Callers are always required to accept a frame, but then to signal when
-      // they are done.
+      bool want_more = (*handler)(items, nitems_in_uint32s, &md);
       d_eth_buf->release_frame(p);
       DEBUG_LOG("-");
       dec_enqueued();
 
-      if (r & data_handler::DONE)
+      if (!want_more)
         break;
     }
-
     return true;
   }
 

Modified: usrp2/branches/developers/eb/wip/host-ng/lib/usrp2_impl.h
===================================================================
--- usrp2/branches/developers/eb/wip/host-ng/lib/usrp2_impl.h   2008-07-27 
23:41:30 UTC (rev 9031)
+++ usrp2/branches/developers/eb/wip/host-ng/lib/usrp2_impl.h   2008-07-28 
06:07:13 UTC (rev 9032)
@@ -97,7 +97,7 @@
     bool set_rx_decim(int decimation_factor);
     bool set_rx_scale_iq(int scale_i, int scale_q);
     bool start_rx_streaming(unsigned int channel, unsigned int 
items_per_frame);
-    bool rx_samples(unsigned int channel, data_handler *handler);
+    bool rx_samples(unsigned int channel, rx_sample_handler *handler);
     bool stop_rx_streaming(unsigned int channel);
     unsigned int rx_overruns() const { return d_num_rx_overruns; }
     unsigned int rx_missing() const { return d_num_rx_missing; }





reply via email to

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