kopia lustrzana https://gitlab.com/Teuniz/DSRemote
Move the code for downloading waveform data into a separate thread
in order to keep the gui responsive.merge-requests/1/head
rodzic
acf53c833f
commit
e1436f3961
|
@ -55,6 +55,7 @@ HEADERS += settings_dialog.h
|
||||||
HEADERS += screen_thread.h
|
HEADERS += screen_thread.h
|
||||||
HEADERS += lan_connect_thread.h
|
HEADERS += lan_connect_thread.h
|
||||||
HEADERS += read_settings_thread.h
|
HEADERS += read_settings_thread.h
|
||||||
|
HEADERS += save_data_thread.h
|
||||||
|
|
||||||
HEADERS += third_party/kiss_fft/kiss_fft.h
|
HEADERS += third_party/kiss_fft/kiss_fft.h
|
||||||
HEADERS += third_party/kiss_fft/_kiss_fft_guts.h
|
HEADERS += third_party/kiss_fft/_kiss_fft_guts.h
|
||||||
|
@ -78,6 +79,7 @@ SOURCES += settings_dialog.cpp
|
||||||
SOURCES += screen_thread.cpp
|
SOURCES += screen_thread.cpp
|
||||||
SOURCES += lan_connect_thread.cpp
|
SOURCES += lan_connect_thread.cpp
|
||||||
SOURCES += read_settings_thread.cpp
|
SOURCES += read_settings_thread.cpp
|
||||||
|
SOURCES += save_data_thread.cpp
|
||||||
|
|
||||||
SOURCES += third_party/kiss_fft/kiss_fft.c
|
SOURCES += third_party/kiss_fft/kiss_fft.c
|
||||||
SOURCES += third_party/kiss_fft/kiss_fftr.c
|
SOURCES += third_party/kiss_fft/kiss_fftr.c
|
||||||
|
|
2
global.h
2
global.h
|
@ -35,7 +35,7 @@
|
||||||
|
|
||||||
|
|
||||||
#define PROGRAM_NAME "DSRemote"
|
#define PROGRAM_NAME "DSRemote"
|
||||||
#define PROGRAM_VERSION "0.32_1610022021"
|
#define PROGRAM_VERSION "0.32_1610091654"
|
||||||
|
|
||||||
#define MAX_PATHLEN 4096
|
#define MAX_PATHLEN 4096
|
||||||
|
|
||||||
|
|
|
@ -64,6 +64,7 @@
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
#include <QProgressDialog>
|
#include <QProgressDialog>
|
||||||
#include <QKeySequence>
|
#include <QKeySequence>
|
||||||
|
#include <QEventLoop>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -86,6 +87,7 @@
|
||||||
#include "screen_thread.h"
|
#include "screen_thread.h"
|
||||||
#include "lan_connect_thread.h"
|
#include "lan_connect_thread.h"
|
||||||
#include "read_settings_thread.h"
|
#include "read_settings_thread.h"
|
||||||
|
#include "save_data_thread.h"
|
||||||
|
|
||||||
#include "third_party/kiss_fft/kiss_fftr.h"
|
#include "third_party/kiss_fft/kiss_fftr.h"
|
||||||
|
|
||||||
|
|
|
@ -55,14 +55,27 @@ void UI_Mainwindow::save_screenshot()
|
||||||
|
|
||||||
tmc_write(":DISP:DATA?");
|
tmc_write(":DISP:DATA?");
|
||||||
|
|
||||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
save_data_thread get_data_thrd(0);
|
||||||
|
|
||||||
qApp->processEvents();
|
QMessageBox w_msg_box;
|
||||||
|
w_msg_box.setIcon(QMessageBox::NoIcon);
|
||||||
|
w_msg_box.setText("Downloading data...");
|
||||||
|
w_msg_box.setStandardButtons(QMessageBox::Abort);
|
||||||
|
|
||||||
n = tmc_read();
|
connect(&get_data_thrd, SIGNAL(finished()), &w_msg_box, SLOT(accept()));
|
||||||
|
|
||||||
QApplication::restoreOverrideCursor();
|
get_data_thrd.start();
|
||||||
|
|
||||||
|
if(w_msg_box.exec() != QDialog::Accepted)
|
||||||
|
{
|
||||||
|
disconnect(&get_data_thrd, 0, 0, 0);
|
||||||
|
strcpy(str, "Aborted by user.");
|
||||||
|
goto OUT_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
disconnect(&get_data_thrd, 0, 0, 0);
|
||||||
|
|
||||||
|
n = get_data_thrd.get_num_bytes_rcvd();
|
||||||
if(n < 0)
|
if(n < 0)
|
||||||
{
|
{
|
||||||
strcpy(str, "Can not read from device.");
|
strcpy(str, "Can not read from device.");
|
||||||
|
@ -150,6 +163,13 @@ void UI_Mainwindow::save_screenshot()
|
||||||
|
|
||||||
OUT_ERROR:
|
OUT_ERROR:
|
||||||
|
|
||||||
|
if(get_data_thrd.isFinished() != true)
|
||||||
|
{
|
||||||
|
connect(&get_data_thrd, SIGNAL(finished()), &w_msg_box, SLOT(accept()));
|
||||||
|
w_msg_box.setText("Waiting for thread to finish, please wait...");
|
||||||
|
w_msg_box.exec();
|
||||||
|
}
|
||||||
|
|
||||||
scrn_timer->start(devparms.screentimerival);
|
scrn_timer->start(devparms.screentimerival);
|
||||||
|
|
||||||
QMessageBox msgBox;
|
QMessageBox msgBox;
|
||||||
|
@ -183,6 +203,10 @@ void UI_Mainwindow::save_memory_waveform()
|
||||||
|
|
||||||
double yinc[MAX_CHNS];
|
double yinc[MAX_CHNS];
|
||||||
|
|
||||||
|
QEventLoop ev_loop;
|
||||||
|
|
||||||
|
save_data_thread get_data_thrd(0);
|
||||||
|
|
||||||
if(device == NULL)
|
if(device == NULL)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
@ -203,7 +227,9 @@ void UI_Mainwindow::save_memory_waveform()
|
||||||
|
|
||||||
QProgressDialog progress("Downloading data...", "Abort", 0, mempnts, this);
|
QProgressDialog progress("Downloading data...", "Abort", 0, mempnts, this);
|
||||||
progress.setWindowModality(Qt::WindowModal);
|
progress.setWindowModality(Qt::WindowModal);
|
||||||
progress.setMinimumDuration(100);
|
progress.setMinimumDuration(0);
|
||||||
|
|
||||||
|
connect(&get_data_thrd, SIGNAL(finished()), &ev_loop, SLOT(quit()));
|
||||||
|
|
||||||
statusLabel->setText("Downloading data...");
|
statusLabel->setText("Downloading data...");
|
||||||
|
|
||||||
|
@ -335,8 +361,6 @@ void UI_Mainwindow::save_memory_waveform()
|
||||||
{
|
{
|
||||||
progress.setValue(bytes_rcvd);
|
progress.setValue(bytes_rcvd);
|
||||||
|
|
||||||
qApp->processEvents();
|
|
||||||
|
|
||||||
if(progress.wasCanceled())
|
if(progress.wasCanceled())
|
||||||
{
|
{
|
||||||
strcpy(str, "Canceled");
|
strcpy(str, "Canceled");
|
||||||
|
@ -366,8 +390,11 @@ void UI_Mainwindow::save_memory_waveform()
|
||||||
|
|
||||||
tmc_write(":WAV:DATA?");
|
tmc_write(":WAV:DATA?");
|
||||||
|
|
||||||
n = tmc_read();
|
get_data_thrd.start();
|
||||||
|
|
||||||
|
ev_loop.exec();
|
||||||
|
|
||||||
|
n = get_data_thrd.get_num_bytes_rcvd();
|
||||||
if(n < 0)
|
if(n < 0)
|
||||||
{
|
{
|
||||||
sprintf(str, "Can not read from device. line %i file %s", __LINE__, __FILE__);
|
sprintf(str, "Can not read from device. line %i file %s", __LINE__, __FILE__);
|
||||||
|
@ -551,6 +578,8 @@ void UI_Mainwindow::save_memory_waveform()
|
||||||
|
|
||||||
OUT_NORMAL:
|
OUT_NORMAL:
|
||||||
|
|
||||||
|
disconnect(&get_data_thrd, 0, 0, 0);
|
||||||
|
|
||||||
if(hdl >= 0)
|
if(hdl >= 0)
|
||||||
{
|
{
|
||||||
edfclose_file(hdl);
|
edfclose_file(hdl);
|
||||||
|
@ -567,6 +596,8 @@ OUT_NORMAL:
|
||||||
|
|
||||||
OUT_ERROR:
|
OUT_ERROR:
|
||||||
|
|
||||||
|
disconnect(&get_data_thrd, 0, 0, 0);
|
||||||
|
|
||||||
progress.reset();
|
progress.reset();
|
||||||
|
|
||||||
statusLabel->setText("Downloading aborted");
|
statusLabel->setText("Downloading aborted");
|
||||||
|
@ -576,6 +607,18 @@ OUT_ERROR:
|
||||||
edfclose_file(hdl);
|
edfclose_file(hdl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(get_data_thrd.isRunning() == true)
|
||||||
|
{
|
||||||
|
QMessageBox w_msg_box;
|
||||||
|
w_msg_box.setIcon(QMessageBox::NoIcon);
|
||||||
|
w_msg_box.setText("Waiting for thread to finish, please wait...");
|
||||||
|
w_msg_box.setStandardButtons(QMessageBox::Abort);
|
||||||
|
|
||||||
|
connect(&get_data_thrd, SIGNAL(finished()), &w_msg_box, SLOT(accept()));
|
||||||
|
|
||||||
|
w_msg_box.exec();
|
||||||
|
}
|
||||||
|
|
||||||
if(progress.wasCanceled() == false)
|
if(progress.wasCanceled() == false)
|
||||||
{
|
{
|
||||||
QMessageBox msgBox;
|
QMessageBox msgBox;
|
||||||
|
@ -688,6 +731,13 @@ void UI_Mainwindow::save_screen_waveform()
|
||||||
wavbuf[2] = NULL;
|
wavbuf[2] = NULL;
|
||||||
wavbuf[3] = NULL;
|
wavbuf[3] = NULL;
|
||||||
|
|
||||||
|
save_data_thread get_data_thrd(0);
|
||||||
|
|
||||||
|
QMessageBox w_msg_box;
|
||||||
|
w_msg_box.setIcon(QMessageBox::NoIcon);
|
||||||
|
w_msg_box.setText("Downloading data...");
|
||||||
|
w_msg_box.setStandardButtons(QMessageBox::Abort);
|
||||||
|
|
||||||
scrn_timer->stop();
|
scrn_timer->stop();
|
||||||
|
|
||||||
scrn_thread->wait();
|
scrn_thread->wait();
|
||||||
|
@ -803,14 +853,20 @@ void UI_Mainwindow::save_screen_waveform()
|
||||||
|
|
||||||
tmc_write(":WAV:DATA?");
|
tmc_write(":WAV:DATA?");
|
||||||
|
|
||||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
connect(&get_data_thrd, SIGNAL(finished()), &w_msg_box, SLOT(accept()));
|
||||||
|
|
||||||
qApp->processEvents();
|
get_data_thrd.start();
|
||||||
|
|
||||||
n = tmc_read();
|
if(w_msg_box.exec() != QDialog::Accepted)
|
||||||
|
{
|
||||||
|
disconnect(&get_data_thrd, 0, 0, 0);
|
||||||
|
strcpy(str, "Aborted by user.");
|
||||||
|
goto OUT_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
QApplication::restoreOverrideCursor();
|
disconnect(&get_data_thrd, 0, 0, 0);
|
||||||
|
|
||||||
|
n = get_data_thrd.get_num_bytes_rcvd();
|
||||||
if(n < 0)
|
if(n < 0)
|
||||||
{
|
{
|
||||||
strcpy(str, "Can not read from device.");
|
strcpy(str, "Can not read from device.");
|
||||||
|
@ -929,6 +985,13 @@ OUT_NORMAL:
|
||||||
|
|
||||||
OUT_ERROR:
|
OUT_ERROR:
|
||||||
|
|
||||||
|
if(get_data_thrd.isFinished() != true)
|
||||||
|
{
|
||||||
|
connect(&get_data_thrd, SIGNAL(finished()), &w_msg_box, SLOT(accept()));
|
||||||
|
w_msg_box.setText("Waiting for thread to finish, please wait...");
|
||||||
|
w_msg_box.exec();
|
||||||
|
}
|
||||||
|
|
||||||
QMessageBox msgBox;
|
QMessageBox msgBox;
|
||||||
msgBox.setIcon(QMessageBox::Critical);
|
msgBox.setIcon(QMessageBox::Critical);
|
||||||
msgBox.setText(str);
|
msgBox.setText(str);
|
||||||
|
|
Ładowanie…
Reference in New Issue