commit-gnuradio
[Top][All Lists]
Advanced

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

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


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

Author: trondeau
Date: 2008-11-16 14:47:06 -0700 (Sun, 16 Nov 2008)
New Revision: 10001

Modified:
   
gnuradio/branches/features/cppdb/gnuradio-examples/c++/usrp_test/usrp_test_tx.cc
Log:
added commandline options to usrp_test_tx

Modified: 
gnuradio/branches/features/cppdb/gnuradio-examples/c++/usrp_test/usrp_test_tx.cc
===================================================================
--- 
gnuradio/branches/features/cppdb/gnuradio-examples/c++/usrp_test/usrp_test_tx.cc
    2008-11-16 21:40:09 UTC (rev 10000)
+++ 
gnuradio/branches/features/cppdb/gnuradio-examples/c++/usrp_test/usrp_test_tx.cc
    2008-11-16 21:47:06 UTC (rev 10001)
@@ -22,7 +22,12 @@
 #include <usrp_test_tx.h>
 #include <gr_io_signature.h>
 #include <gr_head.h>
+#include <stdexcept>
+#include <iostream>
+#include <boost/program_options.hpp>
 
+namespace po = boost::program_options;
+
 // Shared pointer constructor
 usrp_test_tx_sptr make_usrp_test_tx(int which, usrp_subdev_spec spec, 
                                    int interp, double freq, float amp)
@@ -54,6 +59,10 @@
   double target_freq = freq;
   bool ok = usrp->tune(subdev->which(), subdev, target_freq, &r);
 
+  if(!ok) {
+    throw std::runtime_error("Could not set frequency.");
+  }
+
   subdev->set_enable(true);
   
   printf("target_freq:     %f\n", target_freq);
@@ -72,17 +81,69 @@
 
 int main(int argc, char *argv[])
 {
-  if(argc < 2) {
-    fprintf(stderr, "Please enter a target frequency\n");
+  int which = 0;                       // specify which USRP board
+  usrp_subdev_spec spec(0,0);          // specify the d'board side
+  int interp = 128;                    // set the interpolation rate
+  double freq = 0;                     // set the frequency
+  float amp = 5;                       // set the amplitude of the output
+
+  po::options_description cmdconfig("Program options");
+  cmdconfig.add_options()
+    ("help,h", "produce help message")
+    ("which,w", po::value<int>(&which), "select which USRP board")
+    ("tx-subdev-spec,T", po::value<std::string>(), "select USRP Rx side and 
port")
+    ("interp,i", po::value<int>(&interp), "set fpga decimation rate")
+    ("frequency,f", po::value<double>(), "set RF frequency")
+    ("amplitdue,a", po::value<float>(&amp), "set amplitude")
+    ;
+  
+  po::variables_map vm;
+  po::store(po::command_line_parser(argc, argv).
+           options(cmdconfig).run(), vm);
+  po::notify(vm);
+  
+  if (vm.count("help")) {
+    std::cout << cmdconfig << "\n";
+    return 1;
+  }
+  
+  if(vm.count("frequency")) {
+    freq = vm["frequency"].as<double>();
+  }
+  else {
+    fprintf(stderr, "You must specify a frequency.\n");
     return -1;
   }
 
-  int which = 0;                       // specify which USRP board
-  usrp_subdev_spec spec(0,0);          // specify the d'board side
-  int interp = 128;                    // set the intepolation rate
-  double freq = strtod(argv[1], NULL); // set the frequency
-  float amp = 5;                       // set the amplutide
+  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") {
+      spec.side = 0;
+      spec.subdev = 0;
+    }
+    else if(s == "A:1" || s == "0:1") {
+      spec.side = 0;
+      spec.subdev = 1;
+    }
+    else if(s == "B" || s == "B:0" || s == "1:0") {
+      spec.side = 1;
+      spec.subdev = 0;
+    }
+    else if(s == "B:1" || s == "1:1") {
+      spec.side = 1;
+      spec.subdev = 1;
+    }
+    else {
+      fprintf(stderr, "Incorrect subdevice specifications.\n");
+      return -1;
+    }
+  }
 
+  printf("which:  %d\n", which);
+  printf("interp: %d\n", interp);
+  printf("freq:   %g\n", freq);
+  printf("amp:    %f\n", amp);
+
   usrp_test_tx_sptr top_block = make_usrp_test_tx(which, spec, 
                                                  interp, freq, amp);
   top_block->run();





reply via email to

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