[Discuss-gnuradio] transmitting from file stored by usrp_rx_cfile.py
From:
Jaze Dalton
Subject:
[Discuss-gnuradio] transmitting from file stored by usrp_rx_cfile.py
Date:
Thu, 2 Apr 2009 15:59:22 -0400
I am trying to transmit from a file stored using usrp_rx_cfile.py (or usrp_rx_cfile created using usrp_rx_cfile.cc/h). I have been able to successfully do this using a usrp_tx_cfile.cc/h program derived from the rx version. I can't, however, get similar functionality using python. I am new to python, so I am hoping I have just missed some key insight. I have listed below the source for my cc and py versions of usrp_tx_cfile and the associated command line output from the transmit side. I am running on Mac OS X with gnuradio code pulled down on Feb 13, 2009. My daughterboards are RFX2400 and I am receiving on two other machines with the same USRP set up, but different hardware and OS (Linux). I am using usrp_fft and usrp_oscope on the receiving side. To test functionality, I stored data on the Mac using usrp_rx_cfile while running "usrp_siggen -f 2500000000" on one of the other machines.
Also, I noticed that when I use the subdev->gain_min() and subdev->gain_max() functions, both return 0 instead of correct values.
C++ code is shown below first, followed by the non-working python code. Any help is much appreciated!
-Jaze
So, when I compile and run this code, I see the waveform on the receiver:
/* * usrp_tx_cfile.cc - code based on usrp_rx_cfile.cc */
// Shared pointer constructor
usrp_tx_cfile_sptr make_usrp_tx_cfile(int which, usrp_subdev_spec spec, int interp, double freq, float gain, bool width8, bool nohb, bool output_shorts, int nsamples,
const std::string &filename) { return gnuradio::get_initial_sptr(new usrp_tx_cfile(which, spec, interp, freq, gain, width8, nohb,
output_shorts, nsamples, filename)); }
// Hierarchical block constructor, with no inputs or outputs usrp_tx_cfile::usrp_tx_cfile(int which, usrp_subdev_spec spec,
int interp, double freq, float gain, bool width8, bool nohb, bool output_shorts, int nsamples, const std::string &filename) : gr_top_block("usrp_tx_cfile"),
d_which(which), d_spec(spec), d_interp(interp), d_freq(freq), d_gain(gain), d_width8(width8), d_nohb(nohb), d_nsamples(nsamples), d_filename(filename) { usrp_sink_c_sptr usrp = usrp_make_sink_c(d_which, d_interp);
// 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);
/* 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_tx_mux_value(d_spec); printf("mux: %#08x\n", mux); usrp->set_mux(mux);
float gain_min = subdev->gain_min();
float gain_max = subdev->gain_max(); printf ("gain min is %g. gain max is %g.\n", gain_min, gain_max); if(d_gain == -1) { //d_gain = (gain_min + gain_max)/2.0; printf("No gain specified. Setting to max gain.\n");
d_gain = gain_max; d_gain = 90; } printf("gain: %g\n", d_gain); subdev->set_gain(d_gain);
/* Set the USRP/dboard frequency */ usrp_tune_result r; //bool ok = usrp->tune(0, subdev, freq, &r); //DDC 0 bool ok = usrp->tune(subdev->which(), subdev, d_freq, &r);
if(!ok) {
throw std::runtime_error("Could not set frequency."); }
subdev->set_enable(true);
/* The rest */ d_src = gr_make_file_source(sizeof(gr_complex), d_filename.c_str());
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 interp = 128; // 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: usrp_tx_cfile [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 A or B (default=A)") ("interp,i", po::value<int>(&interp), "set fgpa interpolation rate to INTERP")
("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")
;
$ ~/gnuradio/gr-usrp/apps/usrp_tx_cfile -f 2500000000 in.dat which: 0 interp: 128 freq: 2.5e+09 gain: -1 width-8 No no-hb no
Subdevice name is A: Flex 2400 Tx MIMO B
Subdevice freq range: (2.3e+09, 2.7e+09) mux: 0x000098 gain min is 0. gain max is 0. No gain specified. Setting to max gain. gain: 90 baseband rate: 1e+06 $
Here is the python version, which doesn't seem to transmit anything:
#!/usr/bin/env python
""" Read samples a file and transmit using USRP
"""
from gnuradio import gr, eng_notation from gnuradio import audio from gnuradio import usrp
from gnuradio.eng_option import eng_option from optparse import OptionParser import sys
class my_top_block(gr.top_block):
def __init__(self): gr.top_block.__init__(self)
usage="%prog: [options] output_filename"
parser = OptionParser(option_class=eng_option, usage=usage) parser.add_option("-R", "--tx-subdev-spec", type="subdev", default=(0, 0), help="select USRP tx side A or B (default=A)")
parser.add_option("-i", "--interp", type="int", default=128, help="set fgpa decimation rate to INTERP [default=%default]") parser.add_option("-f", "--freq", type="eng_float", default=None,
help="set frequency to FREQ", metavar="FREQ") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)")
(options, args) = parser.parse_args () if len(args) != 1: parser.print_help() raise SystemExit, 1 filename = args[0]
if options.freq is None: parser.print_help()
sys.stderr.write('You must specify the frequency with -f FREQ\n'); raise SystemExit, 1
if options.tx_subdev_spec is None: options.tx_subdev_spec = usrp.pick_tx_subdevice(self.u) self.u.set_mux(usrp.determine_tx_mux_value(self.u, options.tx_subdev_spec))