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; }
bool UHDDevice::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 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; if (extref) usrp_dev->set_clock_source("external"); /* 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(tx_rate, rx_rate); /* Create receive buffer */ size_t buf_len = SAMPLE_BUF_SZ / sizeof(uint32_t); rx_buffer = new SampleBuffer(buf_len, rx_rate); /* Set receive chain sample offset */ ts_offset = get_dev_offset(dev_type); /* Initialize and shadow gain values */ init_gains(); LOG(INFO) << "\n" << usrp_dev->get_pp_string(); return true; }
bool uhd_device::open() { LOG(INFO) << "creating USRP device..."; // Use the first available USRP2 / N210 uhd::device_addr_t dev_addr("type=usrp2"); try { usrp_dev = uhd::usrp::single_usrp::make(dev_addr); } catch(...) { LOG(ERROR) << "USRP make failed"; return false; } // Set master clock rate usrp_dev->set_master_clock_rate(master_clk_rt); // 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(uint32_t); rx_smpl_buf = new smpl_buf(buf_len, actual_smpl_rt); // Set receive chain sample offset ts_offset = (TIMESTAMP)(rx_smpl_offset * actual_smpl_rt); // Initialize and shadow gain values init_gains(); // Set reference clock set_ref_clk(use_ext_ref); // Print configuration LOG(INFO) << usrp_dev->get_pp_string(); return true; }
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; }