commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r9145 - usrp2/trunk/host-ng/apps


From: eb
Subject: [Commit-gnuradio] r9145 - usrp2/trunk/host-ng/apps
Date: Fri, 1 Aug 2008 15:35:50 -0600 (MDT)

Author: eb
Date: 2008-08-01 15:35:50 -0600 (Fri, 01 Aug 2008)
New Revision: 9145

Modified:
   usrp2/trunk/host-ng/apps/test2_usrp2.cc
   usrp2/trunk/host-ng/apps/tx_samples.cc
Log:
Added SIGINT handler.  Now quiet unless -v

Modified: usrp2/trunk/host-ng/apps/test2_usrp2.cc
===================================================================
--- usrp2/trunk/host-ng/apps/test2_usrp2.cc     2008-08-01 20:35:55 UTC (rev 
9144)
+++ usrp2/trunk/host-ng/apps/test2_usrp2.cc     2008-08-01 21:35:50 UTC (rev 
9145)
@@ -30,7 +30,33 @@
 #include <boost/scoped_ptr.hpp>
 #include <boost/shared_ptr.hpp>
 #include <stdexcept>
+#include <signal.h>
 
+static volatile bool signaled = false;
+
+static void 
+sig_handler(int sig)
+{
+  signaled = true;
+}
+
+static void
+install_sig_handler(int signum,
+                   void (*new_handler)(int))
+{
+  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");
+  }
+}
+
 // ------------------------------------------------------------------------
 
 class rx_nop_handler : public usrp2::rx_sample_handler
@@ -196,9 +222,9 @@
   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");
   fprintf(stderr, "  -o OUTPUT_FILENAME   specify file to receive samples 
[default=none]\n");
   fprintf(stderr, "  -s                   write complex<short> 
[default=complex<float>]\n");
+  fprintf(stderr, "  -v                   verbose output\n");
 }
 
 int
@@ -213,10 +239,11 @@
   size_t nsamples = static_cast<size_t>(250e6);
   bool output_shorts = false;
   char *output_filename = 0;
+  bool verbose = false;
 
   int ch;
 
-  while ((ch = getopt(argc, argv, "he:m:f:d:g:N:o:s")) != EOF){
+  while ((ch = getopt(argc, argv, "he:m:f:d:g:N:o:sv")) != EOF){
     double tmp;
     switch (ch){
 
@@ -281,6 +308,10 @@
       output_filename = optarg;
       break;
       
+    case 'v':
+      verbose = true;
+      break;
+
     case 'h':
     default:
       usage(argv[0]);
@@ -289,6 +320,9 @@
   }
 
 
+  install_sig_handler(SIGINT, sig_handler);
+
+
   typedef boost::shared_ptr<rx_nop_handler> handler_sptr;
   handler_sptr handler;
 
@@ -301,7 +335,6 @@
   else
     handler = handler_sptr(new rx_nop_handler(nsamples));
 
-
   gruel::rt_status_t rt = gruel::enable_realtime_scheduling();
   if (rt != gruel::RT_OK)
     std::cerr << "Failed to enable realtime scheduling" << std::endl;
@@ -324,31 +357,35 @@
     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 (verbose){
+    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 (verbose)
+    printf("USRP2 using decimation rate of %d\n", rx_decim);
     
   if (!u2->start_rx_streaming(0)){
     fprintf(stderr, "start_rx_streaming failed\n");
     exit(1);
   }
 
-  printf("Receiving %zd samples\n\n", nsamples);
+  if (verbose)
+    printf("Receiving %zd samples\n\n", nsamples);
   
   struct timeval start, end;
   gettimeofday(&start, 0);
 
 
-  while(handler->nsamples() < handler->max_samples()){
+  while(!signaled && handler->nsamples() < handler->max_samples()){
     bool ok = u2->rx_samples(0, handler.get());
     if (!ok){
       fprintf(stderr, "u2->rx_samples failed\n");
@@ -356,7 +393,6 @@
     }
   }
 
-
   gettimeofday(&end, 0);
   long n_usecs = end.tv_usec-start.tv_usec;
   long n_secs = end.tv_sec-start.tv_sec;
@@ -366,13 +402,15 @@
   
   u2->stop_rx_streaming();
 
-  printf("\nCopy handler called %zd times.\n", handler->nframes());
-  printf("Copy handler called with %zd bytes.\n\n", 
handler->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()); 
+  if (verbose){
+    printf("\nCopy handler called %zd times.\n", handler->nframes());
+    printf("Copy handler called with %zd bytes.\n\n", 
handler->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;
 }

Modified: usrp2/trunk/host-ng/apps/tx_samples.cc
===================================================================
--- usrp2/trunk/host-ng/apps/tx_samples.cc      2008-08-01 20:35:55 UTC (rev 
9144)
+++ usrp2/trunk/host-ng/apps/tx_samples.cc      2008-08-01 21:35:50 UTC (rev 
9145)
@@ -25,9 +25,38 @@
 #include <complex>
 #include <getopt.h>
 #include <gruel/realtime.h>
+#include <signal.h>
+#include <stdexcept>
 
+
 typedef std::complex<float> fcomplex;
 
+static volatile bool signaled = false;
+
+static void 
+sig_handler(int sig)
+{
+  signaled = true;
+}
+
+static void
+install_sig_handler(int signum,
+                   void (*new_handler)(int))
+{
+  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");
+  }
+}
+
+
 static const char *
 prettify_progname(const char *progname)                // that's probably 
almost a word ;)
 {
@@ -161,7 +190,9 @@
     }
   }
 
+  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;
@@ -204,7 +235,7 @@
   md.start_of_burst = 1;
   md.send_now = 1;
 
-  while (1){
+  while (!signaled){
 
     std::complex<int16_t> samples[MAX_SAMPLES];
 





reply via email to

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