commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r9980 - gnuradio/branches/features/cppdb/gnuradio-exam


From: trondeau
Subject: [Commit-gnuradio] r9980 - gnuradio/branches/features/cppdb/gnuradio-examples/c++/usrp_test
Date: Wed, 12 Nov 2008 17:31:15 -0700 (MST)

Author: trondeau
Date: 2008-11-12 17:31:15 -0700 (Wed, 12 Nov 2008)
New Revision: 9980

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:
adding a bit of flexibility to the example code; now with your own frequency.

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-13 00:20:30 UTC (rev 9979)
+++ 
gnuradio/branches/features/cppdb/gnuradio-examples/c++/usrp_test/usrp_test_rx.cc
    2008-11-13 00:31:15 UTC (rev 9980)
@@ -21,23 +21,20 @@
 
 #include <usrp_test_rx.h>
 #include <gr_io_signature.h>
-#include <usrp_source_c.h>
 #include <gr_head.h>
 
 // Shared pointer constructor
-usrp_test_sptr make_usrp_test()
+usrp_test_sptr make_usrp_test(int which, usrp_subdev_spec spec, int decim, 
double freq, float gain)
 {
-  return gnuradio::get_initial_sptr(new usrp_test());
+  return gnuradio::get_initial_sptr(new usrp_test(which, spec, decim, freq, 
gain));
 }
 
 // Hierarchical block constructor, with no inputs or outputs
-usrp_test::usrp_test() : 
+usrp_test::usrp_test(int which, usrp_subdev_spec spec, int decim, double freq, 
float gain) : 
     gr_top_block("usrp_test")
 {
-  int decim = 64;
-  usrp_source_c_sptr usrp = usrp_make_source_c(0, decim);
+  usrp_source_c_sptr usrp = usrp_make_source_c(which, decim);
 
-  usrp_subdev_spec spec(0,0);
   db_base_sptr subdev = usrp->selected_subdev(spec);
   printf("Subdevice name is %s\n", subdev->name().c_str());
   printf("Subdevice freq range: (%g, %g)\n", subdev->freq_min(), 
subdev->freq_max());
@@ -51,12 +48,14 @@
 
   float gain_min = subdev->gain_min();
   float gain_max = subdev->gain_max();
-  printf("gain: (%g, %g)\n",  gain_min, gain_max);
+  printf("gain range: (%g, %g)\n",  gain_min, gain_max);
+  if(gain == -1) {
+    gain = (gain_min + gain_max)/2.0;
+  }
+  subdev->set_gain(gain);
   
-  subdev->set_gain((gain_min + gain_max)/2.0);
-  
   usrp_tune_result r;
-  double target_freq = 101.3e6;
+  double target_freq = freq;
   bool ok = usrp->tune(0, subdev, target_freq, &r);
   
   printf("target_freq:     %f\n", target_freq);
@@ -74,9 +73,20 @@
   connect(head, 0, sink, 0);
 }
 
-int main()
+int main(int argc, char *argv[])
 {
-  usrp_test_sptr top_block = make_usrp_test();
+  if(argc < 2) {
+    fprintf(stderr, "Please enter a target frequency\n");
+    return -1;
+  }
+
+  int which = 0;                       // specify which USRP board
+  usrp_subdev_spec spec(0,0);          // specify the d'board side
+  int decim = 64;                      // set the decimation rate
+  double freq = strtod(argv[1], NULL); // set the frequency
+  float gain = -1;                     // set the gain; -1 will set the 
mid-point gain
+
+  usrp_test_sptr top_block = make_usrp_test(which, spec, decim, freq, gain);
   top_block->run();
   
   std::vector<gr_complex> data = top_block->sink->data();

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-13 00:20:30 UTC (rev 9979)
+++ 
gnuradio/branches/features/cppdb/gnuradio-examples/c++/usrp_test/usrp_test_rx.h 
    2008-11-13 00:31:15 UTC (rev 9980)
@@ -20,6 +20,7 @@
  */
 
 #include <gr_top_block.h>
+#include <usrp_source_c.h>
 #include <gr_vector_sink_c.h>
 
 class usrp_test;
@@ -29,8 +30,8 @@
 class usrp_test : public gr_top_block
 {
 private:
-    usrp_test();
-    friend usrp_test_sptr make_usrp_test();
+    usrp_test(int which, usrp_subdev_spec spec, int decim, double freq, float 
gain);
+    friend usrp_test_sptr make_usrp_test(int which, usrp_subdev_spec spec, int 
decim, double freq, float gain);
 
  public:
     gr_vector_sink_c_sptr sink;





reply via email to

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