commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r10000 - gnuradio/branches/features/cppdb/gnuradio-exa


From: trondeau
Subject: [Commit-gnuradio] r10000 - gnuradio/branches/features/cppdb/gnuradio-examples/c++/usrp_test
Date: Sun, 16 Nov 2008 14:40:09 -0700 (MST)

Author: trondeau
Date: 2008-11-16 14:40:09 -0700 (Sun, 16 Nov 2008)
New Revision: 10000

Modified:
   
gnuradio/branches/features/cppdb/gnuradio-examples/c++/usrp_test/usrp_test_rx.cc
   
gnuradio/branches/features/cppdb/gnuradio-examples/c++/usrp_test/usrp_test_rx.h
Log:
Cleaning up and improving options.

Modified: 
gnuradio/branches/features/cppdb/gnuradio-examples/c++/usrp_test/usrp_test_rx.cc
===================================================================
--- 
gnuradio/branches/features/cppdb/gnuradio-examples/c++/usrp_test/usrp_test_rx.cc
    2008-11-16 20:56:02 UTC (rev 9999)
+++ 
gnuradio/branches/features/cppdb/gnuradio-examples/c++/usrp_test/usrp_test_rx.cc
    2008-11-16 21:40:09 UTC (rev 10000)
@@ -30,26 +30,29 @@
 
 // Shared pointer constructor
 usrp_test_rx_sptr make_usrp_test_rx(int which, usrp_subdev_spec spec, 
-                                   int decim, double freq, float gain)
+                                   int decim, double freq, float gain,
+                                   int nsamples)
 {
   return gnuradio::get_initial_sptr(new usrp_test_rx(which, spec, 
-                                                    decim, freq, gain));
+                                                    decim, freq, gain,
+                                                    nsamples));
 }
 
 // Hierarchical block constructor, with no inputs or outputs
 usrp_test_rx::usrp_test_rx(int which, usrp_subdev_spec spec, 
-                          int decim, double freq, float gain) : 
+                          int decim, double freq, float gain,
+                          int nsamples) : 
     gr_top_block("usrp_test_rx")
 {
   usrp_source_c_sptr usrp = usrp_make_source_c(which, decim);
 
   db_base_sptr subdev = usrp->selected_subdev(spec);
-  printf("Subdevice name is %s\n", subdev->name().c_str());
+  printf("Subdevice name is %s\n", subdev->side_and_name().c_str());
   printf("Subdevice freq range: (%g, %g)\n", 
         subdev->freq_min(), subdev->freq_max());
 
   unsigned int mux = usrp->determine_rx_mux_value(spec);
-  printf("mux: %x\n",  mux);
+  printf("mux: %#08x\n",  mux);
   usrp->set_mux(mux);
 
   float input_rate = usrp->adc_freq() / usrp->decim_rate();
@@ -61,6 +64,7 @@
   if(gain == -1) {
     gain = (gain_min + gain_max)/2.0;
   }
+  printf("gain: %g\n", gain);
   subdev->set_gain(gain);
   
   usrp_tune_result r;
@@ -79,11 +83,16 @@
   }
 
   /* The rest */
-  gr_block_sptr head = gr_make_head(sizeof(gr_complex), 1024);
-  sink = gr_make_vector_sink_c();
+  gr_block_sptr head = gr_make_head(sizeof(gr_complex), nsamples);
+  fsink = gr_make_file_sink(sizeof(gr_complex), "received.dat");
 
-  connect(usrp, 0, head, 0);
-  connect(head, 0, sink, 0);
+  if(nsamples == -1) {
+    connect(usrp, 0, fsink, 0);
+  }
+  else {
+    connect(usrp, 0, head, 0);
+    connect(head, 0, fsink, 0);
+  }
 }
 
 int main(int argc, char *argv[])
@@ -93,15 +102,17 @@
   int decim = 64;                      // set the decimation rate
   double freq = 0;                     // set the frequency
   float gain = -1;                     // set the gain; -1 will set the 
mid-point gain
+  int nsamples = -1;                   // set the number of samples to 
collect; -1 will continue
 
   po::options_description cmdconfig("Program options");
   cmdconfig.add_options()
     ("help,h", "produce help message")
-    ("which,w", po::value<int>(), "select which USRP board")
+    ("which,w", po::value<int>(&which), "select which USRP board")
     ("rx-subdev-spec,R", po::value<std::string>(), "select USRP Rx side and 
port")
-    ("decim,d", po::value<int>(), "set fpga decimation rate")
+    ("decim,d", po::value<int>(&decim), "set fpga decimation rate")
     ("frequency,f", po::value<double>(), "set RF frequency")
     ("gain,g", po::value<float>(&gain), "set gain in dB")
+    ("nsamples,N", po::value<int>(&nsamples), "set the number of samples to 
collect; -1 will continue")
     ;
   
   po::variables_map vm;
@@ -122,18 +133,6 @@
     return -1;
   }
 
-  if(vm.count("which")) {
-    which = vm["which"].as<double>();
-  }
-
-  if(vm.count("decim")) {
-    decim = vm["decim"].as<int>();
-  }
-
-  if(vm.count("gain")) {
-    gain = vm["gain"].as<float>();
-  }
-  
   if(vm.count("rx-subdev-spec")) {
     std::string s = vm["rx-subdev-spec"].as<std::string>();
     if(s == "A" || s == "A:0" || s == "0:0") {
@@ -156,25 +155,18 @@
       fprintf(stderr, "Incorrect subdevice specifications.\n");
       return -1;
     }
-
   }
 
-  printf("which: %d\n", which);
-  printf("decim: %d\n", decim);
-  printf("freq:  %g\n", freq);
-  printf("gain:  %f\n", gain);
+  printf("which:   %d\n", which);
+  printf("decim:   %d\n", decim);
+  printf("freq:    %g\n", freq);
+  printf("gain:    %f\n", gain);
+  printf("samples: %d\n", nsamples);
 
   usrp_test_rx_sptr top_block = make_usrp_test_rx(which, spec, 
-                                                 decim, freq, gain);
+                                                 decim, freq, gain,
+                                                 nsamples);
   top_block->run();
-  
-  std::vector<gr_complex> data = top_block->sink->data();
-  
-  printf("data size: %zu\n", data.size());
-  for(size_t i=0; i < data.size(); i++) {
-    printf("%f + %fj\n", data[i].real(), data[i].imag());
-  }
-  printf("\n");
-  
+    
   return 0;
 }

Modified: 
gnuradio/branches/features/cppdb/gnuradio-examples/c++/usrp_test/usrp_test_rx.h
===================================================================
--- 
gnuradio/branches/features/cppdb/gnuradio-examples/c++/usrp_test/usrp_test_rx.h 
    2008-11-16 20:56:02 UTC (rev 9999)
+++ 
gnuradio/branches/features/cppdb/gnuradio-examples/c++/usrp_test/usrp_test_rx.h 
    2008-11-16 21:40:09 UTC (rev 10000)
@@ -21,7 +21,7 @@
 
 #include <gr_top_block.h>
 #include <usrp_source_c.h>
-#include <gr_vector_sink_c.h>
+#include <gr_file_sink.h>
 
 class usrp_test_rx;
 typedef boost::shared_ptr<usrp_test_rx> usrp_test_rx_sptr;
@@ -31,12 +31,13 @@
 {
 private:
     usrp_test_rx(int which, usrp_subdev_spec spec, 
-                int decim, double freq, float gain);
+                int decim, double freq, float gain,
+                int nsamples);
     friend usrp_test_rx_sptr make_usrp_test_rx(int which, 
                                               usrp_subdev_spec spec, 
                                               int decim, double freq, 
-                                              float gain);
+                                              float gain, int nsamples);
 
  public:
-    gr_vector_sink_c_sptr sink;
+    gr_file_sink_sptr fsink;
 };





reply via email to

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