Guest User

Untitled

a guest
Feb 16th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1. #include <uhd/usrp/multi_usrp.hpp>
  2. #include <uhd/utils/thread.hpp>
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. int main() {
  7. // UHD TwinRx
  8. std::string device_args = "type=x300,addr=192.168.30.2,second_addr=192.168.40.2";
  9. std::string sub_dev = "A:0 A:1 B:0 B:1";
  10.  
  11. std::cout << boost::format("Creating the usrp device with: %s...") % device_args << std::endl;
  12. uhd::usrp::multi_usrp::sptr usrp = uhd::usrp::multi_usrp::make(device_args);
  13.  
  14. std::string ref = "internal";
  15. std::cout << boost::format("Lock mboard clocks: %f") % ref << std::endl;
  16. usrp->set_clock_source(ref);
  17.  
  18. std::cout << boost::format("subdev set to: %f") % sub_dev << std::endl;
  19. usrp->set_rx_subdev_spec(sub_dev);
  20. std::cout << boost::format("Using Device: %s") % usrp->get_pp_string() << std::endl;
  21.  
  22. // rf tune parameters
  23. uint64_t freq = 2450e6;
  24. uint32_t rate = 100e6; // sample rate
  25. uint32_t bw = 80e6; // bandwidth
  26. double gain = 80.0; // gain
  27. int channel = 0;
  28.  
  29. // set sample rate
  30. std::cout << boost::format("Setting RX Rate: %f Msps...") % (rate / 1e6) << std::endl;
  31. usrp->set_rx_rate(rate, channel);
  32. std::cout << boost::format("Actual RX Rate: %f Msps...") % (usrp->get_rx_rate(channel) / 1e6) << std::endl;
  33.  
  34. // set freq
  35. std::cout << boost::format("Setting RX Freq: %f MHz...") % (freq / 1e6) << std::endl;
  36. uhd::tune_request_t tune_request(freq);
  37. usrp->set_rx_freq(tune_request, channel);
  38. std::cout << boost::format("Actual RX Freq: %f MHz...") % (usrp->get_rx_freq(channel) / 1e6) << std::endl;
  39.  
  40. // set the rf gain
  41. std::cout << boost::format("Setting RX Gain: %f dB...") % gain << std::endl;
  42. usrp->set_rx_gain(gain, channel);
  43. std::cout << boost::format("Actual RX Gain: %f dB...") % usrp->get_rx_gain(channel) << std::endl;
  44.  
  45. // set the IF filter bandwidth
  46. std::cout << boost::format("Setting RX Bandwidth: %f MHz...") % (bw / 1e6) << std::endl;
  47. usrp->set_rx_bandwidth(bw, channel);
  48. std::cout << boost::format("Actual RX Bandwidth: %f MHz...") % (usrp->get_rx_bandwidth(channel) / 1e6) << std::endl;
  49.  
  50. //init recv variables
  51. uhd::rx_metadata_t md;
  52. size_t block_per_sec = 50;
  53. double seconds_in_future = 1.5;
  54. double timeout = 1.0;
  55. size_t recv_cnt = 0;
  56. size_t recv_limit = 10;
  57.  
  58. // init rx streamer
  59. uhd::stream_args_t stream_args("fc32"); //complex float
  60. stream_args.channels.push_back(0);
  61. uhd::rx_streamer::sptr rx_stream = usrp->get_rx_stream(stream_args);
  62.  
  63. //fill in the command
  64. uhd::stream_cmd_t cmd_start(uhd::stream_cmd_t::STREAM_MODE_START_CONTINUOUS);
  65. cmd_start.stream_now = false;
  66. cmd_start.time_spec = uhd::time_spec_t(seconds_in_future);
  67.  
  68. // issue stream command
  69. rx_stream->issue_stream_cmd(cmd_start);
  70.  
  71. // generate buffer size based on block_per_sec_
  72. size_t buff_size = ((rate) / block_per_sec);
  73. buff_size = buff_size - (buff_size % rx_stream->get_max_num_samps());
  74. buff_size = std::max(buff_size, rx_stream->get_max_num_samps());
  75. std::vector<std::complex<float> > buff(buff_size);
  76.  
  77. // run recv() recv_limit times
  78. while (recv_cnt++ < recv_limit) {
  79.  
  80. // recv iq data into buff
  81. size_t num_rx_samps = rx_stream->recv(&buff.front(), buff.size(), md, timeout);
  82. 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;
  83.  
  84. }
  85.  
  86. //stop the stream
  87. uhd::stream_cmd_t cmd_stop(uhd::stream_cmd_t::STREAM_MODE_STOP_CONTINUOUS);
  88. cmd_stop.stream_now = true;
  89.  
  90. //issue command
  91. rx_stream->issue_stream_cmd(cmd_stop);
  92.  
  93. return 0;
  94. }
Add Comment
Please, Sign In to add comment