提交 8e462ba1 编写于 作者: M manjaro

Save file Ok

上级 86388722
......@@ -113,7 +113,7 @@ static inline quint64 time_ms(void)
CPlotter::CPlotter(QWidget *parent)
: QFrame(parent)
, m_maxSize(1024,768)
, m_maxSize(1920,1080)
{
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
setFocusPolicy(Qt::StrongFocus);
......
......@@ -2,16 +2,21 @@
#include "ui_specwidget.h"
#include "qtgui/bookmarks.h"
#include <QSettings>
#include <QDir>
#include <QDateTime>
#include <QFileInfo>
#include <QFileDialog>
specWidget::specWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::specWidget),
ui(new Ui::specWidget),
m_attenMod(new QStandardItemModel(this)),
m_runth(new uhd_io_thread(this)),
m_attenMod(new QStandardItemModel(this))
m_saveth(new uhd_io_thread(this)),
m_bSaveToFile(false)
{
ui->setupUi(this);
Bookmarks::create();
loadSettings();
ui->plotter->setFftFill(false);
ui->plotter->setPeakHold(true);
ui->plotter->setFftPlotColor(QColor(255,255,255));
......@@ -43,7 +48,8 @@ specWidget::specWidget(QWidget *parent) :
connect (ui->plotter,&CPlotter::newZoomLevel,this, &specWidget::evt_newZoomLevel);
connect (ui->freqCtrl,&CFreqCtrl::newFrequency,this, &specWidget::setCenterFreq);
//resetFFT();
loadSettings();
}
specWidget::~specWidget()
......@@ -114,7 +120,10 @@ void specWidget::setCenterFreq(quint64 f){
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);
}
if (ui->doubleSpinBox_center->value() * 1e6 !=ui->freqCtrl->getFrequency())
ui->doubleSpinBox_center->setValue(ui->freqCtrl->getFrequency()/1e6);
......@@ -172,6 +181,10 @@ void specWidget::setSampleRate(double rate){
usrp->set_rx_bandwidth(bw,m_channel);
ui->plotter->setSampleRate(usrp->get_rx_rate(m_channel));
}
else
{
ui->plotter->setSampleRate(rate);
}
}
double specWidget::getSampleRate(void){
return ui->plotter->getSampleRate();
......@@ -263,6 +276,27 @@ void specWidget::loadSettings()
if (m_nFFTSize<128)
m_nFFTSize = 128;
const int comboBox_atn = settings.value("spectrum/comboBox_atn",0).toInt();
ui->comboBox_atn->setCurrentIndex(comboBox_atn);
const int spinBox_chan = settings.value("spectrum/spinBox_chan",0).toInt();
ui->spinBox_chan->setValue(spinBox_chan);
const int spinBox_gain = settings.value("spectrum/spinBox_gain",0).toInt();
ui->spinBox_gain->setValue(spinBox_gain);
const double doubleSpinBox_range_max = settings.value("spectrum/doubleSpinBox_range_max",0).toInt();
ui->doubleSpinBox_range_max->setValue(doubleSpinBox_range_max);
const double doubleSpinBox_range_min = settings.value("spectrum/doubleSpinBox_range_min",-150).toInt();
ui->doubleSpinBox_range_min->setValue(doubleSpinBox_range_min);
const QString lineEdit_dev = settings.value("spectrum/lineEdit_dev","").toString();
ui->lineEdit_dev->setText(lineEdit_dev);
const QString lineEdit_folder = settings.value("spectrum/lineEdit_folder","./").toString();
ui->lineEdit_folder->setText(lineEdit_folder);
}
void specWidget::saveSettings()
{
......@@ -275,6 +309,22 @@ void specWidget::saveSettings()
settings.setValue("spectrum/spinBox_fftUpdate",spinBox_fftUpdate);
const int comboBox_fftSize = ui->comboBox_fftSize->currentIndex();
settings.setValue("spectrum/comboBox_fftSize",comboBox_fftSize);
const int comboBox_atn = ui->comboBox_atn->currentIndex();
settings.setValue("spectrum/comboBox_atn",comboBox_atn);
const int spinBox_gain = ui->spinBox_gain->value();
settings.setValue("spectrum/spinBox_gain",spinBox_gain);
const int spinBox_chan = ui->spinBox_chan->value();
settings.setValue("spectrum/spinBox_chan",spinBox_chan);
const double doubleSpinBox_range_max = ui->doubleSpinBox_range_max->value();
settings.setValue("spectrum/doubleSpinBox_range_max",doubleSpinBox_range_max);
const double doubleSpinBox_range_min = ui->doubleSpinBox_range_min->value();
settings.setValue("spectrum/doubleSpinBox_range_min",doubleSpinBox_range_min);
const QString lineEdit_dev = ui->lineEdit_dev->text();
settings.setValue("spectrum/lineEdit_dev",lineEdit_dev);
const QString lineEdit_folder = ui->lineEdit_folder->text();
settings.setValue("spectrum/lineEdit_folder",lineEdit_folder);
}
void specWidget::freeFFT()
{
......@@ -283,6 +333,13 @@ void specWidget::freeFFT()
killTimer(m_nTimerID);
m_nTimerID = -1;
}
if (m_runth->isRunning())
{
stop_signal_called = true;
m_runth->wait();
m_saveth->wait();
}
if (m_pFFTPlan)
{
fftw_destroy_plan(m_pFFTPlan);
......@@ -300,12 +357,19 @@ void specWidget::freeFFT()
}
m_dHammingWnd.clear();
m_dFFTAmp.clear();
}
void specWidget::resetFFT()
{
ui->pushButton_reset->setText(tr("Start"));
m_channel = ui->spinBox_chan->value();
if (m_nTimerID>=0)
killTimer(m_nTimerID);
freeFFT();
if (usrp)
{
close_device();
}
m_pFFTIn = (fftw_complex *) fftw_malloc(sizeof(fftw_complex) * m_nFFTSize);
m_pFFTOut = (fftw_complex *) fftw_malloc(sizeof(fftw_complex) * m_nFFTSize);
m_pFFTPlan = fftw_plan_dft_1d(m_nFFTSize,m_pFFTIn,m_pFFTOut,FFTW_FORWARD,FFTW_ESTIMATE);
......@@ -315,35 +379,78 @@ void specWidget::resetFFT()
m_dFFTAmp.push_back(0);
}
int updateIntelv = 1000.0 /ui->spinBox_fftUpdate->value() + .5;
if (m_nTimerID>=0)
killTimer(m_nTimerID);
if (usrp)
{
close_device();
}
m_channel = ui->spinBox_chan->value();
if (!usrp)
open_device();
if (!usrp)
return;
//开始
setSampleRate(getSampleRate());
setCenterFreq(ui->plotter->getCenterFreq());
QString atn = ui->comboBox_atn->currentText();
if (atn.size())
usrp->set_rx_antenna(atn.toStdString(),m_channel);
if (m_runth->isRunning())
{
stop_signal_called = true;
m_runth->wait();
}
on_spinBox_gain_valueChanged(ui->spinBox_gain->value());
m_runth->setRunner([&](void){
run_IO();
});
//保存文件
m_strFolder = ui->lineEdit_folder->text();
save_count = 0;
m_bSaveToFile = ui->checkBox_save->isChecked();
double dfreq = ui->doubleSpinBox_center->value();
double spr = ui->doubleSpinBox_spr->value();
m_saveth->setRunner([&,dfreq,spr](void){
QFile fOut;
while (!stop_signal_called)
{
if (save_count + 100 < rx_count)
{
std::shared_ptr< short > buf = vec_buffer[save_count % bufsz];
size_t len = vec_buffersz[save_count % bufsz];
++save_count;
if (!m_bSaveToFile)
{
QThread::msleep(10);
continue;
}
if (fOut.isOpen())
{
if (fOut.size()>=1024*1024*1024)
fOut.close();
}
if (!fOut.isOpen())
{
QDir dir;
dir.mkpath(m_strFolder);
QDateTime dtm = QDateTime::currentDateTime();
QString sdtm = dtm.toString("yyyy_MM_dd_HH_mm_ss.zzz");
QString fm = m_strFolder + "/";
fm += QString("%1MHz_%2Sps_%3.iq.sc16Intel.pcm").arg(dfreq,0,'f',6)
.arg(spr,0,'f',6).arg(sdtm);
fOut.setFileName(fm);
if (!fOut.open(QIODevice::WriteOnly))
m_bSaveToFile = false;
}
if (!m_bSaveToFile)
continue;
fOut.write((char *)buf.get(),len * sizeof(short)*2);
}
else
QThread::msleep(10);
}
if (fOut.isOpen())
fOut.close();
});
m_runth->start();
m_saveth->start();
m_nTimerID = startTimer(updateIntelv);
ui->pushButton_reset->setText(tr("Stop"));
}
......@@ -380,37 +487,50 @@ void specWidget::timerEvent(QTimerEvent * e)
const int fft_bytes_needed = m_nFFTSize *2 * 2;
//int fft
if (e->timerId()==m_nTimerID)
if (e->timerId()==m_nTimerID )
{
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 total_cp = 0;
memset(pBufIQ,0,sizeof(double)*2*sppoints);
while (total_cp < sppoints)
if (!m_bSaveToFile)
{
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 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 total_cp = 0;
memset(pBufIQ,0,sizeof(double)*2*sppoints);
while (total_cp < sppoints)
{
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;
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)
{
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;
}
++curr_tx;
curr_tx %= bufsz;
if (!sz)
break;
}
appendWavComplex(pBufIQ,sppoints,ref1v);
if (m_nCurrentCenter>=0 && m_nCurrentCenter < m_nFFTSize)
{
ui->sMeter->setLevel(m_dFFTAmp[m_nCurrentCenter]);
//ui->sMeter->setSqlLevel(m_dFFTAmp[m_nCurrentCenter]);
}
++curr_tx;
curr_tx %= bufsz;
if (!sz)
break;
}
appendWavComplex(pBufIQ,sppoints,ref1v);
if (m_nCurrentCenter>=0 && m_nCurrentCenter < m_nFFTSize)
else
{
ui->sMeter->setLevel(m_dFFTAmp[m_nCurrentCenter]);
//ui->sMeter->setSqlLevel(m_dFFTAmp[m_nCurrentCenter]);
int he = rx_count - save_count;
ui->lcdNumber_saveBehind->display(he);
if (he >= bufsz)
m_bSaveToFile = false;
}
static int ccct = 0;
if (++ccct % 10==0)
{
......@@ -438,6 +558,7 @@ void specWidget::on_comboBox_fftSize_activated(int index)
m_nFFTSize = 65536;
if (m_nFFTSize<128)
m_nFFTSize = 128;
resetFFT();
saveSettings();
}
......@@ -480,3 +601,15 @@ void specWidget::on_spinBox_chan_valueChanged(int arg1)
{
m_channel = arg1;
}
void specWidget::on_toolButton_br_clicked()
{
QString str = QFileDialog::getExistingDirectory(this,tr("Output to"),ui->lineEdit_folder->text());
if (str.length())
ui->lineEdit_folder->setText(str);
}
void specWidget::on_checkBox_save_stateChanged(int arg1)
{
m_bSaveToFile = arg1==0?false:true;
}
......@@ -107,6 +107,10 @@ private slots:
void on_spinBox_chan_valueChanged(int arg1);
void on_toolButton_br_clicked();
void on_checkBox_save_stateChanged(int arg1);
private:
void loadSettings();
void saveSettings();
......@@ -127,7 +131,10 @@ private:
double m_dManuAdd = 0;
//Thread
uhd_io_thread * m_runth = nullptr;
uhd_io_thread * m_saveth = nullptr;
std::atomic<long long> save_count;
std::atomic<bool> m_bSaveToFile;
QString m_strFolder;
};
#endif // SPECWIDGET_H
......@@ -11,7 +11,7 @@
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
<string>USRP Spectrum</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
......@@ -46,6 +46,9 @@
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
......@@ -55,18 +58,12 @@
</spacer>
</item>
<item>
<widget class="QLabel" name="label_fft_status">
<property name="maximumSize">
<size>
<width>155456</width>
<height>56844</height>
</size>
</property>
<property name="text">
<string>...</string>
<widget class="QLCDNumber" name="lcdNumber_saveBehind">
<property name="digitCount">
<number>8</number>
</property>
<property name="scaledContents">
<bool>true</bool>
<property name="segmentStyle">
<enum>QLCDNumber::Flat</enum>
</property>
</widget>
</item>
......@@ -362,7 +359,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>310</width>
<width>166</width>
<height>164</height>
</rect>
</property>
......@@ -533,6 +530,45 @@
<attribute name="label">
<string>Save</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_3">
<item row="2" column="0">
<widget class="QCheckBox" name="checkBox_save">
<property name="text">
<string>Recording to Files</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_11">
<property name="text">
<string>Folder</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QToolButton" name="toolButton_br">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLineEdit" name="lineEdit_folder"/>
</item>
<item row="3" column="0">
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
</item>
......
......@@ -62,8 +62,9 @@ uhd_device::~uhd_device()
stop_signal_called = true;
while (streaming)
{
QThread::msleep(1000);
QThread::msleep(100);
}
}
void uhd_device::setDevArgs(const std::string &args)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册