From 9b2ae7e07787b248328ecbe44c07695bb6a796f2 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 11 Mar 2011 12:17:46 -0800 Subject: uhd: added continuous streaming and new options to tx_waveforms --- host/examples/rx_samples_to_file.cpp | 8 ++--- host/examples/tx_samples_from_file.cpp | 8 ++--- host/examples/tx_waveforms.cpp | 66 ++++++++++++++++++++++++---------- 3 files changed, 55 insertions(+), 27 deletions(-) (limited to 'host/examples') diff --git a/host/examples/rx_samples_to_file.cpp b/host/examples/rx_samples_to_file.cpp index 61add87c7..d44315701 100644 --- a/host/examples/rx_samples_to_file.cpp +++ b/host/examples/rx_samples_to_file.cpp @@ -78,11 +78,11 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ ("nsamps", po::value(&total_num_samps)->default_value(0), "total number of samples to receive") ("spb", po::value(&spb)->default_value(10000), "samples per buffer") ("rate", po::value(&rate), "rate of incoming samples") - ("freq", po::value(&freq), "rf center frequency in Hz") + ("freq", po::value(&freq), "RF center frequency in Hz") ("gain", po::value(&gain), "gain for the RF chain") - ("ant", po::value(&ant), "select antenna") - ("subdev", po::value(&subdev), "select subdevice") - ("bw", po::value(&bw), "select IF filter bandwidth in Hz") + ("ant", po::value(&ant), "daughterboard antenna selection") + ("subdev", po::value(&subdev), "daughterboard subdevice specification") + ("bw", po::value(&bw), "daughterboard IF filter bandwidth in Hz") ; po::variables_map vm; po::store(po::parse_command_line(argc, argv, desc), vm); diff --git a/host/examples/tx_samples_from_file.cpp b/host/examples/tx_samples_from_file.cpp index 7824f4389..acf899fa9 100644 --- a/host/examples/tx_samples_from_file.cpp +++ b/host/examples/tx_samples_from_file.cpp @@ -73,11 +73,11 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ ("type", po::value(&type)->default_value("float"), "sample type: double, float, or short") ("spb", po::value(&spb)->default_value(10000), "samples per buffer") ("rate", po::value(&rate), "rate of outgoing samples") - ("freq", po::value(&freq), "rf center frequency in Hz") + ("freq", po::value(&freq), "RF center frequency in Hz") ("gain", po::value(&gain), "gain for the RF chain") - ("ant", po::value(&ant), "select antenna") - ("subdev", po::value(&subdev), "select subdevice") - ("bw", po::value(&bw), "select IF filter bandwidth in Hz") + ("ant", po::value(&ant), "daughterboard antenna selection") + ("subdev", po::value(&subdev), "daughterboard subdevice specification") + ("bw", po::value(&bw), "daughterboard IF filter bandwidth in Hz") ; po::variables_map vm; po::store(po::parse_command_line(argc, argv, desc), vm); diff --git a/host/examples/tx_waveforms.cpp b/host/examples/tx_waveforms.cpp index 05d49a8b3..9c45e918b 100644 --- a/host/examples/tx_waveforms.cpp +++ b/host/examples/tx_waveforms.cpp @@ -20,16 +20,19 @@ #include #include #include -#include //system time #include #include #include #include #include +#include #include namespace po = boost::program_options; +static bool stop_signal_called = false; +void sig_int_handler(int){stop_signal_called = true;} + /*********************************************************************** * Waveform generators **********************************************************************/ @@ -61,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, wave_type; - size_t total_duration, spb; - double rate, freq, gain, wave_freq; + std::string args, wave_type, ant, subdev; + size_t spb; + double rate, freq, gain, wave_freq, bw; float ampl; //setup the program options @@ -71,12 +74,14 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ desc.add_options() ("help", "help message") ("args", po::value(&args)->default_value(""), "single uhd device address args") - ("duration", po::value(&total_duration)->default_value(3), "number of seconds to transmit") ("spb", po::value(&spb)->default_value(10000), "samples per buffer") - ("rate", po::value(&rate)->default_value(1.5e6), "rate of outgoing samples") - ("freq", po::value(&freq)->default_value(0), "rf center frequency in Hz") + ("rate", po::value(&rate), "rate of outgoing samples") + ("freq", po::value(&freq), "RF center frequency in Hz") ("ampl", po::value(&l)->default_value(float(0.3)), "amplitude of the waveform") - ("gain", po::value(&gain)->default_value(0), "gain for the RF chain") + ("gain", po::value(&gain), "gain for the RF chain") + ("ant", po::value(&ant), "daughterboard antenna selection") + ("subdev", po::value(&subdev), "daughterboard subdevice specification") + ("bw", po::value(&bw), "daughterboard IF filter bandwidth in Hz") ("wave-type", po::value(&wave_type)->default_value("CONST"), "waveform type (CONST, SQUARE, RAMP, SINE)") ("wave-freq", po::value(&wave_freq)->default_value(0), "waveform frequency in Hz") ; @@ -94,22 +99,43 @@ 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 tx 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 TX Rate: %f Msps...") % (rate/1e6) << std::endl; usrp->set_tx_rate(rate); std::cout << boost::format("Actual TX Rate: %f Msps...") % (usrp->get_tx_rate()/1e6) << std::endl << std::endl; - //set the tx center frequency - std::cout << boost::format("Setting TX 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 TX 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 tx rf 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 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; + } //for the const wave, set the wave freq for small samples per period if (wave_freq == 0 and wave_type == "CONST"){ @@ -144,9 +170,11 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ md.start_of_burst = false; //never SOB when continuous md.end_of_burst = false; - //send the data in multiple packets - boost::system_time end_time(boost::get_system_time() + boost::posix_time::seconds(total_duration)); - while(end_time > boost::get_system_time()){ + std::signal(SIGINT, &sig_int_handler); + std::cout << "Press Ctrl + C to stop streaming..." << std::endl; + + //send data until the signal handler gets called + while(not stop_signal_called){ //fill the buffer with the waveform for (size_t n = 0; n < buff.size(); n++){ -- cgit v1.2.3