mirror of
				https://github.com/gnss-sdr/gnss-sdr
				synced 2025-10-30 06:52:58 +00:00 
			
		
		
		
	Fix device_address bug, added comments, code cleaning
git-svn-id: https://svn.code.sf.net/p/gnss-sdr/code/trunk@269 64b25241-fba3-4117-9849-534c7e92360d
This commit is contained in:
		| @@ -33,7 +33,6 @@ | |||||||
| #include <gnuradio/gr_uhd_usrp_source.h> | #include <gnuradio/gr_uhd_usrp_source.h> | ||||||
| #include <uhd/types/device_addr.hpp> | #include <uhd/types/device_addr.hpp> | ||||||
| #include <uhd/exception.hpp> | #include <uhd/exception.hpp> | ||||||
| //#include <boost/program_options.hpp> |  | ||||||
| #include <gnuradio/gr_file_sink.h> | #include <gnuradio/gr_file_sink.h> | ||||||
| #include "configuration_interface.h" | #include "configuration_interface.h" | ||||||
| #include "gnss_sdr_valve.h" | #include "gnss_sdr_valve.h" | ||||||
| @@ -50,34 +49,34 @@ UhdSignalSource::UhdSignalSource(ConfigurationInterface* configuration, | |||||||
|                 role_(role), in_stream_(in_stream), out_stream_(out_stream), |                 role_(role), in_stream_(in_stream), out_stream_(out_stream), | ||||||
|                 queue_(queue) |                 queue_(queue) | ||||||
| { | { | ||||||
|  |  | ||||||
|     // DUMP PARAMETERS |     // DUMP PARAMETERS | ||||||
|     std::string empty = ""; |     std::string empty = ""; | ||||||
|     std::string default_dump_file = "./data/signal_source.dat"; |     std::string default_dump_file = "./data/signal_source.dat"; | ||||||
|     std::string default_item_type = "short"; |     std::string default_item_type = "short"; | ||||||
|     samples_ = configuration->property(role + ".samples", 0); |     samples_ = configuration->property(role + ".samples", 0); | ||||||
|     dump_ = configuration->property(role + ".dump", false); |     dump_ = configuration->property(role + ".dump", false); | ||||||
|     dump_filename_ = configuration->property(role + ".dump_filename", |     dump_filename_ = configuration->property(role + ".dump_filename", default_dump_file); | ||||||
|             default_dump_file); |  | ||||||
|  |  | ||||||
|     // UHD PARAMETERS |     // UHD PARAMETERS | ||||||
|     uhd::device_addr_t dev_addr; |     uhd::device_addr_t dev_addr; | ||||||
|     device_address_= configuration->property(role + ".device_address", empty); |     device_address_= configuration->property(role + ".device_address", empty); | ||||||
|     if (empty.compare(empty)!=0) |     // When left empty, the device discovery routines will search all | ||||||
|  |     // available transports on the system (ethernet, usb...). | ||||||
|  |     // To narrow down the discovery process to a particular device, | ||||||
|  |     // specify a transport key/value pair specific to your device. | ||||||
|  |     if (empty.compare(device_address_) != 0) // if not empty | ||||||
|  |     //if (empty.compare(empty) != 0) ?? | ||||||
|         { |         { | ||||||
|             dev_addr["addr0"] = device_address_; |             dev_addr["addr0"] = device_address_; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|     subdevice_ = configuration->property(role + ".subdevice", empty); |     subdevice_ = configuration->property(role + ".subdevice", empty); | ||||||
|  |  | ||||||
|     freq_ = configuration->property(role + ".freq", GPS_L1_FREQ_HZ); |     freq_ = configuration->property(role + ".freq", GPS_L1_FREQ_HZ); | ||||||
|     gain_ = configuration->property(role + ".gain", (double)50.0); |     gain_ = configuration->property(role + ".gain", (double)50.0); | ||||||
|     sample_rate_ = configuration->property(role + ".sampling_frequency", (double)4.0e6); |     sample_rate_ = configuration->property(role + ".sampling_frequency", (double)4.0e6); | ||||||
|  |  | ||||||
|     IF_bandwidth_hz_ = configuration->property(role + ".IF_bandwidth_hz", sample_rate_/2); |     IF_bandwidth_hz_ = configuration->property(role + ".IF_bandwidth_hz", sample_rate_/2); | ||||||
|  |     item_type_ = configuration->property(role + ".item_type", default_item_type); | ||||||
|  |  | ||||||
|     item_type_ = configuration->property(role + ".item_type", |  | ||||||
|             default_item_type); |  | ||||||
|     if (item_type_.compare("short") == 0) |     if (item_type_.compare("short") == 0) | ||||||
|         { |         { | ||||||
|             item_size_ = sizeof(short); |             item_size_ = sizeof(short); | ||||||
| @@ -89,67 +88,80 @@ UhdSignalSource::UhdSignalSource(ConfigurationInterface* configuration, | |||||||
|             //uhd_source_= uhd::usrp::multi_usrp::make(dev_addr); |             //uhd_source_= uhd::usrp::multi_usrp::make(dev_addr); | ||||||
|  |  | ||||||
|             // single source |             // single source | ||||||
|             // * \param device_addr the address to identify the hardware |             // param: device_addr the address to identify the hardware | ||||||
|             // * \param io_type the desired output data type |             // 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_ = uhd_make_usrp_source(dev_addr, uhd::stream_args_t("fc32")); | ||||||
|  |             std::cout << boost::format("Using Device: %s") % uhd_source_->get_pp_string() << std::endl; | ||||||
|  |  | ||||||
|             // 2.1 set sampling clock reference |             // 2.1 set sampling clock reference | ||||||
|             //Lock mboard clocks internal, external, or mimo |             // Set the clock source for the usrp device. | ||||||
|  |             // Options: internal, external, or MIMO | ||||||
|             std::string clk_reference = "internal"; |             std::string clk_reference = "internal"; | ||||||
|             uhd_source_->set_clock_source(clk_reference); |             uhd_source_->set_clock_source(clk_reference); | ||||||
|  |  | ||||||
|             // 2.2 set sampling rate |             // 2.2 set the sample rate for the usrp device | ||||||
|             uhd_source_->set_samp_rate(sample_rate_); |             uhd_source_->set_samp_rate(sample_rate_); | ||||||
|             std::cout << boost::format("Actual RX Rate: %f [SPS]...") % (uhd_source_->get_samp_rate()) << std::endl << std::endl; |             // the actual sample rate may differ from the rate set | ||||||
|             DLOG(INFO) << boost::format("Actual RX Rate: %f [SPS]...") % (uhd_source_->get_samp_rate()) << std::endl << std::endl; |             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. set rx frequency |             // 3. Tune the usrp device to the desired center frequency | ||||||
|             uhd_source_->set_center_freq(freq_); |             uhd_source_->set_center_freq(freq_); | ||||||
|             std::cout << boost::format("Actual RX Freq: %f [Hz]...") % (uhd_source_->get_center_freq()) << std::endl << std::endl; |             std::cout << boost::format("Actual USRP center freq.: %f [Hz]...") % (uhd_source_->get_center_freq()) << std::endl << std::endl; | ||||||
|             DLOG(INFO) << boost::format("Actual RX 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: Asign the remanent IF from the PLL tune error |             // 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; |             std::cout << boost::format("PLL Frequency tune error %f [Hz]...") % (uhd_source_->get_center_freq() - freq_) << std::endl; | ||||||
|             DLOG(INFO) <<  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 rx gain |             // 4. set the gain for the daughterboard | ||||||
|             uhd_source_->set_gain(gain_); |             uhd_source_->set_gain(gain_); | ||||||
|             std::cout << boost::format("Actual RX Gain: %f dB...") % uhd_source_->get_gain() << std::endl << std::endl; |             std::cout << boost::format("Actual daughterboard gain set to: %f dB...") % uhd_source_->get_gain() << std::endl; | ||||||
|             DLOG(INFO) << boost::format("Actual RX Gain: %f dB...") % uhd_source_->get_gain() << std::endl << std::endl; |             LOG(INFO) << boost::format("Actual daughterboard gain set to: %f dB...") % uhd_source_->get_gain(); | ||||||
|  |  | ||||||
|             //5. set the IF filter bandwidth |             //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; | ||||||
|             std::cout << boost::format("Setting RX Bandwidth: %f [Hz]...") % IF_bandwidth_hz_ << std::endl; |  | ||||||
|             uhd_source_->set_bandwidth(IF_bandwidth_hz_); |             uhd_source_->set_bandwidth(IF_bandwidth_hz_); | ||||||
|             ///std::cout << boost::format("Actual RX Bandwidth: %f MHz...") % uhd_source_->get_rx_bandwidth() << std::endl << std::endl; |  | ||||||
|             //DLOG(INFO) << boost::format("Actual RX Bandwidth: %f MHz...") % uhd_source_->get_rx_bandwidth() << std::endl << std::endl; |  | ||||||
|  |  | ||||||
|             //set the antenna (optional) |             //set the antenna (optional) | ||||||
|             //uhd_source_->set_antenna(ant); |             //uhd_source_->set_antenna(ant); | ||||||
|  |  | ||||||
|             //LO lock status |             // We should wait? #include <boost/thread.hpp> | ||||||
|             //Check Ref and LO Lock detect |             // 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<std::string> sensor_names; |             std::vector<std::string> sensor_names; | ||||||
|             sensor_names = uhd_source_->get_sensor_names(0); |             sensor_names = uhd_source_->get_sensor_names(0); | ||||||
|             if (std::find(sensor_names.begin(), sensor_names.end(), "lo_locked") != sensor_names.end()) { |             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); |                     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 "; |                     std::cout << boost::format("Check for front-end %s ...") % lo_locked.to_pp_string() << " is "; | ||||||
|                     if (lo_locked.to_bool() == true) |                     if (lo_locked.to_bool() == true) | ||||||
|                         { |                         { | ||||||
|                             std::cout << "Locked" << std::endl; |                             std::cout << "Locked" << std::endl; | ||||||
|                 }else{ |                         } | ||||||
|                 	std::cout<<"UNLOCKED!!!!"<<std::endl; |                     else | ||||||
|  |                         { | ||||||
|  |                             std::cout << "UNLOCKED!" <<std::endl; | ||||||
|                         } |                         } | ||||||
|                     //UHD_ASSERT_THROW(lo_locked.to_bool()); |                     //UHD_ASSERT_THROW(lo_locked.to_bool()); | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
|  |             // Set subdevice specification string for USRP family devices. It is composed of: | ||||||
|  |             // <motherboard slot name>:<daughterboard frontend name> | ||||||
|  |             // 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); |             uhd_source_->set_subdev_spec(subdevice_, 0); | ||||||
|         } |         } | ||||||
|     else |     else | ||||||
|         { |         { | ||||||
|             LOG_AT_LEVEL(WARNING) << item_type_ |             LOG_AT_LEVEL(WARNING) << item_type_ << " unrecognized item type. Using short."; | ||||||
|                     << " unrecognized item type. Using short."; |  | ||||||
|             item_size_ = sizeof(short); |             item_size_ = sizeof(short); | ||||||
|         } |         } | ||||||
|  |  | ||||||
| @@ -166,21 +178,21 @@ UhdSignalSource::UhdSignalSource(ConfigurationInterface* configuration, | |||||||
|             file_sink_ = gr_make_file_sink(item_size_, dump_filename_.c_str()); |             file_sink_ = gr_make_file_sink(item_size_, dump_filename_.c_str()); | ||||||
|             DLOG(INFO) << "file_sink(" << file_sink_->unique_id() << ")"; |             DLOG(INFO) << "file_sink(" << file_sink_->unique_id() << ")"; | ||||||
|         } |         } | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| UhdSignalSource::~UhdSignalSource() | UhdSignalSource::~UhdSignalSource() | ||||||
| { | {} | ||||||
| } |  | ||||||
|  |  | ||||||
|  |  | ||||||
| void UhdSignalSource::connect(gr_top_block_sptr top_block) | void UhdSignalSource::connect(gr_top_block_sptr top_block) | ||||||
| { | { | ||||||
|  |  | ||||||
|     if (samples_ != 0) |     if (samples_ != 0) | ||||||
|         { |         { | ||||||
|             top_block->connect(uhd_source_, 0, valve_, 0); |             top_block->connect(uhd_source_, 0, valve_, 0); | ||||||
|             DLOG(INFO) << "connected usrp source to valve"; |             DLOG(INFO) << "connected usrp source to valve"; | ||||||
|  |  | ||||||
|             if (dump_) |             if (dump_) | ||||||
|                 { |                 { | ||||||
|                     top_block->connect(valve_, 0, file_sink_, 0); |                     top_block->connect(valve_, 0, file_sink_, 0); | ||||||
| @@ -197,13 +209,14 @@ void UhdSignalSource::connect(gr_top_block_sptr top_block) | |||||||
|         } |         } | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| void UhdSignalSource::disconnect(gr_top_block_sptr top_block) | void UhdSignalSource::disconnect(gr_top_block_sptr top_block) | ||||||
| { | { | ||||||
|  |  | ||||||
|     if (samples_ != 0) |     if (samples_ != 0) | ||||||
|         { |         { | ||||||
|             top_block->disconnect(uhd_source_, 0, valve_, 0); |             top_block->disconnect(uhd_source_, 0, valve_, 0); | ||||||
|  |             DLOG(INFO) << "usrp source disconnected"; | ||||||
|             if (dump_) |             if (dump_) | ||||||
|                 { |                 { | ||||||
|                     top_block->disconnect(valve_, 0, file_sink_, 0); |                     top_block->disconnect(valve_, 0, file_sink_, 0); | ||||||
| @@ -218,12 +231,16 @@ void UhdSignalSource::disconnect(gr_top_block_sptr top_block) | |||||||
|         } |         } | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| gr_basic_block_sptr UhdSignalSource::get_left_block() | gr_basic_block_sptr UhdSignalSource::get_left_block() | ||||||
| { | { | ||||||
|     LOG_AT_LEVEL(WARNING) << "Trying to get signal source left block."; |     LOG_AT_LEVEL(WARNING) << "Trying to get signal source left block."; | ||||||
|     return gr_basic_block_sptr(); |     return gr_basic_block_sptr(); | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| gr_basic_block_sptr UhdSignalSource::get_right_block() | gr_basic_block_sptr UhdSignalSource::get_right_block() | ||||||
| { | { | ||||||
|     if (samples_ != 0) |     if (samples_ != 0) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Carles Fernandez
					Carles Fernandez