diff --git a/src/algorithms/signal_source/adapters/CMakeLists.txt b/src/algorithms/signal_source/adapters/CMakeLists.txt index 82a605366..9eb7c8f4b 100644 --- a/src/algorithms/signal_source/adapters/CMakeLists.txt +++ b/src/algorithms/signal_source/adapters/CMakeLists.txt @@ -128,6 +128,7 @@ include_directories( ${GFlags_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS} ${GNURADIO_RUNTIME_INCLUDE_DIRS} + ${VOLK_INCLUDE_DIRS} ) if(ARCH_64BITS) diff --git a/src/algorithms/signal_source/adapters/file_signal_source.cc b/src/algorithms/signal_source/adapters/file_signal_source.cc index e1a6ea92b..60ae43af1 100644 --- a/src/algorithms/signal_source/adapters/file_signal_source.cc +++ b/src/algorithms/signal_source/adapters/file_signal_source.cc @@ -38,6 +38,7 @@ #include #include #include +#include #include "gnss_sdr_valve.h" #include "configuration_interface.h" @@ -82,11 +83,11 @@ FileSignalSource::FileSignalSource(ConfigurationInterface* configuration, } else if (item_type_.compare("short") == 0) { - item_size_ = sizeof(short int); + item_size_ = sizeof(int16_t); } else if (item_type_.compare("byte") == 0) { - item_size_ = sizeof(char); + item_size_ = sizeof(int8_t); } else { diff --git a/src/algorithms/signal_source/adapters/uhd_signal_source.cc b/src/algorithms/signal_source/adapters/uhd_signal_source.cc index 97ae83538..f19ac99dd 100644 --- a/src/algorithms/signal_source/adapters/uhd_signal_source.cc +++ b/src/algorithms/signal_source/adapters/uhd_signal_source.cc @@ -32,6 +32,7 @@ #include #include #include +#include #include #include "configuration_interface.h" #include "gnss_sdr_valve.h" @@ -48,7 +49,7 @@ UhdSignalSource::UhdSignalSource(ConfigurationInterface* configuration, // DUMP PARAMETERS std::string empty = ""; std::string default_dump_file = "./data/signal_source.dat"; - std::string default_item_type = "short"; + std::string default_item_type = "cshort"; samples_ = configuration->property(role + ".samples", 0); dump_ = configuration->property(role + ".dump", false); dump_filename_ = configuration->property(role + ".dump_filename", default_dump_file); @@ -71,95 +72,100 @@ UhdSignalSource::UhdSignalSource(ConfigurationInterface* configuration, IF_bandwidth_hz_ = configuration->property(role + ".IF_bandwidth_hz", sample_rate_/2); item_type_ = configuration->property(role + ".item_type", default_item_type); - if (item_type_.compare("short") == 0) + // 1. Make the uhd driver instance + //uhd_source_= uhd::usrp::multi_usrp::make(dev_addr); + + // single source + // param: device_addr the address to identify the hardware + // param: io_type the desired output data type + // fc64: Complex floating point (64-bit floats) range [-1.0, +1.0]. + // fc32: Complex floating point (32-bit floats) range [-1.0, +1.0]. + // sc16: Complex signed integer (16-bit integers) range [-32768, +32767]. + // sc8: Complex signed integer (8-bit integers) range [-128, 127]. + if (item_type_.compare("cbyte") == 0) { - item_size_ = sizeof(short); + item_size_ = sizeof(lv_8sc_t); + uhd_source_ = gr::uhd::usrp_source::make(dev_addr, uhd::stream_args_t("sc8")); + } + else if (item_type_.compare("cshort") == 0) + { + item_size_ = sizeof(lv_16sc_t); + uhd_source_ = gr::uhd::usrp_source::make(dev_addr, uhd::stream_args_t("sc16")); } else if (item_type_.compare("gr_complex") == 0) { item_size_ = sizeof(gr_complex); - // 1. Make the uhd driver instance - //uhd_source_= uhd::usrp::multi_usrp::make(dev_addr); - - // single source - // param: device_addr the address to identify the hardware - // param: io_type the desired output data type - // fc64: Complex floating point (64-bit floats) range [-1.0, +1.0]. - // fc32: Complex floating point (32-bit floats) range [-1.0, +1.0]. - // sc16: Complex signed integer (16-bit integers) range [-32768, +32767]. - // sc8: Complex signed integer (8-bit integers) range [-128, 127]. - //uhd_source_ = uhd_make_usrp_source(dev_addr, uhd::stream_args_t("fc32")); uhd_source_ = gr::uhd::usrp_source::make(dev_addr, uhd::stream_args_t("fc32")); - - - // 2.1 set sampling clock reference - // Set the clock source for the usrp device. - // Options: internal, external, or MIMO - std::string clk_reference = "internal"; - uhd_source_->set_clock_source(clk_reference); - - // 2.2 set the sample rate for the usrp device - uhd_source_->set_samp_rate(sample_rate_); - // the actual sample rate may differ from the rate set - std::cout << boost::format("Sampling Rate for the USRP device: %f [sps]...") % (uhd_source_->get_samp_rate()) << std::endl; - LOG(INFO) << boost::format("Sampling Rate for the USRP device: %f [sps]...") % (uhd_source_->get_samp_rate()); - - // 3. Tune the usrp device to the desired center frequency - uhd_source_->set_center_freq(freq_); - std::cout << boost::format("Actual USRP center freq.: %f [Hz]...") % (uhd_source_->get_center_freq()) << std::endl << std::endl; - LOG(INFO) << boost::format("Actual USRP center freq. set to: %f [Hz]...") % (uhd_source_->get_center_freq()); - - // TODO: Assign the remnant IF from the PLL tune error - std::cout << boost::format("PLL Frequency tune error %f [Hz]...") % (uhd_source_->get_center_freq() - freq_) << std::endl; - LOG(INFO) << boost::format("PLL Frequency tune error %f [Hz]...") % (uhd_source_->get_center_freq() - freq_); - - // 4. set the gain for the daughterboard - uhd_source_->set_gain(gain_); - std::cout << boost::format("Actual daughterboard gain set to: %f dB...") % uhd_source_->get_gain() << std::endl; - LOG(INFO) << boost::format("Actual daughterboard gain set to: %f dB...") % uhd_source_->get_gain(); - - //5. Set the bandpass filter on the RF frontend - std::cout << boost::format("Setting RF bandpass filter bandwidth to: %f [Hz]...") % IF_bandwidth_hz_ << std::endl; - uhd_source_->set_bandwidth(IF_bandwidth_hz_); - - //set the antenna (optional) - //uhd_source_->set_antenna(ant); - - // We should wait? #include - // boost::this_thread::sleep(boost::posix_time::seconds(1)); - - // Check out the status of the lo_locked sensor (boolean for LO lock state) - std::vector sensor_names; - sensor_names = uhd_source_->get_sensor_names(0); - if (std::find(sensor_names.begin(), sensor_names.end(), "lo_locked") != sensor_names.end()) - { - uhd::sensor_value_t lo_locked = uhd_source_->get_sensor("lo_locked", 0); - std::cout << boost::format("Check for front-end %s ...") % lo_locked.to_pp_string() << " is "; - if (lo_locked.to_bool() == true) - { - std::cout << "Locked" << std::endl; - } - else - { - std::cout << "UNLOCKED!" <: - // For motherboards: All USRP family motherboards have a first slot named A:. - // The USRP1 has two daughterboard subdevice slots, known as A: and B:. - // For daughterboards, see http://files.ettus.com/uhd_docs/manual/html/dboards.html - // "0" is valid for DBSRX, DBSRX2, WBX Series - uhd_source_->set_subdev_spec(subdevice_, 0); } else { - LOG(WARNING) << item_type_ << " unrecognized item type. Using short."; - item_size_ = sizeof(short); + LOG(WARNING) << item_type_ << " unrecognized item type. Using cshort."; + item_size_ = sizeof(lv_16sc_t); + uhd_source_ = gr::uhd::usrp_source::make(dev_addr, uhd::stream_args_t("sc16")); } + // 2.1 set sampling clock reference + // Set the clock source for the usrp device. + // Options: internal, external, or MIMO + std::string clk_reference = "internal"; + uhd_source_->set_clock_source(clk_reference); + + // 2.2 set the sample rate for the usrp device + uhd_source_->set_samp_rate(sample_rate_); + // the actual sample rate may differ from the rate set + std::cout << boost::format("Sampling Rate for the USRP device: %f [sps]...") % (uhd_source_->get_samp_rate()) << std::endl; + LOG(INFO) << boost::format("Sampling Rate for the USRP device: %f [sps]...") % (uhd_source_->get_samp_rate()); + + // 3. Tune the usrp device to the desired center frequency + uhd_source_->set_center_freq(freq_); + std::cout << boost::format("Actual USRP center freq.: %f [Hz]...") % (uhd_source_->get_center_freq()) << std::endl << std::endl; + LOG(INFO) << boost::format("Actual USRP center freq. set to: %f [Hz]...") % (uhd_source_->get_center_freq()); + + // TODO: Assign the remnant IF from the PLL tune error + std::cout << boost::format("PLL Frequency tune error %f [Hz]...") % (uhd_source_->get_center_freq() - freq_) << std::endl; + LOG(INFO) << boost::format("PLL Frequency tune error %f [Hz]...") % (uhd_source_->get_center_freq() - freq_); + + // 4. set the gain for the daughterboard + uhd_source_->set_gain(gain_); + std::cout << boost::format("Actual daughterboard gain set to: %f dB...") % uhd_source_->get_gain() << std::endl; + LOG(INFO) << boost::format("Actual daughterboard gain set to: %f dB...") % uhd_source_->get_gain(); + + //5. Set the bandpass filter on the RF frontend + std::cout << boost::format("Setting RF bandpass filter bandwidth to: %f [Hz]...") % IF_bandwidth_hz_ << std::endl; + uhd_source_->set_bandwidth(IF_bandwidth_hz_); + + //set the antenna (optional) + //uhd_source_->set_antenna(ant); + + // We should wait? #include + // boost::this_thread::sleep(boost::posix_time::seconds(1)); + + // Check out the status of the lo_locked sensor (boolean for LO lock state) + std::vector sensor_names; + sensor_names = uhd_source_->get_sensor_names(0); + if (std::find(sensor_names.begin(), sensor_names.end(), "lo_locked") != sensor_names.end()) + { + uhd::sensor_value_t lo_locked = uhd_source_->get_sensor("lo_locked", 0); + std::cout << boost::format("Check for front-end %s ...") % lo_locked.to_pp_string() << " is "; + if (lo_locked.to_bool() == true) + { + std::cout << "Locked" << std::endl; + } + else + { + std::cout << "UNLOCKED!" <: + // For motherboards: All USRP family motherboards have a first slot named A:. + // The USRP1 has two daughterboard subdevice slots, known as A: and B:. + // For daughterboards, see http://files.ettus.com/uhd_docs/manual/html/dboards.html + // "0" is valid for DBSRX, DBSRX2, WBX Series + uhd_source_->set_subdev_spec(subdevice_, 0); + if (samples_ != 0) { LOG(INFO) << "Send STOP signal after " << samples_ << " samples"; @@ -170,7 +176,6 @@ UhdSignalSource::UhdSignalSource(ConfigurationInterface* configuration, if (dump_) { LOG(INFO) << "Dumping output into file " << dump_filename_; - //file_sink_ = gr_make_file_sink(item_size_, dump_filename_.c_str()); file_sink_ = gr::blocks::file_sink::make(item_size_, dump_filename_.c_str()); DLOG(INFO) << "file_sink(" << file_sink_->unique_id() << ")"; }