Sorry for that, basically I tried the below code, but I get an error saying 
"timeout". So not able to understand where I am going wrong. Please help!


BR

Snehasish

________________________________
From: USRP-users <usrp-users-boun...@lists.ettus.com> on behalf of Marcus D. 
Leech via USRP-users <usrp-users@lists.ettus.com>
Sent: Wednesday, August 9, 2017 9:10:51 PM
To: usrp-users@lists.ettus.com
Subject: Re: [USRP-users] help with receivng multiple frequencies

On 08/09/2017 10:29 AM, Snehasish Kar via USRP-users wrote:

Hi

I am trying to receive multiple frequencies with one usro x310 separately from 
two daughter boards. But not able to receive it properly. Below is my code. 
Please help me with it.

Could you describe what you mean by "not properly receive it"?



#include <fstream>
#include <iostream>
#include <csignal>
#include <stdlib.h>
#include <complex>
#include <string.h>
#include "../include/conf.hpp"
#include <boost/format.hpp>
#include <boost/thread.hpp>
#include <uhd/types/tune_request.hpp>
#include <uhd/utils/thread_priority.hpp>
#include <uhd/utils/safe_main.hpp>
#include <uhd/usrp/multi_usrp.hpp>
#include <uhd/exception.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/program_options.hpp>
#include <boost/algorithm/string.hpp>

static bool stop_signal_called = false;
void sig_int_handler(int){
    stop_signal_called = true;
}

void startStreaming(uhd::rx_streamer::sptr rx_stream, 
uhd::usrp::multi_usrp::sptr usrp){
    //setup streaming
    size_t total_num_samps = 10000;
    double seconds_in_future = 1.5;
    std::cout << std::endl;
    std::cout << boost::format(
          "Begin streaming %u samples, %f seconds in the future..."
    ) % total_num_samps % seconds_in_future << std::endl;
    uhd::stream_cmd_t stream_cmd((total_num_samps ==0)? 
uhd::stream_cmd_t::STREAM_MODE_START_CONTINUOUS:uhd::stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_DONE);
    stream_cmd.num_samps = size_t(total_num_samps);
    stream_cmd.stream_now = true; //true
    stream_cmd.time_spec = uhd::time_spec_t();
    rx_stream->issue_stream_cmd(stream_cmd); //tells all channels to stream

    //meta-data will be filled in by recv()
    uhd::rx_metadata_t md;

    //allocate buffers to receive with samples (one buffer per channel)
    const size_t samps_per_buff = rx_stream->get_max_num_samps();
    std::vector<std::vector<std::complex<float> > > 
buffs(usrp->get_rx_num_channels(), std::vector<std::complex<float> 
>(samps_per_buff));

    //create a vector of pointers to point to each of the channel buffers
    std::vector<std::complex<float> *> buff_ptrs;
    for (size_t i = 0; i < buffs.size(); i++) 
buff_ptrs.push_back(&buffs[i].front());
    double timeout = 3.0;//seconds_in_future + 0.1; //timeout (delay before 
receive + padding)
    size_t num_acc_samps = 0; //number of accumulated samples
    while(num_acc_samps < total_num_samps){
     //receive a single packet
     size_t num_rx_samps = rx_stream->recv(buff_ptrs, samps_per_buff, md, 
timeout);
     //use a small timeout for subsequent packets
     timeout = 0.1;
     //handle the error code
     if (md.error_code == uhd::rx_metadata_t::ERROR_CODE_TIMEOUT) break;
     if (md.error_code != uhd::rx_metadata_t::ERROR_CODE_NONE){
      throw std::runtime_error(str(boost::format("Receiver error %s") % 
md.strerror()));
     }
     std::cout << 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;
          num_acc_samps += num_rx_samps;
     }
     if (num_acc_samps < total_num_samps) std::cerr << "Receive timeout before 
all samples received..." << std::endl;
     //finished
     std::cout << std::endl << "Done!" << std::endl << std::endl;
}

typedef boost::function<uhd::sensor_value_t (const std::string&)> 
get_sensor_fn_t;

bool check_locked_sensor(std::vector<std::string> sensor_names, const char* 
sensor_name, get_sensor_fn_t get_sensor_fn, double setup_time){
    if (std::find(sensor_names.begin(), sensor_names.end(), sensor_name) == 
sensor_names.end())
        return false;

    boost::system_time start = boost::get_system_time();
    boost::system_time first_lock_time;

    std::cout << boost::format("Waiting for \"%s\": ") % sensor_name;
    std::cout.flush();

    while (true) {
        if ((not first_lock_time.is_not_a_date_time()) and
                (boost::get_system_time() > (first_lock_time + 
boost::posix_time::seconds(setup_time))))
        {
            std::cout << " locked." << std::endl;
            break;
        }
        if (get_sensor_fn(sensor_name).to_bool()){
            if (first_lock_time.is_not_a_date_time())
                first_lock_time = boost::get_system_time();
            std::cout << "+";
            std::cout.flush();
        }
        else {
            first_lock_time = boost::system_time();    //reset to 'not a date 
time'

            if (boost::get_system_time() > (start + 
boost::posix_time::seconds(setup_time))){
                std::cout << std::endl;
                throw std::runtime_error(str(boost::format("timed out waiting 
for consecutive locks on sensor \"%s\"") % sensor_name));
            }
            std::cout << "_";
            std::cout.flush();
        }
        boost::this_thread::sleep(boost::posix_time::milliseconds(100));
    }
    std::cout << std::endl;
    return true;
}


int UHD_SAFE_MAIN(int argc, char *argv[]){
    uhd::set_thread_priority_safe();
    int i=0;
    std::string args, type ;
    struct rfSettings rfParam[3];
    double rate, freq, gain, bw, setupTime, totalTime;
    memset(rfParam,0x00,sizeof(rfParam));

    /*****************************Koyel to check***************************/

    rfParam[0].freq = 935800000;
    strcpy(rfParam[0].band,"P-GSM");
    rfParam[0].bandwidth = 25000000;
    rfParam[0].samplerate = 50000000;
    rfParam[0].total_time = 0x00;
    rfParam[0].setup_time = 1.0;

    rfParam[1].freq = 925000000;
    strcpy(rfParam[1].band,"E-GSM");
    rfParam[1].bandwidth = 35000000;
    rfParam[1].samplerate = 70000000;
    rfParam[1].setup_time = 1.0;

    rfParam[2].freq = 1805200000;
    strcpy(rfParam[1].band,"DCS");
    rfParam[2].bandwidth = 74600000;
    rfParam[2].samplerate = 149200000;
    rfParam[2].setup_time = 1.0;

    /*************************************************************************/

    std::string subdev("A:0 B:0");
    std::string sync("internal");
    for(i=0;i<3;i++){
        if(strcmp(rfParam[i].band,"P-GSM")==0x00){
            rate = rfParam[i].samplerate;
            freq = rfParam[i].freq;
            gain = rfParam[i].gain;
            bw = rfParam[i].bandwidth;
            setupTime = rfParam[i].setup_time;
            totalTime = rfParam[i].total_time;
            break;
        }
    }

    //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);

        //always select the subdevice first, the channel mapping affects the 
other settings
        usrp->set_rx_subdev_spec(subdev); //sets across all mboards
        std::cout << boost::format("Using Device: %s") % usrp->get_pp_string() 
<< std::endl;

        //set the rx sample rate (sets across all channels)
        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;
        std::cout << boost::format("Setting device timestamp to 0...") << 
std::endl;
        if (sync == "now"){
            //This is not a true time lock, the devices will be off by a few 
RTT.
            //Rather, this is just to allow for demonstration of the code below.
            usrp->set_time_now(uhd::time_spec_t(0.0));
        }
        else if (sync == "pps"){
            usrp->set_time_source("external");
            usrp->set_time_unknown_pps(uhd::time_spec_t(0.0));
            boost::this_thread::sleep(boost::posix_time::seconds(1)); //wait 
for pps sync pulse
        }
        else if (sync == "mimo"){
            UHD_ASSERT_THROW(usrp->get_num_mboards() == 2);

            //make mboard 1 a slave over the MIMO Cable
            usrp->set_clock_source("mimo", 1);
            usrp->set_time_source("mimo", 1);

            //set time on the master (mboard 0)
            usrp->set_time_now(uhd::time_spec_t(0.0), 0);

            //sleep a bit while the slave locks its time to the master
            boost::this_thread::sleep(boost::posix_time::milliseconds(100));
        }
        else if(sync=="internal"){
            usrp->set_time_source(sync);
        }
        /*
         * create a receive streamer
         * linearly map channels (index0 = channel0, index1 = channel1, ...)
         */
        uhd::stream_args_t stream_args("fc32","sc16"); //complex floats
        stream_args.channels = boost::assign::list_of(0)(1);
        uhd::rx_streamer::sptr rx_stream = usrp->get_rx_stream(stream_args);
        std::signal(SIGINT, &sig_int_handler);
        std::cout << "Press Ctrl + C to stop streaming..." << std::endl;
        check_locked_sensor(usrp->get_rx_sensor_names(0), "lo_locked", 
boost::bind(&uhd::usrp::multi_usrp::get_rx_sensor, usrp, _1, 0), 
rfParam[0].setup_time);
        startStreaming(rx_stream,usrp);
}


BR

Snehasish



_______________________________________________
USRP-users mailing list
USRP-users@lists.ettus.com<mailto:USRP-users@lists.ettus.com>
http://lists.ettus.com/mailman/listinfo/usrp-users_lists.ettus.com


_______________________________________________
USRP-users mailing list
USRP-users@lists.ettus.com
http://lists.ettus.com/mailman/listinfo/usrp-users_lists.ettus.com

Reply via email to