提交 0575f005 编写于 作者: D dev

Add win32 C interface.

The mismatch of special compiler versions or boost versions can cause several uncertain memory exceptions.
Using C API instead of C++ API can avoid these errors.
上级 2b4519ce
#include "specwidget.h"
#ifdef __GNUC__
#ifdef Q_OS_LINUX
#include <unistd.h>
#endif
#include <QApplication>
int main(int argc, char *argv[])
{
#ifdef __GNUC__
#ifdef Q_OS_LINUX
nice(0);
#endif
QApplication a(argc, argv);
......
......@@ -33,8 +33,6 @@ specWidget::specWidget(QWidget *parent) :
m_attenMod->appendRow(new QStandardItem("TX/RX"));
m_attenMod->appendRow(new QStandardItem("RX2"));
m_attenMod->appendRow(new QStandardItem("RX"));
m_attenMod->appendRow(new QStandardItem("TX"));
ui->comboBox_atn->setModel(m_attenMod);
//连接
......@@ -120,17 +118,8 @@ void specWidget::setBookmarksEnabled(bool enabled){
ui->plotter->setBookmarksEnabled(enabled);
}
void specWidget::setCenterFreq(quint64 f){
if (usrp)
{
using uhd::tune_request_t;
tune_request_t tune_request_rx = tune_request_t((double)f, 0);
usrp->set_rx_freq(tune_request_rx,m_channel);
ui->plotter->setCenterFreq(usrp->get_rx_freq(m_channel));
}
else
{
ui->plotter->setCenterFreq(f);
}
f = set_center_freq(f);
ui->plotter->setCenterFreq(f);
if (ui->doubleSpinBox_center->value() * 1e6 !=ui->freqCtrl->getFrequency())
ui->doubleSpinBox_center->setValue(ui->freqCtrl->getFrequency()/1e6);
//ui->plotter->setCenterFreq(f);
......@@ -175,22 +164,8 @@ void specWidget::setFreqDigits(int digits){
ui->plotter->setFreqDigits(digits);
}
void specWidget::setSampleRate(double rate){
if (usrp)
{
double bw = rate;
if (bw >56e6)
bw = 56e6;
if (bw <200000)
bw = 200000;
fprintf(stderr,"bw = %lf\n",bw);
usrp->set_rx_rate(rate);
usrp->set_rx_bandwidth(bw,m_channel);
ui->plotter->setSampleRate(usrp->get_rx_rate(m_channel));
}
else
{
ui->plotter->setSampleRate(rate);
}
rate = set_sample_rate(rate);
ui->plotter->setSampleRate(rate);
}
double specWidget::getSampleRate(void){
return ui->plotter->getSampleRate();
......@@ -224,7 +199,10 @@ void specWidget::on_pushButton_reset_clicked()
if (m_runth->isRunning())
{
if (m_nTimerID>=0)
{
killTimer(m_nTimerID);
m_nTimerID = -1;
}
if (usrp)
{
......@@ -375,7 +353,10 @@ void specWidget::resetFFT()
{
ui->pushButton_reset->setText(tr("Start"));
if (m_nTimerID>=0)
{
killTimer(m_nTimerID);
m_nTimerID = -1;
}
freeFFT();
int pg = ui->toolBox_tool->currentIndex();
ui->toolBox_tool->setCurrentIndex(2);
......@@ -407,10 +388,13 @@ void specWidget::resetFFT()
//开始
setSampleRate(getSampleRate());
long long bw = ui->spinBox_bw->value()*1000;
bw = set_rx_bandwidth(bw);
ui->spinBox_bw->setValue(bw/1000);
setCenterFreq(ui->plotter->getCenterFreq());
QString atn = ui->comboBox_atn->currentText();
if (atn.size())
usrp->set_rx_antenna(atn.toStdString(),m_channel);
set_rx_atn(atn.toStdString());
on_spinBox_gain_valueChanged(ui->spinBox_gain->value());
m_runth->setRunner([&](void){
......@@ -507,7 +491,7 @@ void specWidget::timerEvent(QTimerEvent * e)
{
const int num_blocks = m_nFFTSize/m_spb_size + 3;
if (!m_bSaveToFile)
{
{
double ref1v = 16384;
int curr_tx = (rx_count + bufsz - num_blocks ) % bufsz ;
int total_cp = 0;
......@@ -581,7 +565,7 @@ void specWidget::on_doubleSpinBox_center_valueChanged(double arg1)
void specWidget::on_spinBox_gain_valueChanged(int arg1)
{
if (usrp)
usrp->set_rx_gain(arg1,m_channel);
set_rx_gain(arg1);
//usrp->set_rx_agc(true,m_channel);
}
......@@ -601,7 +585,7 @@ void specWidget::on_comboBox_atn_currentIndexChanged(const QString &arg1)
if (arg1.size())
{
if (usrp)
usrp->set_rx_antenna(arg1.toStdString(),m_channel);
set_rx_atn(arg1.toStdString());
}
}
......@@ -629,6 +613,6 @@ void specWidget::on_spinBox_bw_valueChanged(int arg1)
bw = ui->plotter->getSampleRate();
if (bw <200000)
bw = 200000;
if (usrp)
usrp->set_rx_bandwidth(bw,m_channel);
bw = set_rx_bandwidth(bw);
}
......@@ -28,7 +28,13 @@
#include <fftw3.h>
#include <vector>
#include <QStandardItemModel>
#ifdef Q_OS_WINDOWS
#include "uhd_device_win32.h"
#endif
#ifdef Q_OS_LINUX
#include "uhd_device.h"
#endif
#include "stdout_watcher.h"
namespace Ui {
class specWidget;
......
#include "stdout_watcher.h"
#include <stdio.h>
#include <thread>
#ifdef __GNUC__
#ifdef Q_OS_LINUX
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#endif
#ifdef _MSVC_LANG
#ifdef Q_OS_WINDOWS
#include <io.h>
#include <fcntl.h>
#endif
......@@ -25,47 +25,56 @@ void stdout_watcher::stop_and_wait()
wait();
}
#ifdef _MSVC_LANG
#ifdef Q_OS_WINDOWS
#define OUT_BUFF_SIZE 1024
void stdout_watcher::run()
{
return;
auto pt = [&](FILE * stda,bool stderrb)->void{
HANDLE hOutputReadTmp = 0;
HANDLE hOutputWrite = 0;
if (!CreatePipe(&hOutputReadTmp,&hOutputWrite,0,0))
emit evt_stdata("[stdout watcher]:CreatePipe Error.",stderrb);
int hCrt =_open_osfhandle( (long)hOutputWrite, _O_TEXT );
FILE *hf = _fdopen( hCrt, "w" );
*stda = *hf;
int i = setvbuf( stda, NULL, _IONBF, 0 );
CHAR lpBuffer[1024];
DWORD nBytesRead;
int fdStdOutPipe[2];
int fdStdOut;
if (_pipe(fdStdOutPipe, OUT_BUFF_SIZE*1024, O_TEXT)!=0)
{
return ;
}
fdStdOut = _dup(_fileno(stda));
fflush( stda );
_dup2(fdStdOutPipe[1], _fileno(stda));
ios::sync_with_stdio();
setvbuf( stda, NULL, _IONBF, 0 ); // absolutely needed
QByteArray arrbuf;
while(!m_bStop)
{
if (!ReadFile(hOutputReadTmp, lpBuffer,sizeof(lpBuffer),
&nBytesRead,NULL) || !nBytesRead)
char buffer[OUT_BUFF_SIZE*2];
int nOutRead = _read(fdStdOutPipe[0], (void *)buffer,(size_t) OUT_BUFF_SIZE);
buffer[nOutRead] = '\0';
if (nOutRead >0 )
{
if (GetLastError() == ERROR_BROKEN_PIPE)
break; // pipe done - normal exit path.
else
emit evt_stdata("ReadFile",stderrb);
arrbuf.append(buffer,nOutRead);
}
int cp = 0;
int sz = arrbuf.size();
const char * p = arrbuf.constData();
if (nBytesRead >0 )
for (int i=0;i<sz;++i)
{
emit evt_stdata(QByteArray(lpBuffer,nBytesRead),stderrb);
if (p[i]=='\n')
{
QByteArray arrEmit = arrbuf.left(i);
emit evt_stdata(arrEmit,stderrb);
arrbuf = arrbuf.mid(i+1);
break;
}
}
}
_dup2(fdStdOut, _fileno(stda));
ios::sync_with_stdio();
_close(fdStdOut);
_close(fdStdOutPipe[0]);
_close(fdStdOutPipe[1]);
fclose(hf);
_close(hCrt);
CloseHandle(hOutputReadTmp);
CloseHandle(hOutputWrite);
};
std::thread t1(pt, stderr,true);
......@@ -77,7 +86,7 @@ void stdout_watcher::run()
#endif
#ifdef __GNUC__
#ifdef Q_OS_LINUX
void stdout_watcher::run()
{
......
......@@ -3,8 +3,20 @@
#include <QThread>
#include <atomic>
#ifdef _MSVC_LANG
#include<windows.h>
#ifdef Q_OS_WINDOWS
#include <stdio.h>
#include <fcntl.h>
#include <io.h>
#include <iostream>
#include <windows.h>
#ifndef _USE_OLD_IOSTREAMS
using namespace std;
#endif
#define CHECK(a) if ((a)!= 0) return -1;
#endif
class stdout_watcher : public QThread
{
......
......@@ -12,6 +12,8 @@ using std::string;
using std::vector;
using std::shared_ptr;
#define UHD_CALL(X) try{ X;} catch (...) {fprintf(stderr,"Exception in %s:%d\n",__FILE__,__LINE__);}
uhd_io_thread::uhd_io_thread (std::function<void (void)> runner,QObject * p)
:QThread(p)
,m_runner(runner)
......@@ -42,7 +44,7 @@ uhd_device::uhd_device()
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)
for (size_t i=0;i<bufsz;++i)
{
m_buffer_tmFrag[i] = 0;
m_buffer_tmSec[i] = 0;
......@@ -103,15 +105,15 @@ bool uhd_device::open_device()
string ref = "internal";
std::atomic<bool> finished(false);
std::thread thr([&]()->void{
try{
usrp = multi_usrp::make(m_dev_args);
}
catch (...)
{
fprintf (stderr,"Error in USRP init.\n");
}
finished = true;
});
try{
usrp = multi_usrp::make(m_dev_args);
}
catch (...)
{
fprintf (stderr,"Error in USRP init.\n");
}
finished = true;
});
while (!finished)
{
......@@ -124,7 +126,14 @@ bool uhd_device::open_device()
if (!usrp)
return false;
usrp->set_clock_source(ref,multi_usrp::ALL_MBOARDS);
try{
usrp->set_clock_source(ref,multi_usrp::ALL_MBOARDS);
}
catch(...)
{
}
//if (rx_op.subdev.size())
// usrp->set_rx_subdev_spec(rx_op.subdev,multi_usrp::ALL_MBOARDS);
stop_signal_called = false;
......@@ -193,9 +202,9 @@ void uhd_device::run_IO()
} catch (...) {
stop_signal_called = true;
}
stream_cmd.stream_now = false;
rx_stream->issue_stream_cmd(stream_cmd);
streaming = false;
stream_cmd.stream_now = false;
rx_stream->issue_stream_cmd(stream_cmd);
streaming = false;
};
//启动线程
uhd_io_thread * rx_thread = new uhd_io_thread(thcall_rx,0);
......@@ -209,6 +218,50 @@ void uhd_device::run_IO()
//退出
rx_thread->wait();
rx_thread->deleteLater();
}
quint64 uhd_device::set_center_freq(const quint64 freq_in_hz)
{
if (usrp)
{
using uhd::tune_request_t;
tune_request_t tune_request_rx = tune_request_t((double)freq_in_hz);
usrp->set_rx_freq(tune_request_rx,m_channel);
return (quint64)(usrp->get_rx_freq(m_channel));
}
else
return freq_in_hz;
}
double uhd_device::set_sample_rate(const double sprate)
{
if (usrp)
{
usrp->set_rx_rate(sprate);
return usrp->get_rx_rate(m_channel);
}
return sprate;
}
void uhd_device::set_rx_atn(const std::string & atn)
{
if (usrp)
usrp->set_rx_antenna(atn.c_str(),m_channel);
}
double uhd_device::set_rx_gain(double gain)
{
if (usrp)
usrp->set_rx_gain(gain,m_channel);
return usrp->get_rx_gain(m_channel);
}
double uhd_device::set_rx_bandwidth(double bw)
{
if (usrp)
{
usrp->set_rx_bandwidth(bw,m_channel);
bw = usrp->get_rx_bandwidth(m_channel);
}
return bw;
}
......@@ -13,6 +13,7 @@
#include <vector>
#include <atomic>
#include <QThread>
#include <string>
class uhd_io_thread: public QThread{
Q_OBJECT
public:
......@@ -43,7 +44,7 @@ protected:
std::string m_dev_args;
size_t m_spb_size = 65536;
uhd::usrp::multi_usrp::sptr usrp;
int m_channel = 0;
size_t m_channel = 0;
protected:
//初始化队列
double * m_buffer_tmFrag;
......@@ -51,10 +52,15 @@ protected:
short * m_buffer_iq_all;
short * * m_buffer_iq;
int * m_buf_iqsize;
const int bufsz = 1024;
const size_t bufsz = 1024;
//收发计数
long long rx_count ;
public:
quint64 set_center_freq(const quint64 freq_in_hz);
double set_sample_rate(const double sprate);
void set_rx_atn(const std::string & ana);
double set_rx_gain(double gain);
double set_rx_bandwidth(double bw);
};
#endif // UHD_DEVICE_H
#include "uhd_device_win32.h"
#include <QThread>
#include <QDebug>
#include <QCoreApplication>
using std::endl;
using std::string;
using std::vector;
using std::shared_ptr;
#define UHD_DO(X) \
{\
uhd_error e = (X);\
char buf_errs[512];\
if (e) { snprintf(buf_errs,sizeof(buf_errs),"Error in %s line %d, NO %d.",__FILE__,__LINE__,e);\
std::string ev = __FILE__;\
ev += ":";\
ev += buf_errs;\
return_code = 1;\
fputs(buf_errs,stderr);\
}\
};
uhd_io_thread::uhd_io_thread (std::function<void (void)> runner,QObject * p)
:QThread(p)
,m_runner(runner)
{
}
uhd_io_thread::uhd_io_thread (QObject * p)
:QThread(p)
{
}
void uhd_io_thread::run()
{
if (m_runner)
m_runner();
}
uhd_device::uhd_device()
:stop_signal_called(false)
,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 size_t [bufsz];
for (int i=0;i<bufsz;++i)
{
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(const std::string &args)
:stop_signal_called(false)
,streaming(false)
,m_dev_args (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 size_t [bufsz];
for (int i=0;i<bufsz;++i)
{
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()
{
stop_signal_called = true;
while (streaming)
{
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)
{
this->m_dev_args = args;
}
std::string uhd_device::devArgs() const
{
return m_dev_args;
}
bool uhd_device::open_device()
{
string ref = "internal";
std::atomic<bool> finished(false);
std::thread thr([&]()->void{
try{
UHD_DO(uhd_usrp_make(&usrp, m_dev_args.c_str()));
}
catch(std::string er)
{
fputs(er.c_str(),stderr);
}
finished = true;
});
while (!finished)
{
QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
QThread::msleep(20);
}
thr.join();
if (!usrp)
return false;
try{
uhd_usrp_set_clock_source(usrp,ref.c_str(),0);
}
catch(std::string er)
{
fputs(er.c_str(),stderr);
}
//if (rx_op.subdev.size())
// usrp->set_rx_subdev_spec(rx_op.subdev,multi_usrp::ALL_MBOARDS);
stop_signal_called = false;
return usrp?true:false;
}
bool uhd_device::close_device()
{
stop_signal_called = true;
while (streaming)
{
QThread::msleep(1000);
}
if (usrp)
uhd_usrp_free(&usrp);
usrp = 0;
return true;
}
/*!
* 范例落盘函数,使用环形队列保持跟随收发
*/
void uhd_device::run_IO()
{
//设置接收通道,母板号为0(multi-usrp支持级联)
//UHD_DO(uhd_usrp_set_rx_subdev_spec(usrp,0,0));
//创建流对象实例
char rx_cpu_format[] = "sc16";
char rx_otw_format[] = "sc16";
char rx_args[] = "";
const size_t rx_channel_count = 1;
//接收信号。MIMO时,可以指定0,1
size_t rx_channel[] = {(size_t)m_channel};
uhd_stream_args_t rx_stream_args = {
/*.cpu_format = */rx_cpu_format,
/*.otw_format = */rx_otw_format,
/*.args = */rx_args,
/*.channel_list = */rx_channel,
/*.n_channels = */rx_channel_count
};
uhd_rx_streamer_handle rx_streamer = 0;
uhd_rx_metadata_handle rx_meta = 0;
rx_count = 0;
//接收线程
auto thcall_rx = [&]()->void{
// Create RX streamer
UHD_DO(uhd_rx_streamer_make(&rx_streamer));
// Create RX metadata
UHD_DO(uhd_rx_metadata_make(&rx_meta));
uhd_stream_cmd_t rx_stream_cmd = {
/*.stream_mode = */UHD_STREAM_MODE_START_CONTINUOUS,
/*.num_samps = */0,
/*.stream_now = */true,
/*.time_spec_full_secs = */0,
/*.time_spec_frac_secs = */0
};
streaming = true;
rx_stream_args.channel_list = rx_channel;
UHD_DO(uhd_usrp_get_rx_stream(usrp, &rx_stream_args, rx_streamer));
// Set up buffer
UHD_DO(uhd_rx_streamer_max_num_samps(rx_streamer, &m_spb_size));
fprintf(stderr, "Buffer size in samples: %zu\n", m_spb_size);
try {
UHD_DO(uhd_rx_streamer_issue_stream_cmd(rx_streamer, &rx_stream_cmd));
while (!stop_signal_called)
{
const int off = rx_count % bufsz;
UHD_DO(uhd_rx_streamer_recv(rx_streamer,(void **) &(m_buffer_iq[off]), m_spb_size, &rx_meta, 10, true, &m_buf_iqsize[off]));
++rx_count;
//md_rx可以读取时戳
UHD_DO(uhd_rx_metadata_time_spec(rx_meta,&m_buffer_tmSec[off],&m_buffer_tmFrag[off]));
uhd_rx_metadata_error_code_t error_code;
UHD_DO(uhd_rx_metadata_error_code(rx_meta, &error_code));
if(error_code != UHD_RX_METADATA_ERROR_CODE_NONE){
fprintf(stderr, "Warning: Error code 0x%x was returned during streaming.\n", error_code);
uhd_usrp_last_error(usrp, error_string, 512);
fputs(error_string,stderr);
UHD_DO(uhd_rx_streamer_issue_stream_cmd(rx_streamer, &rx_stream_cmd));
}
}
} catch (...) {
stop_signal_called = true;
}
rx_stream_cmd.stream_now = false;
UHD_DO(uhd_rx_streamer_issue_stream_cmd(rx_streamer, &rx_stream_cmd));
streaming = false;
};
//启动线程
uhd_io_thread * rx_thread = new uhd_io_thread(thcall_rx,0);
rx_thread->start(QThread::TimeCriticalPriority);
//主线程不断打印状态
while (!stop_signal_called)
{
//cerr<<"RX" << rx_count<<"\r";
std::this_thread::sleep_for(std::chrono::milliseconds(400));
}
if (rx_streamer) uhd_rx_streamer_free(&rx_streamer);
if (rx_meta) uhd_rx_metadata_free(&rx_meta);
//退出
rx_thread->wait();
rx_thread->deleteLater();
}
quint64 uhd_device::set_center_freq(const quint64 freq_in_hz)
{
if (!usrp)
return freq_in_hz;
fprintf(stderr, "Setting RX frequency: %f MHz...\n", freq_in_hz/1e6);
uhd_tune_result_t rx_tune_result;
uhd_tune_request_t rx_tune_request =
{
/*.target_freq =*/ (double)freq_in_hz,
/*.rf_freq_policy =*/ UHD_TUNE_REQUEST_POLICY_AUTO,
/*.rf_freq =*/ 0,
/*.dsp_freq_policy = */UHD_TUNE_REQUEST_POLICY_AUTO,
/*.dsp_freq =*/ 0,
/*.args =*/ 0
};
UHD_DO(uhd_usrp_set_rx_freq(usrp, &rx_tune_request, m_channel, &rx_tune_result));
double freq = 0;
UHD_DO(uhd_usrp_get_rx_freq(usrp, m_channel, &freq));
fprintf(stderr, "Actual RX frequency: %f MHz...\n", freq / 1e6);
return (quint64)(freq * 1e6 +.5);
}
double uhd_device::set_sample_rate(const double sprate)
{
if (usrp)
{
double srate = sprate;
double bw = sprate;
if (bw >56e6)
bw = 56e6;
if (bw <200000)
bw = 200000;
fprintf(stderr, "Setting RX Rate: %f...\n", sprate);
UHD_DO(uhd_usrp_set_rx_rate(usrp, sprate, m_channel));
// See what rate actually is
UHD_DO(uhd_usrp_get_rx_rate(usrp, m_channel, &srate));
fprintf(stderr, "Actual RX Rate: %f...\n", srate);
fprintf(stderr, "Setting RX Bandwidth: %f MHz...\n", bw/1e6);
UHD_DO(uhd_usrp_set_rx_bandwidth(usrp, bw, m_channel));
//Band
UHD_DO(uhd_usrp_get_rx_bandwidth(usrp, m_channel, &bw));
fprintf(stderr, "Actual RX Bandwidth: %f MHz...\n", bw / 1e6);
return srate;
}
return sprate;
}
void uhd_device::set_rx_atn(const std::string & atn)
{
if (usrp)
uhd_usrp_set_rx_antenna(usrp,atn.c_str(),m_channel);
}
double uhd_device::set_rx_gain(double gain)
{
if (!usrp)
return gain;
// Set gain
fprintf(stderr, "Setting RX Gain: %f dB...\n",(float) gain);
UHD_DO(uhd_usrp_set_rx_gain(usrp, gain,m_channel,""));
// See what gain actually is
UHD_DO(uhd_usrp_get_rx_gain(usrp, m_channel,"", &gain));
fprintf(stderr, "Actual RX Gain: %lf...\n", gain);
return gain;
}
double uhd_device::set_rx_bandwidth(double bw)
{
if (usrp)
{
fprintf(stderr, "Setting RX Bandwidth: %f MHz...\n", bw/1e6);
UHD_DO(uhd_usrp_set_rx_bandwidth(usrp, bw, m_channel));
//Band
UHD_DO(uhd_usrp_get_rx_bandwidth(usrp, m_channel, &bw));
fprintf(stderr, "Actual RX Bandwidth: %f MHz...\n", bw / 1e6);
}
return bw;
}
#ifndef UHD_DEVICE_H
#define UHD_DEVICE_H
#include <functional>
#include <vector>
#include <atomic>
#include <QThread>
#include <uhd.h>
class uhd_io_thread: public QThread{
Q_OBJECT
public:
explicit uhd_io_thread (QObject * p);
explicit uhd_io_thread (std::function<void (void)> runner,QObject * p);
void setRunner(std::function<void (void)> r){ m_runner = r;}
public:
void run() override;
private:
std::function<void (void)> m_runner;
};
class uhd_device{
public:
uhd_device();
uhd_device(const std::string &args);
~uhd_device();
public:
void setDevArgs(const std::string &args);
std::string devArgs() const ;
public:
bool open_device();
bool close_device();
void run_IO();
protected:
std::atomic<bool> stop_signal_called;
std::atomic<bool> streaming;
std::string m_dev_args;
size_t m_spb_size = 10000;
uhd_usrp_handle usrp = 0;
char error_string[512];
int return_code = 0;
int m_channel = 0;
protected:
//初始化队列
double * m_buffer_tmFrag;
long long * m_buffer_tmSec;
short * m_buffer_iq_all;
short * * m_buffer_iq;
size_t * m_buf_iqsize;
const int bufsz = 8192;
//收发计数
long long rx_count ;
public:
quint64 set_center_freq(const quint64 freq_in_hz);
double set_sample_rate(const double sprate);
void set_rx_atn(const std::string & ana);
double set_rx_gain(double);
double set_rx_bandwidth(double bw);
};
#endif // UHD_DEVICE_H
......@@ -2,7 +2,7 @@ QT += core gui network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++11
CONFIG += c++17
# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
......@@ -23,8 +23,7 @@ SOURCES += \
qtgui/meter.cpp \
qtgui/plotter.cpp \
specwidget.cpp \
stdout_watcher.cpp \
uhd_device.cpp
stdout_watcher.cpp
HEADERS += \
qtgui/bookmarks.h \
......@@ -34,26 +33,29 @@ HEADERS += \
qtgui/meter.h \
qtgui/plotter.h \
specwidget.h \
stdout_watcher.h \
uhd_device.h
stdout_watcher.h
FORMS += \
specwidget.ui
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
LIBS += -luhd
win32{
mkoptions = $$find(QMAKESPEC, "vc")
count(mkoptions, 1){
INCLUDEPATH +="$$PWD/3rdlibs/win32/fftw"
INCLUDEPATH +="$(UHD_PKG_PATH)/include"
contains(QT_ARCH, i386) {
LIBS+=-L"$$PWD/3rdlibs/win32/fftw/x86" -llibfftw3-3 -L"$(UHD_PKG_PATH)/lib"
LIBS+=-L"$$PWD/3rdlibs/win32/fftw/x86" -llibfftw3-3
} else {
LIBS+=-L"$$PWD/3rdlibs/win32/fftw/x64" -llibfftw3-3 -L"$(UHD_PKG_PATH)/lib"
LIBS+=-L"$$PWD/3rdlibs/win32/fftw/x64" -llibfftw3-3
}
} else: LIBS+=-lfftw3
}else: LIBS+=-lfftw3 -lpthread
INCLUDEPATH +="$(UHD_PKG_PATH)/include"
LIBS += -L"$(UHD_PKG_PATH)/lib"
SOURCES += \
uhd_device_win32.cpp
HEADERS += \
uhd_device_win32.h
}else {
SOURCES += \
uhd_device.cpp
HEADERS += \
uhd_device.h
LIBS+=-lfftw3 -lpthread
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册