commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r8582 - in usrp2/trunk/host-ng: apps include/usrp2 lib


From: jcorgan
Subject: [Commit-gnuradio] r8582 - in usrp2/trunk/host-ng: apps include/usrp2 lib
Date: Wed, 11 Jun 2008 19:02:17 -0600 (MDT)

Author: jcorgan
Date: 2008-06-11 19:02:14 -0600 (Wed, 11 Jun 2008)
New Revision: 8582

Added:
   usrp2/trunk/host-ng/include/usrp2/copy_handler.h
   usrp2/trunk/host-ng/include/usrp2/data_handler.h
Removed:
   usrp2/trunk/host-ng/lib/copy_handler.h
Modified:
   usrp2/trunk/host-ng/apps/test_eth.cc
   usrp2/trunk/host-ng/include/usrp2/Makefile.am
   usrp2/trunk/host-ng/lib/copy_handler.cc
   usrp2/trunk/host-ng/lib/eth_buffer.cc
   usrp2/trunk/host-ng/lib/eth_buffer.h
Log:
work-in-progress, now invoking data handlers in receive path

Modified: usrp2/trunk/host-ng/apps/test_eth.cc
===================================================================
--- usrp2/trunk/host-ng/apps/test_eth.cc        2008-06-12 00:29:56 UTC (rev 
8581)
+++ usrp2/trunk/host-ng/apps/test_eth.cc        2008-06-12 01:02:14 UTC (rev 
8582)
@@ -21,10 +21,21 @@
 #endif
 
 #include <../lib/eth_buffer.h>
+#include <usrp2/data_handler.h>
 #include <gr_realtime.h>
 #include <linux/if_ether.h>
 #include <iostream>
 
+class print_handler : public usrp2::data_handler
+{
+public:
+  
+  virtual uint32_t operator()(const void *base, unsigned int len) {
+    printf("@%p: %u bytes\n", base, len);
+    return 0;
+  }
+};
+
 int
 main(int argc, char **argv)
 {
@@ -38,9 +49,10 @@
     return 1;
   }
   
-  int res;    
+  int res;
+  print_handler p;
   do {
-    res = buf.rx_frames(NULL, 1000);
+    res = buf.rx_frames(&p, 1000);
   }
   while (res != -1);
     

Modified: usrp2/trunk/host-ng/include/usrp2/Makefile.am
===================================================================
--- usrp2/trunk/host-ng/include/usrp2/Makefile.am       2008-06-12 00:29:56 UTC 
(rev 8581)
+++ usrp2/trunk/host-ng/include/usrp2/Makefile.am       2008-06-12 01:02:14 UTC 
(rev 8582)
@@ -22,4 +22,6 @@
 usrp2includedir = $(includedir)/usrp2
 
 usrp2include_HEADERS = \
+       copy_handler.h \
+       data_handler.h \
        usrp2.h

Copied: usrp2/trunk/host-ng/include/usrp2/copy_handler.h (from rev 8575, 
usrp2/trunk/host-ng/lib/copy_handler.h)
===================================================================
--- usrp2/trunk/host-ng/include/usrp2/copy_handler.h                            
(rev 0)
+++ usrp2/trunk/host-ng/include/usrp2/copy_handler.h    2008-06-12 01:02:14 UTC 
(rev 8582)
@@ -0,0 +1,45 @@
+/* -*- 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 this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#ifndef INCLUDED_COPY_HANDLER_H
+#define INCLUDED_COPY_HANDLER_H
+
+#include <usrp2/data_handler.h>
+#include <boost/utility.hpp>
+
+namespace usrp2 {
+
+  class copy_handler : data_handler, boost::noncopyable {
+
+    uint8_t *d_dest;      // next write pointer
+    unsigned int d_space; // space left in destination buffer
+    unsigned int d_bytes; // total bytes copied
+    unsigned int d_times; // number of times invoked
+
+  public:
+    copy_handler(void *dest, unsigned int len);
+    ~copy_handler();
+ 
+    virtual uint32_t operator()(const void *base, unsigned int len);
+  };
+    
+} // namespace usrp2
+
+#endif /* INCLUDED_COPY_HANDLER_H */

Added: usrp2/trunk/host-ng/include/usrp2/data_handler.h
===================================================================
--- usrp2/trunk/host-ng/include/usrp2/data_handler.h                            
(rev 0)
+++ usrp2/trunk/host-ng/include/usrp2/data_handler.h    2008-06-12 01:02:14 UTC 
(rev 8582)
@@ -0,0 +1,46 @@
+/* -*- 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 this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#ifndef INCLUDED_DATA_HANDLER_H
+#define INCLUDED_DATA_HANDLER_H
+
+#include <stdint.h>
+
+namespace usrp2 {
+
+  /*!
+   * \brief abstract function object called to handle received data blocks
+   */
+  class data_handler {
+  public:
+    static const uint32_t KEEP = 0x0001; // do not discard data
+    static const uint32_t DONE = 0x0010; // do not call this object again
+    
+    /*!
+     * \param base points to the beginning of the data
+     * \param len is the length in bytes of the data
+     */
+      virtual uint32_t operator()(const void *base, unsigned int len) = 0;
+      virtual ~data_handler();
+  };
+
+} // namespace usrp2
+
+#endif /* INCLUDED_DATA_HANDLER_H */

Modified: usrp2/trunk/host-ng/lib/copy_handler.cc
===================================================================
--- usrp2/trunk/host-ng/lib/copy_handler.cc     2008-06-12 00:29:56 UTC (rev 
8581)
+++ usrp2/trunk/host-ng/lib/copy_handler.cc     2008-06-12 01:02:14 UTC (rev 
8582)
@@ -23,12 +23,12 @@
 #include <config.h>
 #endif
 
-#include "copy_handler.h"
+#include <usrp2/copy_handler.h>
 
 namespace usrp2 {
     
-  copy_handler::copy_handler(uint8_t *dest, size_t len)
-    : d_dest(dest), d_space(len), d_bytes(0), d_times(0)
+  copy_handler::copy_handler(void *dest, unsigned int len)
+    : d_dest((uint8_t *)dest), d_space(len), d_bytes(0), d_times(0)
   {
   }
 
@@ -38,19 +38,18 @@
   }
   
   uint32_t
-  copy_handler::operator()(const void *base, size_t len)
+  copy_handler::operator()(const void *base, unsigned int len)
   {
     if (len > d_space)
-      return eth_buffer::handler::KEEP |
-             eth_buffer::handler::BREAK; // can't do anything, retry later
+      return KEEP|DONE; // can't do anything, retry later
       
-    memcpy(d_dest, base, len);
+    memcpy(&d_dest[d_bytes], base, len);
     d_space -= len;
     d_bytes += len;
     d_times++;
     
     if (d_space == 0)
-      return eth_buffer::handler::BREAK; // don't call me anymore
+      return DONE; // don't call me anymore
   }
 
 } // namespace usrp2

Deleted: usrp2/trunk/host-ng/lib/copy_handler.h

Modified: usrp2/trunk/host-ng/lib/eth_buffer.cc
===================================================================
--- usrp2/trunk/host-ng/lib/eth_buffer.cc       2008-06-12 00:29:56 UTC (rev 
8581)
+++ usrp2/trunk/host-ng/lib/eth_buffer.cc       2008-06-12 01:02:14 UTC (rev 
8582)
@@ -25,6 +25,7 @@
 
 #include "eth_buffer.h"
 #include "ethernet.h"
+#include <usrp2/data_handler.h>
 #include <linux/if_packet.h>
 #include <sys/socket.h>
 #include <sys/mman.h>
@@ -33,7 +34,7 @@
 #include <cmath>
 #include <errno.h>
 
-#define ETH_BUFFER_DEBUG      1 // define to 0 or 1
+#define ETH_BUFFER_DEBUG      0 // define to 0 or 1
 #if ETH_BUFFER_DEBUG
 #define DEBUG_LOG(x) ::write(2, (x), 1)
 #else
@@ -46,7 +47,7 @@
 
 namespace usrp2 {
 
-  eth_buffer::handler::~handler()
+  data_handler::~data_handler()
   {
     // default nop destructor
   }
@@ -168,7 +169,7 @@
   }
   
   int 
-  eth_buffer::rx_frames(handler *f, int timeout)
+  eth_buffer::rx_frames(data_handler *f, int timeout)
   {
     DEBUG_LOG("'");
       
@@ -185,14 +186,14 @@
 
       DEBUG_LOG("P");
 
-      poll(&pfd, 1, timeout);
-      if (pfd.revents & POLLERR) {
+      int pres = poll(&pfd, 1, timeout);
+      if (pres == -1) {
         perror("poll");
         DEBUG_LOG("E");
        return -1;
       }
 
-      if (!(pfd.revents & POLLIN)) {
+      if (pres == 0) {
         DEBUG_LOG("T");
        return 2;
       }
@@ -203,11 +204,23 @@
       if (ETH_BUFFER_DEBUG)
        DEBUG_LOG("R");
       
-      // Do stuff with it
-
-      ((tpacket_hdr *)d_ring[d_head])->tp_status = TP_STATUS_KERNEL; // mark 
it done
+      // Get start of ethernet frame and length
+      tpacket_hdr *hdr = (tpacket_hdr *)d_ring[d_head];
+      void *base = (uint8_t *)hdr+TPACKET_HDRLEN;
+      unsigned int len = hdr->tp_len;
+      
+      // Invoke data handler
+      int r = 0;
+      if (f)
+        r = (*f)(base, len);
+      
+      // data_handler::KEEP not yet implemented
+      hdr->tp_status = TP_STATUS_KERNEL; // mark it free
       if (++d_head == d_frame_nr)
        d_head = 0;
+
+      if (r & data_handler::DONE)
+        break;
     }
 
     return 1;

Modified: usrp2/trunk/host-ng/lib/eth_buffer.h
===================================================================
--- usrp2/trunk/host-ng/lib/eth_buffer.h        2008-06-12 00:29:56 UTC (rev 
8581)
+++ usrp2/trunk/host-ng/lib/eth_buffer.h        2008-06-12 01:02:14 UTC (rev 
8582)
@@ -30,6 +30,7 @@
 namespace usrp2 {
 
   class ethernet;
+  class data_handler;
 
   /*!
    * \brief high-performance interface to send and receive raw
@@ -56,29 +57,7 @@
 
   public:
 
-    // 
----------------------------------------------------------------------------
-
     /*!
-     * \brief abstract function object called to handle received ethernet 
frames.
-     */
-    class handler {
-    public:
-      enum result {
-        KEEP  = 0x0001, // retain frame for next rx_frames call
-        BREAK = 0x0010  // immediately return from rx_frames
-      };
-      
-      /*!
-       * \param base points to the beginning of the frame (the 14-byte 
ethernet header).
-       * \param len is the length in bytes of the frame.
-       */
-      virtual uint32_t operator()(const void *base, size_t len) = 0;
-      virtual ~handler();
-    };
-
-    // 
----------------------------------------------------------------------------
-
-    /*!
      * \param rx_bufsize is a hint as to the number of bytes of memory
      * to allocate for received ethernet frames (0 -> reasonable default)
      */
@@ -113,7 +92,7 @@
 
     /*!
      * \brief Call \p f for each frame in the receive buffer.
-     * \param f is the frame handler
+     * \param f is the frame data handler
      * \param timeout controls behavior when there are no frames to read
      *
      * If \p timeout is 0, rx_frames will not wait for frames if none are 
@@ -127,12 +106,12 @@
      * \p f will be called on each ethernet frame that is available.
      * \p f returns a bit vector with one of the following set or cleared:
      * 
-     * handler::KEEP  - hold onto the frame and present it again during the
-     *                  next call to rx_frames, otherwise discard it
+     * data_handler::KEEP  - hold onto the frame and present it again during 
+                             the next call to rx_frames, otherwise discard it
      *
-     * handler::BREAK - return from rx_frames even though more frames might
-     *                  be available, otherwise continue if more frames are 
-     *                  ready
+     * data_handler::BREAK - return from rx_frames even though more frames
+     *                       might be available, otherwise continue if more 
+     *                       frames are ready
      *
      * The idea of holding onto a frame for the next iteration allows
      * the caller to scan the received packet stream for particular
@@ -146,7 +125,7 @@
      * \returns  2 if timeout occurred
      * \returns -1 if there was an unrecoverable error.
      */
-    int rx_frames(handler *f, int timeout=-1);
+    int rx_frames(data_handler *f, int timeout=-1);
 
     /*
      * \brief Write an ethernet frame to the interface.





reply via email to

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