commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r11061 - in gnuradio/branches/developers/eb/vrt: gr-vr


From: eb
Subject: [Commit-gnuradio] r11061 - in gnuradio/branches/developers/eb/vrt: gr-vrt/src vrt/apps vrt/include/vrt vrt/lib
Date: Tue, 19 May 2009 17:44:49 -0600 (MDT)

Author: eb
Date: 2009-05-19 17:44:48 -0600 (Tue, 19 May 2009)
New Revision: 11061

Added:
   gnuradio/branches/developers/eb/vrt/vrt/include/vrt/copiers.h
   gnuradio/branches/developers/eb/vrt/vrt/include/vrt/rx.h
   gnuradio/branches/developers/eb/vrt/vrt/lib/copiers.cc
   gnuradio/branches/developers/eb/vrt/vrt/lib/rx.cc
Removed:
   gnuradio/branches/developers/eb/vrt/vrt/include/vrt/rx_udp.h
   gnuradio/branches/developers/eb/vrt/vrt/lib/rx_udp.cc
Modified:
   gnuradio/branches/developers/eb/vrt/gr-vrt/src/Makefile.am
   gnuradio/branches/developers/eb/vrt/gr-vrt/src/vrt_source_32fc.cc
   gnuradio/branches/developers/eb/vrt/gr-vrt/src/vrt_source_32fc.h
   gnuradio/branches/developers/eb/vrt/vrt/apps/simple_rx_samples.cc
   gnuradio/branches/developers/eb/vrt/vrt/include/vrt/Makefile.am
   gnuradio/branches/developers/eb/vrt/vrt/lib/Makefile.am
Log:
work-in-progress: compiles

Modified: gnuradio/branches/developers/eb/vrt/gr-vrt/src/Makefile.am
===================================================================
--- gnuradio/branches/developers/eb/vrt/gr-vrt/src/Makefile.am  2009-05-19 
21:38:39 UTC (rev 11060)
+++ gnuradio/branches/developers/eb/vrt/gr-vrt/src/Makefile.am  2009-05-19 
23:44:48 UTC (rev 11061)
@@ -53,7 +53,8 @@
 
 libgnuradio_vrt_la_SOURCES = \
        vrt_base.cc \
-       vrt_source_base.cc
+       vrt_source_base.cc \
+       vrt_source_32fc.cc
 
 #libgnuradio_vrt_la_SOURCES = \
 #      rx_16sc_handler.cc \

Modified: gnuradio/branches/developers/eb/vrt/gr-vrt/src/vrt_source_32fc.cc
===================================================================
--- gnuradio/branches/developers/eb/vrt/gr-vrt/src/vrt_source_32fc.cc   
2009-05-19 21:38:39 UTC (rev 11060)
+++ gnuradio/branches/developers/eb/vrt/gr-vrt/src/vrt_source_32fc.cc   
2009-05-19 23:44:48 UTC (rev 11061)
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2008 Free Software Foundation, Inc.
+ * Copyright 2008,2009 Free Software Foundation, Inc.
  * 
  * This file is part of GNU Radio
  * 
@@ -25,45 +25,106 @@
 #endif
 
 #include <vrt_source_32fc.h>
-#include <rx_32fc_handler.h>
+#include <vrt/expanded_header.h>
+#include <vrt/copiers.h>
 #include <gr_io_signature.h>
 #include <iostream>
 
-vrt_source_32fc_sptr
-vrt_make_source_32fc(const std::string &ifc, const std::string &mac_addr) 
-  throw (std::runtime_error)
+class rx_32fc_handler : public vrt::rx_packet_handler
 {
-  return gnuradio::get_initial_sptr(new vrt_source_32fc(ifc, mac_addr));
+  int                                d_noutput_items;
+  std::complex<float>               *d_out;
+  int                               *d_oo;             // output index
+  std::vector< std::complex<float> > &d_remainder;
+
+public:
+
+  rx_32fc_handler(int noutput_items, std::complex<float> *out,
+                 int *oo, std::vector< std::complex<float> > &remainder)
+    : d_noutput_items(noutput_items), d_out(out),
+      d_oo(oo), d_remainder(remainder) {}
+
+  ~rx_32fc_handler();
+
+  bool operator()(const uint32_t *payload,
+                 size_t n32_bit_words,
+                 const vrt::expanded_header *hdr);
+};
+
+rx_32fc_handler::~rx_32fc_handler()
+{
 }
 
-vrt_source_32fc::vrt_source_32fc(const std::string &ifc, const std::string 
&mac_addr) 
+bool
+rx_32fc_handler::operator()(const uint32_t *payload,
+                           size_t n32_bit_words,
+                           const vrt::expanded_header *hdr)
+{
+  // copy as many as will fit into the output buffer.
+
+  size_t n = std::min(n32_bit_words, (size_t)(d_noutput_items - *d_oo));
+  vrt::copy_net_16sc_to_host_32fc(n, payload, &d_out[*d_oo]);
+  *d_oo += n;
+
+  // if there are any left over, copy them into remainder and tell
+  // our caller we're had enough for now.
+
+  size_t r = n32_bit_words - n;
+  if (r > 0){
+    assert(d_remainder.size() == 0);
+    d_remainder.resize(r);
+    vrt::copy_net_16sc_to_host_32fc(r, &payload[n], &d_remainder[0]);
+    return false;              // Stop calling us.
+  }
+
+  return true;                 // Keep calling us, we've got more room
+}
+
+
+// ------------------------------------------------------------------------
+
+vrt_source_32fc::vrt_source_32fc(const char *name,
+                                vrt_ctrl_base::sptr ctrl,
+                                int data_socket_fd,
+                                size_t rx_bufsize)
   throw (std::runtime_error)
-  : vrt_source_base("vrt_source_32fc",
-                     gr_make_io_signature(1, 1, sizeof(gr_complex)),
-                     ifc, mac_addr)
+  : vrt_source_base(name,
+                   gr_make_io_signature(1, 1, sizeof(gr_complex)),
+                   ctrl, data_socket_fd, rx_bufsize)
 {
-  set_output_multiple(USRP2_MIN_RX_SAMPLES);
 }
 
 vrt_source_32fc::~vrt_source_32fc()
 {
-  // NOP
 }
 
 int
 vrt_source_32fc::work(int noutput_items,
-                       gr_vector_const_void_star &input_items,
-                       gr_vector_void_star &output_items)
+                     gr_vector_const_void_star &input_items,
+                     gr_vector_void_star &output_items)
 {
   gr_complex *out = (gr_complex *)output_items[0];
+  int  oo = 0;
 
-  rx_32fc_handler::sptr handler = rx_32fc_handler::make(noutput_items, 
USRP2_MIN_RX_SAMPLES, out);
+  // Handle any samples left over from the last call.
+  int t = std::min(noutput_items, (int)d_remainder.size());
+  if (t != 0){
+    for (int i = 0; i < t; i++)
+      out[i] = d_remainder[i];
+    d_remainder.erase(d_remainder.begin(), d_remainder.begin()+t);
+    oo = t;
+  }
+  if (noutput_items - oo == 0)
+    return oo;
+  
+  // While we've got room, and there are packets, handle them
+  rx_32fc_handler h(noutput_items, out, &oo, d_remainder);
+  bool ok = d_rx->rx_packets(&h);
 
-  bool ok = d_u2->rx_samples(0, handler.get()); // FIXME: channel number 
instead of 0
   if (!ok){
-    std::cerr << "vrt::rx_samples() failed" << std::endl;
+    std::cerr << "vrt_source_32fc: vrt::rx_packets() failed" << std::endl;
     return -1; // say we're done
   }
 
-  return handler->nsamples();
+  return oo;
 }

Modified: gnuradio/branches/developers/eb/vrt/gr-vrt/src/vrt_source_32fc.h
===================================================================
--- gnuradio/branches/developers/eb/vrt/gr-vrt/src/vrt_source_32fc.h    
2009-05-19 21:38:39 UTC (rev 11060)
+++ gnuradio/branches/developers/eb/vrt/gr-vrt/src/vrt_source_32fc.h    
2009-05-19 23:44:48 UTC (rev 11061)
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2008 Free Software Foundation, Inc.
+ * Copyright 2008,2009 Free Software Foundation, Inc.
  * 
  * This file is part of GNU Radio
  * 
@@ -20,29 +20,22 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef INCLUDED_USRP2_SOURCE_32FC_H
-#define INCLUDED_USRP2_SOURCE_32FC_H
+#ifndef INCLUDED_VRT_SOURCE_32FC_H
+#define INCLUDED_VRT_SOURCE_32FC_H
 
 #include <vrt_source_base.h>
 
-class vrt_source_32fc;
-typedef boost::shared_ptr<vrt_source_32fc> vrt_source_32fc_sptr;
-
-vrt_source_32fc_sptr
-vrt_make_source_32fc(const std::string &ifc="eth0",
-                      const std::string &mac="")
-  throw (std::runtime_error);
-
 class vrt_source_32fc : public vrt_source_base
 {
-private:
-  friend vrt_source_32fc_sptr
-  vrt_make_source_32fc(const std::string &ifc,
-                        const std::string &mac) throw (std::runtime_error);
-  
 protected:
-  vrt_source_32fc(const std::string &ifc, const std::string &mac) throw 
(std::runtime_error);
+  vrt_source_32fc(const char *name,
+                 vrt_ctrl_base::sptr ctrl,
+                 int data_socket_fd,
+                 size_t rx_bufsize = 0)
+    throw (std::runtime_error);
 
+  std::vector< std::complex<float> >   d_remainder;
+
 public:
   ~vrt_source_32fc();
 
@@ -51,4 +44,4 @@
           gr_vector_void_star &output_items);
 };
 
-#endif /* INCLUDED_USRP2_SOURCE_32FC_H */
+#endif /* INCLUDED_VRT_SOURCE_32FC_H */

Modified: gnuradio/branches/developers/eb/vrt/vrt/apps/simple_rx_samples.cc
===================================================================
--- gnuradio/branches/developers/eb/vrt/vrt/apps/simple_rx_samples.cc   
2009-05-19 21:38:39 UTC (rev 11060)
+++ gnuradio/branches/developers/eb/vrt/vrt/apps/simple_rx_samples.cc   
2009-05-19 23:44:48 UTC (rev 11061)
@@ -34,7 +34,8 @@
 #include <stdint.h>
 #include <stdio.h>
 #include <string.h>
-#include <vrt/rx_udp.h>
+#include <vrt/rx.h>
+#include <vrt/copiers.h>
 #include <gruel/realtime.h>
 #include <complex>
 
@@ -67,51 +68,7 @@
 }
 
 // ------------------------------------------------------------------------
-// Copy and convert from net format to host format
-// ------------------------------------------------------------------------
 
-void 
-copy_net_16sc_to_host_16sc(size_t nitems,
-                         const uint32_t *items,
-                         std::complex<int16_t> *host_items)
-{
-#ifdef WORDS_BIGENDIAN
-
-  assert(sizeof(items[0]) == sizeof(host_items[0]));
-  memcpy(host_items, items, nitems * sizeof(items[0]));
-
-#else
-
-  // FIXME SIMD welcome here
-
-  for (size_t i = 0; i < nitems; i++){
-    uint32_t t = ntohl(items[i]);
-    //printf("%9d\n", items[i]);
-    host_items[i] = std::complex<int16_t>((t >> 16), t & 0xffff);
-  }
-
-#endif
-}
-
-
-/*
- * endian swap if required and map [-32768, 32767] -> [1.0, +1.0)
- */
-void 
-copy_net_16sc_to_host_32fc(size_t nitems,
-                          const uint32_t *items,
-                          std::complex<float> *host_items)
-{
-  for (size_t i = 0; i < nitems; i++){
-    uint32_t t = ntohl(items[i]);
-    int16_t re = (t >> 16) & 0xffff;
-    int16_t im = (t & 0xffff);
-    host_items[i] = std::complex<float>(re * 1.0/32768, im * 1.0/32768);
-  }
-}
-
-// ------------------------------------------------------------------------
-
 class rx_nop_handler : public vrt::rx_packet_handler
 {
 private:
@@ -194,7 +151,7 @@
 {
   if (d_npackets != 0 && hdr->pkt_cnt() != ((d_last_pkt_cnt + 1) & 0xf)){
     d_nwrong_pkt_cnt++;
-    fprintf(stderr, "bad cnt (pkt %d)\n", d_npackets);
+    fprintf(stderr, "bad cnt (pkt %lld)\n", d_npackets);
   }
   d_last_pkt_cnt = hdr->pkt_cnt();
 
@@ -233,7 +190,7 @@
     size_t host_nitems = nitems;
     std::complex<int16_t> host_items[host_nitems];
 
-    copy_net_16sc_to_host_16sc(nitems, items, host_items);
+    vrt::copy_net_16sc_to_host_16sc(nitems, items, host_items);
 
     size_t n = 0;
     while (n < host_nitems){
@@ -285,7 +242,7 @@
     size_t host_nitems = nitems;
     std::complex<float> host_items[host_nitems];
 
-    copy_net_16sc_to_host_32fc(nitems, items, host_items);
+    vrt::copy_net_16sc_to_host_32fc(nitems, items, host_items);
 
     size_t n = 0;
     while (n < host_nitems){
@@ -534,7 +491,7 @@
                    &ctrl_fd, &ctrl_port_inaddr, &data_fd, &data_port))
     return 1;
 
-  vrt::rx_udp::sptr vrt_receiver = vrt::rx_udp::make(data_fd, rx_bufsize);
+  vrt::rx::sptr vrt_receiver = vrt::rx::make(data_fd, rx_bufsize);
   
 
   rx_nop_handler::sptr handler;

Modified: gnuradio/branches/developers/eb/vrt/vrt/include/vrt/Makefile.am
===================================================================
--- gnuradio/branches/developers/eb/vrt/vrt/include/vrt/Makefile.am     
2009-05-19 21:38:39 UTC (rev 11060)
+++ gnuradio/branches/developers/eb/vrt/vrt/include/vrt/Makefile.am     
2009-05-19 23:44:48 UTC (rev 11061)
@@ -23,6 +23,7 @@
 
 vrtinclude_HEADERS = \
        bits.h \
+       copiers.h \
        expanded_header.h \
-       rx_packet_handler.h \
-       rx_udp.h 
+       rx.h \
+       rx_packet_handler.h

Added: gnuradio/branches/developers/eb/vrt/vrt/include/vrt/copiers.h
===================================================================
--- gnuradio/branches/developers/eb/vrt/vrt/include/vrt/copiers.h               
                (rev 0)
+++ gnuradio/branches/developers/eb/vrt/vrt/include/vrt/copiers.h       
2009-05-19 23:44:48 UTC (rev 11061)
@@ -0,0 +1,49 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2009 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 this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef INCLUDED_VRT_COPIERS_H
+#define INCLUDED_VRT_COPIERS_H
+
+#include <stdint.h>
+#include <stddef.h>
+#include <complex>
+
+namespace vrt {
+
+  /*!
+   * \brief Copy and convert from net format to host format
+   */
+  void 
+  copy_net_16sc_to_host_16sc(size_t nitems,
+                            const uint32_t *items,
+                            std::complex<int16_t> *host_items);
+
+
+  /*!
+   * \brief Copy and convert from net format to host format mapping [-32768, 
32767] -> [1.0, +1.0)
+   */
+  void
+  copy_net_16sc_to_host_32fc(size_t nitems,
+                            const uint32_t *items,
+                            std::complex<float> *host_items);
+};
+
+#endif /* INCLUDED_VRT_COPIERS_H */


Property changes on: 
gnuradio/branches/developers/eb/vrt/vrt/include/vrt/copiers.h
___________________________________________________________________
Added: svn:eol-style
   + native

Copied: gnuradio/branches/developers/eb/vrt/vrt/include/vrt/rx.h (from rev 
11058, gnuradio/branches/developers/eb/vrt/vrt/include/vrt/rx_udp.h)
===================================================================
--- gnuradio/branches/developers/eb/vrt/vrt/include/vrt/rx.h                    
        (rev 0)
+++ gnuradio/branches/developers/eb/vrt/vrt/include/vrt/rx.h    2009-05-19 
23:44:48 UTC (rev 11061)
@@ -0,0 +1,92 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2009 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 this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#ifndef INCLUDED_VRT_RX_H
+#define INCLUDED_VRT_RX_H
+
+#include <boost/shared_ptr.hpp>
+#include <boost/utility.hpp>
+#include <vrt/rx_packet_handler.h>
+
+namespace vrt {
+
+  class socket_rx_buffer;
+
+  /*!
+   * Relatively low-level interface to receive VRT packets over a datagram 
socket.
+   *
+   * (We'll refactor this if/when we use a non-UDP transport.)
+   * No VRT control issues are addressed here.
+   */
+  class rx : boost::noncopyable
+  {
+    int                        d_socket_fd;
+    socket_rx_buffer   *d_srb;
+
+  public:
+    /*!
+     * Shared pointer to this class
+     */ 
+    typedef boost::shared_ptr<rx> sptr;
+
+    /*! 
+     * \brief Static function to return an instance of rx as a shared pointer.
+     *
+     * \param socket_fd file descriptor that data grams will be received from.
+     *                 It is assumed that some higher-level control software
+     *                 opened the appropriate UDP socket for us.  This object
+     *                 assumes management of the socket's lifetime.  The
+     *                 socket will be closed when our destructor fires.
+     *
+     * \param rx_bufsize is a hint as to the number of bytes of memory
+     *                         to allocate for received ethernet frames (0 -> 
reasonable default)
+     */
+    static sptr make(int socket_fd, size_t rx_bufsize = 0);
+
+    /*! 
+     * \param socket_fd file descriptor that data grams will be received from.
+     *                 It is assumed that some higher-level control software
+     *                 opened the appropriate UDP socket for us.  This object
+     *                 assumes management of the socket's lifetime.  The
+     *                 socket will be closed when our destructor fires.
+     *
+     * \param rx_bufsize is a hint as to the number of bytes of memory
+     *                         to allocate for received ethernet frames (0 -> 
reasonable default)
+     */
+    rx(int socket_fd, size_t rx_bufsize = 0);
+    ~rx();
+
+    /*!
+     * \brief Receive packets from the given socket file descriptor.
+     *
+     * Handler will be invoked for all available packets.
+     * This function blocks until at least one packet has been processed.
+     */
+    bool rx_packets(rx_packet_handler *handler);
+
+    /*
+     * \returns the socket_fd.   Useful for select or poll.
+     */
+    int socket_fd() const { return d_socket_fd; }
+  };
+
+}
+
+#endif /* INCLUDED_VRT_RX_H */

Modified: gnuradio/branches/developers/eb/vrt/vrt/lib/Makefile.am
===================================================================
--- gnuradio/branches/developers/eb/vrt/vrt/lib/Makefile.am     2009-05-19 
21:38:39 UTC (rev 11060)
+++ gnuradio/branches/developers/eb/vrt/vrt/lib/Makefile.am     2009-05-19 
23:44:48 UTC (rev 11061)
@@ -28,10 +28,11 @@
        libvrt.la
 
 libvrt_la_SOURCES = \
+       copiers.cc \
        data_handler.cc \
        expanded_header.cc \
+       rx.cc \
        rx_packet_handler.cc \
-       rx_udp.cc \
        socket_rx_buffer.cc
 
 libvrt_la_LIBADD =

Added: gnuradio/branches/developers/eb/vrt/vrt/lib/copiers.cc
===================================================================
--- gnuradio/branches/developers/eb/vrt/vrt/lib/copiers.cc                      
        (rev 0)
+++ gnuradio/branches/developers/eb/vrt/vrt/lib/copiers.cc      2009-05-19 
23:44:48 UTC (rev 11061)
@@ -0,0 +1,69 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2009 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 this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <vrt/copiers.h>
+#include <arpa/inet.h>
+
+namespace vrt {
+
+  void 
+  copy_net_16sc_to_host_16sc(size_t nitems,
+                            const uint32_t *items,
+                            std::complex<int16_t> *host_items)
+  {
+#ifdef WORDS_BIGENDIAN
+
+    assert(sizeof(items[0]) == sizeof(host_items[0]));
+    memcpy(host_items, items, nitems * sizeof(items[0]));
+
+#else
+
+    // FIXME SIMD welcome here
+
+    for (size_t i = 0; i < nitems; i++){
+      uint32_t t = ntohl(items[i]);
+      //printf("%9d\n", items[i]);
+      host_items[i] = std::complex<int16_t>((t >> 16), t & 0xffff);
+    }
+
+#endif
+  }
+
+  void
+  copy_net_16sc_to_host_32fc(size_t nitems,
+                            const uint32_t *items,
+                            std::complex<float> *host_items)
+  {
+    // FIXME SIMD welcome here
+
+    for (size_t i = 0; i < nitems; i++){
+      uint32_t t = ntohl(items[i]);
+      int16_t re = (t >> 16) & 0xffff;
+      int16_t im = (t & 0xffff);
+      host_items[i] = std::complex<float>(re * 1.0/32768, im * 1.0/32768);
+    }
+  }
+
+};
+


Property changes on: gnuradio/branches/developers/eb/vrt/vrt/lib/copiers.cc
___________________________________________________________________
Added: svn:eol-style
   + native

Copied: gnuradio/branches/developers/eb/vrt/vrt/lib/rx.cc (from rev 11058, 
gnuradio/branches/developers/eb/vrt/vrt/lib/rx_udp.cc)
===================================================================
--- gnuradio/branches/developers/eb/vrt/vrt/lib/rx.cc                           
(rev 0)
+++ gnuradio/branches/developers/eb/vrt/vrt/lib/rx.cc   2009-05-19 23:44:48 UTC 
(rev 11061)
@@ -0,0 +1,120 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2009 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 this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <vrt/rx.h>
+#include <vrt/expanded_header.h>
+#include "socket_rx_buffer.h"
+#include "data_handler.h"
+#include <unistd.h>
+#include <stdio.h>
+#include <stdexcept>
+
+static void
+print_words(FILE *fp, size_t offset, uint32_t *buf, size_t n)
+{
+  size_t i;
+  for (i = 0; i < n; i++){
+    if (i % 4 == 0){
+      fprintf(fp, "%04zx:", i);
+    }
+
+    putc(' ', fp);
+    fprintf(fp, "%08x", buf[i]);
+    if (i % 4 == 3)
+      putc('\n', fp);
+  }
+
+  putc('\n', fp);
+}
+
+
+
+namespace vrt {
+  
+  rx::sptr
+  rx::make(int socket_fd, size_t rx_bufsize)
+  {
+    return sptr(new rx(socket_fd, rx_bufsize));
+  }
+
+  rx::rx(int socket_fd, size_t rx_bufsize)
+    : d_socket_fd(socket_fd),
+      d_srb(new socket_rx_buffer(socket_fd, rx_bufsize))
+  {
+  }
+
+  rx::~rx()
+  {
+    delete d_srb;
+    ::close(d_socket_fd);
+  }
+
+
+  class vrt_data_handler : public data_handler
+  {
+    rx_packet_handler  *d_handler;
+
+  public:
+    vrt_data_handler(rx_packet_handler *handler)
+      : d_handler(handler){}
+
+    ~vrt_data_handler();
+
+    result operator()(const void *base, size_t len);
+  };
+
+  vrt_data_handler::~vrt_data_handler(){}
+
+  data_handler::result
+  vrt_data_handler::operator()(const void *base, size_t len)
+  {
+#if 0
+    print_words(0, (uint32_t *)base, len/(sizeof(uint32_t)));
+    return 0;
+#else
+    const uint32_t *payload;
+    size_t n32_bit_words;
+    expanded_header hdr;
+    if (!expanded_header::parse((const uint32_t*) base, len/(sizeof(uint32_t)),
+                               &hdr, &payload, &n32_bit_words)){
+      if (1){
+       fprintf(stderr, "vrt_data_handler: malformed VRT packet!\n");
+       print_words(stderr, 0, (uint32_t *)base, len/(sizeof(uint32_t)));
+      }
+      return 0;
+    }
+    bool want_more = (*d_handler)(payload, n32_bit_words, &hdr);
+    return !want_more ? data_handler::DONE : 0;
+#endif
+  }
+
+
+  bool
+  rx::rx_packets(rx_packet_handler *handler)
+  {
+    vrt_data_handler h(handler);
+    socket_rx_buffer::result r = d_srb->rx_frames(&h, -1);
+    return r == socket_rx_buffer::EB_OK;
+  }
+
+}; // vrt





reply via email to

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