diff --git a/uhd_cpp/uhd_spectrum/main.cpp b/uhd_cpp/uhd_spectrum/main.cpp index fc94028bbcc445579e9fffae43f738943876a474..7593b40bac20b58b0559a981884ae96d7d345202 100644 --- a/uhd_cpp/uhd_spectrum/main.cpp +++ b/uhd_cpp/uhd_spectrum/main.cpp @@ -1,9 +1,14 @@ #include "specwidget.h" - +#ifdef __GNUC__ +#include +#endif #include int main(int argc, char *argv[]) { +#ifdef __GNUC__ + nice(0); +#endif QApplication a(argc, argv); specWidget w; w.show(); diff --git a/uhd_cpp/uhd_spectrum/specwidget.cpp b/uhd_cpp/uhd_spectrum/specwidget.cpp index 90d0940709cf7908c9e9b341ede70315d6d942ca..fcd2ecb508eb671e1365135c3c7258b8afc16749 100644 --- a/uhd_cpp/uhd_spectrum/specwidget.cpp +++ b/uhd_cpp/uhd_spectrum/specwidget.cpp @@ -431,8 +431,8 @@ void specWidget::resetFFT() { if (save_count + 100 < rx_count) { - std::shared_ptr< short > buf = vec_buffer[save_count % bufsz]; - size_t len = vec_buffersz[save_count % bufsz]; + short * buf = m_buffer_iq[save_count % bufsz]; + size_t len = m_buf_iqsize[save_count % bufsz]; ++save_count; if (!m_bSaveToFile) { @@ -459,7 +459,7 @@ void specWidget::resetFFT() } if (!m_bSaveToFile) continue; - fOut.write((char *)buf.get(),len * sizeof(short)*2); + fOut.write((char *)buf,len * sizeof(short)*2); } else QThread::msleep(10); @@ -502,44 +502,39 @@ void specWidget::appendWavComplex(const double (* pWav)[2], const int count, dou void specWidget::timerEvent(QTimerEvent * e) { - static std::shared_ptr ppbuf(new double [65536*4]); + static std::shared_ptr ppbuf(new double [65536*16]); static double (*pBufIQ)[2] = (double (*)[2])ppbuf.get(); - - const int fft_bytes_needed = m_nFFTSize *2 * 2; //int fft if (e->timerId()==m_nTimerID ) { + const int num_blocks = m_nFFTSize/m_spb_size + 3; if (!m_bSaveToFile) - { - const int sppoints = fft_bytes_needed/(sizeof(short))/(2); - Q_ASSERT(sppoints == m_nFFTSize); + { double ref1v = 16384; - int curr_tx = (rx_count + bufsz - 100) % bufsz ; + int curr_tx = (rx_count + bufsz - num_blocks ) % bufsz ; int total_cp = 0; - memset(pBufIQ,0,sizeof(double)*2*sppoints); - while (total_cp < sppoints) + //memset(pBufIQ,0,sizeof(double)*2*sppoints); + while (total_cp < m_nFFTSize) { - const size_t sz = vec_buffersz[curr_tx]; - const short (*datap)[2] = (const short (*)[2])vec_buffer[curr_tx].get(); - for (size_t i=0;i=0 && m_nCurrentCenter < m_nFFTSize) { ui->sMeter->setLevel(m_dFFTAmp[m_nCurrentCenter]); - //ui->sMeter->setSqlLevel(m_dFFTAmp[m_nCurrentCenter]); } + ui->lcdNumber_saveBehind->display(int(rx_count * m_spb_size * 4 /1024 / 1024 )); } else { diff --git a/uhd_cpp/uhd_spectrum/uhd_device.cpp b/uhd_cpp/uhd_spectrum/uhd_device.cpp index 7648831775db5b06d7315c6a5798e697f3ae35b2..9b0d8d1a7544814c875f6ae5b07400c470ce94b4 100644 --- a/uhd_cpp/uhd_spectrum/uhd_device.cpp +++ b/uhd_cpp/uhd_spectrum/uhd_device.cpp @@ -1,5 +1,6 @@ #include "uhd_device.h" #include +#include #include using uhd::tune_request_t; using uhd::tx_streamer; @@ -36,11 +37,17 @@ uhd_device::uhd_device() ,streaming(false) ,rx_count(0) { + m_buffer_tmFrag = new double [bufsz]; + m_buffer_tmSec = new long long [bufsz]; + m_buffer_iq_all = new short [bufsz * m_spb_size * 2]; + m_buffer_iq = new short * [bufsz]; + m_buf_iqsize = new int [bufsz]; for (int i=0;i (new short[m_spb_size * 2])); - vec_buffersz.push_back(0); - vec_buffer_tm.push_back(uhd::time_spec_t()); + m_buffer_tmFrag[i] = 0; + m_buffer_tmSec[i] = 0; + m_buffer_iq[i] = &m_buffer_iq_all[i * m_spb_size * 2]; + m_buf_iqsize[i] = 0; } } @@ -51,11 +58,17 @@ uhd_device::uhd_device(const std::string &args) ,rx_count(0) { + m_buffer_tmFrag = new double [bufsz]; + m_buffer_tmSec = new long long [bufsz]; + m_buffer_iq_all = new short [bufsz * m_spb_size * 2]; + m_buffer_iq = new short * [bufsz]; + m_buf_iqsize = new int [bufsz]; for (int i=0;i (new short[m_spb_size * 2])); - vec_buffersz.push_back(0); - vec_buffer_tm.push_back(uhd::time_spec_t()); + m_buffer_tmFrag[i] = 0; + m_buffer_tmSec[i] = 0; + m_buffer_iq[i] = &m_buffer_iq_all[i * m_spb_size * 2]; + m_buf_iqsize[i] = 0; } } uhd_device::~uhd_device() @@ -66,6 +79,13 @@ uhd_device::~uhd_device() QThread::msleep(100); } + delete[] m_buffer_tmFrag; + delete[] m_buffer_tmSec; + delete[] m_buffer_iq_all ; + delete[] m_buffer_iq; + delete[] m_buf_iqsize; + + } void uhd_device::setDevArgs(const std::string &args) @@ -143,21 +163,30 @@ void uhd_device::run_IO() stream_cmd.time_spec = uhd::time_spec_t(); streaming = true; rx_stream->issue_stream_cmd(stream_cmd); + try { while (!stop_signal_called) { - vec_buffersz[rx_count % bufsz] = rx_stream->recv((void *)(vec_buffer[rx_count % bufsz].get()),m_spb_size,md_rx,0.1,false); - //md_rx可以读取时戳 - vec_buffer_tm[rx_count % bufsz] = md_rx.time_spec; + const int off = rx_count % bufsz; + m_buf_iqsize[off] = rx_stream->recv((void *)(m_buffer_iq[off]),m_spb_size,md_rx,10,false); ++rx_count; + //md_rx可以读取时戳 + m_buffer_tmFrag[off] = md_rx.time_spec.get_frac_secs(); + m_buffer_tmSec[off] = md_rx.time_spec.get_full_secs(); if (md_rx.error_code == uhd::rx_metadata_t::ERROR_CODE_TIMEOUT) - fputs("Time out.",stderr); + { + fputs("Tout",stderr); + rx_stream->issue_stream_cmd(stream_cmd); + } else if (md_rx.error_code == uhd::rx_metadata_t::ERROR_CODE_OVERFLOW) - fputs("Over flow",stderr); + { + fputs("O",stderr); + rx_stream->issue_stream_cmd(stream_cmd); + } else if (md_rx.error_code != uhd::rx_metadata_t::ERROR_CODE_NONE) { cerr << "Receiver error: "<< md_rx.strerror() << endl ; - stop_signal_called = true; + rx_stream->issue_stream_cmd(stream_cmd); } } diff --git a/uhd_cpp/uhd_spectrum/uhd_device.h b/uhd_cpp/uhd_spectrum/uhd_device.h index e97e39c88fddcd50ff0da4f75aa275f7cad7a0dc..51fa4dbe7a5f51db7791eb73ee5a315f99df1658 100644 --- a/uhd_cpp/uhd_spectrum/uhd_device.h +++ b/uhd_cpp/uhd_spectrum/uhd_device.h @@ -41,17 +41,19 @@ protected: std::atomic stop_signal_called; std::atomic streaming; std::string m_dev_args; - size_t m_spb_size = 10000; + size_t m_spb_size = 65536; uhd::usrp::multi_usrp::sptr usrp; int m_channel = 0; protected: //初始化队列 - std::vector< uhd::time_spec_t > vec_buffer_tm; - std::vector< std::shared_ptr< short > > vec_buffer; - std::vector< int > vec_buffersz; - const int bufsz = 65536; + double * m_buffer_tmFrag; + long long * m_buffer_tmSec; + short * m_buffer_iq_all; + short * * m_buffer_iq; + int * m_buf_iqsize; + const int bufsz = 1024; //收发计数 - std::atomic rx_count ; + long long rx_count ; };