diff options
| author | Josh Blum <josh@joshknows.com> | 2011-03-11 12:02:59 -0800 | 
|---|---|---|
| committer | Josh Blum <josh@joshknows.com> | 2011-03-11 12:02:59 -0800 | 
| commit | 60db6edf5209e3e2407db354bdb8a0691e8e4ef4 (patch) | |
| tree | 450102e6a517108c2497a2dc1ead37eafc029566 | |
| parent | 1ab3803180009399aba8d8c58d5fae2645ac1ff3 (diff) | |
| download | uhd-60db6edf5209e3e2407db354bdb8a0691e8e4ef4.tar.gz uhd-60db6edf5209e3e2407db354bdb8a0691e8e4ef4.tar.bz2 uhd-60db6edf5209e3e2407db354bdb8a0691e8e4ef4.zip | |
uhd: a lot of tweaking, new parameters, and sig handler for to/from file examples
| -rw-r--r-- | host/examples/rx_samples_to_file.cpp | 72 | ||||
| -rw-r--r-- | host/examples/tx_samples_from_file.cpp | 59 | 
2 files changed, 98 insertions, 33 deletions
| diff --git a/host/examples/rx_samples_to_file.cpp b/host/examples/rx_samples_to_file.cpp index bbfcc6d7c..61add87c7 100644 --- a/host/examples/rx_samples_to_file.cpp +++ b/host/examples/rx_samples_to_file.cpp @@ -23,10 +23,14 @@  #include <boost/thread.hpp>  #include <iostream>  #include <fstream> +#include <csignal>  #include <complex>  namespace po = boost::program_options; +static bool stop_signal_called = false; +void sig_int_handler(int){stop_signal_called = true;} +  template<typename samp_type> void recv_to_file(      uhd::usrp::multi_usrp::sptr usrp,      const uhd::io_type_t &io_type, @@ -37,7 +41,7 @@ template<typename samp_type> void recv_to_file(      std::vector<samp_type> buff(samps_per_buff);      std::ofstream outfile(file.c_str(), std::ofstream::binary); -    while(true){ +    while(not stop_signal_called){          size_t num_rx_samps = usrp->get_device()->recv(              &buff.front(), buff.size(), md, io_type,              uhd::device::RECV_MODE_FULL_BUFF @@ -60,9 +64,9 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){      uhd::set_thread_priority_safe();      //variables to be set by po -    std::string args, file, type; +    std::string args, file, type, ant, subdev;      size_t total_num_samps, spb; -    double rate, freq, gain; +    double rate, freq, gain, bw;      //setup the program options      po::options_description desc("Allowed options"); @@ -70,12 +74,15 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){          ("help", "help message")          ("args", po::value<std::string>(&args)->default_value(""), "multi uhd device address args")          ("file", po::value<std::string>(&file)->default_value("usrp_samples.dat"), "name of the file to write binary samples to") -        ("type", po::value<std::string>(&type)->default_value("float"), "choose the sample type: double, float, or short") -        ("nsamps", po::value<size_t>(&total_num_samps)->default_value(1000), "total number of samples to receive") +        ("type", po::value<std::string>(&type)->default_value("float"), "sample type: double, float, or short") +        ("nsamps", po::value<size_t>(&total_num_samps)->default_value(0), "total number of samples to receive")          ("spb", po::value<size_t>(&spb)->default_value(10000), "samples per buffer") -        ("rate", po::value<double>(&rate)->default_value(100e6/16), "rate of incoming samples") -        ("freq", po::value<double>(&freq)->default_value(0), "rf center frequency in Hz") -        ("gain", po::value<double>(&gain)->default_value(0), "gain for the RF chain") +        ("rate", po::value<double>(&rate), "rate of incoming samples") +        ("freq", po::value<double>(&freq), "rf center frequency in Hz") +        ("gain", po::value<double>(&gain), "gain for the RF chain") +        ("ant", po::value<std::string>(&ant), "select antenna") +        ("subdev", po::value<std::string>(&subdev), "select subdevice") +        ("bw", po::value<double>(&bw), "select IF filter bandwidth in Hz")      ;      po::variables_map vm;      po::store(po::parse_command_line(argc, argv, desc), vm); @@ -91,30 +98,61 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){      std::cout << std::endl;      std::cout << boost::format("Creating the usrp device with: %s...") % args << std::endl;      uhd::usrp::multi_usrp::sptr usrp = uhd::usrp::multi_usrp::make(args); + +    //always select the subdevice first, the channel mapping affects the other settings +    if (vm.count("subdev")) usrp->set_rx_subdev_spec(subdev); +      std::cout << boost::format("Using Device: %s") % usrp->get_pp_string() << std::endl; -    //set the rx sample rate +    //set the sample rate +    if (not vm.count("rate")){ +        std::cerr << "Please specify the sample rate with --rate" << std::endl; +        return ~0; +    }      std::cout << boost::format("Setting RX Rate: %f Msps...") % (rate/1e6) << std::endl;      usrp->set_rx_rate(rate);      std::cout << boost::format("Actual RX Rate: %f Msps...") % (usrp->get_rx_rate()/1e6) << std::endl << std::endl; -    //set the rx center frequency -    std::cout << boost::format("Setting RX Freq: %f Mhz...") % (freq/1e6) << std::endl; +    //set the center frequency +    if (not vm.count("freq")){ +        std::cerr << "Please specify the center frequency with --freq" << std::endl; +        return ~0; +    } +    std::cout << boost::format("Setting RX Freq: %f MHz...") % (freq/1e6) << std::endl;      usrp->set_rx_freq(freq); -    std::cout << boost::format("Actual RX Freq: %f Mhz...") % (usrp->get_rx_freq()/1e6) << std::endl << std::endl; +    std::cout << boost::format("Actual RX Freq: %f MHz...") % (usrp->get_rx_freq()/1e6) << std::endl << std::endl; + +    //set the rf gain +    if (vm.count("gain")){ +        std::cout << boost::format("Setting RX Gain: %f dB...") % gain << std::endl; +        usrp->set_rx_gain(gain); +        std::cout << boost::format("Actual RX Gain: %f dB...") % usrp->get_rx_gain() << std::endl << std::endl; +    } -    //set the rx rf gain -    std::cout << boost::format("Setting RX Gain: %f dB...") % gain << std::endl; -    usrp->set_rx_gain(gain); -    std::cout << boost::format("Actual RX Gain: %f dB...") % usrp->get_rx_gain() << std::endl << std::endl; +    //set the IF filter bandwidth +    if (vm.count("bw")){ +        std::cout << boost::format("Setting RX Bandwidth: %f MHz...") % bw << std::endl; +        usrp->set_rx_bandwidth(bw); +        std::cout << boost::format("Actual RX Bandwidth: %f MHz...") % usrp->get_rx_bandwidth() << std::endl << std::endl; +    } + +    //set the antenna +    if (vm.count("ant")) usrp->set_rx_antenna(ant);      boost::this_thread::sleep(boost::posix_time::seconds(1)); //allow for some setup time      //setup streaming -    uhd::stream_cmd_t stream_cmd(uhd::stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_DONE); +    uhd::stream_cmd_t stream_cmd((total_num_samps == 0)? +        uhd::stream_cmd_t::STREAM_MODE_START_CONTINUOUS: +        uhd::stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_DONE +    );      stream_cmd.num_samps = total_num_samps;      stream_cmd.stream_now = true;      usrp->issue_stream_cmd(stream_cmd); +    if (total_num_samps == 0){ +        std::signal(SIGINT, &sig_int_handler); +        std::cout << "Press Ctrl + C to stop streaming..." << std::endl; +    }      //recv to file      if (type == "double") recv_to_file<std::complex<double> >(usrp, uhd::io_type_t::COMPLEX_FLOAT64, file, spb); diff --git a/host/examples/tx_samples_from_file.cpp b/host/examples/tx_samples_from_file.cpp index 0483eaa76..7824f4389 100644 --- a/host/examples/tx_samples_from_file.cpp +++ b/host/examples/tx_samples_from_file.cpp @@ -60,9 +60,9 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){      uhd::set_thread_priority_safe();      //variables to be set by po -    std::string args, file, type; +    std::string args, file, type, ant, subdev;      size_t spb; -    double rate, freq, gain; +    double rate, freq, gain, bw;      //setup the program options      po::options_description desc("Allowed options"); @@ -70,11 +70,14 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){          ("help", "help message")          ("args", po::value<std::string>(&args)->default_value(""), "multi uhd device address args")          ("file", po::value<std::string>(&file)->default_value("usrp_samples.dat"), "name of the file to read binary samples from") -        ("type", po::value<std::string>(&type)->default_value("float"), "choose the sample type: double, float, or short") +        ("type", po::value<std::string>(&type)->default_value("float"), "sample type: double, float, or short")          ("spb", po::value<size_t>(&spb)->default_value(10000), "samples per buffer") -        ("rate", po::value<double>(&rate)->default_value(100e6/16), "rate of outgoing samples") -        ("freq", po::value<double>(&freq)->default_value(0), "rf center frequency in Hz") -        ("gain", po::value<double>(&gain)->default_value(0), "gain for the RF chain") +        ("rate", po::value<double>(&rate), "rate of outgoing samples") +        ("freq", po::value<double>(&freq), "rf center frequency in Hz") +        ("gain", po::value<double>(&gain), "gain for the RF chain") +        ("ant", po::value<std::string>(&ant), "select antenna") +        ("subdev", po::value<std::string>(&subdev), "select subdevice") +        ("bw", po::value<double>(&bw), "select IF filter bandwidth in Hz")      ;      po::variables_map vm;      po::store(po::parse_command_line(argc, argv, desc), vm); @@ -90,22 +93,46 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){      std::cout << std::endl;      std::cout << boost::format("Creating the usrp device with: %s...") % args << std::endl;      uhd::usrp::multi_usrp::sptr usrp = uhd::usrp::multi_usrp::make(args); + +    //always select the subdevice first, the channel mapping affects the other settings +    if (vm.count("subdev")) usrp->set_tx_subdev_spec(subdev); +      std::cout << boost::format("Using Device: %s") % usrp->get_pp_string() << std::endl; -    //set the rx sample rate -    std::cout << boost::format("Setting RX Rate: %f Msps...") % (rate/1e6) << std::endl; +    //set the sample rate +    if (not vm.count("rate")){ +        std::cerr << "Please specify the sample rate with --rate" << std::endl; +        return ~0; +    } +    std::cout << boost::format("Setting TX Rate: %f Msps...") % (rate/1e6) << std::endl;      usrp->set_tx_rate(rate); -    std::cout << boost::format("Actual RX Rate: %f Msps...") % (usrp->get_tx_rate()/1e6) << std::endl << std::endl; +    std::cout << boost::format("Actual TX Rate: %f Msps...") % (usrp->get_tx_rate()/1e6) << std::endl << std::endl; -    //set the rx center frequency -    std::cout << boost::format("Setting RX Freq: %f Mhz...") % (freq/1e6) << std::endl; +    //set the center frequency +    if (not vm.count("freq")){ +        std::cerr << "Please specify the center frequency with --freq" << std::endl; +        return ~0; +    } +    std::cout << boost::format("Setting TX Freq: %f MHz...") % (freq/1e6) << std::endl;      usrp->set_tx_freq(freq); -    std::cout << boost::format("Actual RX Freq: %f Mhz...") % (usrp->get_tx_freq()/1e6) << std::endl << std::endl; +    std::cout << boost::format("Actual TX Freq: %f MHz...") % (usrp->get_tx_freq()/1e6) << std::endl << std::endl; + +    //set the rf gain +    if (vm.count("gain")){ +        std::cout << boost::format("Setting TX Gain: %f dB...") % gain << std::endl; +        usrp->set_tx_gain(gain); +        std::cout << boost::format("Actual TX Gain: %f dB...") % usrp->get_tx_gain() << std::endl << std::endl; +    } + +    //set the IF filter bandwidth +    if (vm.count("bw")){ +        std::cout << boost::format("Setting TX Bandwidth: %f MHz...") % bw << std::endl; +        usrp->set_tx_bandwidth(bw); +        std::cout << boost::format("Actual TX Bandwidth: %f MHz...") % usrp->get_tx_bandwidth() << std::endl << std::endl; +    } -    //set the rx rf gain -    std::cout << boost::format("Setting RX Gain: %f dB...") % gain << std::endl; -    usrp->set_tx_gain(gain); -    std::cout << boost::format("Actual RX Gain: %f dB...") % usrp->get_tx_gain() << std::endl << std::endl; +    //set the antenna +    if (vm.count("ant")) usrp->set_tx_antenna(ant);      boost::this_thread::sleep(boost::posix_time::seconds(1)); //allow for some setup time | 
