commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r11041 - gnuradio/branches/developers/eb/vrt/vrt/apps


From: eb
Subject: [Commit-gnuradio] r11041 - gnuradio/branches/developers/eb/vrt/vrt/apps
Date: Fri, 15 May 2009 02:30:53 -0600 (MDT)

Author: eb
Date: 2009-05-15 02:30:52 -0600 (Fri, 15 May 2009)
New Revision: 11041

Modified:
   gnuradio/branches/developers/eb/vrt/vrt/apps/simple_rx_samples.cc
Log:
work-in-progress

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-15 06:18:12 UTC (rev 11040)
+++ gnuradio/branches/developers/eb/vrt/vrt/apps/simple_rx_samples.cc   
2009-05-15 08:30:52 UTC (rev 11041)
@@ -200,49 +200,126 @@
 
 // ------------------------------------------------------------------------
 
-class rx_dummy_handler : public vrt::rx_packet_handler
+class rx_nop_handler : public vrt::rx_packet_handler
 {
-public:
+private:
+  uint64_t     d_max_samples;
+  uint64_t     d_max_quantum;
+  uint64_t     d_nsamples;
   uint64_t     d_npackets;
   int          d_last_pkt_cnt;
   uint64_t     d_nwrong_pkt_cnt;
+
+protected:
+  bool         d_err;
+
+public:
+
+  // Shared pointer to an instance of this class
+  typedef boost::shared_ptr<rx_nop_handler> sptr;
+
+  /*!
+   * Constructor
+   *
+   * \param max_samples  Maximum number of samples to copy. Use zero for no 
maximum.
+   * \param max_quantum  Maximum number of samples required to accept in one 
call.
+   *                     Use 0 to indicate no maximum.
+   */
+  rx_nop_handler(uint64_t max_samples, uint64_t max_quantum=0)
+    : d_max_samples(max_samples), d_max_quantum(max_quantum),
+      d_nsamples(0), d_npackets(0), 
+      d_last_pkt_cnt(0xf), d_nwrong_pkt_cnt(0),
+      d_err(false){}
+
+    
+    ~rx_nop_handler();
   
-  rx_dummy_handler();
-  ~rx_dummy_handler();
-  
   bool operator()(const uint32_t *payload,
                  size_t n32_bit_words,
                  const vrt::expanded_header *hdr);
 
+  /*!
+   * \brief Returns number of packets this copier was called with
+   */
+  uint64_t npackets() const { return d_npackets; }
+
+  /*!
+   * \brief Returns actual number of samples copied
+   */
+  uint64_t nsamples() const { return d_nsamples; }
+
+  /*!
+   * \brief Returns maximum number of samples that will be copied
+   */
+  uint64_t max_samples() const { return d_max_samples; }
+
+  /*!
+   * Returns true if an error has occurred. Derived classes must set d_err to 
true
+   * when an error occurs in the () operator
+   */
+  bool has_errored_p() const { return d_err; }
+
+  /*!
+   * \brief Returns true if this instance has reached the maximum number of 
samples
+   */
+  bool has_finished_p() const 
+  { return d_max_samples == 0 ? false : d_nsamples >= 
d_max_samples-d_max_quantum; }
+      
+  uint64_t nwrong_pkt_cnt() const { return d_nwrong_pkt_cnt; }
+
+
 };
 
-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()
+rx_nop_handler::~rx_nop_handler()
 {
 }
 
 bool
-rx_dummy_handler::operator()(const uint32_t *payload,
+rx_nop_handler::operator()(const uint32_t *payload,
                             size_t n32_bit_words,
                             const vrt::expanded_header *hdr)
 {
+  d_nsamples += n32_bit_words;
+  d_npackets++;
+
+
   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;
+  return !has_finished_p();
 }
 
 // ------------------------------------------------------------------------
 
+static void
+usage(const char *progname)
+{
+  const char *p = strrchr(progname, '/');      // drop leading directory path
+  if (p)
+    p++;
+
+  if (strncmp(p, "lt-", 3) == 0)               // drop lt- libtool prefix
+    p += 3;
+  
+  fprintf(stderr, "Usage: %s [options]\n\n", p);
+  fprintf(stderr, "Options:\n");
+  fprintf(stderr, "  -h                   show this message and exit\n");
+//fprintf(stderr, "  -e ETH_INTERFACE     specify ethernet interface 
[default=eth0]\n");
+//fprintf(stderr, "  -m MAC_ADDR          mac address of USRP2 HH:HH 
[default=first one found]\n");
+//fprintf(stderr, "  -f FREQUENCY         specify receive center frequency in 
Hz [default=0.0]\n");
+//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=infinite]\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
 main(int argc, char **argv)
 {
@@ -250,6 +327,8 @@
   int quad_radio_ctrl_port = 790;
   size_t rx_bufsize = 62.5e6;      // sizeof memory mapped network buffer
   int samples_per_pkt = 0;         // use default
+  uint64_t nsamples = 0;
+  char *output_filename = 0;
   int siggen_param = 0;
 
   int           ctrl_fd;           // socket for control
@@ -258,6 +337,26 @@
   int           data_port;         // our data port number
 
 
+  int ch;
+
+  while ((ch = getopt(argc, argv, "hN:o:")) != EOF){
+    switch (ch){
+    case 'N':
+      nsamples = (uint64_t) strtod(optarg, 0);
+      break;
+
+    case 'o':
+      output_filename = optarg;
+      break;
+
+    case 'h':
+    default:
+      usage(argv[0]);
+      exit(1);
+    }
+  }
+
+
   install_sig_handler(SIGINT, sig_handler);
 
   gruel::rt_status_t rt = gruel::enable_realtime_scheduling();
@@ -272,8 +371,8 @@
   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());
+  rx_nop_handler::sptr handler =
+    rx_nop_handler::sptr(new rx_nop_handler(nsamples));
 
   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");
@@ -282,9 +381,10 @@
 
   // start receiving packets
 
-  uint64_t max_packets = 1000000;
-
-  while(!signaled && handler->d_npackets < max_packets){
+  while(1
+       && !signaled
+       && !handler->has_errored_p()
+       && !handler->has_finished_p()){
     bool ok = vrt_receiver->rx_packets(handler.get());
     if (!ok){
       fprintf(stderr, "vrt->rx_packets failed\n");
@@ -294,10 +394,10 @@
 
   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);
+  printf("%llu packets received, %llu bad pkt_cnt field values, %llu 
samples\n",
+        handler->npackets(), handler->nwrong_pkt_cnt(), handler->nsamples());
 
-  sleep(1);
+  //sleep(1);
 
   return 0;
 }





reply via email to

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