int UHD_SAFE_MAIN(int argc, char *argv[]){ uhd::set_thread_priority_safe(); std::string args, tx_file, rx_file, type, ref, wire_format, cpu_format; double rate, freq, tx_gain, rx_gain, rx_bw, delay, lo_off,seconds_in_future, rx_timeout; rx_bw = RX_BW; rx_gain = RX_GAIN; wire_format = WIRE_FORMAT; cpu_format = CPU_FORMAT; rate = SAMP_RATE; args = ARGS; ref = REF_CLOCK; freq = CENT_FREQ; tx_gain = TX_GAIN; // samples_per_buff = SAMPLES_PER_BUFFER; tx_file = TX_FILENAME; rx_file = RX_FILENAME; seconds_in_future = SYNCH_DELAY; rx_timeout = RX_TIMEOUT; //------------------INIT TX------------------ //Set the scheduling priority on the current thread. Same as set_thread_priority but does not throw on failure. std::cout << boost::format("Creating the usrp device with: %s...") % args << std::endl; uhd::usrp::multi_usrp::sptr usrp = uhd::usrp::multi_usrp::make(args); //Make the usrp by calling the constructor with param the args usrp->set_clock_source(ref); //Set the clock source for the usrp device. This sets the source for a 10 MHz reference clock. Typical options for source: internal, external, MIMO. std::cout << boost::format("Setting TX Rate: %f Msps...") % (rate/1e6) << std::endl; usrp->set_tx_rate(rate); //Set the sample rate std::cout << boost::format("Actual TX Rate: %f Msps...") % (usrp->get_tx_rate()/1e6) << std::endl << std::endl; std::cout << boost::format("Setting TX Freq: %f MHz...") % (freq/1e6) << std::endl; //Set up tuning frequency uhd::tune_request_t tune_request; tune_request = uhd::tune_request_t(freq); //Generate the tune request usrp->set_tx_freq(tune_request); //Tune to CENT_FREQ std::cout << boost::format("Actual TX Freq: %f MHz...") % (usrp->get_tx_freq()/1e6) << std::endl << std::endl; //PRINT Actual CENT_FREQ std::cout << boost::format("Setting TX Gain: %f dB...") % tx_gain << std::endl; usrp->set_tx_gain(tx_gain); //Set the tx_gain std::cout << boost::format("Actual TX Gain: %f dB...") % usrp->get_tx_gain() << std::endl << std::endl; //------------------CHECK STUFF------------------ //Check Ref and LO Lock detect std::vector<std::string> sensor_names; sensor_names = usrp->get_tx_sensor_names(0); if (std::find(sensor_names.begin(), sensor_names.end(), "lo_locked") != sensor_names.end()) { uhd::sensor_value_t lo_locked = usrp->get_tx_sensor("lo_locked",0); std::cout << boost::format("Checking TX: %s ...") % lo_locked.to_pp_string() << std::endl; UHD_ASSERT_THROW(lo_locked.to_bool()); } //------------------INIT RX------------------ //IS THIS NECESSARY? //always select the subdevice first, the channel mapping affects the other settings //usrp->set_rx_subdev_spec(subdev); std::cout << boost::format("Setting RX Rate: %f Msps...") % (rate/1e6) << std::endl; usrp->set_rx_rate(rate); std::cout << boost::format("Actual RX Rate: %f Msps...") % (usrp->get_rx_rate()/1e6) << std::endl << std::endl; //set the center frequency std::cout << boost::format("Setting RX Freq: %f MHz...") % (freq/1e6) << std::endl; usrp->set_rx_freq(tune_request); std::cout << boost::format("Actual RX Freq: %f MHz...") % (usrp->get_rx_freq()/1e6) << std::endl << std::endl; std::cout << boost::format("Setting RX Gain: %f dB...") % rx_gain << std::endl; usrp->set_rx_gain(rx_gain); std::cout << boost::format("Actual RX Gain: %f dB...") % usrp->get_rx_gain() << std::endl << std::endl; boost::this_thread::sleep(boost::posix_time::seconds(1)); //allow 1sec setup time //------------------CHECK STUFF------------------ //Always check for locked sensor check_locked_sensor(usrp->get_rx_sensor_names(0), "lo_locked", boost::bind(&uhd::usrp::multi_usrp::get_rx_sensor, usrp, _1, 0), 1); //------------------INIT FILES--------------- std::ofstream outfile; outfile.open(rx_file.c_str(), std::ofstream::binary); if(!outfile.good()){ std::cout << "OUT File error\n"; return 0; } std::ifstream infile(tx_file.c_str(), std::ifstream::binary); if(!infile.good()){ std::cout << "IN File error\n"; return 0; } //------------------INIT STREAMS--------------- //Stream ARGS uhd::stream_args_t stream_args(cpu_format, wire_format); //Call the constructor of the class stream_args_t and generate the stream_args object with inputs the cpu_format and wire_format (this is the format per sample) tx_stream = usrp->get_tx_stream(stream_args); //Generate a tx_streamer object named tx_stream using the usrp->get_tx_stream(stream_args). Remember, usrp is already initialized uhd::rx_streamer::sptr rx_stream = usrp->get_rx_stream(stream_args); //Generate a tx_streamer object named tx_stream using the usrp->get_tx_stream(stream_args). Remember, usrp is already initialized //Setup metadata //Setup tx_metadata tx_md.start_of_burst = true; //Set start of burst to true for the first packet in the chain. ? tx_md.end_of_burst = false; #define SYNCHED_TXRX 1 //For TX if(SYNCHED_TXRX){ tx_md.has_time_spec = true; }else{ tx_md.has_time_spec = false; } //Setup rx_metadata uhd::rx_metadata_t rx_md; //Setup stream command ONLY FOR RX uhd::stream_cmd_t stream_cmd(uhd::stream_cmd_t::STREAM_MODE_START_CONTINUOUS); stream_cmd.num_samps = samples_per_buff; //For RX if(SYNCHED_TXRX){ stream_cmd.stream_now = false; // tx_md.time_spec = stream_cmd.time_spec; }else{ stream_cmd.stream_now = true; stream_cmd.time_spec = uhd::time_spec_t(); } if(SYNCHED_TXRX){ //Cannt get any faster than this tx_md.time_spec = stream_cmd.time_spec = uhd::time_spec_t(seconds_in_future)+usrp->get_time_now(); } //Create the buffs std::vector<std::complex<float> > small_rx_buff(samples_per_buff); //Fill the TX buffer for (int i = 0; i < samples_per_buff; ++i){ infile.read((char*)&small_tx_buff.at(i), small_tx_buff.size()*sizeof(std::complex<float>)); } infile.close(); //Close the file pointer //Issue the stream command rx_stream->issue_stream_cmd(stream_cmd); //Print number of maximum buffer size printf("MAX TX: %d\n", (int)tx_stream->get_max_num_samps()); printf("MAX RX %d\n", (int)rx_stream->get_max_num_samps()); size_t num_rx_samps = 0; boost::thread txThread(thread_startTx); //receivotrnsmit txThread.join(); //Strart the thread for tx (tx is f blocking) num_rx_samps = rx_stream->recv(&small_rx_buff.front(), small_rx_buff.size(), rx_md, rx_timeout, false); // Receive buffers containing samples described by the metadata. // num_rx_samps = rx_stream->recv(&small_rx_buff.front(), small_rx_buff.size(), rx_md, rx_timeout, false); // Receive buffers containing samples described by the metadata. //Wait for everything to stop boost::this_thread::sleep(boost::posix_time::milliseconds(2000)); //Cleanup and print what happened usrp->issue_stream_cmd(uhd::stream_cmd_t::STREAM_MODE_STOP_CONTINUOUS); // Stop the stream (not really necessary here) double rx_stamp = rx_md.time_spec.get_full_secs() + rx_md.time_spec.get_frac_secs(); double tx_stamp = tx_md.time_spec.get_full_secs() + tx_md.time_spec.get_frac_secs(); double t_diff = rx_stamp - tx_stamp; printf("RX Time stamp: %.12lf\n ΤX Time stamp: %.12lf\n Diff: %.12lf\n",rx_stamp, tx_stamp, t_diff); switch ( rx_md.error_code ) { case uhd::rx_metadata_t::ERROR_CODE_NONE: printf("No error:)\n"); break; case uhd::rx_metadata_t::ERROR_CODE_TIMEOUT: printf("MDError 2\n"); break; case uhd::rx_metadata_t::ERROR_CODE_LATE_COMMAND: printf("MDError 3\n"); break; case uhd::rx_metadata_t::ERROR_CODE_BROKEN_CHAIN: printf("MDError 4\n"); break; case uhd::rx_metadata_t::ERROR_CODE_OVERFLOW: printf("MDError 5\n"); break; case uhd::rx_metadata_t::ERROR_CODE_ALIGNMENT: printf("MDError 6\n"); break; case uhd::rx_metadata_t::ERROR_CODE_BAD_PACKET: printf("MDError 7\n"); break; default: printf("WUT\n"); break; } //write the samples if (outfile.is_open()){ outfile.write((const char*)&small_rx_buff.front(), num_rx_samps*sizeof(std::complex<float>)); } outfile.close(); //Close the file pointer //print std::cout << "Transmitted samples: " << num_tx_samps << '\n'; std::cout << "Received samples: " << num_rx_samps << '\n'; return EXIT_SUCCESS; }
/******************************************************************************* * Main function ******************************************************************************/ int UHD_SAFE_MAIN(int argc, char *argv[]){ uhd::set_thread_priority_safe(); /** Constant Decalartions *************************************************/ const INT32U time = DURATION*(SAMPRATE/SPB); /** Variable Declarations *************************************************/ // (circular) receive buffers std::vector< CINT16 > ch0_rxbuff(time*SPB); // Ch 0 is RX2-A std::vector< CINT16 > ch1_rxbuff(time*SPB); // Ch 1 is RX2-B // Vector of pointers to sectons of rx_buff std::vector< std::vector< CINT16 *> > rxbuffs(time*2, std::vector< CINT16 *>(2)); // Holds the number of received samples returned by rx_stream->recv() INT16U num_rx_samps; // Counters INT16U i = 0,j = 0,k = 0; // Generic counters INT32U write_ctr = 0; // Counts loops through main while() /** Variable Initializations **********************************************/ // Initialise rxbuffs (Vector of pointers) for(i = 0; i < time; i++){ rxbuffs[i][0] = &ch0_rxbuff.front() + SPB * i; rxbuffs[i][1] = &ch1_rxbuff.front() + SPB * i; } /** Main code *************************************************************/ // set USRP Rx params uhd::usrp::multi_usrp::sptr usrp_rx = uhd::usrp::multi_usrp::make(std::string("")); // create a usrp device uhd::tune_request_t tune_request(CARRIERFREQ); // validate tune request usrp_rx->set_master_clock_rate(CLOCKRATE); // set clock rate usrp_rx->set_clock_source(std::string("internal")); // lock mboard clocks // usrp_rx->set_time_source("external"); // Use external reference clock usrp_rx->set_rx_subdev_spec(std::string("A:A A:B")); // select the subdevice usrp_rx->set_rx_rate(SAMPRATE,0); // set the sample rate (Ch 0) usrp_rx->set_rx_rate(SAMPRATE,1); // set the sample rate (Ch 1) usrp_rx->set_rx_freq(tune_request,0); // set the center frequency (Ch 0) usrp_rx->set_rx_freq(tune_request,1); // set the center frequency (Ch 1) usrp_rx->set_rx_gain(RXGAIN,0); // set the rf gain (Ch 0) usrp_rx->set_rx_gain(RXGAIN,1); // set the rf gain (Ch 1) usrp_rx->set_rx_antenna(std::string("TX/RX"),0); // set the antenna (Ch 0) usrp_rx->set_rx_antenna(std::string("TX/RX"),1); // set the antenna (Ch 1) boost::this_thread::sleep(boost::posix_time::seconds(1.0)); // allow for some setup time // check Ref and LO Lock detect for Rx check_locked_sensor(usrp_rx->get_rx_sensor_names(0), "lo_locked", boost::bind(&uhd::usrp::multi_usrp::get_rx_sensor, usrp_rx, _1, 0), 1.0); // create a receive streamer uhd::stream_args_t stream_args_rx("sc16", "sc16"); stream_args_rx.channels = boost::assign::list_of(0)(1); uhd::rx_streamer::sptr rx_stream = usrp_rx->get_rx_stream(stream_args_rx); uhd::rx_metadata_t md_rx; // report stuff to user (things which may differ from what was requested) std::cout << boost::format("Actual RX Rate: %f Msps...") % (usrp_rx->get_rx_rate()/1e6) << std::endl; // set sigint so user can terminate via Ctrl-C std::signal(SIGINT, &sig_int_handler); std::cout << boost::format("Recording RX CH 0 and CH 1 for %i seconds") % DURATION << std::endl << std::endl; std::cout << "Press Enter to start recording..." << std::endl << std::endl; // Wait for "ENTER" key to be pressed while(std::cin.get() != '\n'){} std::cout << "Press Ctrl + C to stop recording..." << std::endl; // setup receive streaming uhd::stream_cmd_t stream_cmd(uhd::stream_cmd_t::STREAM_MODE_START_CONTINUOUS); stream_cmd.stream_now = false; stream_cmd.time_spec = uhd::time_spec_t(0.25)+usrp_rx->get_time_now(); // tell USRP to start streaming 0.25 seconds in the future rx_stream->issue_stream_cmd(stream_cmd); // grab initial block of received samples from USRP with nice long timeout (gets discarded) num_rx_samps = rx_stream->recv(rxbuffs[0], SPB, md_rx, 3.0); while(not stop_signal_called){ // grab block of received samples from USRP num_rx_samps = rx_stream->recv(rxbuffs[write_ctr], SPB, md_rx); // Increment counter write_ctr++; // Check if full time has passed if(write_ctr == time){ break; }else{} // Report progress to terminal std::cout << boost::format("\r\t%2i Percent Complete ") % (write_ctr*100/time) << std::flush; } /** while(not stop_signal_called) *************************************/ // Report progress to terminal std::cout << "\r\tdone! " << std::endl << std::endl; if(stop_signal_called){ std::cout << std::endl << "Writing partial buffers to file (this may take awhile)..." << std::endl; }else{ // Write buffers to file std::cout << "Writing buffers to file (this may take awhile)..." << std::endl; } std::cout << " Channel 0 (RX2-A)..." << std::flush; writebuff("./RX2-A.dat", &ch0_rxbuff.front(), write_ctr*SPB); std::cout << "done!" << std::endl; std::cout << " Channel 1 (RX2-B)..." << std::flush; writebuff("./RX2-B.dat", &ch1_rxbuff.front(), write_ctr*SPB); std::cout << "done!" << std::endl; return EXIT_SUCCESS; } /** main() ****************************************************************/
int UHD_SAFE_MAIN(int argc, char *argv[]){ uhd::set_thread_priority_safe(); //variables to be set by po std::string args, file, type, ant, subdev, ref, wirefmt; size_t total_num_samps, spb; double rate, freq, gain, bw, total_time, setup_time; //setup the program options po::options_description desc("Allowed options"); desc.add_options() ("help", "help message") ("args", po::value<std::string>(&args)->default_value(""), "multi uhd device address args") ("file", po::value<std::string>(&file)->default_value("usrp_samples.dat"), "name of the file to write binary samples to") ("type", po::value<std::string>(&type)->default_value("short"), "sample type: double, float, or short") ("nsamps", po::value<size_t>(&total_num_samps)->default_value(0), "total number of samples to receive") ("duration", po::value<double>(&total_time)->default_value(0), "total number of seconds to receive") ("time", po::value<double>(&total_time), "(DEPRECATED) will go away soon! Use --duration instead") ("spb", po::value<size_t>(&spb)->default_value(10000), "samples per buffer") ("rate", po::value<double>(&rate)->default_value(1e6), "rate of incoming samples") ("freq", po::value<double>(&freq)->default_value(0.0), "RF center frequency in Hz") ("gain", po::value<double>(&gain), "gain for the RF chain") ("ant", po::value<std::string>(&ant), "antenna selection") ("subdev", po::value<std::string>(&subdev), "subdevice specification") ("bw", po::value<double>(&bw), "analog frontend filter bandwidth in Hz") ("ref", po::value<std::string>(&ref)->default_value("internal"), "reference source (internal, external, mimo)") ("wirefmt", po::value<std::string>(&wirefmt)->default_value("sc16"), "wire format (sc8 or sc16)") ("setup", po::value<double>(&setup_time)->default_value(1.0), "seconds of setup time") ("progress", "periodically display short-term bandwidth") ("stats", "show average bandwidth on exit") ("sizemap", "track packet size and display breakdown on exit") ("null", "run without writing to file") ("continue", "don't abort on a bad packet") ("skip-lo", "skip checking LO lock status") ("int-n", "tune USRP with integer-N tuning") ; po::variables_map vm; po::store(po::parse_command_line(argc, argv, desc), vm); po::notify(vm); //print the help message if (vm.count("help")) { std::cout << boost::format("UHD RX samples to file %s") % desc << std::endl; std::cout << std::endl << "This application streams data from a single channel of a USRP device to a file.\n" << std::endl; return ~0; } bool bw_summary = vm.count("progress") > 0; bool stats = vm.count("stats") > 0; bool null = vm.count("null") > 0; bool enable_size_map = vm.count("sizemap") > 0; bool continue_on_bad_packet = vm.count("continue") > 0; if (enable_size_map) std::cout << "Packet size tracking enabled - will only recv one packet at a time!" << std::endl; //create a usrp device std::cout << std::endl; std::cout << boost::format("Creating the usrp device with: %s...") % args << std::endl; uhd::usrp::multi_usrp::sptr usrp = uhd::usrp::multi_usrp::make(args); //Lock mboard clocks usrp->set_clock_source(ref); //always select the subdevice first, the channel mapping affects the other settings if (vm.count("subdev")) usrp->set_rx_subdev_spec(subdev); std::cout << boost::format("Using Device: %s") % usrp->get_pp_string() << std::endl; //set the sample rate if (rate <= 0.0){ std::cerr << "Please specify a valid sample rate" << std::endl; return ~0; } std::cout << boost::format("Setting RX Rate: %f Msps...") % (rate/1e6) << std::endl; usrp->set_rx_rate(rate); std::cout << boost::format("Actual RX Rate: %f Msps...") % (usrp->get_rx_rate()/1e6) << std::endl << std::endl; //set the center frequency if (vm.count("freq")) { //with default of 0.0 this will always be true std::cout << boost::format("Setting RX Freq: %f MHz...") % (freq/1e6) << std::endl; uhd::tune_request_t tune_request(freq); if(vm.count("int-n")) tune_request.args = uhd::device_addr_t("mode_n=integer"); usrp->set_rx_freq(tune_request); std::cout << boost::format("Actual RX Freq: %f MHz...") % (usrp->get_rx_freq()/1e6) << std::endl << std::endl; } //set the rf gain if (vm.count("gain")) { std::cout << boost::format("Setting RX Gain: %f dB...") % gain << std::endl; usrp->set_rx_gain(gain); std::cout << boost::format("Actual RX Gain: %f dB...") % usrp->get_rx_gain() << std::endl << std::endl; } //set the IF filter bandwidth if (vm.count("bw")) { std::cout << boost::format("Setting RX Bandwidth: %f MHz...") % bw << std::endl; usrp->set_rx_bandwidth(bw); std::cout << boost::format("Actual RX Bandwidth: %f MHz...") % usrp->get_rx_bandwidth() << std::endl << std::endl; } //set the antenna if (vm.count("ant")) usrp->set_rx_antenna(ant); boost::this_thread::sleep(boost::posix_time::seconds(setup_time)); //allow for some setup time //check Ref and LO Lock detect if (not vm.count("skip-lo")){ check_locked_sensor(usrp->get_rx_sensor_names(0), "lo_locked", boost::bind(&uhd::usrp::multi_usrp::get_rx_sensor, usrp, _1, 0), setup_time); if (ref == "mimo") check_locked_sensor(usrp->get_mboard_sensor_names(0), "mimo_locked", boost::bind(&uhd::usrp::multi_usrp::get_mboard_sensor, usrp, _1, 0), setup_time); if (ref == "external") check_locked_sensor(usrp->get_mboard_sensor_names(0), "ref_locked", boost::bind(&uhd::usrp::multi_usrp::get_mboard_sensor, usrp, _1, 0), setup_time); } if (total_num_samps == 0){ std::signal(SIGINT, &sig_int_handler); std::cout << "Press Ctrl + C to stop streaming..." << std::endl; } #define recv_to_file_args(format) \ (usrp, format, wirefmt, file, spb, total_num_samps, total_time, bw_summary, stats, null, enable_size_map, continue_on_bad_packet) //recv to file if (type == "double") recv_to_file<std::complex<double> >recv_to_file_args("fc64"); else if (type == "float") recv_to_file<std::complex<float> >recv_to_file_args("fc32"); else if (type == "short") recv_to_file<std::complex<short> >recv_to_file_args("sc16"); else throw std::runtime_error("Unknown type " + type); //finished std::cout << std::endl << "Done!" << std::endl << std::endl; return EXIT_SUCCESS; }
int UHD_SAFE_MAIN(int argc, char *argv[]){ uhd::set_thread_priority_safe(); std::string args, tx_file, rx_file, type, ref, wire_format, cpu_format; size_t samples_per_buff; double rate, freq, tx_gain, rx_gain, rx_bw, delay, lo_off; rx_bw = RX_BW; rx_gain = RX_GAIN; wire_format = WIRE_FORMAT; cpu_format = CPU_FORMAT; rate = SAMP_RATE; args = ARGS; ref = REF_CLOCK; freq = CENT_FREQ; tx_gain = TX_GAIN; samples_per_buff = SAMPLES_PER_BUFFER; tx_file = TX_FILENAME; rx_file = RX_FILENAME; //------------------INIT TX------------------ //Set the scheduling priority on the current thread. Same as set_thread_priority but does not throw on failure. std::cout << boost::format("Creating the usrp device with: %s...") % args << std::endl; uhd::usrp::multi_usrp::sptr usrp = uhd::usrp::multi_usrp::make(args); //Make the usrp by calling the constructor with param the args usrp->set_clock_source(ref); //Set the clock source for the usrp device. This sets the source for a 10 MHz reference clock. Typical options for source: internal, external, MIMO. std::cout << boost::format("Setting TX Rate: %f Msps...") % (rate/1e6) << std::endl; usrp->set_tx_rate(rate); //Set the sample rate std::cout << boost::format("Actual TX Rate: %f Msps...") % (usrp->get_tx_rate()/1e6) << std::endl << std::endl; std::cout << boost::format("Setting TX Freq: %f MHz...") % (freq/1e6) << std::endl; //Set up tuning frequency uhd::tune_request_t tune_request; tune_request = uhd::tune_request_t(freq); //Generate the tune request usrp->set_tx_freq(tune_request); //Tune to CENT_FREQ std::cout << boost::format("Actual TX Freq: %f MHz...") % (usrp->get_tx_freq()/1e6) << std::endl << std::endl; //PRINT Actual CENT_FREQ std::cout << boost::format("Setting TX Gain: %f dB...") % tx_gain << std::endl; usrp->set_tx_gain(tx_gain); //Set the tx_gain std::cout << boost::format("Actual TX Gain: %f dB...") % usrp->get_tx_gain() << std::endl << std::endl; //------------------CHECK STUFF------------------ //Check Ref and LO Lock detect std::vector<std::string> sensor_names; sensor_names = usrp->get_tx_sensor_names(0); if (std::find(sensor_names.begin(), sensor_names.end(), "lo_locked") != sensor_names.end()) { uhd::sensor_value_t lo_locked = usrp->get_tx_sensor("lo_locked",0); std::cout << boost::format("Checking TX: %s ...") % lo_locked.to_pp_string() << std::endl; UHD_ASSERT_THROW(lo_locked.to_bool()); } //------------------INIT TX STREAM------------------ //create a transmit streamer uhd::stream_args_t stream_args(cpu_format, wire_format); //Call the constructor of the class stream_args_t and generate the stream_args object with inputs the cpu_format and wire_format (this is the format per sample) uhd::tx_streamer::sptr tx_stream = usrp->get_tx_stream(stream_args); //Generate a tx_streamer object named tx_stream using the usrp->get_tx_stream(stream_args). Remember, usrp is already initialized //Setup tx_metadata uhd::tx_metadata_t tx_md; //TX metadata structure for describing received IF data. Includes time specification, and start and stop burst flags. The send routines will convert the metadata to IF data headers. tx_md.start_of_burst = false; //Set start of burst to true for the first packet in the chain. ? tx_md.end_of_burst = false; //------------------LOAD DATA AND TX------------------ std::vector<std::complex<float> > tx_buff(samples_per_buff); std::ifstream infile(tx_file.c_str(), std::ifstream::binary); if(!infile.good()){ std::cout << "IN File error\n"; return 0; } //loop until the entire file has been read int i = 0; for (int i = 0; i < samples_per_buff; ++i){ infile.read((char*)&tx_buff.at(i), tx_buff.size()*sizeof(std::complex<float>)); // std::cout << tx_buff.at(i) << ' '; } tx_stream->send(&tx_buff.front(), samples_per_buff, tx_md); infile.close(); //Close the file pointer //------------------INIT RX------------------ //IS THIS NECESSARY? //always select the subdevice first, the channel mapping affects the other settings //usrp->set_rx_subdev_spec(subdev); std::cout << boost::format("Setting RX Rate: %f Msps...") % (rate/1e6) << std::endl; usrp->set_rx_rate(rate); std::cout << boost::format("Actual RX Rate: %f Msps...") % (usrp->get_rx_rate()/1e6) << std::endl << std::endl; //set the center frequency std::cout << boost::format("Setting RX Freq: %f MHz...") % (freq/1e6) << std::endl; usrp->set_rx_freq(tune_request); std::cout << boost::format("Actual RX Freq: %f MHz...") % (usrp->get_rx_freq()/1e6) << std::endl << std::endl; std::cout << boost::format("Setting RX Gain: %f dB...") % rx_gain << std::endl; usrp->set_rx_gain(rx_gain); std::cout << boost::format("Actual RX Gain: %f dB...") % usrp->get_rx_gain() << std::endl << std::endl; boost::this_thread::sleep(boost::posix_time::seconds(1)); //allow 1sec setup time //------------------CHECK STUFF------------------ //Always check for locked sensor check_locked_sensor(usrp->get_rx_sensor_names(0), "lo_locked", boost::bind(&uhd::usrp::multi_usrp::get_rx_sensor, usrp, _1, 0), 1); //------------------INIT RX STREAM--------------- //create a receive streamer with the same args as TX uhd::rx_streamer::sptr rx_stream = usrp->get_rx_stream(stream_args); uhd::rx_metadata_t rx_md; std::vector<std::complex<float> > rx_buff(samples_per_buff); std::ofstream outfile; outfile.open(rx_file.c_str(), std::ofstream::binary); if(!outfile.good()){ std::cout << "OUT File error\n"; return 0; } //If RX_CONT == 1 enable continuoys sampling else just sent some packets and done uhd::stream_cmd_t stream_cmd((RX_CONT == 1)? uhd::stream_cmd_t::STREAM_MODE_START_CONTINUOUS: uhd::stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_DONE ); stream_cmd.num_samps = samples_per_buff; //You might have a problem here... stream_cmd.stream_now = true; //Start streaming ASAP stream_cmd.time_spec = uhd::time_spec_t(); //Setup the time to the USRP time (Why??) rx_stream->issue_stream_cmd(stream_cmd); //Issue a stream command to the usrp device. This tells the usrp to send samples into the host. See the documentation for stream_cmd_t for more info. size_t num_rx_samps = rx_stream->recv(&rx_buff.front(), rx_buff.size(), rx_md, 10.0, false); // Receive buffers containing samples described by the metadata. std::cout << "Samples received in a single shot: " << num_rx_samps << std::endl; if (outfile.is_open()){ outfile.write((const char*)&rx_buff.front(), num_rx_samps*sizeof(std::complex<float>)-1); } return EXIT_SUCCESS; }