예제 #1
1
void get_rx_parameters(uhd::usrp::multi_usrp::sptr usrp, size_t mboard , std::ostream & os)
{
	using namespace std;
	namespace radio = uhd::usrp;
	size_t nchan = 0;

	// Get sub device specification
	os << std::endl << "********** RX Sub Device ***********" << std::endl;
	os << std::endl << "-----> Get Rx Subdevice" << std::endl;
	radio::subdev_spec_t rx_subdev = usrp->get_rx_subdev_spec(mboard);
	os << "RX Subdevice Specification:" << endl;
	os << rx_subdev.to_pp_string() << endl;
	
	os << std::endl << "-----> Get number of RX channels" << std::endl;
	size_t num_rx = usrp->get_rx_num_channels();
	os << "Number of RX channels:" << endl;
	os << num_rx << endl;
	
	os << std::endl << "-----> Get RX Subdevice Name" << std::endl;
	string rx_name = usrp->get_rx_subdev_name(nchan);
	os << "RX Subdevice Name:" << endl;
	os << rx_name << endl;

	os << std::endl << "********** RX Sample Rate ***********" << std::endl;
	os << std::endl << "-----> Get RX Rate" << std::endl;
	double rx_rate = usrp->get_rx_rate(nchan);
	os << "RX Rate:" << endl;
	os << rx_rate << endl;
	
	os << std::endl << "-----> Get RX Rate List" << std::endl;
	uhd::meta_range_t rx_rates = usrp->get_rx_rates(nchan);
	os << "RX Rate List:" << endl;
	os << "Start: " << rx_rates.start() << "   Stop: " << rx_rates.stop() << "   Step: " << rx_rates.step() << endl;
	os << rx_rates.to_pp_string() << endl;
	
	// RX FREQUENCIES
	
	os << std::endl << "********** RX Frequencies ***********" << std::endl;
	os << std::endl << "-----> Get RX Center Frequency" << std::endl;
	double rx_freq = usrp->get_rx_freq(nchan);
	os << "RX Freq:" << endl;
	os << rx_freq << endl;

	os << std::endl << "-----> Get RX Center Frequency Range" << std::endl;
	uhd::freq_range_t rx_freq_range = usrp->get_rx_freq_range(nchan);
	os << "RX Frequency Range:" << endl;
	os << "Start: " << rx_freq_range.start() << "   Stop: " << rx_freq_range.stop() << "   Step: " << rx_freq_range.step() << endl;
	os << rx_freq_range.to_pp_string() << endl;
	
	// RX Front end frequencies
	os << std::endl << "-----> Get RX RF Front End Center Frequency Range" << std::endl;
	try
	{
		os << "RX Front End Frequency Range:" << endl;
		uhd::freq_range_t rx_fe_freq_range = usrp->get_fe_rx_freq_range(nchan);
		os << "Start: " << rx_fe_freq_range.start() << "   Stop: " << rx_fe_freq_range.stop() << "   Step: " << rx_fe_freq_range.step() << endl;
		os << rx_fe_freq_range.to_pp_string() << endl;
	}
		catch (uhd::runtime_error &e)
	{
		os << " Exception occurred : " << e.code() << endl;
	}
	
	// RX GAIN
	
	os << std::endl << "********** RX Gain  ***********" << std::endl;
	
	// Total combined gain
	os << endl << "-----> Get RX Total Gain" << endl;
	os << "RX Total Gain: " ;	
	try
	{
		double rx_total_gain = usrp->get_rx_gain(nchan);
		os << rx_total_gain << endl;
	}
	catch(uhd::runtime_error &e)
	{
		os << "Exception code: " << e.code() << endl;
	}
	
	// List of all gain elements
	os << std::endl << "-----> Get RX gain names" << std::endl;
	std::vector<std::string> rx_gain_names = usrp->get_rx_gain_names(nchan);
	os << "Rx Gain Names: " << std::endl;
	for (int index =0; index < rx_gain_names.size(); index++)
	{
		// Name
		os << "\t" << rx_gain_names[index] << endl;
	}
	for (int index =0; index < rx_gain_names.size(); index++)
	{
		// Name
		os << "\t" << "Name: " << rx_gain_names[index] << "  Value: ";
		// Value
		try
		{
		double element_gain = usrp->get_rx_gain(rx_gain_names[index], nchan);
		os << element_gain << endl;
		}
		catch(uhd::runtime_error &e)
		{
			os << "Exception code while getting value: " << e.code() << endl;
		}
	}

	// Gain ranges for each of the gain elements
	os << std::endl << "-----> Get RX element gain ranges" << std::endl;
	for (int index =0; index < rx_gain_names.size(); index++)
	{
		// Name
		os << "\t" << "Name: " << rx_gain_names[index] << "  Value: ";
		// Value
		try
		{
		uhd::gain_range_t element_gain_range = usrp->get_rx_gain_range(rx_gain_names[index], nchan);
		os << "Start: " << element_gain_range.start() << " End: " << element_gain_range.stop() << " Step: " << element_gain_range.step() << endl;
		}
		catch(uhd::runtime_error &e)
		{
			os << "Exception code while getting value: " << e.code() << endl;
		}
	}

	// Total Gain range
	try
	{
		os << endl << "-----> Get RX Total Gain Range" << endl;
		uhd::gain_range_t rx_total_gain_range = usrp->get_rx_gain_range(nchan);
		os << "RX Total Gain Range: " ;
		os << "Start: " << rx_total_gain_range.start() << " End: " << rx_total_gain_range.stop() << " Step: " << rx_total_gain_range.step() << endl;
	}
	catch(uhd::runtime_error &e)
	{
		os << "Exception code: " << e.code() <<endl;
	}
	
	// ANTENNA FUNCTIONS
	
	os << std::endl << "********** RX ANTENNA ***********" << std::endl;
	// Current Rx Antenna
	os << std::endl << "-----> Get RX Antenna" << std::endl;
	string rx_antenna = usrp->get_rx_antenna(nchan);
	os << "RX Antenna: " ;
	os << rx_antenna << endl;

	// RX Antenna choices
	os << std::endl << "-----> Get Rx Antenna List" << std::endl;
	std::vector<std::string> rx_antennas = usrp->get_rx_antennas(nchan);
	os << "RX Antennas : " << std::endl;
	for (int index =0; index < rx_antennas.size(); index++)
		os << "\t" << rx_antennas[index] << std::endl;
		
		
	// RX BANDWIDTH FUNCTIONS

	os << std::endl << "********** RX BANDWIDTH ***********" << std::endl;
	// Current RX Bandwidth
	os << endl << "-----> Get RX Bandwidth" << endl;
	try
	{
		os << "RX Bandwidth " ;
		double rx_bandwidth = usrp->get_rx_bandwidth(nchan);
		os << rx_bandwidth << endl;
	}
	catch (uhd::runtime_error &e)
	{
		os << "Exception occured " << e.code() << endl;
	}
	
	// RX Bandwidth Range
	os << endl << "-----> Get RX Bandwidth Range" << endl;
	try
	{
		os << "RX Bandwidth Range: " ;
		uhd::gain_range_t rx_bandwidth_range = usrp->get_rx_bandwidth_range(nchan);
		os << "Start: " << rx_bandwidth_range .start() << " End: " << rx_bandwidth_range .stop() << " Step: " << rx_bandwidth_range .step() << endl;
	}
	catch(uhd::runtime_error &e)
	{
		os << "Exception code: " << e.code() <<endl;
	}
	
	// RX DBOARD INTERFACE OBJECT

	os << std::endl << "********** RX DBOARD INTERFACE ***********" << std::endl;
	// RX Dboard Interface
	os << endl << "-----> Get rx_dboard_iface()" << endl;
	try
	{
		os << "RX Dboard Interface " ;
		uhd::usrp::dboard_iface::sptr rx_dboard_iface = usrp->get_rx_dboard_iface(nchan);
		os << rx_dboard_iface << endl;
	}
	catch (uhd::runtime_error &e)
	{
		os << "Exception occured " << e.code() << endl;
	}
	
	// RX _SENSORS

	os << std::endl << "********** RX Sensors  ***********" << std::endl;

	// List of all available sensors
	os << std::endl << "-----> Get RX Sensors Name" << std::endl;
	std::vector<std::string> rx_sensor_names = usrp->get_rx_sensor_names(nchan);
	os << "Sensor Names: " << std::endl;
	for (int index =0; index < rx_sensor_names.size(); index++)
	{
		// Name
		os << "\t" << rx_sensor_names[index] << ":  ";
		// Value
		try
		{
			uhd::sensor_value_t rx_sensor_value = usrp->get_rx_sensor(rx_sensor_names[index], nchan);
			os << rx_sensor_value.to_pp_string()<< std::endl;
		}
		catch(uhd::runtime_error &e)
		{
			os << "Exception occured " << e.code() << endl;
		}
	}
	

}
예제 #2
0
파일: single_rx.cpp 프로젝트: xtype0x/wn_hw
void init_usrp() {
	cout << "Initial USRP" << endl;
	
	usrp = uhd::usrp::multi_usrp::make(usrp_ip);
	usrp->set_rx_rate(rate);
	usrp->set_tx_rate(rate);

	usrp->set_rx_freq(freq);
	usrp->set_tx_freq(freq);

	usrp->set_rx_gain(gain);
	uhd::meta_range_t rx_range = usrp->get_rx_gain_range();
}
예제 #3
0
void uhd_device::init_gains()
{
	uhd::gain_range_t range;

	range = usrp_dev->get_tx_gain_range();
	tx_gain_min = range.start();
	tx_gain_max = range.stop();

	range = usrp_dev->get_rx_gain_range();
	rx_gain_min = range.start();
	rx_gain_max = range.stop();

	usrp_dev->set_tx_gain((tx_gain_min + tx_gain_max) / 2);
	usrp_dev->set_rx_gain((rx_gain_min + rx_gain_max) / 2);

	tx_gain = usrp_dev->get_tx_gain();
	rx_gain = usrp_dev->get_rx_gain();

	return;
}
예제 #4
0
/***********************************************************************
 * Function to find optimal RX gain setting (for the current frequency)
 **********************************************************************/
UHD_INLINE void set_optimal_rx_gain(
    uhd::usrp::multi_usrp::sptr usrp,
    uhd::rx_streamer::sptr rx_stream,
    double wave_freq = 0.0)
{
    const double gain_step = 3.0;
    const double gain_compression_threshold = gain_step * 0.5;
    const double actual_rx_rate = usrp->get_rx_rate();
    const double actual_tx_freq = usrp->get_tx_freq();
    const double actual_rx_freq = usrp->get_rx_freq();
    const double bb_tone_freq = actual_tx_freq - actual_rx_freq + wave_freq;
    const size_t nsamps = size_t(actual_rx_rate / default_fft_bin_size);

    std::vector<samp_type> buff(nsamps);
    uhd::gain_range_t rx_gain_range = usrp->get_rx_gain_range();
    double rx_gain = rx_gain_range.start() + gain_step;
    double curr_dbrms = 0.0;
    double prev_dbrms = 0.0;
    double delta = 0.0;

    // No sense in setting the gain where this is no gain range
    if (rx_gain_range.stop() - rx_gain_range.start() < gain_step)
        return;

    // The algorithm below cycles through the RX gain range
    // looking for the point where the signal begins to get
    // clipped and the gain begins to be compressed.  It does
    // this by looking for the gain setting where the increase
    // in the tone is less than the gain step by more than the
    // gain compression threshold (curr - prev < gain - threshold).

    // Initialize prev_dbrms value
    usrp->set_rx_gain(rx_gain);
    capture_samples(usrp, rx_stream, buff, nsamps);
    prev_dbrms = compute_tone_dbrms(buff, bb_tone_freq/actual_rx_rate);
    rx_gain += gain_step;

    // Find RX gain where signal begins to clip
    while (rx_gain <= rx_gain_range.stop())
    {
        usrp->set_rx_gain(rx_gain);
        capture_samples(usrp, rx_stream, buff, nsamps);
        curr_dbrms = compute_tone_dbrms(buff, bb_tone_freq/actual_rx_rate);
        delta = curr_dbrms - prev_dbrms;

        // check if the gain is compressed beyone the threshold
        if (delta < gain_step - gain_compression_threshold)
            break;  // if so, we are done

        prev_dbrms = curr_dbrms;
        rx_gain += gain_step;
    }

    // The rx_gain value at this point is the gain setting where clipping
    // occurs or the gain setting that is just beyond the gain range.
    // The gain is reduced by 2 steps to make sure it is within the range and
    // under the point where it is clipped with enough room to make adjustments.
    rx_gain -= 2 * gain_step;

    // Make sure the gain is within the range.
    rx_gain = rx_gain_range.clip(rx_gain);

    // Finally, set the gain.
    usrp->set_rx_gain(rx_gain);
}