bool uhd_device::open()
{
	// Register msg handler
	uhd::msg::register_handler(&uhd_msg_handler);

	// Find UHD devices
	uhd::device_addr_t args("");
	uhd::device_addrs_t dev_addrs = uhd::device::find(args);
	if (dev_addrs.size() == 0) {
		LOG(ALERT) << "No UHD devices found";
		return false;
	}

	// Use the first found device
	LOG(INFO) << "Using discovered UHD device " << dev_addrs[0].to_string();
	try {
		usrp_dev = uhd::usrp::multi_usrp::make(dev_addrs[0]);
	} catch(...) {
		LOG(ALERT) << "UHD make failed, device " << dev_addrs[0].to_string();
		return false;
	}

	// Check for a valid device type and set bus type
	if (!parse_dev_type())
		return false;

#ifdef EXTREF
	set_ref_clk(true);
#endif

	// Number of samples per over-the-wire packet
	tx_spp = usrp_dev->get_device()->get_max_send_samps_per_packet();
	rx_spp = usrp_dev->get_device()->get_max_recv_samps_per_packet();

	// Set rates
	actual_smpl_rt = set_rates(desired_smpl_rt);
	if (actual_smpl_rt < 0)
		return false;

	// Create receive buffer
	size_t buf_len = smpl_buf_sz / sizeof(uint64_t);
	rx_smpl_buf = new smpl_buf(buf_len, actual_smpl_rt);

	// Set receive chain sample advance 
	ts_offset = (TIMESTAMP)(rx_offset * actual_smpl_rt); 

	// Initialize and shadow gain values 
	init_gains();

	// Print configuration
	LOG(INFO) << "\n" << usrp_dev->get_pp_string();

	return true;
}
Exemple #2
0
int setup_device(uhd::usrp::multi_usrp::sptr usrp, double rx_gain, double tx_gain, double freq, double rate){

    //create a usrp device
    std::cout << boost::format("Using Device: %s") % usrp->get_pp_string() << std::endl;

    usrp->set_rx_rate(rate);
    usrp->set_rx_freq(freq);
    usrp->set_rx_gain(rx_gain);
	usrp->set_tx_rate(rate);
	usrp->set_tx_freq(freq);
	usrp->set_tx_gain(tx_gain);

}
Exemple #3
0
int setupUSRP(  uhd::usrp::multi_usrp::sptr&  usrp,
                const float                   center_freq,
                const float                   sample_rate,
                const int                     rx_gain,
                const char*                   dev_addr)
{
  //Initialize the USRP to the specified address
  usrp = uhd::usrp::multi_usrp::make(string(dev_addr));
  //Define the clock reference
  usrp->set_clock_source(__USRP_CLK_SRC);

  //Output some useful information
  cout  << "Using the following USRP device: " << endl
        << usrp->get_pp_string() << endl;

  //Try setting the sample rate.  If the rate we get is not the same as the
  //requested rate, we will return with a warning to ensure the user is aware
  //of the actual sample rate
  usrp->set_rx_rate( sample_rate );

  if( usrp->get_rx_rate() != sample_rate )
  {
    ios_base::fmtflags originalFlags = cout.flags();
    cout.setf(ios_base::left,ios_base::floatfield);
    cout.precision(15);
    cout  << "WARNING! Requested rate = " << sample_rate << endl
          << "WARNING! Actual rate = " << usrp->get_rx_rate() << endl;
    cout.setf(originalFlags);
  }

  //Try setting the center frequency.  Like above, if we get a different
  //frequency than the one we're requesting, we will spit out a warning for the
  //user
  usrp->set_rx_freq( center_freq );

  if( usrp->get_rx_freq() != center_freq )
  {
    ios_base::fmtflags originalFlags = cout.flags();
    cout.setf(ios_base::left,ios_base::floatfield);
    cout.precision(15);
    cout  << "WARNING! Requested frequency = " << center_freq << endl
          << "WARNING! Actual frequency = " << usrp->get_rx_freq() << endl;
    cout.setf(originalFlags);
  }

  //Set the RX gain.  There really shouldn't be any problems here, but the user
  //might request something silly like 50dB of gain when the module can't
  //accomodate.  So we'll perform a similar check here.
  usrp->set_rx_gain( rx_gain );

  if( usrp->get_rx_gain() != rx_gain )
  {
    cout  << "WARNING! Requested gain = " << rx_gain << endl
          << "WARNING! Actual gain = " << usrp->get_rx_gain() << endl;
  }

  //Ensure the LO locked
  vector<string> sensor_names;
  sensor_names = usrp->get_rx_sensor_names(0);
  if( find(sensor_names.begin(), sensor_names.end(), "lo_locked")
      != sensor_names.end() )
  {
    uhd::sensor_value_t lo_locked = usrp->get_rx_sensor("lo_locked",0);
    cout  << "Checking RX: " << endl
          << lo_locked.to_pp_string() << endl;
    UHD_ASSERT_THROW(lo_locked.to_bool());      //We should probably catch this
  }

  return 1;
}
Exemple #4
0
int uhd_device::open(const std::string &args, bool extref)
{
	// Find UHD devices
	uhd::device_addr_t addr(args);
	uhd::device_addrs_t dev_addrs = uhd::device::find(addr);
	if (dev_addrs.size() == 0) {
		LOG(ALERT) << "No UHD devices found with address '" << args << "'";
		return -1;
	}

	// Use the first found device
	LOG(INFO) << "Using discovered UHD device " << dev_addrs[0].to_string();
	try {
		usrp_dev = uhd::usrp::multi_usrp::make(dev_addrs[0]);
	} catch(...) {
		LOG(ALERT) << "UHD make failed, device " << dev_addrs[0].to_string();
		return -1;
	}

	// Check for a valid device type and set bus type
	if (!parse_dev_type())
		return -1;

	if (extref)
		set_ref_clk(true);

	// Create TX and RX streamers
	uhd::stream_args_t stream_args("sc16");
	tx_stream = usrp_dev->get_tx_stream(stream_args);
	rx_stream = usrp_dev->get_rx_stream(stream_args);

	// Number of samples per over-the-wire packet
	tx_spp = tx_stream->get_max_num_samps();
	rx_spp = rx_stream->get_max_num_samps();

	// Set rates
	double _tx_rate = select_rate(dev_type, sps);
	double _rx_rate = _tx_rate / sps;
	if ((_tx_rate > 0.0) && (set_rates(_tx_rate, _rx_rate) < 0))
		return -1;

	// Create receive buffer
	size_t buf_len = SAMPLE_BUF_SZ / sizeof(uint32_t);
	rx_smpl_buf = new smpl_buf(buf_len, rx_rate);

	// Set receive chain sample offset 
	double offset = get_dev_offset(dev_type, sps);
	if (offset == 0.0) {
		LOG(ERR) << "Unsupported configuration, no correction applied";
		ts_offset = 0;
	} else  {
		ts_offset = (TIMESTAMP) (offset * rx_rate);
	}

	// Initialize and shadow gain values 
	init_gains();

	// Print configuration
	LOG(INFO) << "\n" << usrp_dev->get_pp_string();

	switch (dev_type) {
	case B100:
		return RESAMP_64M;
	case USRP2:
	case X3XX:
		return RESAMP_100M;
	}

	return NORMAL;
}