From 539c9b5a5560ea5d79c78954ea8e482846a5e966 Mon Sep 17 00:00:00 2001 From: Jason Abele Date: Fri, 16 Sep 2011 10:47:54 -0700 Subject: Updates to example apps Add --ref option to specify mboard clock reference source Add check for lock to mboard clock reference (where applicable) Add check of daughterboard LO lock detect (where applicable) --- host/examples/rx_ascii_art_dft.cpp | 39 +++++++++++++++++++++++-- host/examples/rx_samples_to_file.cpp | 38 +++++++++++++++++++++++- host/examples/rx_samples_to_udp.cpp | 53 ++++++++++++++++++++++++++++++++-- host/examples/tx_samples_from_file.cpp | 37 +++++++++++++++++++++++- host/examples/tx_waveforms.cpp | 38 +++++++++++++++++++++++- 5 files changed, 198 insertions(+), 7 deletions(-) diff --git a/host/examples/rx_ascii_art_dft.cpp b/host/examples/rx_ascii_art_dft.cpp index fa8c4d4a4..11a0ccc24 100644 --- a/host/examples/rx_ascii_art_dft.cpp +++ b/host/examples/rx_ascii_art_dft.cpp @@ -32,7 +32,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ uhd::set_thread_priority_safe(); //variables to be set by po - std::string args, ant, subdev; + std::string args, ant, subdev, ref; size_t num_bins; double rate, freq, gain, bw, frame_rate; float ref_lvl, dyn_rng; @@ -54,6 +54,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ ("frame-rate", po::value(&frame_rate)->default_value(5), "frame rate of the display (fps)") ("ref-lvl", po::value(&ref_lvl)->default_value(0), "reference level for the display (dB)") ("dyn-rng", po::value(&dyn_rng)->default_value(60), "dynamic range for the display (dB)") + ("ref", po::value(&ref)->default_value("INTERNAL"), "waveform type (INTERNAL, EXTERNAL, MIMO)") ; po::variables_map vm; po::store(po::parse_command_line(argc, argv, desc), vm); @@ -70,7 +71,21 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ 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 + //Lock mboard clocks + if (ref == "MIMO") { + uhd::clock_config_t clock_config; + clock_config.ref_source = uhd::clock_config_t::REF_MIMO; + clock_config.pps_source = uhd::clock_config_t::PPS_MIMO; + usrp->set_clock_config(clock_config, 0); + } + else if (ref == "EXTERNAL") { + usrp->set_clock_config(uhd::clock_config_t::external(), 0); + } + else if (ref == "INTERNAL") { + usrp->set_clock_config(uhd::clock_config_t::internal(), 0); + } + + //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; @@ -112,6 +127,26 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ boost::this_thread::sleep(boost::posix_time::seconds(1)); //allow for some setup time + //Check Ref and LO Lock detect + std::vector sensor_names; + sensor_names = usrp->get_rx_sensor_names(0); + if (std::find(sensor_names.begin(), sensor_names.end(), "lo_locked") != sensor_names.end()) { + uhd::sensor_value_t lo_locked = usrp->get_rx_sensor("lo_locked",0); + std::cout << boost::format("Checking RX: %s ...") % lo_locked.to_pp_string() << std::endl; + UHD_ASSERT_THROW(lo_locked.to_bool()); + } + sensor_names = usrp->get_mboard_sensor_names(0); + if ((ref == "MIMO") and (std::find(sensor_names.begin(), sensor_names.end(), "mimo_locked") != sensor_names.end())) { + uhd::sensor_value_t mimo_locked = usrp->get_mboard_sensor("mimo_locked",0); + std::cout << boost::format("Checking RX: %s ...") % mimo_locked.to_pp_string() << std::endl; + UHD_ASSERT_THROW(mimo_locked.to_bool()); + } + if ((ref == "EXTERNAL") and (std::find(sensor_names.begin(), sensor_names.end(), "ref_locked") != sensor_names.end())) { + uhd::sensor_value_t ref_locked = usrp->get_mboard_sensor("ref_locked",0); + std::cout << boost::format("Checking RX: %s ...") % ref_locked.to_pp_string() << std::endl; + UHD_ASSERT_THROW(ref_locked.to_bool()); + } + //allocate recv buffer and metatdata uhd::rx_metadata_t md; std::vector > buff(num_bins); diff --git a/host/examples/rx_samples_to_file.cpp b/host/examples/rx_samples_to_file.cpp index d44315701..05d9b15b7 100644 --- a/host/examples/rx_samples_to_file.cpp +++ b/host/examples/rx_samples_to_file.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -64,7 +65,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; + std::string args, file, type, ant, subdev, ref; size_t total_num_samps, spb; double rate, freq, gain, bw; @@ -83,6 +84,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ ("ant", po::value(&ant), "daughterboard antenna selection") ("subdev", po::value(&subdev), "daughterboard subdevice specification") ("bw", po::value(&bw), "daughterboard IF filter bandwidth in Hz") + ("ref", po::value(&ref)->default_value("INTERNAL"), "waveform type (INTERNAL, EXTERNAL, MIMO)") ; po::variables_map vm; po::store(po::parse_command_line(argc, argv, desc), vm); @@ -99,6 +101,20 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ 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); + //Lock mboard clocks + if (ref == "MIMO") { + uhd::clock_config_t clock_config; + clock_config.ref_source = uhd::clock_config_t::REF_MIMO; + clock_config.pps_source = uhd::clock_config_t::PPS_MIMO; + usrp->set_clock_config(clock_config, 0); + } + else if (ref == "EXTERNAL") { + usrp->set_clock_config(uhd::clock_config_t::external(), 0); + } + else if (ref == "INTERNAL") { + usrp->set_clock_config(uhd::clock_config_t::internal(), 0); + } + //always select the subdevice first, the channel mapping affects the other settings if (vm.count("subdev")) usrp->set_rx_subdev_spec(subdev); @@ -141,6 +157,26 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ boost::this_thread::sleep(boost::posix_time::seconds(1)); //allow for some setup time + //Check Ref and LO Lock detect + std::vector sensor_names; + sensor_names = usrp->get_rx_sensor_names(0); + if (std::find(sensor_names.begin(), sensor_names.end(), "lo_locked") != sensor_names.end()) { + uhd::sensor_value_t lo_locked = usrp->get_rx_sensor("lo_locked",0); + std::cout << boost::format("Checking RX: %s ...") % lo_locked.to_pp_string() << std::endl; + UHD_ASSERT_THROW(lo_locked.to_bool()); + } + sensor_names = usrp->get_mboard_sensor_names(0); + if ((ref == "MIMO") and (std::find(sensor_names.begin(), sensor_names.end(), "mimo_locked") != sensor_names.end())) { + uhd::sensor_value_t mimo_locked = usrp->get_mboard_sensor("mimo_locked",0); + std::cout << boost::format("Checking RX: %s ...") % mimo_locked.to_pp_string() << std::endl; + UHD_ASSERT_THROW(mimo_locked.to_bool()); + } + if ((ref == "EXTERNAL") and (std::find(sensor_names.begin(), sensor_names.end(), "ref_locked") != sensor_names.end())) { + uhd::sensor_value_t ref_locked = usrp->get_mboard_sensor("ref_locked",0); + std::cout << boost::format("Checking RX: %s ...") % ref_locked.to_pp_string() << std::endl; + UHD_ASSERT_THROW(ref_locked.to_bool()); + } + //setup streaming uhd::stream_cmd_t stream_cmd((total_num_samps == 0)? uhd::stream_cmd_t::STREAM_MODE_START_CONTINUOUS: diff --git a/host/examples/rx_samples_to_udp.cpp b/host/examples/rx_samples_to_udp.cpp index 7ea775764..d06f1bc6e 100644 --- a/host/examples/rx_samples_to_udp.cpp +++ b/host/examples/rx_samples_to_udp.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -31,9 +32,9 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ uhd::set_thread_priority_safe(); //variables to be set by po - std::string args; + std::string args, file, ant, subdev, ref; size_t total_num_samps; - double rate, freq, gain; + double rate, freq, gain, bw; std::string addr, port; //setup the program options @@ -45,8 +46,12 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ ("rate", po::value(&rate)->default_value(100e6/16), "rate of incoming samples") ("freq", po::value(&freq)->default_value(0), "rf center frequency in Hz") ("gain", po::value(&gain)->default_value(0), "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") ("port", po::value(&port)->default_value("7124"), "server udp port") ("addr", po::value(&addr)->default_value("192.168.1.10"), "resolvable server address") + ("ref", po::value(&ref)->default_value("INTERNAL"), "waveform type (INTERNAL, EXTERNAL, MIMO)") ; po::variables_map vm; po::store(po::parse_command_line(argc, argv, desc), vm); @@ -64,6 +69,20 @@ 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; + //Lock mboard clocks + if (ref == "MIMO") { + uhd::clock_config_t clock_config; + clock_config.ref_source = uhd::clock_config_t::REF_MIMO; + clock_config.pps_source = uhd::clock_config_t::PPS_MIMO; + usrp->set_clock_config(clock_config, 0); + } + else if (ref == "EXTERNAL") { + usrp->set_clock_config(uhd::clock_config_t::external(), 0); + } + else if (ref == "INTERNAL") { + usrp->set_clock_config(uhd::clock_config_t::internal(), 0); + } + //set the rx sample rate std::cout << boost::format("Setting RX Rate: %f Msps...") % (rate/1e6) << std::endl; usrp->set_rx_rate(rate); @@ -79,8 +98,38 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ 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 + //Check Ref and LO Lock detect + std::vector sensor_names; + sensor_names = usrp->get_rx_sensor_names(0); + if (std::find(sensor_names.begin(), sensor_names.end(), "lo_locked") != sensor_names.end()) { + uhd::sensor_value_t lo_locked = usrp->get_rx_sensor("lo_locked",0); + std::cout << boost::format("Checking RX: %s ...") % lo_locked.to_pp_string() << std::endl; + UHD_ASSERT_THROW(lo_locked.to_bool()); + } + sensor_names = usrp->get_mboard_sensor_names(0); + if ((ref == "MIMO") and (std::find(sensor_names.begin(), sensor_names.end(), "mimo_locked") != sensor_names.end())) { + uhd::sensor_value_t mimo_locked = usrp->get_mboard_sensor("mimo_locked",0); + std::cout << boost::format("Checking RX: %s ...") % mimo_locked.to_pp_string() << std::endl; + UHD_ASSERT_THROW(mimo_locked.to_bool()); + } + if ((ref == "EXTERNAL") and (std::find(sensor_names.begin(), sensor_names.end(), "ref_locked") != sensor_names.end())) { + uhd::sensor_value_t ref_locked = usrp->get_mboard_sensor("ref_locked",0); + std::cout << boost::format("Checking RX: %s ...") % ref_locked.to_pp_string() << std::endl; + UHD_ASSERT_THROW(ref_locked.to_bool()); + } + //setup streaming uhd::stream_cmd_t stream_cmd(uhd::stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_DONE); stream_cmd.num_samps = total_num_samps; diff --git a/host/examples/tx_samples_from_file.cpp b/host/examples/tx_samples_from_file.cpp index acf899fa9..d052baa4a 100644 --- a/host/examples/tx_samples_from_file.cpp +++ b/host/examples/tx_samples_from_file.cpp @@ -60,7 +60,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; + std::string args, file, type, ant, subdev, ref; size_t spb; double rate, freq, gain, bw; @@ -78,6 +78,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ ("ant", po::value(&ant), "daughterboard antenna selection") ("subdev", po::value(&subdev), "daughterboard subdevice specification") ("bw", po::value(&bw), "daughterboard IF filter bandwidth in Hz") + ("ref", po::value(&ref)->default_value("INTERNAL"), "waveform type (INTERNAL, EXTERNAL, MIMO)") ; po::variables_map vm; po::store(po::parse_command_line(argc, argv, desc), vm); @@ -94,6 +95,20 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ 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); + //Lock mboard clocks + if (ref == "MIMO") { + uhd::clock_config_t clock_config; + clock_config.ref_source = uhd::clock_config_t::REF_MIMO; + clock_config.pps_source = uhd::clock_config_t::PPS_MIMO; + usrp->set_clock_config(clock_config, 0); + } + else if (ref == "EXTERNAL") { + usrp->set_clock_config(uhd::clock_config_t::external(), 0); + } + else if (ref == "INTERNAL") { + usrp->set_clock_config(uhd::clock_config_t::internal(), 0); + } + //always select the subdevice first, the channel mapping affects the other settings if (vm.count("subdev")) usrp->set_tx_subdev_spec(subdev); @@ -136,6 +151,26 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ boost::this_thread::sleep(boost::posix_time::seconds(1)); //allow for some setup time + //Check Ref and LO Lock detect + std::vector sensor_names; + sensor_names = usrp->get_tx_sensor_names(0); + if (std::find(sensor_names.begin(), sensor_names.end(), "lo_locked") != sensor_names.end()) { + uhd::sensor_value_t lo_locked = usrp->get_tx_sensor("lo_locked",0); + std::cout << boost::format("Checking TX: %s ...") % lo_locked.to_pp_string() << std::endl; + UHD_ASSERT_THROW(lo_locked.to_bool()); + } + sensor_names = usrp->get_mboard_sensor_names(0); + if ((ref == "MIMO") and (std::find(sensor_names.begin(), sensor_names.end(), "mimo_locked") != sensor_names.end())) { + uhd::sensor_value_t mimo_locked = usrp->get_mboard_sensor("mimo_locked",0); + std::cout << boost::format("Checking TX: %s ...") % mimo_locked.to_pp_string() << std::endl; + UHD_ASSERT_THROW(mimo_locked.to_bool()); + } + if ((ref == "EXTERNAL") and (std::find(sensor_names.begin(), sensor_names.end(), "ref_locked") != sensor_names.end())) { + uhd::sensor_value_t ref_locked = usrp->get_mboard_sensor("ref_locked",0); + std::cout << boost::format("Checking TX: %s ...") % ref_locked.to_pp_string() << std::endl; + UHD_ASSERT_THROW(ref_locked.to_bool()); + } + //send from file if (type == "double") send_from_file >(usrp, uhd::io_type_t::COMPLEX_FLOAT64, file, spb); else if (type == "float") send_from_file >(usrp, uhd::io_type_t::COMPLEX_FLOAT32, file, spb); diff --git a/host/examples/tx_waveforms.cpp b/host/examples/tx_waveforms.cpp index b78cc7d0a..261b1342d 100644 --- a/host/examples/tx_waveforms.cpp +++ b/host/examples/tx_waveforms.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -89,7 +90,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ uhd::set_thread_priority_safe(); //variables to be set by po - std::string args, wave_type, ant, subdev; + std::string args, wave_type, ant, subdev, ref; size_t spb; double rate, freq, gain, wave_freq, bw; float ampl; @@ -109,6 +110,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ ("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") + ("ref", po::value(&ref)->default_value("INTERNAL"), "waveform type (INTERNAL, EXTERNAL, MIMO)") ; po::variables_map vm; po::store(po::parse_command_line(argc, argv, desc), vm); @@ -125,6 +127,20 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ 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); + //Lock mboard clocks + if (ref == "MIMO") { + uhd::clock_config_t clock_config; + clock_config.ref_source = uhd::clock_config_t::REF_MIMO; + clock_config.pps_source = uhd::clock_config_t::PPS_MIMO; + usrp->set_clock_config(clock_config, 0); + } + else if (ref == "EXTERNAL") { + usrp->set_clock_config(uhd::clock_config_t::external(), 0); + } + else if (ref == "INTERNAL") { + usrp->set_clock_config(uhd::clock_config_t::internal(), 0); + } + //always select the subdevice first, the channel mapping affects the other settings if (vm.count("subdev")) usrp->set_tx_subdev_spec(subdev); @@ -200,6 +216,26 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ std::cout << boost::format("Setting device timestamp to 0...") << std::endl; usrp->set_time_now(uhd::time_spec_t(0.0)); + //Check Ref and LO Lock detect + std::vector sensor_names; + sensor_names = usrp->get_tx_sensor_names(0); + if (std::find(sensor_names.begin(), sensor_names.end(), "lo_locked") != sensor_names.end()) { + uhd::sensor_value_t lo_locked = usrp->get_tx_sensor("lo_locked",0); + std::cout << boost::format("Checking TX: %s ...") % lo_locked.to_pp_string() << std::endl; + UHD_ASSERT_THROW(lo_locked.to_bool()); + } + sensor_names = usrp->get_mboard_sensor_names(0); + if ((ref == "MIMO") and (std::find(sensor_names.begin(), sensor_names.end(), "mimo_locked") != sensor_names.end())) { + uhd::sensor_value_t mimo_locked = usrp->get_mboard_sensor("mimo_locked",0); + std::cout << boost::format("Checking TX: %s ...") % mimo_locked.to_pp_string() << std::endl; + UHD_ASSERT_THROW(mimo_locked.to_bool()); + } + if ((ref == "EXTERNAL") and (std::find(sensor_names.begin(), sensor_names.end(), "ref_locked") != sensor_names.end())) { + uhd::sensor_value_t ref_locked = usrp->get_mboard_sensor("ref_locked",0); + std::cout << boost::format("Checking TX: %s ...") % ref_locked.to_pp_string() << std::endl; + UHD_ASSERT_THROW(ref_locked.to_bool()); + } + std::signal(SIGINT, &sig_int_handler); std::cout << "Press Ctrl + C to stop streaming..." << std::endl; -- cgit v1.2.3