Пример #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
void transceive(
    uhd::usrp::multi_usrp::sptr usrp,
    uhd::tx_streamer::sptr tx_stream,
    uhd::rx_streamer::sptr rx_stream,
    unsigned int npulses,
    float pulse_time,
    //std::complex<int16_t>* txbuff,
    std::vector<std::complex<int16_t> >* txbuff0,
    std::vector<std::complex<int16_t> >* txbuff1,
    float tx_ontime,
    std::complex<int16_t>** outdata,
    size_t samps_per_pulse
){
    int debug = 0;
    if (debug){
        std::cout << "samps_per_pulse: " << samps_per_pulse << std::endl;
    }
    //create metadeta tags for transmit streams
    uhd::time_spec_t start_time = usrp->get_time_now() + 0.05;
    uhd::tx_metadata_t md;
    md.start_of_burst = true;
    md.end_of_burst = false;
    md.has_time_spec = true;
    md.time_spec = start_time;
    std::vector<std::complex<int16_t> *> vec_ptr;
    vec_ptr.resize(1);
    //vec_ptr[0] = &txbuff->front();
    
    usrp->set_gpio_attr("RXA","CTRL",0x0, TR_BIT); //GPIO mode
    usrp->set_gpio_attr("RXA","DDR",TR_BIT, TR_BIT); //Direction out
    
    //create metadata tags for receive stream
    uhd::rx_metadata_t rxmd;
    std::vector<std::complex<int16_t> > buff(samps_per_pulse,0);
    if (verbose) std::cout << "rx buff size: " << buff.size() << std::endl;
    if (verbose) std::cout << "tx buff size: " << txbuff0->size() << std::endl;
    uhd::stream_cmd_t stream_cmd = uhd::stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_DONE;
    stream_cmd.num_samps = npulses*samps_per_pulse;
    stream_cmd.stream_now = false;
    stream_cmd.time_spec = start_time + 22 / usrp->get_rx_rate(); //Digital hardware delay is 22 samples long.  Found by experiment.
    if (verbose) std::cout << "time spec: " << stream_cmd.time_spec.get_real_secs() << std::endl;
    
    //loop for every pulse in the sequence
    size_t spb;
    std::vector<std::complex<int16_t>* > rx_dptr;
    rx_dptr.resize(usrp->get_rx_num_channels());
    spb = tx_stream->get_max_num_samps();
    if (verbose) std::cout << "npulses: " << npulses << std::endl;
    boost::thread_group rx_threads;
    boost::thread_group tx_threads;
    for (int ipulse=0; ipulse<npulses; ipulse++){
        if (debug) std::cout << "pulse number: " << ipulse << std::endl;
        for (size_t ichan=0; ichan<usrp->get_rx_num_channels(); ichan++){
         rx_dptr[ichan] = ipulse*samps_per_pulse + outdata[ichan];
        }
        
        float timeout = 1.1;
        
        //usrp->set_command_time(start_time-50e-6,0);
        //usrp->set_gpio_attr("RXA","OUT",TR_BIT, TR_BIT);
        
        if (ipulse==0){
            if (verbose) std::cout << "time spec: " << stream_cmd.time_spec.get_real_secs() << std::endl;
            if (verbose) std::cout << "Issuing stream command to start collecting samples\n";
            usrp->issue_stream_cmd(stream_cmd);
        }
        
        //usrp->set_command_time(start_time+tx_ontime,0);
        //usrp->set_gpio_attr("RXA","OUT",0x0, TR_BIT);
        
        size_t acc_samps=0;
        if (ipulse%2 == 0) {
            vec_ptr[0] = &txbuff0->front();
        }
        if (ipulse%2 == 1) {
            vec_ptr[0] = &txbuff1->front();
        }
        
        if (ipulse != npulses-1) {
             tx_threads.create_thread(boost::bind(tx_worker,
                 txbuff0->size(), tx_stream, start_time, vec_ptr[0], 0));
        }
        if (ipulse == npulses-1) {
             tx_threads.create_thread(boost::bind(tx_worker,
                 txbuff0->size(), tx_stream, start_time, vec_ptr[0], 1));
        }
        
        rx_threads.join_all();
        rx_threads.create_thread(boost::bind(rx_worker,
         rx_stream, samps_per_pulse, rx_dptr));
        
        //for (int k=0; k<10; k++){
        // //std::cout << "raw data: " << outdata[0][i][k] << "\t" << outdata[1][i][k] << std::endl;
        // std::cout << "raw data: " << rx_dptr[0][k] << " " << rx_dptr[1][k] << std::endl;
        //}
        //for (int k=0; k<samps_per_pulse; k++)
        //    outdata[i][k] += buff[k];
        
        
        start_time += float(pulse_time);
    }
    tx_threads.join_all();
    rx_threads.join_all();
}