commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r10997 - in gnuradio/branches/developers/eb/vrt/vrt: a


From: eb
Subject: [Commit-gnuradio] r10997 - in gnuradio/branches/developers/eb/vrt/vrt: apps include/vrt lib
Date: Sat, 9 May 2009 01:52:50 -0600 (MDT)

Author: eb
Date: 2009-05-09 01:52:49 -0600 (Sat, 09 May 2009)
New Revision: 10997

Modified:
   gnuradio/branches/developers/eb/vrt/vrt/apps/Makefile.am
   gnuradio/branches/developers/eb/vrt/vrt/apps/simple_rx_samples.cc
   gnuradio/branches/developers/eb/vrt/vrt/include/vrt/expanded_headers.h
   gnuradio/branches/developers/eb/vrt/vrt/lib/rx_udp.cc
   gnuradio/branches/developers/eb/vrt/vrt/lib/socket_rx_buffer.cc
Log:
work-in-progress

Modified: gnuradio/branches/developers/eb/vrt/vrt/apps/Makefile.am
===================================================================
--- gnuradio/branches/developers/eb/vrt/vrt/apps/Makefile.am    2009-05-08 
23:52:50 UTC (rev 10996)
+++ gnuradio/branches/developers/eb/vrt/vrt/apps/Makefile.am    2009-05-09 
07:52:49 UTC (rev 10997)
@@ -23,7 +23,8 @@
     $(CPPUNIT_INCLUDES)
 
 LDADD = \
-       $(VRT_LA)
+       $(VRT_LA) \
+       $(GRUEL_LA)
 
 
 bin_PROGRAMS = 

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-08 23:52:50 UTC (rev 10996)
+++ gnuradio/branches/developers/eb/vrt/vrt/apps/simple_rx_samples.cc   
2009-05-09 07:52:49 UTC (rev 10997)
@@ -24,23 +24,48 @@
 #include <sys/types.h>
 #include <sys/socket.h>
 
+#include <iostream>
+#include <boost/scoped_ptr.hpp>
+#include <boost/shared_ptr.hpp>
+#include <stdexcept>
+#include <signal.h>
 #include <unistd.h>
+#include <stdint.h>
 #include <stdio.h>
 #include <string.h>
 #include <vrt/rx_udp.h>
+#include <gruel/realtime.h>
 
 #define        MIN_IP_LOCAL_PORT       32768
 #define        MAX_IP_LOCAL_PORT       61000
 
-#if 0
+static volatile bool signaled = false;
+
+static void 
+sig_handler(int sig)
+{
+  signaled = true;
+}
+
 static void
-pdie(const char *msg)
+install_sig_handler(int signum,
+                   void (*new_handler)(int))
 {
-  perror(msg);
-  exit(1);
+  struct sigaction new_action;
+  memset (&new_action, 0, sizeof (new_action));
+
+  new_action.sa_handler = new_handler;
+  sigemptyset (&new_action.sa_mask);
+  new_action.sa_flags = 0;
+
+  if (sigaction (signum, &new_action, 0) < 0){
+    perror ("sigaction (install new)");
+    throw std::runtime_error ("sigaction");
+  }
 }
-#endif
 
+// ------------------------------------------------------------------------
+
 static bool
 open_sockets(const char *quad_radio_ip, int quad_radio_ctrl_port,
             int *ctrl_fd_ptr, struct in_addr *ctrl_port_inaddr,
@@ -165,28 +190,91 @@
   return true;
 }
 
+static bool
+send_stop_rx_command(int ctrl_fd)
+{
+  struct in_addr in_addr;
+  in_addr.s_addr = 0;
+  return send_rx_command(ctrl_fd, false, in_addr, 0, 0, 0);
+}
+
+// ------------------------------------------------------------------------
+
+class rx_dummy_handler : public vrt::rx_packet_handler
+{
+public:
+  uint64_t     d_npackets;
+  int          d_last_pkt_cnt;
+  uint64_t     d_nwrong_pkt_cnt;
+  
+  rx_dummy_handler();
+  ~rx_dummy_handler();
+  
+  bool operator()(const uint32_t *payload,
+                 size_t n32_bit_words,
+                 const vrt::expanded_headers *hdrs);
+
+};
+
+rx_dummy_handler::rx_dummy_handler()
+  : d_npackets(0), d_last_pkt_cnt(0xf), d_nwrong_pkt_cnt(0)
+{
+}
+
+rx_dummy_handler::~rx_dummy_handler()
+{
+}
+
+bool
+rx_dummy_handler::operator()(const uint32_t *payload,
+                            size_t n32_bit_words,
+                            const vrt::expanded_headers *hdr)
+{
+  if (hdr->pkt_cnt() != ((d_last_pkt_cnt + 1) & 0xf)){
+    d_nwrong_pkt_cnt++;
+    fprintf(stderr, "bad cnt ");
+  }
+
+  d_last_pkt_cnt = hdr->pkt_cnt();
+  d_npackets++;
+
+  return true;
+}
+
+// ------------------------------------------------------------------------
+
 int
 main(int argc, char **argv)
 {
   const char *quad_radio_ip = "192.168.123.123";
   int quad_radio_ctrl_port = 790;
-  size_t rx_bufsize = 0;           // use default (62.5MB)
-  int  samples_per_pkt = 0;        // use default
-  int  siggen_param = 0;
+  size_t rx_bufsize = 62.5e6;      // sizeof memory mapped network buffer
+  int samples_per_pkt = 0;         // use default
+  int siggen_param = 0;
 
   int           ctrl_fd;           // socket for control
   struct in_addr ctrl_port_inaddr;  // our ip addr
   int           data_fd;           // socket for data
   int           data_port;         // our data port number
 
+
+  install_sig_handler(SIGINT, sig_handler);
+
+  gruel::rt_status_t rt = gruel::enable_realtime_scheduling();
+  if (rt != gruel::RT_OK)
+    std::cerr << "Failed to enable realtime scheduling" << std::endl;
+
+  
   if (!open_sockets(quad_radio_ip, quad_radio_ctrl_port,
                    &ctrl_fd, &ctrl_port_inaddr, &data_fd, &data_port))
     return 1;
 
-
-  vrt::rx_udp::sptr vrt_receiver = vrt::rx_udp::make(data_port, rx_bufsize);
+  vrt::rx_udp::sptr vrt_receiver = vrt::rx_udp::make(data_fd, rx_bufsize);
   
 
+  boost::shared_ptr<rx_dummy_handler> handler =
+    boost::shared_ptr<rx_dummy_handler>(new rx_dummy_handler());
+
   if (!send_rx_command(ctrl_fd, true, ctrl_port_inaddr, data_port, 
samples_per_pkt, siggen_param)){
     fprintf(stderr, "failed to send_rx_command\n");
     return 1;
@@ -194,9 +282,22 @@
 
   // start receiving packets
 
-  while(1){
-    sleep(5);
+  uint64_t     niter = 0;
+  uint64_t     max_iter = 1000000;
+
+  while(!signaled && niter++ < max_iter){
+    bool ok = vrt_receiver->rx_packets(handler.get());
+    if (!ok){
+      fprintf(stderr, "vrt->rx_packets failed\n");
+      send_stop_rx_command(ctrl_fd);
+      return 1;
+    }
   }
 
+  send_stop_rx_command(ctrl_fd);
+
+  printf("%llu packets received, %llu bad pkt_cnt field values\n",
+        handler->d_npackets, handler->d_nwrong_pkt_cnt);
+
   return 0;
 }

Modified: gnuradio/branches/developers/eb/vrt/vrt/include/vrt/expanded_headers.h
===================================================================
--- gnuradio/branches/developers/eb/vrt/vrt/include/vrt/expanded_headers.h      
2009-05-08 23:52:50 UTC (rev 10996)
+++ gnuradio/branches/developers/eb/vrt/vrt/include/vrt/expanded_headers.h      
2009-05-09 07:52:49 UTC (rev 10997)
@@ -46,24 +46,26 @@
       : header(0), stream_id(0), class_id(0),
        integer_secs(0), fractional_secs(0), trailer(0) {}
 
-    int pkt_type(){
+    int pkt_type() const {
       return (header & VRTH_PT_MASK) >> 28;
     }
     
     // packet type predicates
-    bool if_data_p() { return s_if_data[pkt_type()]; }
-    bool ext_data_p() { return s_ext_data[pkt_type()]; }
-    bool if_context_p() { return (header & VRTH_PT_MASK) == 
VRTH_PT_IF_CONTEXT; }
-    bool ext_context_p() { return (header & VRTH_PT_MASK) == 
VRTH_PT_EXT_CONTEXT; }
+    bool if_data_p() const { return s_if_data[pkt_type()]; }
+    bool ext_data_p() const { return s_ext_data[pkt_type()]; }
+    bool if_context_p() const { return (header & VRTH_PT_MASK) == 
VRTH_PT_IF_CONTEXT; }
+    bool ext_context_p() const { return (header & VRTH_PT_MASK) == 
VRTH_PT_EXT_CONTEXT; }
 
-    bool data_p() { return s_data[pkt_type()]; }       // if_data_p() || 
ext_data_p()
-    bool context_p() { return s_context[pkt_type()]; } // if_context_p() || 
ext_context_p()
+    bool data_p() const { return s_data[pkt_type()]; } // if_data_p() || 
ext_data_p()
+    bool context_p() const { return s_context[pkt_type()]; }   // 
if_context_p() || ext_context_p()
 
     // optional info predicates
-    bool stream_id_p() { return s_stream_id[pkt_type()]; }
-    bool class_id_p() { return (header & VRTH_HAS_CLASSID) != 0; }
-    bool trailer_p() { return (header & VRTH_HAS_TRAILER) != 0 && data_p(); }
+    bool stream_id_p() const { return s_stream_id[pkt_type()]; }
+    bool class_id_p() const { return (header & VRTH_HAS_CLASSID) != 0; }
+    bool trailer_p() const { return (header & VRTH_HAS_TRAILER) != 0 && 
data_p(); }
 
+    int pkt_cnt() const { return vrth_pkt_cnt(header); }
+
   private:
     static unsigned char s_if_data[16];
     static unsigned char s_ext_data[16];

Modified: gnuradio/branches/developers/eb/vrt/vrt/lib/rx_udp.cc
===================================================================
--- gnuradio/branches/developers/eb/vrt/vrt/lib/rx_udp.cc       2009-05-08 
23:52:50 UTC (rev 10996)
+++ gnuradio/branches/developers/eb/vrt/vrt/lib/rx_udp.cc       2009-05-09 
07:52:49 UTC (rev 10997)
@@ -26,6 +26,7 @@
 #include "socket_rx_buffer.h"
 #include "data_handler.h"
 #include <stdio.h>
+#include <stdexcept>
 
 static void
 print_words(size_t offset, uint32_t *buf, size_t n)

Modified: gnuradio/branches/developers/eb/vrt/vrt/lib/socket_rx_buffer.cc
===================================================================
--- gnuradio/branches/developers/eb/vrt/vrt/lib/socket_rx_buffer.cc     
2009-05-08 23:52:50 UTC (rev 10996)
+++ gnuradio/branches/developers/eb/vrt/vrt/lib/socket_rx_buffer.cc     
2009-05-09 07:52:49 UTC (rev 10997)
@@ -61,6 +61,10 @@
       d_buflen = (size_t)DEFAULT_MEM_SIZE;
     else
       d_buflen = std::min((size_t)MAX_MEM_SIZE, rx_bufsize);
+
+    if (!open()){
+      throw std::runtime_error("socket_rx_buffer::open failed");
+    }
   }
 
   socket_rx_buffer::~socket_rx_buffer()
@@ -172,7 +176,7 @@
       pfd.revents = 0;
       pfd.events = POLLIN;
 
-      DEBUG_LOG("P");
+      // DEBUG_LOG("P");
 
       int pres = poll(&pfd, 1, timeout_in_ms);
       if (pres == -1) {





reply via email to

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