本文整理汇总了C++中uhd::usrp::multi_usrp::sptr类的典型用法代码示例。如果您正苦于以下问题:C++ sptr类的具体用法?C++ sptr怎么用?C++ sptr使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了sptr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: recv_to_file
template<typename samp_type> void recv_to_file(
uhd::usrp::multi_usrp::sptr usrp,
const uhd::io_type_t &io_type,
const std::string &file,
size_t samps_per_buff
){
uhd::rx_metadata_t md;
std::vector<samp_type> buff(samps_per_buff);
//std::ofstream outfile(file.c_str(), std::ofstream::binary);
while(not stop_signal_called){
size_t num_rx_samps = usrp->get_device()->recv(
&buff.front(), buff.size(), md, io_type,
uhd::device::RECV_MODE_FULL_BUFF
);
if (md.error_code == uhd::rx_metadata_t::ERROR_CODE_TIMEOUT) break;
if (md.error_code != uhd::rx_metadata_t::ERROR_CODE_NONE){
break;
//throw std::runtime_error(str(boost::format(
// "Unexpected error code 0x%x"
//) % md.error_code));
}
//outfile.write((const char*)&buff.front(), num_rx_samps*sizeof(samp_type));
}
//outfile.close();
}
示例2: tx_thread
/***********************************************************************
* Transmit thread
**********************************************************************/
static void tx_thread(uhd::usrp::multi_usrp::sptr usrp, const double tx_wave_ampl)
{
uhd::set_thread_priority_safe();
//create a transmit streamer
uhd::stream_args_t stream_args("fc32"); //complex floats
uhd::tx_streamer::sptr tx_stream = usrp->get_tx_stream(stream_args);
//setup variables and allocate buffer
uhd::tx_metadata_t md;
md.has_time_spec = false;
std::vector<samp_type> buff(tx_stream->get_max_num_samps()*10);
//fill buff and send until interrupted
while (not boost::this_thread::interruption_requested())
{
for (size_t i = 0; i < buff.size(); i++)
buff[i] = float(tx_wave_ampl);
tx_stream->send(&buff.front(), buff.size(), md);
}
//send a mini EOB packet
md.end_of_burst = true;
tx_stream->send("", 0, md);
}
示例3: send_from_file
template<typename samp_type> void send_from_file(
uhd::usrp::multi_usrp::sptr usrp,
const std::string &cpu_format,
const std::string &wire_format,
const std::string &file,
size_t samps_per_buff
){
//create a transmit streamer
uhd::stream_args_t stream_args(cpu_format, wire_format);
uhd::tx_streamer::sptr tx_stream = usrp->get_tx_stream(stream_args);
uhd::tx_metadata_t md;
md.start_of_burst = false;
md.end_of_burst = false;
std::vector<samp_type> buff(samps_per_buff);
std::ifstream infile(file.c_str(), std::ifstream::binary);
//loop until the entire file has been read
while(not md.end_of_burst and not stop_signal_called){
infile.read((char*)&buff.front(), buff.size()*sizeof(samp_type));
size_t num_tx_samps = infile.gcount()/sizeof(samp_type);
md.end_of_burst = infile.eof();
tx_stream->send(&buff.front(), num_tx_samps, md);
}
infile.close();
}
示例4: capture_samples
/***********************************************************************
* Data capture routine
**********************************************************************/
static void capture_samples(
uhd::usrp::multi_usrp::sptr usrp,
uhd::rx_streamer::sptr rx_stream,
std::vector<samp_type > &buff,
const size_t nsamps_requested
){
buff.resize(nsamps_requested);
uhd::rx_metadata_t md;
uhd::stream_cmd_t stream_cmd(uhd::stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_DONE);
stream_cmd.num_samps = buff.size();
stream_cmd.stream_now = true;
usrp->issue_stream_cmd(stream_cmd);
const size_t num_rx_samps = rx_stream->recv(&buff.front(), buff.size(), md);
//validate the received data
if (md.error_code != uhd::rx_metadata_t::ERROR_CODE_NONE){
throw std::runtime_error(str(boost::format(
"Receiver error: %s"
) % md.strerror()));
}
//we can live if all the data didnt come in
if (num_rx_samps > buff.size()/2){
buff.resize(num_rx_samps);
return;
}
if (num_rx_samps != buff.size()){
throw std::runtime_error("did not get all the samples requested");
}
}
示例5: send_from_file
template<typename samp_type> void send_from_file(
uhd::usrp::multi_usrp::sptr usrp,
const uhd::io_type_t &io_type,
const std::string &file,
size_t samps_per_buff
){
uhd::tx_metadata_t md;
md.start_of_burst = false;
md.end_of_burst = false;
std::vector<samp_type> buff(samps_per_buff);
std::ifstream infile(file.c_str(), std::ifstream::binary);
//loop until the entire file has been read
while(not md.end_of_burst){
infile.read((char*)&buff.front(), buff.size()*sizeof(samp_type));
size_t num_tx_samps = infile.gcount()/sizeof(samp_type);
md.end_of_burst = infile.eof();
usrp->get_device()->send(
&buff.front(), num_tx_samps, md, io_type,
uhd::device::SEND_MODE_FULL_BUFF
);
}
infile.close();
}
示例6: set_optimum_defaults
/***********************************************************************
* Set standard defaults for devices
**********************************************************************/
static inline void set_optimum_defaults(uhd::usrp::multi_usrp::sptr usrp)
{
uhd::property_tree::sptr tree = usrp->get_device()->get_tree();
// Will work on 1st subdev, top-level must make sure it's the right one
uhd::usrp::subdev_spec_t subdev_spec = usrp->get_rx_subdev_spec();
const uhd::fs_path mb_path = "/mboards/0";
const std::string mb_name = tree->access<std::string>(mb_path / "name").get();
if (mb_name.find("USRP2") != std::string::npos or
mb_name.find("N200") != std::string::npos or
mb_name.find("N210") != std::string::npos or
mb_name.find("X300") != std::string::npos or
mb_name.find("X310") != std::string::npos)
{
usrp->set_tx_rate(12.5e6);
usrp->set_rx_rate(12.5e6);
}
else if (mb_name.find("B100") != std::string::npos)
{
usrp->set_tx_rate(4e6);
usrp->set_rx_rate(4e6);
}
else
{
throw std::runtime_error("self-calibration is not supported for this device");
}
const uhd::fs_path tx_fe_path = "/mboards/0/dboards/" + subdev_spec[0].db_name + "/tx_frontends/0";
const std::string tx_name = tree->access<std::string>(tx_fe_path / "name").get();
if (tx_name.find("WBX") == std::string::npos and
tx_name.find("SBX") == std::string::npos and
tx_name.find("CBX") == std::string::npos and
tx_name.find("RFX") == std::string::npos and
tx_name.find("UBX") == std::string::npos
)
{
throw std::runtime_error("self-calibration is not supported for this TX dboard");
}
usrp->set_tx_gain(0);
const uhd::fs_path rx_fe_path = "/mboards/0/dboards/" + subdev_spec[0].db_name + "/rx_frontends/0";
const std::string rx_name = tree->access<std::string>(rx_fe_path / "name").get();
if (rx_name.find("WBX") == std::string::npos and
rx_name.find("SBX") == std::string::npos and
rx_name.find("CBX") == std::string::npos and
rx_name.find("RFX") == std::string::npos and
rx_name.find("UBX") == std::string::npos
)
{
throw std::runtime_error("self-calibration is not supported for this RX dboard");
}
usrp->set_rx_gain(0);
}
示例7: tx_stream_args
uhd::tx_streamer::sptr
Responder::create_tx_streamer(uhd::usrp::multi_usrp::sptr usrp)
{
uhd::stream_args_t tx_stream_args("fc32"); //complex floats
if (_allow_late_bursts == false)
{
tx_stream_args.args["underflow_policy"] = "next_burst";
}
uhd::tx_streamer::sptr tx_stream = usrp->get_tx_stream(tx_stream_args);
return tx_stream;
}
示例8: tune_rx_and_tx
/***********************************************************************
* 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();
}
示例9: return_usrp_config_string
std::string return_usrp_config_string(uhd::usrp::multi_usrp::sptr usrp, int chan, bool test_tx, bool test_rx, bool is_b2xx){
uhd::dict<std::string, std::string> tx_info = usrp->get_usrp_tx_info(chan);
uhd::dict<std::string, std::string> rx_info = usrp->get_usrp_rx_info(chan);
std::string info_string;
std::string mboard_id, mboard_serial;
std::string tx_serial, tx_subdev_name, tx_subdev_spec;
std::string rx_serial, rx_subdev_name, rx_subdev_spec;
mboard_id = tx_info.get("mboard_id");
if(tx_info.get("mboard_serial") == "") mboard_serial = "no serial";
else mboard_serial = tx_info.get("mboard_serial");
info_string = str(boost::format("Motherboard: %s (%s)\n") % mboard_id % mboard_serial);
if(test_tx){
if(tx_info.get("tx_serial") == "") tx_serial = "no serial";
else tx_serial = tx_info.get("tx_serial");
tx_subdev_name = tx_info.get("tx_subdev_name");
tx_subdev_spec = tx_info.get("tx_subdev_spec");
info_string += is_b2xx ? str(boost::format("TX: %s (%s)")
% tx_subdev_name % tx_subdev_spec)
: str(boost::format("TX: %s (%s, %s)")
% tx_subdev_name % tx_serial % tx_subdev_spec);
}
if(test_tx and test_rx) info_string += "\n";
if(test_rx){
if(rx_info.get("rx_serial") == "") rx_serial = "no serial";
else rx_serial = rx_info.get("rx_serial");
rx_subdev_name = rx_info.get("rx_subdev_name");
rx_subdev_spec = rx_info.get("rx_subdev_spec");
info_string += is_b2xx ? str(boost::format("RX: %s (%s)")
% rx_subdev_name % rx_subdev_spec)
: str(boost::format("RX: %s (%s, %s)")
% rx_subdev_name % rx_serial % rx_subdev_spec);
}
return info_string;
}
示例10: stream_args
uhd::rx_streamer::sptr
Responder::create_rx_streamer(uhd::usrp::multi_usrp::sptr usrp)
{
uhd::stream_args_t stream_args("fc32"); //complex floats
if (_samps_per_packet > 0)
{
stream_args.args["spp"] = str(boost::format("%d") % _samps_per_packet);
}
uhd::rx_streamer::sptr rx_stream = usrp->get_rx_stream(stream_args);
_samps_per_packet = rx_stream->get_max_num_samps();
return rx_stream;
}
示例11: rx_hammer
/***********************************************************************
* RX Hammer
**********************************************************************/
void rx_hammer(uhd::usrp::multi_usrp::sptr usrp, const std::string &rx_cpu, const std::string &rx_otw){
uhd::set_thread_priority_safe();
//create a receive streamer
uhd::stream_args_t stream_args(rx_cpu, rx_otw);
for (size_t ch = 0; ch < usrp->get_num_mboards(); ch++) //linear channel mapping
stream_args.channels.push_back(ch);
uhd::rx_streamer::sptr rx_stream = usrp->get_rx_stream(stream_args);
//print pre-test summary
std::cout << boost::format(
"Testing receive rate %f Msps"
) % (usrp->get_rx_rate()/1e6) << std::endl;
//setup variables and allocate buffer
uhd::rx_metadata_t md;
const size_t max_samps_per_packet = rx_stream->get_max_num_samps();
std::vector<char> buff(max_samps_per_packet*uhd::convert::get_bytes_per_item(rx_cpu));
std::vector<void *> buffs;
for (size_t ch = 0; ch < stream_args.channels.size(); ch++)
buffs.push_back(&buff.front()); //same buffer for each channel
bool had_an_overflow = false;
uhd::time_spec_t last_time;
const double rate = usrp->get_rx_rate();
double timeout = 1;
uhd::stream_cmd_t cmd(uhd::stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_DONE);
cmd.time_spec = usrp->get_time_now() + uhd::time_spec_t(0.05);
cmd.stream_now = (buffs.size() == 1);
srand( time(NULL) );
while (not boost::this_thread::interruption_requested()){
cmd.num_samps = rand() % 100000;
usrp->issue_stream_cmd(cmd);
num_rx_samps += rx_stream->recv(buffs, max_samps_per_packet, md, timeout, true);
//handle the error codes
switch(md.error_code){
case uhd::rx_metadata_t::ERROR_CODE_NONE:
if (had_an_overflow){
had_an_overflow = false;
num_dropped_samps += boost::math::iround((md.time_spec - last_time).get_real_secs()*rate);
}
break;
case uhd::rx_metadata_t::ERROR_CODE_OVERFLOW:
had_an_overflow = true;
last_time = md.time_spec;
num_overflows++;
break;
default:
std::cerr << "Error code: " << md.error_code << std::endl;
std::cerr << "Unexpected error on recv, continuing..." << std::endl;
break;
}
}
}
示例12: setup_device
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);
}
示例13: flush_recv
bool uhd_device::flush_recv(size_t num_pkts)
{
uhd::rx_metadata_t md;
size_t num_smpls;
uint32_t buff[rx_spp];
float timeout;
// Use .01 sec instead of the default .1 sec
timeout = .01;
for (size_t i = 0; i < num_pkts; i++) {
num_smpls = usrp_dev->get_device()->recv(
buff,
rx_spp,
md,
uhd::io_type_t::COMPLEX_INT16,
uhd::device::RECV_MODE_ONE_PACKET,
timeout);
if (!num_smpls) {
switch (md.error_code) {
case uhd::rx_metadata_t::ERROR_CODE_TIMEOUT:
return true;
default:
continue;
}
}
}
return true;
}
示例14: set_ref_clk
void uhd_device::set_ref_clk(bool ext_clk)
{
if (ext_clk)
usrp_dev->set_clock_source("external");
return;
}
示例15: set
void set(const std::vector<Set> sets) const
{
for(const auto set : sets)
{
usrp->set_tree_value(set.path, set.value);
set.print();
}
std::cout << std::endl;
}