diff options
author | Nicholas Corgan <nick.corgan@ettus.com> | 2012-10-10 12:54:26 -0700 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2012-10-10 13:29:43 -0700 |
commit | d9829759d4b63cbe28040cf46f54bdb70c7189e7 (patch) | |
tree | 7077c6e910c0e3d474ef55690a6c92ec708fcee7 | |
parent | 01d90259772520e555de4eacedd33aeebf51fa45 (diff) | |
download | uhd-d9829759d4b63cbe28040cf46f54bdb70c7189e7.tar.gz uhd-d9829759d4b63cbe28040cf46f54bdb70c7189e7.tar.bz2 uhd-d9829759d4b63cbe28040cf46f54bdb70c7189e7.zip |
examples: tx_samples_from_file can now repeatedly transmit file with optional delays between transmissions
-rw-r--r-- | host/examples/tx_samples_from_file.cpp | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/host/examples/tx_samples_from_file.cpp b/host/examples/tx_samples_from_file.cpp index c0812c007..04a6a63d4 100644 --- a/host/examples/tx_samples_from_file.cpp +++ b/host/examples/tx_samples_from_file.cpp @@ -1,5 +1,5 @@ // -// Copyright 2011 Ettus Research LLC +// Copyright 2011-2012 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -24,9 +24,13 @@ #include <iostream> #include <fstream> #include <complex> +#include <csignal> 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 send_from_file( uhd::usrp::multi_usrp::sptr usrp, const std::string &cpu_format, @@ -34,6 +38,7 @@ template<typename samp_type> void send_from_file( const std::string &file, size_t samps_per_buff ){ + //create a transmit streamer uhd::stream_args_t stream_args(cpu_format, wire_format); uhd::tx_streamer::sptr tx_stream = usrp->get_tx_stream(stream_args); @@ -45,7 +50,8 @@ template<typename samp_type> void send_from_file( std::ifstream infile(file.c_str(), std::ifstream::binary); //loop until the entire file has been read - while(not md.end_of_burst){ + + while(not md.end_of_burst and not stop_signal_called){ infile.read((char*)&buff.front(), buff.size()*sizeof(samp_type)); size_t num_tx_samps = infile.gcount()/sizeof(samp_type); @@ -64,7 +70,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ //variables to be set by po std::string args, file, type, ant, subdev, ref, wirefmt; size_t spb; - double rate, freq, gain, bw; + double rate, freq, gain, bw, delay; //setup the program options po::options_description desc("Allowed options"); @@ -82,6 +88,8 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ ("bw", po::value<double>(&bw), "daughterboard IF filter bandwidth in Hz") ("ref", po::value<std::string>(&ref)->default_value("internal"), "waveform type (internal, external, mimo)") ("wirefmt", po::value<std::string>(&wirefmt)->default_value("sc16"), "wire format (sc8 or sc16)") + ("delay", po::value<double>(&delay)->default_value(0.0), "specify a delay between repeated transmission of file") + ("repeat", "repeatedly transmit file") ; po::variables_map vm; po::store(po::parse_command_line(argc, argv, desc), vm); @@ -93,6 +101,8 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ return ~0; } + bool repeat = vm.count("repeat"); + //create a usrp device std::cout << std::endl; std::cout << boost::format("Creating the usrp device with: %s...") % args << std::endl; @@ -163,11 +173,21 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ UHD_ASSERT_THROW(ref_locked.to_bool()); } + //set sigint if user wants to receive + if(repeat){ + std::signal(SIGINT, &sig_int_handler); + std::cout << "Press Ctrl + C to stop streaming..." << std::endl; + } + //send from file - if (type == "double") send_from_file<std::complex<double> >(usrp, "fc64", wirefmt, file, spb); - else if (type == "float") send_from_file<std::complex<float> >(usrp, "fc32", wirefmt, file, spb); - else if (type == "short") send_from_file<std::complex<short> >(usrp, "sc16", wirefmt, file, spb); - else throw std::runtime_error("Unknown type " + type); + do{ + if (type == "double") send_from_file<std::complex<double> >(usrp, "fc64", wirefmt, file, spb); + else if (type == "float") send_from_file<std::complex<float> >(usrp, "fc32", wirefmt, file, spb); + else if (type == "short") send_from_file<std::complex<short> >(usrp, "sc16", wirefmt, file, spb); + else throw std::runtime_error("Unknown type " + type); + + if(repeat and delay != 0.0) boost::this_thread::sleep(boost::posix_time::milliseconds(delay)); + } while(repeat and not stop_signal_called); //finished std::cout << std::endl << "Done!" << std::endl << std::endl; |