summaryrefslogtreecommitdiffstats
path: root/host/examples
diff options
context:
space:
mode:
Diffstat (limited to 'host/examples')
-rw-r--r--host/examples/CMakeLists.txt5
-rw-r--r--host/examples/benchmark_rate.cpp57
-rw-r--r--host/examples/test_dboard_coercion.cpp604
-rw-r--r--host/examples/test_timed_commands.cpp129
-rw-r--r--host/examples/transport_hammer.cpp340
-rw-r--r--host/examples/tx_waveforms.cpp5
6 files changed, 1122 insertions, 18 deletions
diff --git a/host/examples/CMakeLists.txt b/host/examples/CMakeLists.txt
index 3c9a3880a..b49268652 100644
--- a/host/examples/CMakeLists.txt
+++ b/host/examples/CMakeLists.txt
@@ -1,5 +1,5 @@
#
-# Copyright 2010-2011 Ettus Research LLC
+# Copyright 2010-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
@@ -25,8 +25,11 @@ SET(example_sources
rx_samples_to_file.cpp
rx_samples_to_udp.cpp
rx_timed_samples.cpp
+ test_dboard_coercion.cpp
test_messages.cpp
test_pps_input.cpp
+ test_timed_commands.cpp
+ transport_hammer.cpp
tx_bursts.cpp
tx_samples_from_file.cpp
tx_timed_samples.cpp
diff --git a/host/examples/benchmark_rate.cpp b/host/examples/benchmark_rate.cpp
index 8f00e25de..8a000f6c3 100644
--- a/host/examples/benchmark_rate.cpp
+++ b/host/examples/benchmark_rate.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
@@ -16,6 +16,7 @@
//
#include <uhd/utils/thread_priority.hpp>
+#include <uhd/convert.hpp>
#include <uhd/utils/safe_main.hpp>
#include <uhd/usrp/multi_usrp.hpp>
#include <boost/program_options.hpp>
@@ -40,11 +41,13 @@ unsigned long long num_seq_errors = 0;
/***********************************************************************
* Benchmark RX Rate
**********************************************************************/
-void benchmark_rx_rate(uhd::usrp::multi_usrp::sptr usrp, const std::string &rx_otw){
+void benchmark_rx_rate(uhd::usrp::multi_usrp::sptr usrp, const std::string &rx_cpu, const std::string &rx_otw){
uhd::set_thread_priority_safe();
//create a receive streamer
- uhd::stream_args_t stream_args("fc32", rx_otw); //complex floats
+ uhd::stream_args_t stream_args(rx_cpu, rx_otw);
+ for (size_t ch = 0; ch < usrp->get_num_mboards(); ch++) //linear channel mapping
+ stream_args.channels.push_back(ch);
uhd::rx_streamer::sptr rx_stream = usrp->get_rx_stream(stream_args);
//print pre-test summary
@@ -55,16 +58,20 @@ void benchmark_rx_rate(uhd::usrp::multi_usrp::sptr usrp, const std::string &rx_o
//setup variables and allocate buffer
uhd::rx_metadata_t md;
const size_t max_samps_per_packet = rx_stream->get_max_num_samps();
- std::vector<std::complex<float> > buff(max_samps_per_packet);
+ std::vector<char> buff(max_samps_per_packet*uhd::convert::get_bytes_per_item(rx_cpu));
+ std::vector<void *> buffs;
+ for (size_t ch = 0; ch < stream_args.channels.size(); ch++)
+ buffs.push_back(&buff.front()); //same buffer for each channel
bool had_an_overflow = false;
uhd::time_spec_t last_time;
const double rate = usrp->get_rx_rate();
- usrp->issue_stream_cmd(uhd::stream_cmd_t::STREAM_MODE_START_CONTINUOUS);
+ uhd::stream_cmd_t cmd(uhd::stream_cmd_t::STREAM_MODE_START_CONTINUOUS);
+ cmd.time_spec = usrp->get_time_now() + uhd::time_spec_t(0.05);
+ cmd.stream_now = (buffs.size() == 1);
+ usrp->issue_stream_cmd(cmd);
while (not boost::this_thread::interruption_requested()){
- num_rx_samps += rx_stream->recv(
- &buff.front(), buff.size(), md
- );
+ num_rx_samps += rx_stream->recv(buffs, max_samps_per_packet, md);
//handle the error codes
switch(md.error_code){
@@ -94,11 +101,13 @@ void benchmark_rx_rate(uhd::usrp::multi_usrp::sptr usrp, const std::string &rx_o
/***********************************************************************
* Benchmark TX Rate
**********************************************************************/
-void benchmark_tx_rate(uhd::usrp::multi_usrp::sptr usrp, const std::string &tx_otw){
+void benchmark_tx_rate(uhd::usrp::multi_usrp::sptr usrp, const std::string &tx_cpu, const std::string &tx_otw){
uhd::set_thread_priority_safe();
//create a transmit streamer
- uhd::stream_args_t stream_args("fc32", tx_otw); //complex floats
+ uhd::stream_args_t stream_args(tx_cpu, tx_otw);
+ for (size_t ch = 0; ch < usrp->get_num_mboards(); ch++) //linear channel mapping
+ stream_args.channels.push_back(ch);
uhd::tx_streamer::sptr tx_stream = usrp->get_tx_stream(stream_args);
//print pre-test summary
@@ -108,17 +117,22 @@ void benchmark_tx_rate(uhd::usrp::multi_usrp::sptr usrp, const std::string &tx_o
//setup variables and allocate buffer
uhd::tx_metadata_t md;
- md.has_time_spec = false;
+ md.time_spec = usrp->get_time_now() + uhd::time_spec_t(0.05);
const size_t max_samps_per_packet = tx_stream->get_max_num_samps();
- std::vector<std::complex<float> > buff(max_samps_per_packet);
+ std::vector<char> buff(max_samps_per_packet*uhd::convert::get_bytes_per_item(tx_cpu));
+ std::vector<const void *> buffs;
+ for (size_t ch = 0; ch < stream_args.channels.size(); ch++)
+ buffs.push_back(&buff.front()); //same buffer for each channel
+ md.has_time_spec = (buffs.size() != 1);
while (not boost::this_thread::interruption_requested()){
- num_tx_samps += tx_stream->send(&buff.front(), buff.size(), md);
+ num_tx_samps += tx_stream->send(buffs, max_samps_per_packet, md);
+ md.has_time_spec = false;
}
//send a mini EOB packet
md.end_of_burst = true;
- tx_stream->send("", 0, md);
+ tx_stream->send(buffs, 0, md);
}
void benchmark_tx_rate_async_helper(uhd::usrp::multi_usrp::sptr usrp){
@@ -163,6 +177,8 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
double duration;
double rx_rate, tx_rate;
std::string rx_otw, tx_otw;
+ std::string rx_cpu, tx_cpu;
+ std::string mode;
//setup the program options
po::options_description desc("Allowed options");
@@ -174,6 +190,9 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
("tx_rate", po::value<double>(&tx_rate), "specify to perform a TX rate test (sps)")
("rx_otw", po::value<std::string>(&rx_otw)->default_value("sc16"), "specify the over-the-wire sample mode for RX")
("tx_otw", po::value<std::string>(&tx_otw)->default_value("sc16"), "specify the over-the-wire sample mode for TX")
+ ("rx_cpu", po::value<std::string>(&rx_cpu)->default_value("fc32"), "specify the host/cpu sample mode for RX")
+ ("tx_cpu", po::value<std::string>(&tx_cpu)->default_value("fc32"), "specify the host/cpu sample mode for TX")
+ ("mode", po::value<std::string>(&mode)->default_value("none"), "multi-channel sync mode option: none, mimo")
;
po::variables_map vm;
po::store(po::parse_command_line(argc, argv, desc), vm);
@@ -201,18 +220,24 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
uhd::usrp::multi_usrp::sptr usrp = uhd::usrp::multi_usrp::make(args);
std::cout << boost::format("Using Device: %s") % usrp->get_pp_string() << std::endl;
+ if (mode == "mimo"){
+ usrp->set_clock_source("mimo", 0);
+ usrp->set_time_source("mimo", 0);
+ boost::this_thread::sleep(boost::posix_time::seconds(1));
+ }
+
boost::thread_group thread_group;
//spawn the receive test thread
if (vm.count("rx_rate")){
usrp->set_rx_rate(rx_rate);
- thread_group.create_thread(boost::bind(&benchmark_rx_rate, usrp, rx_otw));
+ thread_group.create_thread(boost::bind(&benchmark_rx_rate, usrp, rx_cpu, rx_otw));
}
//spawn the transmit test thread
if (vm.count("tx_rate")){
usrp->set_tx_rate(tx_rate);
- thread_group.create_thread(boost::bind(&benchmark_tx_rate, usrp, tx_otw));
+ thread_group.create_thread(boost::bind(&benchmark_tx_rate, usrp, tx_cpu, tx_otw));
thread_group.create_thread(boost::bind(&benchmark_tx_rate_async_helper, usrp));
}
diff --git a/host/examples/test_dboard_coercion.cpp b/host/examples/test_dboard_coercion.cpp
new file mode 100644
index 000000000..03dd6dbe9
--- /dev/null
+++ b/host/examples/test_dboard_coercion.cpp
@@ -0,0 +1,604 @@
+//
+// Copyright 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
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+//
+
+#include <uhd/utils/thread_priority.hpp>
+#include <uhd/utils/safe_main.hpp>
+#include <uhd/usrp/multi_usrp.hpp>
+#include <boost/program_options.hpp>
+#include <boost/format.hpp>
+#include <boost/thread/thread.hpp>
+#include <boost/math/special_functions/round.hpp>
+#include <iostream>
+#include <complex>
+#include <vector>
+
+namespace po = boost::program_options;
+
+/************************************************************************
+ * Misc functions
+************************************************************************/
+
+std::string return_MHz_string(double freq){
+ std::string nice_string = std::string(str(boost::format("%5.2f MHz") % (freq / 1e6)));
+ return nice_string;
+}
+
+std::string return_USRP_config_string(uhd::usrp::multi_usrp::sptr usrp, bool test_tx, bool test_rx){
+ uhd::dict<std::string, std::string> tx_info = usrp->get_usrp_tx_info();
+ uhd::dict<std::string, std::string> rx_info = usrp->get_usrp_rx_info();
+ std::string info_string;
+ std::string mboard_id, mboard_serial;
+ std::string tx_serial, tx_subdev_name, tx_subdev_spec;
+ std::string rx_serial, rx_subdev_name, rx_subdev_spec;
+
+ mboard_id = tx_info.get("mboard_id");
+ if(tx_info.get("mboard_serial") != "") mboard_serial = tx_info.get("mboard_serial");
+ else mboard_serial = "no serial";
+
+ info_string = std::string(str(boost::format("Motherboard: %s (%s)\n") % mboard_id % mboard_serial));
+
+ if(test_tx){
+ if(tx_info.get("tx_serial") != "") tx_serial = tx_info.get("tx_serial");
+ else tx_serial = "no serial";
+ tx_subdev_name = tx_info.get("tx_subdev_name");
+ tx_subdev_spec = tx_info.get("tx_subdev_spec");
+
+ info_string += std::string(str(boost::format("TX: %s (%s, %s)") % tx_subdev_name % tx_serial % tx_subdev_spec));
+ }
+ if(test_tx and test_rx) info_string += "\n";
+ if(test_rx){
+ if(rx_info.get("rx_serial") != "") rx_serial = rx_info.get("rx_serial");
+ else rx_serial = "no serial";
+ rx_subdev_name = rx_info.get("rx_subdev_name");
+ rx_subdev_spec = rx_info.get("rx_subdev_spec");
+
+ info_string += std::string(str(boost::format("RX: %s (%s, %s)") % rx_subdev_name % rx_serial % rx_subdev_spec));
+ }
+
+ return info_string;
+}
+
+/************************************************************************
+ * TX Frequency/Gain Coercion
+************************************************************************/
+
+std::string tx_test(uhd::usrp::multi_usrp::sptr usrp, bool test_gain, std::string ref, bool verbose){
+
+ //Establish frequency range
+
+ std::vector<double> freqs;
+ std::vector<double> xcvr_freqs;
+
+ BOOST_FOREACH(const uhd::range_t &range, usrp->get_fe_tx_freq_range()){
+ double freq_begin = range.start();
+ double freq_end = range.stop();
+ double freq_step;
+
+ if(usrp->get_usrp_tx_info().get("tx_subdev_name") == "XCVR2450 TX"){
+ xcvr_freqs.push_back(freq_begin);
+ xcvr_freqs.push_back(freq_end);
+ }
+
+ if(freq_end - freq_begin > 1000e6) freq_step = 100e6;
+ else if(freq_end - freq_begin < 300e6) freq_step = 10e6;
+ else freq_step = 50e6;
+
+ double current_freq = freq_begin;
+
+ while(current_freq < freq_end){
+ freqs.push_back(current_freq);
+ current_freq += freq_step;
+ }
+ if(freq_end != *freqs.end()) freqs.push_back(freq_end);
+ }
+
+ std::vector<double> gains;
+
+ if(test_gain){
+
+ //Establish gain range
+
+ double gain_begin = usrp->get_tx_gain_range().start();
+ if(gain_begin < 0.0) gain_begin = 0.0;
+ double gain_end = usrp->get_tx_gain_range().stop();
+
+ double current_gain = gain_begin;
+ while(current_gain < gain_end){
+ gains.push_back(current_gain);
+ current_gain++;
+ }
+ if(gain_end != *gains.end()) gains.push_back(gain_end);
+
+ }
+
+ //Establish error-storing variables
+
+ std::vector<double> bad_tune_freqs;
+ std::vector<double> no_lock_freqs;
+ std::vector< std::vector< double > > bad_gain_vals;
+ std::vector<std::string> dboard_sensor_names = usrp->get_tx_sensor_names();
+ std::vector<std::string> mboard_sensor_names = usrp->get_mboard_sensor_names();
+ bool has_sensor;
+
+ if(ref == "internal") has_sensor = (std::find(dboard_sensor_names.begin(), dboard_sensor_names.end(), "lo_locked")) != dboard_sensor_names.end();
+ else if(ref == "external") has_sensor = (std::find(mboard_sensor_names.begin(), mboard_sensor_names.end(), "ref_locked")) != mboard_sensor_names.end();
+ else has_sensor = (std::find(mboard_sensor_names.begin(), mboard_sensor_names.end(), "mimo_locked")) != mboard_sensor_names.end();
+
+ for(std::vector<double>::iterator f = freqs.begin(); f != freqs.end(); ++f){
+
+ //Testing for successful frequency tune
+
+ usrp->set_tx_freq(*f);
+ boost::this_thread::sleep(boost::posix_time::microseconds(long(1000)));
+
+ double actual_freq = usrp->get_tx_freq();
+
+ if(*f == 0.0){
+ if(floor(actual_freq + 0.5) == 0.0){
+ if(verbose) std::cout << boost::format("\nTX frequency successfully tuned to %s.") % return_MHz_string(*f) << std::endl;
+ }
+ else{
+ if(verbose) std::cout << boost::format("\nTX frequency tuned to %s instead of %s.") % return_MHz_string(actual_freq) % return_MHz_string(*f) << std::endl;
+ }
+ }
+ else{
+ if((*f / actual_freq > 0.9999) and (*f / actual_freq < 1.0001)){
+ if(verbose) std::cout << boost::format("\nTX frequency successfully tuned to %s.") % return_MHz_string(*f) << std::endl;
+ }
+ else{
+ if(verbose) std::cout << boost::format("\nTX frequency tuned to %s instead of %s.") % return_MHz_string(actual_freq) % return_MHz_string(*f) << std::endl;
+ bad_tune_freqs.push_back(*f);
+ }
+ }
+
+ //Testing for successful lock
+
+ if(has_sensor){
+ if(ref == "internal"){
+ if(usrp->get_tx_sensor("lo_locked",0).to_bool()){
+ if(verbose) std::cout << boost::format("LO successfully locked at TX frequency %s.") % return_MHz_string(*f) << std::endl;
+ }
+ else{
+ if(verbose) std::cout << boost::format("LO did not successfully lock at TX frequency %s.") % return_MHz_string(*f) << std::endl;
+ no_lock_freqs.push_back(*f);
+ }
+ }
+ else if(ref == "external"){
+ if(usrp->get_mboard_sensor("ref_locked",0).to_bool()){
+ if(verbose) std::cout << boost::format("REF successfully locked at TX frequency %s.") % return_MHz_string(*f) << std::endl;
+ }
+ else{
+ if(verbose) std::cout << boost::format("REF did not successfully lock at TX frequency %s.") % return_MHz_string(*f) << std::endl;
+ no_lock_freqs.push_back(*f);
+ }
+ }
+ else if(ref == "mimo"){
+ if(usrp->get_mboard_sensor("mimo_locked",0).to_bool()){
+ if(verbose) std::cout << boost::format("MIMO successfully locked at TX frequency %s.") % return_MHz_string(*f) << std::endl;
+ }
+ else{
+ if(verbose) std::cout << boost::format("MIMO did not successfully lock at TX frequency %s.") % return_MHz_string(*f) << std::endl;
+ no_lock_freqs.push_back(*f);
+ }
+ }
+ }
+
+ if(test_gain){
+
+ //Testing for successful gain tune
+
+ for(std::vector<double>::iterator g = gains.begin(); g != gains.end(); ++g){
+ usrp->set_tx_gain(*g);
+ boost::this_thread::sleep(boost::posix_time::microseconds(1000));
+
+ double actual_gain = usrp->get_tx_gain();
+
+ if(*g == 0.0){
+ if(actual_gain == 0.0){
+ if(verbose) std::cout << boost::format("TX gain successfully set to %5.2f at TX frequency %s.") % *g % return_MHz_string(*f) << std::endl;
+ }
+ else{
+ if(verbose) std::cout << boost::format("TX gain set to %5.2f instead of %5.2f at TX frequency %s.") % actual_gain % *g % return_MHz_string(*f) << std::endl;
+ std::vector<double> bad_gain_freq;
+ bad_gain_freq.push_back(*f);
+ bad_gain_freq.push_back(*g);
+ bad_gain_vals.push_back(bad_gain_freq);
+ }
+ }
+ else{
+ if((*g / actual_gain) > 0.9 and (*g / actual_gain) < 1.1){
+ if(verbose) std::cout << boost::format("TX gain successfully set to %5.2f at TX frequency %s.") % *g % return_MHz_string(*f) << std::endl;
+ }
+ else{
+ if(verbose) std::cout << boost::format("TX gain set to %5.2f instead of %5.2f at TX frequency %s.") % actual_gain % *g % return_MHz_string(*f) << std::endl;
+ std::vector<double> bad_gain_freq;
+ bad_gain_freq.push_back(*f);
+ bad_gain_freq.push_back(*g);
+ bad_gain_vals.push_back(bad_gain_freq);
+ }
+ }
+ }
+ }
+ }
+
+ std::string tx_results = "TX Summary:\n";
+ if(usrp->get_usrp_tx_info().get("tx_subdev_name") == "XCVR2450 TX"){
+ tx_results += std::string(str(boost::format("Frequency Range: %s - %s, %s - %s\n") % return_MHz_string(xcvr_freqs.at(0)) % return_MHz_string(xcvr_freqs.at(1)) %
+ return_MHz_string(xcvr_freqs.at(2)) % return_MHz_string(xcvr_freqs.at(3))));
+ }
+ else tx_results += std::string(str(boost::format("Frequency Range: %s - %s\n") % return_MHz_string(freqs.front()) % return_MHz_string(freqs.back())));
+ if(test_gain) tx_results += std::string(str(boost::format("Gain Range: %5.2f - %5.2f\n") % gains.front() % gains.back()));
+
+ if(bad_tune_freqs.empty()) tx_results += "USRP successfully tuned to all frequencies.";
+ else{
+ tx_results += "USRP did not successfully tune to the following frequencies: ";
+ for(std::vector<double>::iterator i = bad_tune_freqs.begin(); i != bad_tune_freqs.end(); ++i){
+ if(i != bad_tune_freqs.begin()) tx_results += ", ";
+ tx_results += return_MHz_string(*i);
+ }
+ }
+ if(has_sensor){
+
+ std::string sensor_str;
+ if(ref == "internal") sensor_str = "LO";
+ else if(ref == "external") sensor_str = "REF";
+ else if(ref == "mimo") sensor_str = "MIMO";
+
+ tx_results += "\n";
+ if(no_lock_freqs.empty()) tx_results += std::string(str(boost::format("%s successfully locked at all frequencies.") % sensor_str));
+ else{
+ tx_results += std::string(str(boost::format("%s did not successfully lock at the following frequencies: ") % sensor_str));;
+ for(std::vector<double>::iterator i = no_lock_freqs.begin(); i != no_lock_freqs.end(); ++i){
+ if( i != no_lock_freqs.begin()) tx_results += ", ";
+ tx_results += return_MHz_string(*i);
+ }
+ }
+ }
+ if(test_gain){
+ tx_results += "\n";
+ if(bad_gain_vals.empty()) tx_results += "USRP successfully set all specified gain values at all frequencies.";
+ else{
+ tx_results += "USRP did not successfully set gain under the following circumstances:";
+ for(std::vector< std::vector<double> >::iterator i = bad_gain_vals.begin(); i != bad_gain_vals.end(); ++i){
+ std::vector<double> bad_pair = *i;
+ double bad_freq = bad_pair.front();
+ double bad_gain = bad_pair.back();
+ tx_results += std::string(str(boost::format("\nFrequency: %s, Gain: %5.2f") % return_MHz_string(bad_freq) % bad_gain));
+ }
+ }
+ }
+
+ return tx_results;
+}
+
+/************************************************************************
+ * RX Frequency/Gain Coercion
+************************************************************************/
+
+std::string rx_test(uhd::usrp::multi_usrp::sptr usrp, bool test_gain, std::string ref, bool verbose){
+
+ //Establish frequency range
+
+ std::vector<double> freqs;
+ std::vector<double> xcvr_freqs;
+
+ BOOST_FOREACH(const uhd::range_t &range, usrp->get_fe_rx_freq_range()){
+ double freq_begin = range.start();
+ double freq_end = range.stop();
+
+ if(usrp->get_usrp_rx_info().get("rx_subdev_name") == "XCVR2450 RX"){
+ xcvr_freqs.push_back(freq_begin);
+ xcvr_freqs.push_back(freq_end);
+ }
+
+ double freq_step;
+
+ if(freq_end - freq_begin > 1000e6) freq_step = 100e6;
+ else if(freq_end - freq_begin < 300e6) freq_step = 10e6;
+ else freq_step = 50e6;
+
+ double current_freq = freq_begin;
+
+ while(current_freq < freq_end){
+ freqs.push_back(current_freq);
+ current_freq += freq_step;
+ }
+ }
+
+ std::vector<double> gains;
+
+ if(test_gain){
+
+ //Establish gain range
+
+ double gain_begin = usrp->get_rx_gain_range().start();
+ if(gain_begin < 0.0) gain_begin = 0.0;
+ double gain_end = usrp->get_rx_gain_range().stop();
+
+ double current_gain = gain_begin;
+ while(current_gain < gain_end){
+ gains.push_back(current_gain);
+ current_gain++;
+ }
+ if(gain_end != *gains.end()) gains.push_back(gain_end);
+
+ }
+
+ //Establish error-storing variables
+
+ std::vector<double> bad_tune_freqs;
+ std::vector<double> no_lock_freqs;
+ std::vector< std::vector< double > > bad_gain_vals;
+ std::vector<std::string> dboard_sensor_names = usrp->get_rx_sensor_names();
+ std::vector<std::string> mboard_sensor_names = usrp->get_mboard_sensor_names();
+ bool has_sensor;
+
+ if(ref == "internal") has_sensor = (std::find(dboard_sensor_names.begin(), dboard_sensor_names.end(), "lo_locked")) != dboard_sensor_names.end();
+ else if(ref == "external") has_sensor = (std::find(mboard_sensor_names.begin(), mboard_sensor_names.end(), "ref_locked")) != mboard_sensor_names.end();
+ else has_sensor = (std::find(mboard_sensor_names.begin(), mboard_sensor_names.end(), "mimo_locked")) != mboard_sensor_names.end();
+
+ for(std::vector<double>::iterator f = freqs.begin(); f != freqs.end(); ++f){
+
+ //Testing for successful frequency tune
+
+ usrp->set_rx_freq(*f);
+ boost::this_thread::sleep(boost::posix_time::microseconds(long(1000)));
+
+ double actual_freq = usrp->get_rx_freq();
+
+ if(*f == 0.0){
+ if(floor(actual_freq + 0.5) == 0.0){
+ if(verbose) std::cout << boost::format("\nRX frequency successfully tuned to %s.") % return_MHz_string(*f) << std::endl;
+ }
+ else{
+ if(verbose) std::cout << boost::format("\nRX frequency tuned to %s instead of %s.") % return_MHz_string(actual_freq) % return_MHz_string(*f) << std::endl;
+ }
+ }
+ else{
+ if((*f / actual_freq > 0.9999) and (*f / actual_freq < 1.0001)){
+ if(verbose) std::cout << boost::format("\nRX frequency successfully tuned to %s.") % return_MHz_string(*f) << std::endl;
+ }
+ else{
+ if(verbose) std::cout << boost::format("\nRX frequency tuned to %s instead of %s.") % return_MHz_string(actual_freq) % return_MHz_string(*f) << std::endl;
+ bad_tune_freqs.push_back(*f);
+ }
+ }
+
+ //Testing for successful lock
+
+ if(has_sensor){
+ if(ref == "internal"){
+ if(usrp->get_rx_sensor("lo_locked",0).to_bool()){
+ if(verbose) std::cout << boost::format("LO successfully locked at RX frequency %s.") % return_MHz_string(*f) << std::endl;
+ }
+ else{
+ if(verbose) std::cout << boost::format("LO did not successfully lock at RX frequency %s.") % return_MHz_string(*f) << std::endl;
+ no_lock_freqs.push_back(*f);
+ }
+ }
+ else if(ref == "external"){
+ if(usrp->get_mboard_sensor("ref_locked",0).to_bool()){
+ if(verbose) std::cout << boost::format("REF successfully locked at RX frequency %s.") % return_MHz_string(*f) << std::endl;
+ }
+ else{
+ if(verbose) std::cout << boost::format("REF did not successfully lock at RX frequency %s.") % return_MHz_string(*f) << std::endl;
+ no_lock_freqs.push_back(*f);
+ }
+ }
+ else if(ref == "mimo"){
+ if(usrp->get_mboard_sensor("mimo_locked",0).to_bool()){
+ if(verbose) std::cout << boost::format("MIMO successfully locked at RX frequency %s.") % return_MHz_string(*f) << std::endl;
+ }
+ else{
+ if(verbose) std::cout << boost::format("MIMO did not successfully lock at RX frequency %s.") % return_MHz_string(*f) << std::endl;
+ no_lock_freqs.push_back(*f);
+ }
+ }
+ }
+
+ if(test_gain){
+
+ //Testing for successful gain tune
+
+ for(std::vector<double>::iterator g = gains.begin(); g != gains.end(); ++g){
+ usrp->set_rx_gain(*g);
+ boost::this_thread::sleep(boost::posix_time::microseconds(1000));
+
+ double actual_gain = usrp->get_rx_gain();
+
+ if(*g == 0.0){
+ if(actual_gain == 0.0){
+ if(verbose) std::cout << boost::format("RX gain successfully set to %5.2f at RX frequency %s.") % *g % return_MHz_string(*f) << std::endl;
+ }
+ else{
+ if(verbose) std::cout << boost::format("RX gain set to %5.2f instead of %5.2f at RX frequency %s.") % actual_gain % *g % return_MHz_string(*f) << std::endl;
+ std::vector<double> bad_gain_freq;
+ bad_gain_freq.push_back(*f);
+ bad_gain_freq.push_back(*g);
+ bad_gain_vals.push_back(bad_gain_freq);
+ }
+ }
+ else{
+ if((*g / actual_gain) > 0.9 and (*g / actual_gain) < 1.1){
+ if(verbose) std::cout << boost::format("RX gain successfully set to %5.2f at RX frequency %s.") % *g % return_MHz_string(*f) << std::endl;
+ }
+ else{
+ if(verbose) std::cout << boost::format("RX gain set to %5.2f instead of %5.2f at RX frequency %s.") % actual_gain % *g % return_MHz_string(*f) << std::endl;
+ std::vector<double> bad_gain_freq;
+ bad_gain_freq.push_back(*f);
+ bad_gain_freq.push_back(*g);
+ bad_gain_vals.push_back(bad_gain_freq);
+ }
+ }
+ }
+ }
+ }
+
+ std::string rx_results = "RX Summary:\n";
+ if(usrp->get_usrp_rx_info().get("rx_subdev_name") == "XCVR2450 RX"){
+ rx_results += std::string(str(boost::format("Frequency Range: %s - %s, %s - %s\n") % return_MHz_string(xcvr_freqs.at(0)) % return_MHz_string(xcvr_freqs.at(1)) %
+ return_MHz_string(xcvr_freqs.at(2)) % return_MHz_string(xcvr_freqs.at(3))));
+ }
+ else rx_results += std::string(str(boost::format("Frequency Range: %s - %s\n") % return_MHz_string(freqs.front()) % return_MHz_string(freqs.back())));
+ if(test_gain) rx_results += std::string(str(boost::format("Gain Range: %5.2f - %5.2f\n") % gains.front() % gains.back()));
+
+ if(bad_tune_freqs.empty()) rx_results += "USRP successfully tuned to all frequencies.";
+ else{
+ rx_results += "USRP did not successfully tune to the following frequencies: ";
+ for(std::vector<double>::iterator i = bad_tune_freqs.begin(); i != bad_tune_freqs.end(); ++i){
+ if(i != bad_tune_freqs.begin()) rx_results += ", ";
+ rx_results += return_MHz_string(*i);
+ }
+ }
+ if(has_sensor){
+
+ std::string sensor_str;
+ if(ref == "internal") sensor_str = "LO";
+ else if(ref == "external") sensor_str = "REF";
+ else if(ref == "mimo") sensor_str = "MIMO";
+
+ rx_results += "\n";
+ if(no_lock_freqs.empty()) rx_results += std::string(str(boost::format("%s successfully locked at all frequencies.") % sensor_str));
+ else{
+ rx_results += std::string(str(boost::format("%s did not successfully lock at the following frequencies: ") % sensor_str));
+ for(std::vector<double>::iterator i = no_lock_freqs.begin(); i != no_lock_freqs.end(); ++i){
+ if( i != no_lock_freqs.begin()) rx_results += ", ";
+ rx_results += return_MHz_string(*i);
+ }
+ }
+ }
+ if(test_gain){
+ rx_results += "\n";
+ if(bad_gain_vals.empty()) rx_results += "USRP successfully set all specified gain values at all frequencies.";
+ else{
+ rx_results += "USRP did not successfully set gain under the following circumstances:";
+ for(std::vector< std::vector<double> >::iterator i = bad_gain_vals.begin(); i != bad_gain_vals.end(); ++i){
+ std::vector<double> bad_pair = *i;
+ double bad_freq = bad_pair.front();
+ double bad_gain = bad_pair.back();
+ rx_results += std::string(str(boost::format("\nFrequency: %s, Gain: %5.2f") % return_MHz_string(bad_freq) % bad_gain));
+ }
+ }
+ }
+
+ return rx_results;
+}
+
+/************************************************************************
+ * Initial Setup
+************************************************************************/
+
+int UHD_SAFE_MAIN(int argc, char *argv[]){
+
+ //Variables
+ std::string args;
+ double gain_step;
+ std::string ref;
+ std::string tx_results;
+ std::string rx_results;
+ std::string usrp_config;
+
+ //Set up the program options
+ po::options_description desc("Allowed Options");
+ desc.add_options()
+ ("help", "help message")
+ ("args", po::value<std::string>(&args)->default_value(""), "Specify the UHD device")
+ ("gain_step", po::value<double>(&gain_step)->default_value(1.0), "Specify the delta between gain scans")
+ ("tx", "Specify to test TX frequency and gain coercion")
+ ("rx", "Specify to test RX frequency and gain coercion")
+ ("ref", po::value<std::string>(&ref)->default_value("internal"), "Test for lock with internal, external, or mimo")
+ ("no_tx_gain", "Do not test TX gain")
+ ("no_rx_gain", "Do not test RX gain")
+ ("verbose", "Output every frequency and gain check instead of just final summary")
+ ;
+ po::variables_map vm;
+ po::store(po::parse_command_line(argc, argv, desc), vm);
+ po::notify(vm);
+
+ //Create a USRP device
+ std::cout << std::endl;
+ uhd::device_addrs_t device_addrs = uhd::device::find(args);
+ 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);
+ std::cout << std::endl << boost::format("Using Device: %s") % usrp->get_pp_string() << std::endl;
+ usrp->set_tx_rate(1e6);
+ usrp->set_rx_rate(1e6);
+
+ //Boolean variables based on command line input
+ bool test_tx = vm.count("tx") > 0;
+ bool test_rx = vm.count("rx") > 0;
+ bool test_tx_gain = !(vm.count("no_tx_gain") > 0) and (usrp->get_tx_gain_range().stop() > 0);
+ bool test_rx_gain = !(vm.count("no_rx_gain") > 0) and (usrp->get_rx_gain_range().stop() > 0);
+ bool verbose = vm.count("verbose") > 0;
+
+ //Help messages, errors
+ if(vm.count("help") > 0){
+ std::cout << "UHD Daughterboard Coercion Test\n"
+ "This program tests your USRP daughterboard(s) to\n"
+ "make sure that they can successfully tune to all\n"
+ "frequencies and gains in their advertised ranges.\n\n";
+ std::cout << desc << std::endl;
+ return ~0;
+ }
+
+ if(ref != "internal" and ref != "external" and ref != "mimo"){
+ std::cout << desc << std::endl;
+ std::cout << "REF must equal internal, external, or mimo." << std::endl;
+ return ~0;
+ }
+
+ if(vm.count("tx") + vm.count("rx") == 0){
+ std::cout << desc << std::endl;
+ std::cout << "Specify --tx to test for TX frequency coercion\n"
+ "Specify --rx to test for RX frequency coercion\n";
+ return ~0;
+ }
+
+ if(test_rx and usrp->get_usrp_rx_info().get("rx_id") == "Basic RX (0x0001)"){
+ std::cout << desc << std::endl;
+ std::cout << "This test does not work with the Basic RX daughterboard." << std::endl;
+ return ~0;
+ }
+ else if(test_rx and usrp->get_usrp_rx_info().get("rx_id") == "Unknown (0xffff)"){
+ std::cout << desc << std::endl;
+ std::cout << "This daughterboard is unrecognized, or there is no RX daughterboard." << std::endl;
+ return ~0;
+ }
+
+ if(test_tx and usrp->get_usrp_tx_info().get("tx_id") == "Basic TX (0x0000)"){
+ std::cout << desc << std::endl;
+ std::cout << "This test does not work with the Basic TX daughterboard." << std::endl;
+ return ~0;
+ }
+ else if(test_tx and usrp->get_usrp_tx_info().get("tx_id") == "Unknown (0xffff)"){
+ std::cout << desc << std::endl;
+ std::cout << "This daughterboard is unrecognized, or there is no TX daughterboard." << std::endl;
+ return ~0;
+ }
+
+ usrp_config = return_USRP_config_string(usrp, test_tx, test_rx);
+ if(test_tx) tx_results = tx_test(usrp, test_tx_gain, ref, verbose);
+ if(test_rx) rx_results = rx_test(usrp, test_rx_gain, ref, verbose);
+
+ if(verbose) std::cout << std::endl;
+ std::cout << usrp_config << std::endl << std::endl;
+ if(test_tx) std::cout << tx_results << std::endl;
+ if(test_tx and test_rx) std::cout << std::endl;
+ if(test_rx) std::cout << rx_results << std::endl;
+
+ return 0;
+}
diff --git a/host/examples/test_timed_commands.cpp b/host/examples/test_timed_commands.cpp
new file mode 100644
index 000000000..34c83dfd6
--- /dev/null
+++ b/host/examples/test_timed_commands.cpp
@@ -0,0 +1,129 @@
+//
+// Copyright 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
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+//
+
+#include <uhd/utils/thread_priority.hpp>
+#include <uhd/utils/safe_main.hpp>
+#include <uhd/usrp/multi_usrp.hpp>
+#include <boost/program_options.hpp>
+#include <boost/format.hpp>
+#include <iostream>
+#include <complex>
+
+namespace po = boost::program_options;
+
+int UHD_SAFE_MAIN(int argc, char *argv[]){
+ uhd::set_thread_priority_safe();
+
+ //variables to be set by po
+ std::string args;
+
+ //setup the program options
+ po::options_description desc("Allowed options");
+ desc.add_options()
+ ("help", "help message")
+ ("args", po::value<std::string>(&args)->default_value(""), "single uhd device address args")
+ ;
+ po::variables_map vm;
+ po::store(po::parse_command_line(argc, argv, desc), vm);
+ po::notify(vm);
+
+ //print the help message
+ if (vm.count("help")){
+ std::cout << boost::format("UHD Test Timed Commands %s") % desc << std::endl;
+ return ~0;
+ }
+
+ //create a usrp device
+ 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);
+ std::cout << boost::format("Using Device: %s") % usrp->get_pp_string() << std::endl;
+
+ //check if timed commands are supported
+ std::cout << std::endl;
+ std::cout << "Testing support for timed commands on this hardware... " << std::flush;
+ try{
+ usrp->set_command_time(uhd::time_spec_t(0.0));
+ usrp->clear_command_time();
+ }
+ catch (const std::exception &e){
+ std::cout << "fail" << std::endl;
+ std::cerr << "Got exception: " << e.what() << std::endl;
+ std::cerr << "Timed commands are not supported on this hardware." << std::endl;
+ return ~0;
+ }
+ std::cout << "pass" << std::endl;
+
+ //readback time really fast, time diff is small
+ std::cout << std::endl;
+ std::cout << "Perform fast readback of registers:" << std::endl;
+ uhd::time_spec_t total_time;
+ for (size_t i = 0; i < 100; i++){
+ const uhd::time_spec_t t0 = usrp->get_time_now();
+ const uhd::time_spec_t t1 = usrp->get_time_now();
+ total_time += (t1-t0);
+ }
+ std::cout << boost::format(
+ "Difference between paired reads: %f us"
+ ) % (total_time.get_real_secs()/100*1e6) << std::endl;
+
+ //use a timed command to start a stream at a specific time
+ //this is not the right way start streaming at time x,
+ //but it should approximate it within control RTT/2
+ //setup streaming
+ std::cout << std::endl;
+ std::cout << "About to start streaming using timed command:" << std::endl;
+
+ //create a receive streamer
+ uhd::stream_args_t stream_args("fc32"); //complex floats
+ uhd::rx_streamer::sptr rx_stream = usrp->get_rx_stream(stream_args);
+
+ uhd::stream_cmd_t stream_cmd(uhd::stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_DONE);
+ stream_cmd.num_samps = 100;
+ stream_cmd.stream_now = true;
+ const uhd::time_spec_t stream_time = usrp->get_time_now() + uhd::time_spec_t(0.1);
+ usrp->set_command_time(stream_time);
+ usrp->issue_stream_cmd(stream_cmd);
+ usrp->clear_command_time();
+
+ //meta-data will be filled in by recv()
+ uhd::rx_metadata_t md;
+
+ //allocate buffer to receive with samples
+ std::vector<std::complex<float> > buff(stream_cmd.num_samps);
+
+ const size_t num_rx_samps = rx_stream->recv(&buff.front(), buff.size(), md);
+ if (md.error_code != uhd::rx_metadata_t::ERROR_CODE_NONE){
+ throw std::runtime_error(str(boost::format(
+ "Unexpected error code 0x%x"
+ ) % md.error_code));
+ }
+ std::cout << boost::format(
+ "Received packet: %u samples, %u full secs, %f frac secs"
+ ) % num_rx_samps % md.time_spec.get_full_secs() % md.time_spec.get_frac_secs() << std::endl;
+ std::cout << boost::format(
+ "Stream time was: %u full secs, %f frac secs"
+ ) % stream_time.get_full_secs() % stream_time.get_frac_secs() << std::endl;
+ std::cout << boost::format(
+ "Difference between stream time and first packet: %f us"
+ ) % ((md.time_spec-stream_time).get_real_secs()/100*1e6) << std::endl;
+
+ //finished
+ std::cout << std::endl << "Done!" << std::endl << std::endl;
+
+ return 0;
+}
diff --git a/host/examples/transport_hammer.cpp b/host/examples/transport_hammer.cpp
new file mode 100644
index 000000000..597614050
--- /dev/null
+++ b/host/examples/transport_hammer.cpp
@@ -0,0 +1,340 @@
+//
+// Copyright 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
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+//
+
+#include <uhd/utils/thread_priority.hpp>
+#include <uhd/utils/safe_main.hpp>
+#include <uhd/usrp/multi_usrp.hpp>
+#include <boost/program_options.hpp>
+#include <boost/format.hpp>
+#include <boost/thread/thread.hpp>
+#include <boost/math/special_functions/round.hpp>
+#include <iostream>
+#include <complex>
+
+namespace po = boost::program_options;
+
+/************************************************************************
+ * RX Samples
+ ************************************************************************/
+
+void rx_hammer(uhd::usrp::multi_usrp::sptr usrp, double rx_rate, bool rx_rand, int rx_low, int rx_high, int rx_step, bool verbose){
+ uhd::set_thread_priority_safe();
+
+ //Set RX sample rate
+ std::cout << boost::format("Setting RX rate: %f Msps") % (rx_rate/1e6) << std::endl;
+ usrp->set_rx_rate(rx_rate);
+ std::cout << boost::format("Actual RX rate: %f Msps") % (usrp->get_rx_rate()/1e6) << std::endl << std::endl;
+
+ if(rx_rand){
+ std::srand((unsigned int) time(NULL));
+
+ while(true){
+ size_t total_num_samps = (rand() % (rx_high - rx_low)) + rx_low;
+
+ usrp->set_time_now(uhd::time_spec_t(0.0));
+
+ //Create a receive streamer
+ uhd::stream_args_t stream_args("fc32");
+ uhd::rx_streamer::sptr rx_stream = usrp->get_rx_stream(stream_args);
+
+ std::cout << boost::format("About to receive %u samples.") % total_num_samps << std::endl;
+
+ uhd::stream_cmd_t stream_cmd(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);
+
+ //Metadata will be filled in by recv()
+ uhd::rx_metadata_t md;
+
+ //Allocate buffer to receive with samples
+ std::vector<std::complex<float> > buff(rx_stream->get_max_num_samps());
+ double timeout = 1;
+
+ size_t num_acc_samps = 0; //Number of accumulated samples
+ while(num_acc_samps < total_num_samps){
+ //Receive a single packet
+ size_t num_rx_samps = rx_stream->recv(
+ &buff.front(), buff.size(), md, timeout, true
+ );
+
+ //Handle the error code
+ if(md.error_code == uhd::rx_metadata_t::ERROR_CODE_TIMEOUT){std::cout << "timeout" << std::endl; break;}
+ if(md.error_code != uhd::rx_metadata_t::ERROR_CODE_NONE && md.error_code != uhd::rx_metadata_t::ERROR_CODE_OVERFLOW){
+ std::cout << "Error" << std::endl;
+ throw std::runtime_error(str(boost::format(
+ "Unexpected error code 0x%x"
+ ) % md.error_code));
+ }
+ num_acc_samps += num_rx_samps;
+ }
+
+ if(num_acc_samps < total_num_samps) std::cerr << "Received timeout before all samples were received..." << std::endl;
+ else std::cout << boost::format("Successfully received %u samples.") % total_num_samps << std::endl;
+ }
+ }
+ else{
+ for(int i = int(rx_low); i <= int(rx_high); i += rx_step){
+ usrp->set_time_now(uhd::time_spec_t(0.0));
+
+ //Create a receive streamer
+ uhd::stream_args_t stream_args("fc32");
+ uhd::rx_streamer::sptr rx_stream = usrp->get_rx_stream(stream_args);
+
+ //Set up streaming
+ std::cout << boost::format ("About to receive %u samples.") % i << std::endl;
+ uhd::stream_cmd_t stream_cmd(uhd::stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_DONE);
+ stream_cmd.num_samps = i;
+ stream_cmd.stream_now = true;
+ usrp->issue_stream_cmd(stream_cmd);
+
+ //Metadata will be filled in by recv()
+ uhd::rx_metadata_t md;
+
+ //Allocate buffer to receive with samples
+ std::vector<std::complex<float> > buff(rx_stream->get_max_num_samps());
+
+ double timeout = 1;
+
+ size_t num_acc_samps = 0; //Number of accumulated samples
+ while(int(num_acc_samps) < i){
+ //Receive a single packet
+ size_t num_rx_samps = rx_stream->recv(
+ &buff.front(), buff.size(), md, timeout, true
+ );
+
+ //Handle the error code
+ if (md.error_code == uhd::rx_metadata_t::ERROR_CODE_TIMEOUT) break;
+ if (md.error_code != uhd::rx_metadata_t::ERROR_CODE_NONE && md.error_code != uhd::rx_metadata_t::ERROR_CODE_OVERFLOW){
+ throw std::runtime_error(str(boost::format(
+ "Unexpected error code 0x%x"
+ ) % md.error_code));
+ }
+
+ if(verbose) std::cout << boost::format("Received %u samples.") % num_rx_samps << std::endl;
+
+ num_acc_samps += num_rx_samps;
+
+ }
+ std::cout << boost::format("Successfully received %u samples.") % i << std::endl;
+
+ if (int(num_acc_samps) < i) std::cerr << "Timeout received before all samples were received..." << std::endl;
+
+ }
+ }
+}
+
+/************************************************************************
+ * TX Samples
+ ************************************************************************/
+
+void tx_hammer(uhd::usrp::multi_usrp::sptr usrp, double tx_rate, bool tx_rand, int tx_low, int tx_high, int tx_step, double tx_ampl, bool verbose){
+ uhd::set_thread_priority_safe();
+
+ //Set the TX sample rate
+ std::cout << boost::format("Setting TX Rate: %f Msps...") % (tx_rate / 1e6) << std::endl;
+ usrp->set_tx_rate(tx_rate);
+ std::cout << boost::format("Actual TX Rate: %f Msps...") % (usrp->get_tx_rate()/1e6) << std::endl << std::endl;
+ usrp->set_time_now(uhd::time_spec_t(0.0));
+
+ //Create a transmit streamer
+ uhd::stream_args_t stream_args("fc32"); //complex floats
+ uhd::tx_streamer::sptr tx_stream = usrp->get_tx_stream(stream_args);
+
+ //Allocate buffer with data to send
+ std::vector<std::complex<float> > buff(tx_stream->get_max_num_samps(), std::complex<float>(tx_ampl, tx_ampl));
+
+ //Setup metadata for the first packet
+ uhd::tx_metadata_t md;
+ md.start_of_burst = false;
+ md.end_of_burst = false;
+ md.has_time_spec = false;
+
+ if(tx_rand){
+ std::srand((unsigned int) time(NULL));
+
+ while(true){
+ size_t total_num_samps = (rand() % (tx_high - tx_low)) + tx_low;
+ size_t num_acc_samps = 0;
+ float timeout = 1;
+
+ std::cout << boost::format("About to send %u samples.") % total_num_samps << std::endl;
+
+ usrp->set_time_now(uhd::time_spec_t(0.0));
+
+ while(num_acc_samps < total_num_samps){
+ size_t samps_to_send = std::min(total_num_samps - num_acc_samps, buff.size());
+
+ //Send a single packet
+ size_t num_tx_samps = tx_stream->send(&buff.front(), samps_to_send, md, timeout);
+
+ if(num_tx_samps < samps_to_send) std::cerr << "Send timeout..." << std::endl;
+
+ num_acc_samps += num_tx_samps;
+ }
+
+ md.end_of_burst = true;
+ tx_stream->send("", 0, md);
+
+ if(verbose) std::cout << std::endl;
+ std::cout << "Waiting for async burst ACK... " << std::flush;
+ uhd::async_metadata_t async_md;
+ bool got_async_burst_ack = false;
+
+ //Loop through all messages for the ACK packet (may have underflow messages in queue)
+ while (not got_async_burst_ack and usrp->get_device()->recv_async_msg(async_md, timeout)){
+ got_async_burst_ack = (async_md.event_code == uhd::async_metadata_t::EVENT_CODE_BURST_ACK);
+ }
+ std::cout << (got_async_burst_ack? "Success!" : "Failure...") << std::endl;
+
+ std::cout << boost::format("Successfully sent %u samples.") % total_num_samps << std::endl;
+
+ }
+ }
+ else{
+ float timeout = 1;
+
+ for(int i = int(tx_low); i <= int(tx_high); i += tx_step){
+
+ usrp->set_time_now(uhd::time_spec_t(0.0));
+
+ std::cout << boost::format("About to send %u samples.") % i << std::endl;
+ if(verbose) std::cout << std::endl;
+
+ size_t num_acc_samps = 0; //Number of accumulated samples
+ size_t total_num_samps = i;
+
+ while(num_acc_samps < total_num_samps){
+ size_t samps_to_send = std::min(total_num_samps - num_acc_samps, buff.size());
+
+ //Send a single packet
+ size_t num_tx_samps = tx_stream->send(
+ &buff.front(), samps_to_send, md, timeout
+ );
+
+ if (num_tx_samps < samps_to_send) std::cerr << "Send timeout..." << std::endl;
+
+ num_acc_samps += num_tx_samps;
+ }
+
+ //Send a mini EOB packet
+ md.end_of_burst = true;
+ tx_stream->send("", 0, md);
+
+ std::cout << std::endl << "Waiting for async burst ACK... " << std::flush;
+ uhd::async_metadata_t async_md;
+ bool got_async_burst_ack = false;
+ //Loop through all messages for the ACK packet (may have underflow messages in queue)
+ while (not got_async_burst_ack and usrp->get_device()->recv_async_msg(async_md, timeout)){
+ got_async_burst_ack = (async_md.event_code == uhd::async_metadata_t::EVENT_CODE_BURST_ACK);
+ }
+ std::cout << (got_async_burst_ack? "Success!" : "Failure...") << std::endl;
+
+ }
+ //Finished
+ std::cout << "Done!" << std::endl;
+ }
+}
+
+/************************************************************************
+ * Main code + dispatcher
+ ************************************************************************/
+
+int UHD_SAFE_MAIN(int argc, char *argv[]){
+ uhd::set_thread_priority_safe();
+
+ //Variables to be set by program options
+ std::string args;
+ double rx_rate;
+ int rx_low;
+ int rx_high;
+ int rx_step;
+ double tx_rate;
+ int tx_low;
+ int tx_high;
+ int tx_step;
+ double tx_ampl;
+
+ //Set up the program options
+ po::options_description desc("Allowed options");
+ desc.add_options()
+ ("help", "Print this help message.")
+ ("args", po::value<std::string>(&args)->default_value(""), "Single UHD device address args.")
+ ("rx_rate", po::value<double>(&rx_rate), "RX sample rate.")
+ ("rx_rand", "Specify to use random amounts of RX samples (between rx_low and rx_high values).")
+ ("rx_low", po::value<int>(&rx_low)->default_value(1), "Lowest value of RX samples.")
+ ("rx_high", po::value<int>(&rx_high)->default_value(10000), "Highest value of RX samples.")
+ ("rx_step", po::value<int>(&rx_step)->default_value(10), "Delta between number of collected RX samples.")
+ ("tx_rate", po::value<double>(&tx_rate), "TX sample rate.")
+ ("tx_rand", "Specify to use random amounts of TX samples (between tx_low and tx_high values).")
+ ("tx_low", po::value<int>(&tx_low)->default_value(1), "Lowest value of TX samples.")
+ ("tx_high", po::value<int>(&tx_high)->default_value(10000), "Highest value of TX samples.")
+ ("tx_step", po::value<int>(&tx_step)->default_value(10), "Delta between number of sent TX samples.")
+ ("tx_ampl", po::value<double>(&tx_ampl)->default_value(0.5), "TX amplitude.")
+ ("verbose", "Enables verbosity")
+ ;
+ po::variables_map vm;
+ po::store(po::parse_command_line(argc, argv, desc), vm);
+ po::notify(vm);
+
+ //Set verbose or RX/TX random if requested by user
+ bool rx_rand = vm.count("rx_rand") > 0;
+ bool tx_rand = vm.count("tx_rand") > 0;
+ bool verbose = vm.count("verbose") > 0;
+
+ //Print the help message
+
+ if (vm.count("help") or (vm.count("rx_rate") + vm.count("tx_rate")) == 0){
+ std::cout << boost::format("UHD Transport Hammer %s") % desc << std::endl;
+ std::cout <<
+ " Specify --rx_rate for a receive-only test.\n"
+ " Specify --tx_rate for a transmit-only test.\n"
+ " Specify both options for a full-duplex test.\n"
+ << std::endl;
+ return ~0;
+ }
+
+ //Create a USRP device
+ std::cout << std::endl;
+ uhd::device_addrs_t device_addrs = uhd::device::find(args);
+ 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);
+ std::cout << boost::format("Using Device: %s") % usrp->get_pp_string() << std::endl;
+
+ boost::thread_group thread_group;
+
+ //Spawn the receive test thread
+ if (vm.count("rx_rate")){
+ usrp->set_rx_rate(rx_rate);
+ thread_group.create_thread(boost::bind(&rx_hammer, usrp, rx_rate, rx_rand, rx_low, rx_high, rx_step, verbose));
+ }
+
+ //Spawn the transmit test thread
+ if (vm.count("tx_rate")){
+ usrp->set_tx_rate(tx_rate);
+ thread_group.create_thread(boost::bind(&tx_hammer, usrp, tx_rate, tx_rand, tx_low, tx_high, tx_step, tx_ampl, verbose));
+ }
+
+ //Interrupt and join the threads
+ boost::this_thread::sleep(boost::posix_time::microseconds(long(1e6)));
+ thread_group.interrupt_all();
+ thread_group.join_all();
+ //Finished
+ std::cout << std::endl << "Done!" << std::endl << std::endl;
+
+ return 0;
+}
diff --git a/host/examples/tx_waveforms.cpp b/host/examples/tx_waveforms.cpp
index 6a377fdac..3c5eecd65 100644
--- a/host/examples/tx_waveforms.cpp
+++ b/host/examples/tx_waveforms.cpp
@@ -1,5 +1,5 @@
//
-// Copyright 2010-2011 Ettus Research LLC
+// Copyright 2010-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,6 +24,7 @@
#include <boost/math/special_functions/round.hpp>
#include <boost/foreach.hpp>
#include <boost/format.hpp>
+#include <boost/thread.hpp>
#include <iostream>
#include <complex>
#include <csignal>
@@ -174,6 +175,8 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
if (vm.count("ant")) usrp->set_tx_antenna(ant, chan);
}
+ boost::this_thread::sleep(boost::posix_time::seconds(1)); //allow for some setup time
+
//for the const wave, set the wave freq for small samples per period
if (wave_freq == 0 and wave_type == "CONST"){
wave_freq = usrp->get_tx_rate()/2;