root / host / examples / rx_timed_samples.cpp @ 83bd55d6
History | View | Annotate | Download (3.7 KB)
| 1 |
//
|
|---|---|
| 2 |
// Copyright 2010 Ettus Research LLC
|
| 3 |
//
|
| 4 |
// This program is free software: you can redistribute it and/or modify
|
| 5 |
// it under the terms of the GNU General Public License as published by
|
| 6 |
// the Free Software Foundation, either version 3 of the License, or
|
| 7 |
// (at your option) any later version.
|
| 8 |
//
|
| 9 |
// This program is distributed in the hope that it will be useful,
|
| 10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 12 |
// GNU General Public License for more details.
|
| 13 |
//
|
| 14 |
// You should have received a copy of the GNU General Public License
|
| 15 |
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 16 |
//
|
| 17 |
|
| 18 |
#include <uhd/utils/safe_main.hpp> |
| 19 |
#include <uhd/usrp/simple_usrp.hpp> |
| 20 |
#include <boost/program_options.hpp> |
| 21 |
#include <boost/format.hpp> |
| 22 |
#include <iostream> |
| 23 |
#include <complex> |
| 24 |
|
| 25 |
namespace po = boost::program_options;
|
| 26 |
|
| 27 |
int UHD_SAFE_MAIN(int argc, char *argv[]){ |
| 28 |
//variables to be set by po
|
| 29 |
std::string transport_args;
|
| 30 |
int seconds_in_future;
|
| 31 |
size_t total_num_samps; |
| 32 |
|
| 33 |
//setup the program options
|
| 34 |
po::options_description desc("Allowed options");
|
| 35 |
desc.add_options() |
| 36 |
("help", "help message") |
| 37 |
("args", po::value<std::string>(&transport_args)->default_value(""), "simple uhd transport args") |
| 38 |
("secs", po::value<int>(&seconds_in_future)->default_value(3), "number of seconds in the future to receive") |
| 39 |
("nsamps", po::value<size_t>(&total_num_samps)->default_value(1000), "total number of samples to receive") |
| 40 |
; |
| 41 |
po::variables_map vm; |
| 42 |
po::store(po::parse_command_line(argc, argv, desc), vm); |
| 43 |
po::notify(vm); |
| 44 |
|
| 45 |
//print the help message
|
| 46 |
if (vm.count("help")){ |
| 47 |
std::cout << boost::format("UHD RX Timed Samples %s") % desc << std::endl;
|
| 48 |
return ~0; |
| 49 |
} |
| 50 |
|
| 51 |
//create a usrp device
|
| 52 |
std::cout << std::endl; |
| 53 |
std::cout << boost::format("Creating the usrp device with: %s...")
|
| 54 |
% transport_args << std::endl; |
| 55 |
uhd::usrp::simple_usrp::sptr sdev = uhd::usrp::simple_usrp::make(transport_args); |
| 56 |
uhd::device::sptr dev = sdev->get_device(); |
| 57 |
std::cout << boost::format("Using Device: %s") % sdev->get_name() << std::endl;
|
| 58 |
|
| 59 |
//set properties on the device
|
| 60 |
double rx_rate = sdev->get_rx_rates()[4]; //pick some rate |
| 61 |
std::cout << boost::format("Setting RX Rate: %f Msps...") % (rx_rate/1e6) << std::endl; |
| 62 |
sdev->set_rx_rate(rx_rate); |
| 63 |
std::cout << boost::format("Setting device timestamp to 0...") << std::endl;
|
| 64 |
sdev->set_time_now(uhd::time_spec_t(0));
|
| 65 |
|
| 66 |
//setup streaming
|
| 67 |
std::cout << std::endl; |
| 68 |
std::cout << boost::format("Begin streaming %u samples, %d seconds in the future...")
|
| 69 |
% total_num_samps % seconds_in_future << std::endl; |
| 70 |
uhd::stream_cmd_t stream_cmd(uhd::stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_DONE); |
| 71 |
stream_cmd.num_samps = total_num_samps; |
| 72 |
stream_cmd.stream_now = false;
|
| 73 |
stream_cmd.time_spec = uhd::time_spec_t(seconds_in_future); |
| 74 |
sdev->issue_stream_cmd(stream_cmd); |
| 75 |
|
| 76 |
//loop until total number of samples reached
|
| 77 |
size_t num_acc_samps = 0; //number of accumulated samples |
| 78 |
while(num_acc_samps < total_num_samps){
|
| 79 |
uhd::rx_metadata_t md; |
| 80 |
std::complex<float> buff[1000]; |
| 81 |
size_t num_rx_samps = dev->recv( |
| 82 |
boost::asio::buffer(buff, sizeof(buff)),
|
| 83 |
md, uhd::io_type_t::COMPLEX_FLOAT32 |
| 84 |
); |
| 85 |
if (num_rx_samps == 0) continue; //wait for packets with contents |
| 86 |
|
| 87 |
std::cout << boost::format("Got packet: %u samples, %u secs, %u ticks")
|
| 88 |
% num_rx_samps % md.time_spec.secs % md.time_spec.ticks << std::endl; |
| 89 |
|
| 90 |
num_acc_samps += num_rx_samps; |
| 91 |
} |
| 92 |
|
| 93 |
//finished
|
| 94 |
std::cout << std::endl << "Done!" << std::endl << std::endl;
|
| 95 |
|
| 96 |
return 0; |
| 97 |
} |