diff options
Diffstat (limited to 'OutputUHD.cpp')
-rw-r--r-- | OutputUHD.cpp | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/OutputUHD.cpp b/OutputUHD.cpp index a56112d..f1fe3bf 100644 --- a/OutputUHD.cpp +++ b/OutputUHD.cpp @@ -37,9 +37,10 @@ using namespace std; -OutputUHD::OutputUHD(double txgain) +OutputUHD::OutputUHD(double txgain, double samplerate) { m_txgain = txgain; + m_samplerate = samplerate; uhd::set_thread_priority_safe(); @@ -47,7 +48,6 @@ OutputUHD::OutputUHD(double txgain) m_usrp = uhd::usrp::multi_usrp::make(device); - m_samplerate = 2048000; m_usrp->set_tx_rate(m_samplerate); m_usrp->set_rx_rate(m_samplerate); @@ -70,6 +70,17 @@ OutputUHD::OutputUHD(double txgain) uhd::stream_args_t stream_args("fc32"); //complex floats myTxStream = m_usrp->get_tx_stream(stream_args); + + myRxStream = m_usrp->get_rx_stream(stream_args); + uhd::stream_cmd_t stream_cmd(true ? + uhd::stream_cmd_t::STREAM_MODE_START_CONTINUOUS: + uhd::stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_DONE + ); + stream_cmd.num_samps = 0; + stream_cmd.stream_now = true; + stream_cmd.time_spec = uhd::time_spec_t(); + myRxStream->issue_stream_cmd(stream_cmd); + } size_t OutputUHD::Transmit(const complexf *samples, size_t sizeIn, double *first_sample_time) @@ -97,3 +108,36 @@ size_t OutputUHD::Transmit(const complexf *samples, size_t sizeIn, double *first return num_acc_samps; } +size_t OutputUHD::Receive(complexf *samples, size_t sizeIn, double *first_sample_time) +{ + const double rx_timeout = 20.0; + + uhd::rx_metadata_t md; + size_t usrp_max_num_samps = myRxStream->get_max_num_samps(); + + *first_sample_time = md.time_spec.get_real_secs(); + + size_t num_acc_samps = 0; //number of accumulated samples + while (num_acc_samps < sizeIn) { + size_t samps_to_send = std::min(sizeIn - num_acc_samps, usrp_max_num_samps); + + //send a single packet + size_t num_rx_samps = myRxStream->recv( + &samples[num_acc_samps], + samps_to_send, md, rx_timeout); + + if (num_acc_samps == 0) { + if (md.has_time_spec) { + *first_sample_time = md.time_spec.get_real_secs(); + } + else { + MDEBUG("samp %zu no time spec!\n", num_acc_samps); + } + } + + num_acc_samps += num_rx_samps; + } + + return num_acc_samps; +} + |