Changeset 9145

Show
Ignore:
Timestamp:
08/01/08 15:35:50
Author:
eb
Message:

Added SIGINT handler. Now quiet unless -v

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • usrp2/trunk/host-ng/apps/test2_usrp2.cc

    r9142 r9145  
    3131#include <boost/shared_ptr.hpp> 
    3232#include <stdexcept> 
     33#include <signal.h> 
     34 
     35static volatile bool signaled = false; 
     36 
     37static void  
     38sig_handler(int sig) 
     39{ 
     40  signaled = true; 
     41} 
     42 
     43static void 
     44install_sig_handler(int signum, 
     45                    void (*new_handler)(int)) 
     46{ 
     47  struct sigaction new_action; 
     48  memset (&new_action, 0, sizeof (new_action)); 
     49 
     50  new_action.sa_handler = new_handler; 
     51  sigemptyset (&new_action.sa_mask); 
     52  new_action.sa_flags = 0; 
     53 
     54  if (sigaction (signum, &new_action, 0) < 0){ 
     55    perror ("sigaction (install new)"); 
     56    throw std::runtime_error ("sigaction"); 
     57  } 
     58} 
    3359 
    3460// ------------------------------------------------------------------------ 
     
    197223  fprintf(stderr, "  -g GAIN              specify receive daughterboard gain [default=0]\n"); 
    198224  fprintf(stderr, "  -N NSAMPLES          specify number of samples to receive [default=250e6]\n"); 
    199 //fprintf(stderr, "  -b BUFSIZE           specify size of receive buffer [default=64k]\n"); 
    200225  fprintf(stderr, "  -o OUTPUT_FILENAME   specify file to receive samples [default=none]\n"); 
    201226  fprintf(stderr, "  -s                   write complex<short> [default=complex<float>]\n"); 
     227  fprintf(stderr, "  -v                   verbose output\n"); 
    202228} 
    203229 
     
    214240  bool output_shorts = false; 
    215241  char *output_filename = 0; 
     242  bool verbose = false; 
    216243 
    217244  int ch; 
    218245 
    219   while ((ch = getopt(argc, argv, "he:m:f:d:g:N:o:s")) != EOF){ 
     246  while ((ch = getopt(argc, argv, "he:m:f:d:g:N:o:sv")) != EOF){ 
    220247    double tmp; 
    221248    switch (ch){ 
     
    282309      break; 
    283310       
     311    case 'v': 
     312      verbose = true; 
     313      break; 
     314 
    284315    case 'h': 
    285316    default: 
     
    288319    } 
    289320  } 
     321 
     322 
     323  install_sig_handler(SIGINT, sig_handler); 
    290324 
    291325 
     
    302336    handler = handler_sptr(new rx_nop_handler(nsamples)); 
    303337 
    304  
    305338  gruel::rt_status_t rt = gruel::enable_realtime_scheduling(); 
    306339  if (rt != gruel::RT_OK) 
     
    325358  } 
    326359 
    327   printf("Daughterboard configuration:\n"); 
    328   printf("  baseband_freq=%f\n", tr.baseband_freq); 
    329   printf("       ddc_freq=%f\n", tr.dxc_freq); 
    330   printf("  residual_freq=%f\n", tr.residual_freq); 
    331   printf("       inverted=%s\n\n", tr.spectrum_inverted ? "yes" : "no"); 
     360  if (verbose){ 
     361    printf("Daughterboard configuration:\n"); 
     362    printf("  baseband_freq=%f\n", tr.baseband_freq); 
     363    printf("       ddc_freq=%f\n", tr.dxc_freq); 
     364    printf("  residual_freq=%f\n", tr.residual_freq); 
     365    printf("       inverted=%s\n\n", tr.spectrum_inverted ? "yes" : "no"); 
     366  } 
    332367   
    333368  if (!u2->set_rx_decim(rx_decim)) { 
     
    336371  } 
    337372 
    338   printf("USRP2 using decimation rate of %d\n", rx_decim); 
     373  if (verbose) 
     374    printf("USRP2 using decimation rate of %d\n", rx_decim); 
    339375     
    340376  if (!u2->start_rx_streaming(0)){ 
     
    343379  } 
    344380 
    345   printf("Receiving %zd samples\n\n", nsamples); 
     381  if (verbose) 
     382    printf("Receiving %zd samples\n\n", nsamples); 
    346383   
    347384  struct timeval start, end; 
     
    349386 
    350387 
    351   while(handler->nsamples() < handler->max_samples()){ 
     388  while(!signaled && handler->nsamples() < handler->max_samples()){ 
    352389    bool ok = u2->rx_samples(0, handler.get()); 
    353390    if (!ok){ 
     
    356393    } 
    357394  } 
    358  
    359395 
    360396  gettimeofday(&end, 0); 
     
    367403  u2->stop_rx_streaming(); 
    368404 
    369   printf("\nCopy handler called %zd times.\n", handler->nframes()); 
    370   printf("Copy handler called with %zd bytes.\n\n", handler->nsamples()*sizeof(uint32_t)); 
    371   printf("Elapsed time was %5.3f seconds.\n", elapsed); 
    372   printf("Packet rate was %1.0f pkts/sec.\n", pps); 
    373   printf("Approximate throughput was %5.2f MB/sec.\n", mbs); 
    374   printf("Total instances of overruns was %d.\n", u2->rx_overruns()); 
    375   printf("Total missing frames was %d.\n", u2->rx_missing());  
     405  if (verbose){ 
     406    printf("\nCopy handler called %zd times.\n", handler->nframes()); 
     407    printf("Copy handler called with %zd bytes.\n\n", handler->nsamples()*sizeof(uint32_t)); 
     408    printf("Elapsed time was %5.3f seconds.\n", elapsed); 
     409    printf("Packet rate was %1.0f pkts/sec.\n", pps); 
     410    printf("Approximate throughput was %5.2f MB/sec.\n", mbs); 
     411    printf("Total instances of overruns was %d.\n", u2->rx_overruns()); 
     412    printf("Total missing frames was %d.\n", u2->rx_missing()); 
     413  } 
    376414 
    377415  return 0; 
  • usrp2/trunk/host-ng/apps/tx_samples.cc

    r9142 r9145  
    2626#include <getopt.h> 
    2727#include <gruel/realtime.h> 
     28#include <signal.h> 
     29#include <stdexcept> 
     30 
    2831 
    2932typedef std::complex<float> fcomplex; 
     33 
     34static volatile bool signaled = false; 
     35 
     36static void  
     37sig_handler(int sig) 
     38{ 
     39  signaled = true; 
     40} 
     41 
     42static void 
     43install_sig_handler(int signum, 
     44                    void (*new_handler)(int)) 
     45{ 
     46  struct sigaction new_action; 
     47  memset (&new_action, 0, sizeof (new_action)); 
     48 
     49  new_action.sa_handler = new_handler; 
     50  sigemptyset (&new_action.sa_mask); 
     51  new_action.sa_flags = 0; 
     52 
     53  if (sigaction (signum, &new_action, 0) < 0){ 
     54    perror ("sigaction (install new)"); 
     55    throw std::runtime_error ("sigaction"); 
     56  } 
     57} 
     58 
    3059 
    3160static const char * 
     
    162191  } 
    163192 
     193  install_sig_handler(SIGINT, sig_handler); 
     194 
    164195 
    165196  gruel::rt_status_t rt = gruel::enable_realtime_scheduling(); 
     
    205236  md.send_now = 1; 
    206237 
    207   while (1){ 
     238  while (!signaled){ 
    208239 
    209240    std::complex<int16_t> samples[MAX_SAMPLES];