commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r10024 - gnuradio/branches/features/cppdb/gr-usrp/apps


From: trondeau
Subject: [Commit-gnuradio] r10024 - gnuradio/branches/features/cppdb/gr-usrp/apps
Date: Wed, 19 Nov 2008 22:55:39 -0700 (MST)

Author: trondeau
Date: 2008-11-19 22:55:38 -0700 (Wed, 19 Nov 2008)
New Revision: 10024

Modified:
   gnuradio/branches/features/cppdb/gr-usrp/apps/usrp_test_tx.cc
   gnuradio/branches/features/cppdb/gr-usrp/apps/usrp_test_tx.h
Log:
Adding options to transmit example to mimic options and behavior or 
usrp_siggen.py

Modified: gnuradio/branches/features/cppdb/gr-usrp/apps/usrp_test_tx.cc
===================================================================
--- gnuradio/branches/features/cppdb/gr-usrp/apps/usrp_test_tx.cc       
2008-11-20 03:25:52 UTC (rev 10023)
+++ gnuradio/branches/features/cppdb/gr-usrp/apps/usrp_test_tx.cc       
2008-11-20 05:55:38 UTC (rev 10024)
@@ -22,23 +22,57 @@
 #include <usrp_test_tx.h>
 #include <gr_io_signature.h>
 #include <gr_head.h>
+#include <gr_noise_type.h>
 #include <stdexcept>
 #include <iostream>
 #include <boost/program_options.hpp>
 
 namespace po = boost::program_options;
 
+usrp_subdev_spec
+str_to_subdev(std::string spec_str)
+{
+  usrp_subdev_spec spec;
+  if(spec_str == "A" || spec_str == "A:0" || spec_str == "0:0") {
+    spec.side = 0;
+    spec.subdev = 0;
+  }
+  else if(spec_str == "A:1" || spec_str == "0:1") {
+    spec.side = 0;
+    spec.subdev = 1;
+  }
+  else if(spec_str == "B" || spec_str == "B:0" || spec_str == "1:0") {
+    spec.side = 1;
+    spec.subdev = 0;
+  }
+  else if(spec_str == "B:1" || spec_str == "1:1") {
+    spec.side = 1;
+    spec.subdev = 1;
+  }
+  else {
+    throw std::range_error("Incorrect subdevice specifications.\n");
+  }
+
+  return spec;
+}
+
 // Shared pointer constructor
 usrp_test_tx_sptr make_usrp_test_tx(int which, usrp_subdev_spec spec, 
-                                   int interp, double freq, float amp)
+                                   double rf_freq, int interp, double wfreq,
+                                   int waveform, float amp, float gain, 
+                                   float offset)
 {
   return gnuradio::get_initial_sptr(new usrp_test_tx(which, spec, 
-                                                    interp, freq, amp));
+                                                    rf_freq, interp, wfreq,
+                                                    waveform, amp, gain, 
+                                                    offset));
 }
 
 // Hierarchical block constructor, with no inputs or outputs
 usrp_test_tx::usrp_test_tx(int which, usrp_subdev_spec spec, 
-                          int interp, double freq, float amp) : 
+                          double rf_freq, int interp, double wfreq,
+                          int waveform, float amp, float gain, 
+                          float offset) :
     gr_top_block("usrp_test_tx")
 {
   usrp_sink_c_sptr usrp = usrp_make_sink_c(which, interp);
@@ -52,11 +86,16 @@
   printf("mux: %#08x\n",  mux);
   usrp->set_mux(mux);
 
+  if(gain == -1) {
+    gain = subdev->gain_max();
+  }
+  subdev->set_gain(gain);
+
   float input_rate = usrp->dac_freq() / usrp->interp_rate();
   printf("baseband rate: %g\n",  input_rate);
 
   usrp_tune_result r;
-  double target_freq = freq;
+  double target_freq = rf_freq;
   bool ok = usrp->tune(subdev->which(), subdev, target_freq, &r);
 
   if(!ok) {
@@ -72,10 +111,21 @@
   printf("r.residual_freq: %f\n", r.residual_freq);
   printf("r.inverted:      %d\n", r.inverted);
 
-  /* The rest */
-  printf("Amplitude: %f\n", amp);
-  source = gr_make_sig_source_c(input_rate, GR_SIN_WAVE, 1e3, amp);
-  
+  /* Set up the signal source */
+  siggen = gr_make_sig_source_c(input_rate, GR_SIN_WAVE, wfreq, amp);
+  noisegen = gr_make_noise_source_c (GR_UNIFORM, amp);
+  if(waveform == GR_SIN_WAVE || waveform == GR_CONST_WAVE) {
+    source = siggen;
+  }
+  else if(waveform == GR_UNIFORM || waveform == GR_GAUSSIAN) {
+    source = noisegen;
+  }
+  else {
+    throw std::range_error("Unknown waveform type.\n");
+  }
+
+  siggen->set_waveform((gr_waveform_t)waveform);
+
   connect(source, 0, usrp, 0);
 }
 
@@ -84,17 +134,30 @@
   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
+  double rf_freq = 0;                  // set the frequency
+  double wfreq = 100e3;                // set the waveform frequency
   float amp = 5;                       // set the amplitude of the output
+  float gain = -1;                     // set the d'board PGA gain
+  float offset = 0;                    // set waveform offset
+  int waveform;
 
   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")
+    ("which,W", po::value<int>(&which), "select which USRP board")
+    ("tx-subdev-spec,T", po::value<std::string>(), "select USRP Tx side A or 
B")
+    ("rf-freq,f", po::value<double>(), "set RF center frequency to FREQ")
+    ("interp,i", po::value<int>(&interp), "set fgpa interpolation rate to 
INTERP")
+
+    ("sine", "generate a complex sinusoid [default]")
+    ("const", "generate a constant output")
+    ("gaussian", "generate Gaussian random output")
+    ("uniform", "generate Uniform random output")
+
+    ("waveform-freq,w", po::value<double>(&wfreq), "set waveform frequency to 
FREQ")
     ("amplitdue,a", po::value<float>(&amp), "set amplitude")
+    ("gain,g", po::value<float>(&gain), "set output gain to GAIN")
+    ("offset,o", po::value<float>(&offset), "set waveform offset to OFFSET")
     ;
   
   po::variables_map vm;
@@ -107,8 +170,8 @@
     return 1;
   }
   
-  if(vm.count("frequency")) {
-    freq = vm["frequency"].as<double>();
+  if(vm.count("rf-freq")) {
+    rf_freq = vm["rf-freq"].as<double>();
   }
   else {
     fprintf(stderr, "You must specify a frequency.\n");
@@ -117,35 +180,34 @@
 
   if(vm.count("tx-subdev-spec")) {
     std::string s = vm["tx-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;
-    }
+    spec = str_to_subdev(s);
   }
 
-  printf("which:  %d\n", which);
-  printf("interp: %d\n", interp);
-  printf("freq:   %g\n", freq);
-  printf("amp:    %f\n", amp);
+  if(vm.count("sine")) {
+    waveform = GR_SIN_WAVE;
+  }
+  else if(vm.count("const")) {
+    waveform = GR_CONST_WAVE;
+  }
+  else if(vm.count("gaussian")) {
+    waveform = GR_GAUSSIAN;
+  }
+  else if(vm.count("uniform")) {
+    waveform = GR_UNIFORM;
+  }
+  else {
+    waveform = GR_SIN_WAVE;
+  }
 
-  usrp_test_tx_sptr top_block = make_usrp_test_tx(which, spec, 
-                                                 interp, freq, amp);
+  printf("which:   %d\n", which);
+  printf("interp:  %d\n", interp);
+  printf("rf_freq: %g\n", rf_freq);
+  printf("amp:     %f\n", amp);
+
+  usrp_test_tx_sptr top_block = make_usrp_test_tx(which, spec, rf_freq, 
+                                                 interp, wfreq, waveform,
+                                                 amp, gain, offset);
+
   top_block->run();
   
   return 0;

Modified: gnuradio/branches/features/cppdb/gr-usrp/apps/usrp_test_tx.h
===================================================================
--- gnuradio/branches/features/cppdb/gr-usrp/apps/usrp_test_tx.h        
2008-11-20 03:25:52 UTC (rev 10023)
+++ gnuradio/branches/features/cppdb/gr-usrp/apps/usrp_test_tx.h        
2008-11-20 05:55:38 UTC (rev 10024)
@@ -22,7 +22,10 @@
 #include <gr_top_block.h>
 #include <usrp_sink_c.h>
 #include <gr_sig_source_c.h>
+#include <gr_noise_source_c.h>
 
+usrp_subdev_spec str_to_subdev(std::string spec_str);
+
 class usrp_test_tx;
 typedef boost::shared_ptr<usrp_test_tx> usrp_test_tx_sptr;
 usrp_test_tx_sptr make_usrp_test_tx();
@@ -31,12 +34,16 @@
 {
 private:
     usrp_test_tx(int which, usrp_subdev_spec spec, 
-                int interp, double freq, float amp);
-    friend usrp_test_tx_sptr make_usrp_test_tx(int which, 
-                                              usrp_subdev_spec spec, 
-                                              int interp, double freq,
-                                              float amp);
+                double rf_freq, int interp, double wfreq,
+                int waveform, float amp, float gain, 
+                float offset);
+    friend usrp_test_tx_sptr make_usrp_test_tx(int which, usrp_subdev_spec 
spec, 
+                                              double rf_freq, int interp, 
double wfreq,
+                                              int waveform, float amp, float 
gain, 
+                                              float offset);
 
  public:
-    gr_sig_source_c_sptr source;
+    gr_block_sptr source;
+    gr_sig_source_c_sptr siggen;
+    gr_noise_source_c_sptr noisegen;
 };





reply via email to

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