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; }
std::vector<Event> instrumentation::snapshot() { VLOG(3) << "snapshot()"; std::vector<Event> events; Event event; event.add_tag(k_instrumentation_tag); event.set_host(k_fqdn); event.set_state("ok"); event.set_ttl(k_default_ttl); set_rates(events, event); set_latencies(events, event); set_gauges(events, event); set_mem_meausres(events, event); return events; }
static void device_test (GtkWidget *w, alsa_driver *d) { guint chmin, chmax, i; gint err; gchar *new_device; d->can8 = FALSE; d->can16 = FALSE; d->canmono = FALSE; d->canstereo = FALSE; d->signedness8 = FALSE; d->signedness16 = FALSE; new_device = gtk_combo_box_get_active_text(GTK_COMBO_BOX(d->alsa_device)); if(g_ascii_strcasecmp(d->device, new_device)) { g_free(d->device); d->device = g_strdup(new_device); gui_hlp_combo_box_prepend_text_or_set_active(GTK_COMBO_BOX(d->alsa_device), d->device, FALSE); } for(i = 0; i < NUM_FORMATS; i++){ d->devcap[i].minfreq = 8000; d->devcap[i].maxfreq = 44100; d->devcap[i].minbufsize = 256; } d->devcap[MONO8].maxbufsize = 65536; d->devcap[STEREO8].maxbufsize = 32768; d->devcap[MONO16].maxbufsize = 32768; d->devcap[STEREO16].maxbufsize = 16384; if(pcm_open_and_load_hwparams(d) < 0) return; if(!snd_pcm_hw_params_test_format(d->soundfd, d->hwparams, SND_PCM_FORMAT_U8)) { d->can8 = TRUE; } if(!snd_pcm_hw_params_test_format(d->soundfd, d->hwparams, SND_PCM_FORMAT_S8)) { d->can8 = TRUE; d->signedness8 = TRUE; } if(!snd_pcm_hw_params_test_format(d->soundfd, d->hwparams, SND_PCM_FORMAT_U16)) { d->can16 = TRUE; } if(!snd_pcm_hw_params_test_format(d->soundfd, d->hwparams, SND_PCM_FORMAT_S16)) { d->can16 = TRUE; d->signedness16 = TRUE; } if((err = snd_pcm_hw_params_get_channels_min(d->hwparams, &chmin)) < 0) { alsa_error(N_("Unable to get minimal channels number"), err); snd_pcm_close(d->soundfd); return; } if((err = snd_pcm_hw_params_get_channels_max(d->hwparams, &chmax)) < 0) { alsa_error(N_("Unable to get maximal channels number"), err); snd_pcm_close(d->soundfd); return; } if(chmin > 2) { error_error("Both mono and stereo are not supported by ALSA device!!!"); snd_pcm_close(d->soundfd); return; } if(chmin == 1) d->canmono = TRUE; if(chmax >= 2) d->canstereo = TRUE; if(d->can8) { if((err = snd_pcm_hw_params_set_format(d->soundfd, d->hwparams, d->signedness8 ? SND_PCM_FORMAT_S8 : SND_PCM_FORMAT_U8)) < 0) { alsa_error(N_("Unable to set audio format"), err); snd_pcm_close(d->soundfd); return; } if(d->canmono) { if(set_rates(d, 1, MONO8) < 0) { snd_pcm_close(d->soundfd); return; } } if(d->canstereo) { snd_pcm_close(d->soundfd); if(pcm_open_and_load_hwparams(d) < 0) return; if(set_rates(d, 2, STEREO8) < 0) { snd_pcm_close(d->soundfd); return; } } } if(d->can16) { snd_pcm_close(d->soundfd); if(pcm_open_and_load_hwparams(d) < 0) return; if((err = snd_pcm_hw_params_set_format(d->soundfd, d->hwparams, d->signedness16 ? SND_PCM_FORMAT_S16 : SND_PCM_FORMAT_U16)) < 0) { alsa_error(N_("Unable to set audio format"), err); snd_pcm_close(d->soundfd); return; } if(d->canmono) { if(set_rates(d, 1, MONO16) < 0) { snd_pcm_close(d->soundfd); return; } } if(d->canstereo) { snd_pcm_close(d->soundfd); if(pcm_open_and_load_hwparams(d) < 0) return; if(set_rates(d, 2, STEREO16) < 0) { snd_pcm_close(d->soundfd); return; } } } snd_pcm_close(d->soundfd); update_controls(d); }
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; }