Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
colorEagleStdio
uhd_spectrum
提交
8e462ba1
uhd_spectrum
项目概览
colorEagleStdio
/
uhd_spectrum
通知
18
Star
8
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
uhd_spectrum
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
8e462ba1
编写于
1月 19, 2021
作者:
M
manjaro
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Save file Ok
上级
86388722
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
234 addition
and
57 deletion
+234
-57
qtgui/plotter.cpp
qtgui/plotter.cpp
+1
-1
specwidget.cpp
specwidget.cpp
+174
-41
specwidget.h
specwidget.h
+8
-1
specwidget.ui
specwidget.ui
+49
-13
uhd_device.cpp
uhd_device.cpp
+2
-1
未找到文件。
qtgui/plotter.cpp
浏览文件 @
8e462ba1
...
...
@@ -113,7 +113,7 @@ static inline quint64 time_ms(void)
CPlotter
::
CPlotter
(
QWidget
*
parent
)
:
QFrame
(
parent
)
,
m_maxSize
(
1
024
,
768
)
,
m_maxSize
(
1
920
,
1080
)
{
setSizePolicy
(
QSizePolicy
::
Expanding
,
QSizePolicy
::
Expanding
);
setFocusPolicy
(
Qt
::
StrongFocus
);
...
...
specwidget.cpp
浏览文件 @
8e462ba1
...
...
@@ -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
;
}
specwidget.h
浏览文件 @
8e462ba1
...
...
@@ -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
specwidget.ui
浏览文件 @
8e462ba1
...
...
@@ -11,7 +11,7 @@
</rect>
</property>
<property
name=
"windowTitle"
>
<string>
For
m
</string>
<string>
USRP Spectru
m
</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=
"s
caledContents
"
>
<
bool>
true
</bool
>
<property
name=
"s
egmentStyle
"
>
<
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>
...
...
uhd_device.cpp
浏览文件 @
8e462ba1
...
...
@@ -62,8 +62,9 @@ uhd_device::~uhd_device()
stop_signal_called
=
true
;
while
(
streaming
)
{
QThread
::
msleep
(
100
0
);
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录