提交 c300b65a 编写于 作者: M manjaro

b210 Linux 下 61.44M 连续处理

上级 9e159a6f
#include "specwidget.h"
#ifdef __GNUC__
#include <unistd.h>
#endif
#include <QApplication>
int main(int argc, char *argv[])
{
#ifdef __GNUC__
nice(0);
#endif
QApplication a(argc, argv);
specWidget w;
w.show();
......
......@@ -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<double> ppbuf(new double [65536*4]);
static std::shared_ptr<double> 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<sz && total_cp < sppoints;++i,++total_cp)
const size_t sz = m_buf_iqsize[curr_tx];
const short (*datap)[2] = (const short (*)[2])m_buffer_iq[curr_tx];
for (size_t i=0;i<sz && total_cp < m_nFFTSize;++i,++total_cp)
{
double hv = (1 -0.46 ) - 0.46 * cos(2*3.1415926*total_cp/(sppoints-1));
pBufIQ[total_cp][0] =datap[i][0] * hv;
pBufIQ[total_cp][1] =datap[i][1] * hv;
pBufIQ[total_cp][0] =datap[i][0];
pBufIQ[total_cp][1] =datap[i][1];
}
++curr_tx;
curr_tx %= bufsz;
if (!sz)
break;
}
appendWavComplex(pBufIQ,sppoints,ref1v);
appendWavComplex(pBufIQ,m_nFFTSize,ref1v);
if (m_nCurrentCenter>=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
{
......
#include "uhd_device.h"
#include <QThread>
#include <QDebug>
#include <QCoreApplication>
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<bufsz;++i)
{
vec_buffer.push_back(shared_ptr< short > (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<bufsz;++i)
{
vec_buffer.push_back(shared_ptr< short > (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);
}
}
......
......@@ -41,17 +41,19 @@ protected:
std::atomic<bool> stop_signal_called;
std::atomic<bool> 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<long long> rx_count ;
long long rx_count ;
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册