aboutsummaryrefslogtreecommitdiffstats
path: root/host/examples
diff options
context:
space:
mode:
Diffstat (limited to 'host/examples')
-rw-r--r--host/examples/gpio.cpp2
-rw-r--r--host/examples/init_usrp/CMakeLists.txt19
-rw-r--r--host/examples/rx_samples_to_file.cpp26
-rw-r--r--host/examples/test_dboard_coercion.cpp12
-rw-r--r--host/examples/test_messages.cpp5
-rw-r--r--host/examples/tx_samples_from_file.cpp28
-rw-r--r--host/examples/tx_waveforms.cpp1
7 files changed, 64 insertions, 29 deletions
diff --git a/host/examples/gpio.cpp b/host/examples/gpio.cpp
index 02c73e96b..e47b2ab27 100644
--- a/host/examples/gpio.cpp
+++ b/host/examples/gpio.cpp
@@ -129,7 +129,7 @@ void output_reg_values(
for (int i = num_bits - 1; i >= 0; i--)
std::cout << (boost::format(" %2d") % i);
std::cout << std::endl;
- BOOST_FOREACH(std::string &attr, attrs)
+ for(std::string &attr: attrs)
{
std::cout << (boost::format("%10s:%s")
% attr % to_bit_string(uint32_t(usrp->get_gpio_attr(bank, attr)), num_bits))
diff --git a/host/examples/init_usrp/CMakeLists.txt b/host/examples/init_usrp/CMakeLists.txt
index 4ce51125f..139f9b853 100644
--- a/host/examples/init_usrp/CMakeLists.txt
+++ b/host/examples/init_usrp/CMakeLists.txt
@@ -46,6 +46,25 @@ find_package(UHD "3.8.0" REQUIRED)
#find_package(UHD 3.8.1 EXACT REQUIRED)
### Configure Compiler ########################################################
+IF(CMAKE_VERSION VERSION_LESS "3.1")
+ IF(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
+ SET(CMAKE_CXX_FLAGS "--std=gnu++11 ${CMAKE_CXX_FLAGS}")
+ ELSEIF(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
+ IF("${IS_APPLE}" STREQUAL "")
+ SET(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
+ ELSE()
+ SET(CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++ ${CMAKE_CXX_FLAGS}")
+ ENDIF()
+ ENDIF()
+ELSE()
+ SET(CMAKE_CXX_STANDARD 11)
+ENDIF()
+
+IF(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" AND ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
+ SET(CMAKE_EXE_LINKER_FLAGS "-lthr ${CMAKE_EXE_LINKER_FLAGS}")
+ SET(CMAKE_CXX_FLAGS "-stdlib=libc++ ${CMAKE_CXX_FLAGS}")
+ENDIF()
+
include_directories(
${Boost_INCLUDE_DIRS}
${UHD_INCLUDE_DIRS}
diff --git a/host/examples/rx_samples_to_file.cpp b/host/examples/rx_samples_to_file.cpp
index 934dce586..444fd155c 100644
--- a/host/examples/rx_samples_to_file.cpp
+++ b/host/examples/rx_samples_to_file.cpp
@@ -37,6 +37,7 @@ template<typename samp_type> void recv_to_file(
uhd::usrp::multi_usrp::sptr usrp,
const std::string &cpu_format,
const std::string &wire_format,
+ const std::string &channel,
const std::string &file,
size_t samps_per_buff,
unsigned long long num_requested_samples,
@@ -50,6 +51,9 @@ template<typename samp_type> void recv_to_file(
unsigned long long num_total_samps = 0;
//create a receive streamer
uhd::stream_args_t stream_args(cpu_format,wire_format);
+ std::vector<size_t> channel_nums;
+ channel_nums.push_back(boost::lexical_cast<size_t>(channel));
+ stream_args.channels = channel_nums;
uhd::rx_streamer::sptr rx_stream = usrp->get_rx_stream(stream_args);
uhd::rx_metadata_t md;
@@ -209,7 +213,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
uhd::set_thread_priority_safe();
//variables to be set by po
- std::string args, file, type, ant, subdev, ref, wirefmt;
+ std::string args, file, type, ant, subdev, ref, wirefmt, channel;
size_t total_num_samps, spb;
double rate, freq, gain, bw, total_time, setup_time;
@@ -229,9 +233,10 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
("gain", po::value<double>(&gain), "gain for the RF chain")
("ant", po::value<std::string>(&ant), "antenna selection")
("subdev", po::value<std::string>(&subdev), "subdevice specification")
+ ("channel", po::value<std::string>(&channel)->default_value("0"), "which channel to use")
("bw", po::value<double>(&bw), "analog frontend filter bandwidth in Hz")
("ref", po::value<std::string>(&ref)->default_value("internal"), "reference source (internal, external, mimo)")
- ("wirefmt", po::value<std::string>(&wirefmt)->default_value("sc16"), "wire format (sc8 or sc16)")
+ ("wirefmt", po::value<std::string>(&wirefmt)->default_value("sc16"), "wire format (sc8, sc16 or s16)")
("setup", po::value<double>(&setup_time)->default_value(1.0), "seconds of setup time")
("progress", "periodically display short-term bandwidth")
("stats", "show average bandwidth on exit")
@@ -329,12 +334,19 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
}
#define recv_to_file_args(format) \
- (usrp, format, wirefmt, file, spb, total_num_samps, total_time, bw_summary, stats, null, enable_size_map, continue_on_bad_packet)
+ (usrp, format, wirefmt, channel, file, spb, total_num_samps, total_time, bw_summary, stats, null, enable_size_map, continue_on_bad_packet)
//recv to file
- if (type == "double") recv_to_file<std::complex<double> >recv_to_file_args("fc64");
- else if (type == "float") recv_to_file<std::complex<float> >recv_to_file_args("fc32");
- else if (type == "short") recv_to_file<std::complex<short> >recv_to_file_args("sc16");
- else throw std::runtime_error("Unknown type " + type);
+ if (wirefmt == "s16") {
+ if (type == "double") recv_to_file<double>recv_to_file_args("f64");
+ else if (type == "float") recv_to_file<float>recv_to_file_args("f32");
+ else if (type == "short") recv_to_file<short>recv_to_file_args("s16");
+ else throw std::runtime_error("Unknown type " + type);
+ } else {
+ if (type == "double") recv_to_file<std::complex<double> >recv_to_file_args("fc64");
+ else if (type == "float") recv_to_file<std::complex<float> >recv_to_file_args("fc32");
+ else if (type == "short") recv_to_file<std::complex<short> >recv_to_file_args("sc16");
+ else throw std::runtime_error("Unknown type " + type);
+ }
//finished
std::cout << std::endl << "Done!" << std::endl << std::endl;
diff --git a/host/examples/test_dboard_coercion.cpp b/host/examples/test_dboard_coercion.cpp
index 81c45fcb3..0119f39cd 100644
--- a/host/examples/test_dboard_coercion.cpp
+++ b/host/examples/test_dboard_coercion.cpp
@@ -102,7 +102,7 @@ std::string coercion_test(uhd::usrp::multi_usrp::sptr usrp, std::string type, in
std::cout << boost::format("\nTesting %s coercion...") % type << std::endl;
- BOOST_FOREACH(const uhd::range_t &range, freq_ranges){
+ for(const uhd::range_t &range: freq_ranges){
double freq_begin = range.start();
double freq_end = range.stop();
@@ -152,7 +152,7 @@ std::string coercion_test(uhd::usrp::multi_usrp::sptr usrp, std::string type, in
bool has_sensor = (std::find(dboard_sensor_names.begin(), dboard_sensor_names.end(), "lo_locked")) != dboard_sensor_names.end();
- BOOST_FOREACH(double freq, freqs){
+ for(double freq: freqs){
//Testing for successful frequency tune
if(type == "TX") usrp->set_tx_freq(freq,chan);
@@ -212,7 +212,7 @@ std::string coercion_test(uhd::usrp::multi_usrp::sptr usrp, std::string type, in
//Testing for successful gain tune
- BOOST_FOREACH(double gain, gains){
+ for(double gain: gains){
if(type == "TX") usrp->set_tx_gain(gain,chan);
else usrp->set_rx_gain(gain,chan);
@@ -266,7 +266,7 @@ std::string coercion_test(uhd::usrp::multi_usrp::sptr usrp, std::string type, in
}
else{
results += "USRP did not successfully tune to the following frequencies: ";
- BOOST_FOREACH(double bad_freq, bad_tune_freqs){
+ for(double bad_freq: bad_tune_freqs){
if(bad_freq != *bad_tune_freqs.begin()) results += ", ";
results += MHz_str(bad_freq);
}
@@ -282,7 +282,7 @@ std::string coercion_test(uhd::usrp::multi_usrp::sptr usrp, std::string type, in
}
else{
results += "LO did not lock at the following frequencies: ";
- BOOST_FOREACH(double bad_freq, no_lock_freqs){
+ for(double bad_freq: no_lock_freqs){
if(bad_freq != *no_lock_freqs.begin()) results += ", ";
results += MHz_str(bad_freq);
}
@@ -298,7 +298,7 @@ std::string coercion_test(uhd::usrp::multi_usrp::sptr usrp, std::string type, in
}
else{
results += "USRP did not successfully set gain under the following circumstances:";
- BOOST_FOREACH(double_pair bad_pair, bad_gain_vals){
+ for(double_pair bad_pair: bad_gain_vals){
double bad_freq = bad_pair.first;
double bad_gain = bad_pair.second;
results += str(boost::format("\nFrequency: %s, Gain: %5.2f") % MHz_str(bad_freq) % bad_gain);
diff --git a/host/examples/test_messages.cpp b/host/examples/test_messages.cpp
index 43b035d19..8a50e4c85 100644
--- a/host/examples/test_messages.cpp
+++ b/host/examples/test_messages.cpp
@@ -23,7 +23,6 @@
#include <uhd/usrp/multi_usrp.hpp>
#include <boost/assign/list_of.hpp>
#include <boost/program_options.hpp>
-#include <boost/foreach.hpp>
#include <boost/bind.hpp>
#include <boost/format.hpp>
#include <cstdlib>
@@ -330,7 +329,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
//init result counts
uhd::dict<std::string, size_t> failures, successes;
- BOOST_FOREACH(const std::string &key, tests.keys()){
+ for(const std::string &key: tests.keys()){
failures[key] = 0;
successes[key] = 0;
}
@@ -352,7 +351,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
//print the result summary
bool any_failure = false;
std::cout << std::endl << "Summary:" << std::endl << std::endl;
- BOOST_FOREACH(const std::string &key, tests.keys()){
+ for(const std::string &key: tests.keys()){
std::cout << boost::format(
"%s -> %3u successes, %3u failures"
) % key % successes[key] % failures[key] << std::endl;
diff --git a/host/examples/tx_samples_from_file.cpp b/host/examples/tx_samples_from_file.cpp
index cc7e963d5..b09efe454 100644
--- a/host/examples/tx_samples_from_file.cpp
+++ b/host/examples/tx_samples_from_file.cpp
@@ -33,17 +33,11 @@ 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,
- const std::string &wire_format,
+ uhd::tx_streamer::sptr tx_stream,
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);
-
uhd::tx_metadata_t md;
md.start_of_burst = false;
md.end_of_burst = false;
@@ -69,7 +63,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
uhd::set_thread_priority_safe();
//variables to be set by po
- std::string args, file, type, ant, subdev, ref, wirefmt;
+ std::string args, file, type, ant, subdev, ref, wirefmt, channel;
size_t spb;
double rate, freq, gain, bw, delay, lo_off;
@@ -91,6 +85,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
("ref", po::value<std::string>(&ref)->default_value("internal"), "reference source (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")
+ ("channel", po::value<std::string>(&channel)->default_value("0"), "which channel to use")
("repeat", "repeatedly transmit file")
("int-n", "tune USRP with integer-n tuning")
;
@@ -186,11 +181,22 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
std::cout << "Press Ctrl + C to stop streaming..." << std::endl;
}
+ //create a transmit streamer
+ std::string cpu_format;
+ std::vector<size_t> channel_nums;
+ if (type == "double") cpu_format = "fc64";
+ else if (type == "float") cpu_format = "fc32";
+ else if (type == "short") cpu_format = "sc16";
+ uhd::stream_args_t stream_args(cpu_format, wirefmt);
+ channel_nums.push_back(boost::lexical_cast<size_t>(channel));
+ stream_args.channels = channel_nums;
+ uhd::tx_streamer::sptr tx_stream = usrp->get_tx_stream(stream_args);
+
//send from file
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);
+ if (type == "double") send_from_file<std::complex<double> >(tx_stream, file, spb);
+ else if (type == "float") send_from_file<std::complex<float> >(tx_stream, file, spb);
+ else if (type == "short") send_from_file<std::complex<short> >(tx_stream, 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));
diff --git a/host/examples/tx_waveforms.cpp b/host/examples/tx_waveforms.cpp
index b2a8f944c..d596d9ed4 100644
--- a/host/examples/tx_waveforms.cpp
+++ b/host/examples/tx_waveforms.cpp
@@ -23,7 +23,6 @@
#include <uhd/exception.hpp>
#include <boost/program_options.hpp>
#include <boost/math/special_functions/round.hpp>
-#include <boost/foreach.hpp>
#include <boost/format.hpp>
#include <boost/thread.hpp>
#include <boost/lexical_cast.hpp>