Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <uhd/usrp/multi_usrp.hpp>
- #include <uhd/utils/thread.hpp>
- #include <iostream>
- using namespace std;
- int main() {
- // UHD TwinRx
- std::string device_args = "type=x300,addr=192.168.30.2,second_addr=192.168.40.2";
- std::string sub_dev = "A:0 A:1 B:0 B:1";
- std::cout << boost::format("Creating the usrp device with: %s...") % device_args << std::endl;
- uhd::usrp::multi_usrp::sptr usrp = uhd::usrp::multi_usrp::make(device_args);
- std::string ref = "internal";
- std::cout << boost::format("Lock mboard clocks: %f") % ref << std::endl;
- usrp->set_clock_source(ref);
- std::cout << boost::format("subdev set to: %f") % sub_dev << std::endl;
- usrp->set_rx_subdev_spec(sub_dev);
- std::cout << boost::format("Using Device: %s") % usrp->get_pp_string() << std::endl;
- // rf tune parameters
- uint64_t freq = 2450e6;
- uint32_t rate = 100e6; // sample rate
- uint32_t bw = 80e6; // bandwidth
- double gain = 80.0; // gain
- int channel = 0;
- // set sample rate
- std::cout << boost::format("Setting RX Rate: %f Msps...") % (rate / 1e6) << std::endl;
- usrp->set_rx_rate(rate, channel);
- std::cout << boost::format("Actual RX Rate: %f Msps...") % (usrp->get_rx_rate(channel) / 1e6) << std::endl;
- // set freq
- std::cout << boost::format("Setting RX Freq: %f MHz...") % (freq / 1e6) << std::endl;
- uhd::tune_request_t tune_request(freq);
- usrp->set_rx_freq(tune_request, channel);
- std::cout << boost::format("Actual RX Freq: %f MHz...") % (usrp->get_rx_freq(channel) / 1e6) << std::endl;
- // set the rf gain
- std::cout << boost::format("Setting RX Gain: %f dB...") % gain << std::endl;
- usrp->set_rx_gain(gain, channel);
- std::cout << boost::format("Actual RX Gain: %f dB...") % usrp->get_rx_gain(channel) << std::endl;
- // set the IF filter bandwidth
- std::cout << boost::format("Setting RX Bandwidth: %f MHz...") % (bw / 1e6) << std::endl;
- usrp->set_rx_bandwidth(bw, channel);
- std::cout << boost::format("Actual RX Bandwidth: %f MHz...") % (usrp->get_rx_bandwidth(channel) / 1e6) << std::endl;
- //init recv variables
- uhd::rx_metadata_t md;
- size_t block_per_sec = 50;
- double seconds_in_future = 1.5;
- double timeout = 1.0;
- size_t recv_cnt = 0;
- size_t recv_limit = 10;
- // init rx streamer
- uhd::stream_args_t stream_args("fc32"); //complex float
- stream_args.channels.push_back(0);
- uhd::rx_streamer::sptr rx_stream = usrp->get_rx_stream(stream_args);
- //fill in the command
- uhd::stream_cmd_t cmd_start(uhd::stream_cmd_t::STREAM_MODE_START_CONTINUOUS);
- cmd_start.stream_now = false;
- cmd_start.time_spec = uhd::time_spec_t(seconds_in_future);
- // issue stream command
- rx_stream->issue_stream_cmd(cmd_start);
- // generate buffer size based on block_per_sec_
- size_t buff_size = ((rate) / block_per_sec);
- buff_size = buff_size - (buff_size % rx_stream->get_max_num_samps());
- buff_size = std::max(buff_size, rx_stream->get_max_num_samps());
- std::vector<std::complex<float> > buff(buff_size);
- // run recv() recv_limit times
- while (recv_cnt++ < recv_limit) {
- // recv iq data into buff
- size_t num_rx_samps = rx_stream->recv(&buff.front(), buff.size(), md, timeout);
- std::cout << "UHD Rx : " << boost::format(" - Received packet: %u samples, %u full secs, %f frac secs") % num_rx_samps % md.time_spec.get_full_secs() % md.time_spec.get_frac_secs() << std::endl;
- }
- //stop the stream
- uhd::stream_cmd_t cmd_stop(uhd::stream_cmd_t::STREAM_MODE_STOP_CONTINUOUS);
- cmd_stop.stream_now = true;
- //issue command
- rx_stream->issue_stream_cmd(cmd_stop);
- return 0;
- }
Add Comment
Please, Sign In to add comment