[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r10048 - gnuradio/branches/features/cppdb/gr-usrp/apps
From: |
trondeau |
Subject: |
[Commit-gnuradio] r10048 - gnuradio/branches/features/cppdb/gr-usrp/apps |
Date: |
Mon, 24 Nov 2008 20:34:27 -0700 (MST) |
Author: trondeau
Date: 2008-11-24 20:34:26 -0700 (Mon, 24 Nov 2008)
New Revision: 10048
Modified:
gnuradio/branches/features/cppdb/gr-usrp/apps/usrp_test_rx.cc
gnuradio/branches/features/cppdb/gr-usrp/apps/usrp_test_rx.h
Log:
Adding options to rx test file to mimic usrp_rx_cfile.
Modified: gnuradio/branches/features/cppdb/gr-usrp/apps/usrp_test_rx.cc
===================================================================
--- gnuradio/branches/features/cppdb/gr-usrp/apps/usrp_test_rx.cc
2008-11-24 20:50:00 UTC (rev 10047)
+++ gnuradio/branches/features/cppdb/gr-usrp/apps/usrp_test_rx.cc
2008-11-25 03:34:26 UTC (rev 10048)
@@ -28,105 +28,183 @@
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_rx_sptr make_usrp_test_rx(int which, usrp_subdev_spec spec,
int decim, double freq, float gain,
- int nsamples)
+ bool width8, bool nohb,
+ bool output_shorts, int nsamples,
+ const std::string &filename)
{
return gnuradio::get_initial_sptr(new usrp_test_rx(which, spec,
decim, freq, gain,
- nsamples));
+ width8, nohb,
+ output_shorts,
+ nsamples,
+ filename));
}
// 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 nsamples) :
- gr_top_block("usrp_test_rx")
+ bool width8, bool nohb,
+ bool output_shorts, int nsamples,
+ const std::string &filename) :
+ gr_top_block("usrp_test_rx"),
+ d_which(which), d_spec(spec), d_decim(decim), d_freq(freq),
+ d_gain(gain), d_width8(width8), d_nohb(nohb), d_nsamples(nsamples),
+ d_filename(filename)
{
- usrp_source_c_sptr usrp = usrp_make_source_c(which, decim);
+ usrp_source_c_sptr usrp;
- db_base_sptr subdev = usrp->selected_subdev(spec);
- printf("Subdevice name is %s\n", subdev->side_and_name().c_str());
+ if(d_nohb || (d_decim<8)) {
+ // Min decimation of this firmware is 4.
+ // contains 4 Rx paths without halfbands and 0 tx paths.
+ std::string fpga_filename="std_4rx_0tx.rbf";
+
+ // use default values and add fpga_filename
+ usrp = usrp_make_source_c(d_which, d_decim,
+ 1, -1, 0, 0, 0,
+ fpga_filename.c_str());
+ }
+ else {
+ // standard fpga firmware "std_2rxhb_2tx.rbf" contains
+ // 2 Rx paths with halfband filters and 2 tx paths
+ //(the default) min decimation 8
+ usrp = usrp_make_source_c(d_which, d_decim);
+ }
+
+ if(d_width8) {
+ int sample_width = 8;
+ int sample_shift = 8;
+ int format = usrp->make_format(sample_width, sample_shift);
+ int r = usrp->set_format(format);
+ printf("width8: format=%d r=%d\n", format, r);
+ }
+
+
+ /* Get subdevice and process it */
+ db_base_sptr subdev = usrp->selected_subdev(d_spec);
+ printf("\nSubdevice 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);
+ unsigned int mux = usrp->determine_rx_mux_value(d_spec);
printf("mux: %#08x\n", mux);
usrp->set_mux(mux);
- float input_rate = usrp->adc_freq() / usrp->decim_rate();
- printf("baseband rate: %g\n", input_rate);
-
float gain_min = subdev->gain_min();
float gain_max = subdev->gain_max();
- printf("gain range: (%g, %g)\n", gain_min, gain_max);
- if(gain == -1) {
- gain = (gain_min + gain_max)/2.0;
+ if(d_gain == -1) {
+ d_gain = (gain_min + gain_max)/2.0;
}
- printf("gain: %g\n", gain);
- subdev->set_gain(gain);
-
+ printf("gain: %g\n", d_gain);
+ subdev->set_gain(d_gain);
+
+
+ /* Set the USRP/dboard frequency */
usrp_tune_result r;
- double target_freq = freq;
- bool ok = usrp->tune(0, subdev, target_freq, &r);
+ bool ok = usrp->tune(subdev->which(), subdev, freq, &r);
- printf("target_freq: %f\n", target_freq);
- printf("ok: %s\n", ok ? "true" : "false");
- printf("r.baseband_freq: %f\n", r.baseband_freq);
- printf("r.dxc_freq: %f\n", r.dxc_freq);
- printf("r.residual_freq: %f\n", r.residual_freq);
- printf("r.inverted: %d\n", r.inverted);
-
if(!ok) {
throw std::runtime_error("Could not set frequency.");
}
/* The rest */
- gr_block_sptr head = gr_make_head(sizeof(gr_complex), nsamples);
- fsink = gr_make_file_sink(sizeof(gr_complex), "received.dat");
+ d_dst = gr_make_file_sink(sizeof(gr_complex), d_filename.c_str());
- if(nsamples == -1) {
- connect(usrp, 0, fsink, 0);
+ if(d_nsamples == -1) {
+ connect(usrp, 0, d_dst, 0);
}
else {
- connect(usrp, 0, head, 0);
- connect(head, 0, fsink, 0);
+ d_head = gr_make_head(sizeof(gr_complex), d_nsamples*2);
+ connect(usrp, 0, d_head, 0);
+ connect(d_head, 0, d_dst, 0);
}
}
+
int main(int argc, char *argv[])
{
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
+ int decim = 16; // 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
+ bool width8 = false; // use 8-bit samples across USB
+ bool nohb = false; // don't use halfband filter in USRP
+ bool output_shorts = false; // use shorts
+ std::string filename = "received.dat";
- po::options_description cmdconfig("Program options");
+ po::options_description cmdconfig("Program options: usrp_text_rx [options]
filename");
cmdconfig.add_options()
("help,h", "produce help message")
- ("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>(&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")
+ ("which,W", po::value<int>(&which), "select which USRP board")
+ ("rx-subdev-spec,R", po::value<std::string>(), "select USRP Rx side A or B
(default=A)")
+ ("decim,d", po::value<int>(&decim), "set fgpa decimation rate to DECIM")
+ ("freq,f", po::value<double>(), "set frequency to FREQ")
+ ("gain,g", po::value<float>(), "set gain in dB (default is midpoint)")
+ ("width-8,8", "Enable 8-bit samples across USB")
+ ("no-hb", "don't use halfband filter in usrp")
+ ("output-shorts,s", "output interleaved shorts in stead of complex floats")
+ ("nsamples,N", po::value<int>(&nsamples), "number of samples to collect")
;
+
+ po::options_description fileconfig("Input file options");
+ fileconfig.add_options()
+ ("filename", po::value<std::string>(), "input file")
+ ;
+
+ po::positional_options_description inputfile;
+ inputfile.add("filename", -1);
+
+ po::options_description config;
+ config.add(cmdconfig).add(fileconfig);
po::variables_map vm;
po::store(po::command_line_parser(argc, argv).
- options(cmdconfig).run(), vm);
+ options(config).positional(inputfile).run(), vm);
po::notify(vm);
if (vm.count("help")) {
std::cout << cmdconfig << "\n";
return 1;
}
+
+ if(vm.count("filename")) {
+ filename = vm["filename"].as<std::string>();
+ }
- if(vm.count("frequency")) {
- freq = vm["frequency"].as<double>();
+ if(vm.count("freq")) {
+ freq = vm["freq"].as<double>();
}
else {
fprintf(stderr, "You must specify a frequency.\n");
@@ -135,37 +213,32 @@
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;
- }
+ spec = str_to_subdev(s);
}
- 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);
+ if(vm.count("width-8")) {
+ width8 = true;
+ }
+ if(vm.count("nohb")) {
+ nohb = true;
+ }
+ if(vm.count("output-shorts")) {
+ output_shorts = true;
+ }
- usrp_test_rx_sptr top_block = make_usrp_test_rx(which, spec,
- decim, freq, gain,
- nsamples);
+ std::cout << "which: " << which << std::endl;
+ std::cout << "decim: " << decim << std::endl;
+ std::cout << "freq: " << freq << std::endl;
+ std::cout << "gain: " << gain << std::endl;
+ std::cout << "width-8 " << (width8 ? "Yes" : "No") << std::endl;
+ std::cout << "no-hb " << (nohb ? "Yes" : "no") << std::endl;
+ std::cout << "shorts: " << (output_shorts ? "Yes" : "No") << std::endl;
+ std::cout << "samples: " << nsamples << std::endl;
+
+ usrp_test_rx_sptr top_block = make_usrp_test_rx(which, spec, decim, freq,
+ gain, width8, nohb,
+ output_shorts, nsamples,
+ filename);
top_block->run();
return 0;
Modified: gnuradio/branches/features/cppdb/gr-usrp/apps/usrp_test_rx.h
===================================================================
--- gnuradio/branches/features/cppdb/gr-usrp/apps/usrp_test_rx.h
2008-11-24 20:50:00 UTC (rev 10047)
+++ gnuradio/branches/features/cppdb/gr-usrp/apps/usrp_test_rx.h
2008-11-25 03:34:26 UTC (rev 10048)
@@ -20,24 +20,43 @@
*/
#include <gr_top_block.h>
+#include <usrp_source_base.h>
#include <usrp_source_c.h>
+#include <usrp_source_s.h>
#include <gr_file_sink.h>
class usrp_test_rx;
typedef boost::shared_ptr<usrp_test_rx> usrp_test_rx_sptr;
-usrp_test_rx_sptr make_usrp_test_rx();
+usrp_test_rx_sptr make_usrp_test_rx(int which, usrp_subdev_spec spec,
+ int decim, double freq, float gain,
+ bool width8, bool nohb,
+ bool output_shorts, int nsamples,
+ const std::string &filename);
class usrp_test_rx : public gr_top_block
{
private:
usrp_test_rx(int which, usrp_subdev_spec spec,
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, int nsamples);
+ bool width8, bool nohb,
+ bool output_shorts, int nsamples,
+ const std::string &filename);
+ friend usrp_test_rx_sptr make_usrp_test_rx(int which, usrp_subdev_spec
spec,
+ int decim, double freq, float
gain,
+ bool width8, bool nohb,
+ bool output_shorts, int nsamples,
+ const std::string &filename);
+ int d_which;
+ usrp_subdev_spec d_spec;
+ int d_decim;
+ double d_freq;
+ float d_gain;
+ bool d_width8, d_nohb;
+ int d_nsamples;
+ std::string d_filename;
+
public:
- gr_file_sink_sptr fsink;
+ gr_block_sptr d_head;
+ gr_block_sptr d_dst;
};
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r10048 - gnuradio/branches/features/cppdb/gr-usrp/apps,
trondeau <=