Example #1
0
/***********************************************************************
 * Tune RX and TX routine
 **********************************************************************/
static double tune_rx_and_tx(uhd::usrp::multi_usrp::sptr usrp, const double tx_lo_freq, const double rx_offset)
{
    //tune the transmitter with no cordic
    uhd::tune_request_t tx_tune_req(tx_lo_freq);
    tx_tune_req.dsp_freq_policy = uhd::tune_request_t::POLICY_MANUAL;
    tx_tune_req.dsp_freq = 0;
    usrp->set_tx_freq(tx_tune_req);

    //tune the receiver
    double rx_freq = usrp->get_tx_freq() - rx_offset;
    double min_fe_rx_freq = usrp->get_fe_rx_freq_range().start();
    double max_fe_rx_freq = usrp->get_fe_rx_freq_range().stop();
    uhd::tune_request_t rx_tune_req(rx_freq);
    rx_tune_req.dsp_freq_policy = uhd::tune_request_t::POLICY_MANUAL;
    rx_tune_req.dsp_freq = 0;
    if (rx_freq < min_fe_rx_freq)
        rx_tune_req.dsp_freq = rx_freq - min_fe_rx_freq;
    else if (rx_freq > max_fe_rx_freq)
        rx_tune_req.dsp_freq = rx_freq - max_fe_rx_freq;
    usrp->set_rx_freq(rx_tune_req);

    //wait for the LOs to become locked
    boost::this_thread::sleep(boost::posix_time::milliseconds(50));
    boost::system_time start = boost::get_system_time();
    while (not usrp->get_tx_sensor("lo_locked").to_bool() or not usrp->get_rx_sensor("lo_locked").to_bool())
    {
        if (boost::get_system_time() > start + boost::posix_time::milliseconds(100))
            throw std::runtime_error("timed out waiting for TX and/or RX LO to lock");
    }

    return usrp->get_tx_freq();
}
/***********************************************************************
 * Tune RX and TX routine
 **********************************************************************/
static double tune_rx_and_tx(
    uhd::usrp::multi_usrp::sptr usrp, const double tx_lo_freq, const double rx_offset)
{
    // tune the transmitter with no cordic
    uhd::tune_request_t tx_tune_req(tx_lo_freq);
    tx_tune_req.dsp_freq_policy = uhd::tune_request_t::POLICY_MANUAL;
    tx_tune_req.dsp_freq        = 0;
    usrp->set_tx_freq(tx_tune_req);

    // tune the receiver
    double rx_freq        = usrp->get_tx_freq() - rx_offset;
    double min_fe_rx_freq = usrp->get_fe_rx_freq_range().start();
    double max_fe_rx_freq = usrp->get_fe_rx_freq_range().stop();
    uhd::tune_request_t rx_tune_req(rx_freq);
    rx_tune_req.dsp_freq_policy = uhd::tune_request_t::POLICY_MANUAL;
    rx_tune_req.dsp_freq        = 0;
    if (rx_freq < min_fe_rx_freq)
        rx_tune_req.dsp_freq = rx_freq - min_fe_rx_freq;
    else if (rx_freq > max_fe_rx_freq)
        rx_tune_req.dsp_freq = rx_freq - max_fe_rx_freq;
    usrp->set_rx_freq(rx_tune_req);

    wait_for_lo_lock(usrp);

    return usrp->get_tx_freq();
}
bool uhd_device::setTxFreq(double wFreq)
{
	uhd::tune_result_t tr = usrp_dev->set_tx_freq(wFreq);
	LOG(INFO) << "\n" << tr.to_pp_string();
	tx_freq = usrp_dev->get_tx_freq();

	return true;
}
Example #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);
}
void get_tx_parameters(uhd::usrp::multi_usrp::sptr usrp, size_t mboard, std::ostream & os)
{
	using namespace std;
	namespace radio = uhd::usrp;

	size_t nchan = 0;

	// CONFIGURATION SUB_DEVICE
	
	os << std::endl << "********** TX Sub Device ***********" << std::endl;
	// Get sub device specification
	os << std::endl << "-----> Get TX Subdevice" << std::endl;
	try
	{
	os << "TX Subdevice Specification: ";
	radio::subdev_spec_t tx_subdev = usrp->get_tx_subdev_spec(mboard);
	os << tx_subdev.to_pp_string() << endl;
	}
	catch(uhd::runtime_error &e)
	{
		os << " Exception occurred : " << e.code() << endl;
	}
	
	// Number of tx channels
	os << std::endl << "-----> Get number of TX channels" << std::endl;
	try
	{
	size_t num_tx = usrp->get_tx_num_channels();
	os << "Number of TX channels: " ;
	os << num_tx << endl;
	}
	catch (uhd::runtime_error &e)
	{
		os << " Exception occurred : " << e.code() << endl;
	}
	
	// TX Device Name
	os << std::endl << "-----> Get TX Subdevice Name" << std::endl;
	try
	{
	os << "TX Subdevice Name: ";
	string tx_name = usrp->get_tx_subdev_name(nchan);
	os << tx_name << endl;
	}
	catch (uhd::runtime_error &e)
	{
		os << " Exception occurred : " << e.code() << endl;
	}
	
	// TX SAMPLE RATE
	
	os << std::endl << "********** TX Sample Rate ***********" << std::endl;
	
	// Get Current TX rate
	os << std::endl << "-----> Get TX Rate" << std::endl;
	try
	{
		os << "TX Rate: " ;
		double tx_rate = usrp->get_tx_rate(nchan);
		os << tx_rate << endl;
	}
	catch (uhd::runtime_error &e)
	{
		os << " Exception occurred : " << e.code() << endl;
	}
	
	// Get list of TX rates
	os << std::endl << "-----> Get TX Rate List" << std::endl;
	try
	{
		os << "TX Rate List: " ;
		uhd::meta_range_t tx_rates = usrp->get_tx_rates(nchan);
		os << "Start: " << tx_rates.start() << "   Stop: " << tx_rates.stop() << "   Step: " << tx_rates.step() << endl;
		os << tx_rates.to_pp_string() << endl;
	}
	catch (uhd::runtime_error &e)
	{
		os << " Exception occurred : " << e.code() << endl;
	}

	// TX FREQUENCIES
	
	os << std::endl << "********** TX Frequencies ***********" << std::endl;
	
	// Current TX frequency
	os << std::endl << "-----> Get TX Center Frequency" << std::endl;
	try
	{
		os << "TX Freq: ";
		double tx_freq = usrp->get_tx_freq(nchan);
		os << tx_freq << endl;
	}
	catch (uhd::runtime_error &e)
	{
		os << " Exception occurred : " << e.code() << endl;
	}

	// TX Frequency Range
	os << std::endl << "-----> Get TX Center Frequency Range" << std::endl;
	try
	{
		os << "TX Frequency Range: ";
		uhd::freq_range_t tx_freq_range = usrp->get_tx_freq_range(nchan);
		os << "Start: " << tx_freq_range.start() << "   Stop: " << tx_freq_range.stop() << "   Step: " << tx_freq_range.step() << endl;
		os << tx_freq_range.to_pp_string() << endl;
	}
	catch (uhd::runtime_error &e)
	{
		os << " Exception occurred : " << e.code() << endl;
	}
	
	// Front end TX frequency range
	os << std::endl << "-----> Get TX RF Front End Center Frequency Range" << std::endl;
	try
	{
		os << "TX Front End Frequency Range: ";
		uhd::freq_range_t tx_fe_freq_range = usrp->get_fe_tx_freq_range(nchan);
		os << "Start: " << tx_fe_freq_range.start() << "   Stop: " << tx_fe_freq_range.stop() << "   Step: " << tx_fe_freq_range.step() << endl;
		os << tx_fe_freq_range.to_pp_string() << endl;
	}
	catch (uhd::runtime_error &e)
	{
		os << " Exception occurred : " << e.code() << endl;
	}

	// TX GAIN

	os << std::endl << "********** TX Gain  ***********" << std::endl;
	
	// Total combined gain
	os << endl << "-----> Get TX Total Gain" << endl;
	os << "TX Total Gain: " ;	
	try
	{
		double tx_total_gain = usrp->get_tx_gain(nchan);
		os << tx_total_gain << endl;
	}
	catch(uhd::runtime_error &e)
	{
		os << "Exception code: " << e.code() << endl;
	}
	
	// List of all gain elements
	os << std::endl << "-----> Get TX gain names" << std::endl;
	std::vector<std::string> tx_gain_names = usrp->get_tx_gain_names(nchan);
	os << "Tx Gain Names: " << std::endl;
	for (int index =0; index < tx_gain_names.size(); index++)
	{
		// Name
		os << "\t" << tx_gain_names[index] << endl;
	}
	for (int index =0; index < tx_gain_names.size(); index++)
	{
		// Name
		os << "\t" << "Name: " << tx_gain_names[index] << "  Value: ";
		// Value
		try
		{
		double element_gain = usrp->get_tx_gain(tx_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 TX element gain ranges" << std::endl;
	for (int index =0; index < tx_gain_names.size(); index++)
	{
		// Name
		os << "\t" << "Name: " << tx_gain_names[index] << "  Value: ";
		// Value
		try
		{
		uhd::gain_range_t element_gain_range = usrp->get_tx_gain_range(tx_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 TX Total Gain Range" << endl;
		uhd::gain_range_t tx_total_gain_range = usrp->get_tx_gain_range(nchan);
		os << "TX Total Gain Range: " ;
		os << "Start: " << tx_total_gain_range.start() << " End: " << tx_total_gain_range.stop() << " Step: " << tx_total_gain_range.step() << endl;
	}
	catch(uhd::runtime_error &e)
	{
		os << "Exception code: " << e.code() <<endl;
	}

	// ANTENNA FUNCTIONS
	
	os << std::endl << "********** TX ANTENNA ***********" << std::endl;
	// Current Tx Antenna
	os << std::endl << "-----> Get TX Antenna" << std::endl;
	try
	{
	os << "TX Antenna: " ;
	string tx_antenna = usrp->get_tx_antenna(nchan);
	os << tx_antenna << endl;
	}
	catch(uhd::runtime_error &e)
	{
		os << "Exception code: " << e.code() <<endl;
	}

	// TX Antenna choices
	os << std::endl << "-----> Get Tx Antenna List" << std::endl;
	try
	{
	os << "TX Antennas : " << std::endl;
	std::vector<std::string> tx_antennas = usrp->get_tx_antennas(nchan);
	for (int index =0; index < tx_antennas.size(); index++)
		os << "\t" << tx_antennas[index] << std::endl;
	}
	catch(uhd::runtime_error &e)
	{
		os << "Exception code: " << e.code() <<endl;
	}
		
	// TX BANDWIDTH FUNCTIONS

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

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

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

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