Compare commits
2 Commits
19a637f366
...
04be3f0776
Author | SHA1 | Date | |
---|---|---|---|
|
04be3f0776 | ||
|
42a4a5f0b0 |
|
@ -8,9 +8,9 @@
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
|
#include <QRandomGenerator>
|
||||||
|
|
||||||
#include <QChartView>
|
#include <QChartView>
|
||||||
#include <QLineSeries>
|
|
||||||
#include <QValueAxis>
|
#include <QValueAxis>
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
@ -30,7 +30,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){
|
||||||
digiSetting = NULL;
|
digiSetting = NULL;
|
||||||
readDataThread = NULL;
|
readDataThread = NULL;
|
||||||
|
|
||||||
plot = new QChart();
|
SetUpPlot();
|
||||||
|
|
||||||
QWidget * mainLayoutWidget = new QWidget(this);
|
QWidget * mainLayoutWidget = new QWidget(this);
|
||||||
setCentralWidget(mainLayoutWidget);
|
setCentralWidget(mainLayoutWidget);
|
||||||
|
@ -183,7 +183,13 @@ MainWindow::~MainWindow(){
|
||||||
//delete bnNewExp;
|
//delete bnNewExp;
|
||||||
//delete logInfo;
|
//delete logInfo;
|
||||||
|
|
||||||
if( plot != NULL )delete plot;
|
updateTraceThread->Stop();
|
||||||
|
updateTraceThread->quit();
|
||||||
|
updateTraceThread->wait();
|
||||||
|
delete updateTraceThread;
|
||||||
|
|
||||||
|
delete dataTrace; /// dataTrace must be deleted before plot
|
||||||
|
delete plot;
|
||||||
|
|
||||||
//---- need manually delete
|
//---- need manually delete
|
||||||
if( digiSetting != NULL ) delete digiSetting;
|
if( digiSetting != NULL ) delete digiSetting;
|
||||||
|
@ -214,11 +220,17 @@ void MainWindow::StartACQ(){
|
||||||
bnStartACQ->setEnabled(false);
|
bnStartACQ->setEnabled(false);
|
||||||
bnStopACQ->setEnabled(true);
|
bnStopACQ->setEnabled(true);
|
||||||
|
|
||||||
|
updateTraceThread->start();
|
||||||
|
|
||||||
LogMsg("end of " + QString::fromStdString(__func__));
|
LogMsg("end of " + QString::fromStdString(__func__));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::StopACQ(){
|
void MainWindow::StopACQ(){
|
||||||
|
|
||||||
|
updateTraceThread->Stop();
|
||||||
|
updateTraceThread->quit();
|
||||||
|
updateTraceThread->wait();
|
||||||
|
|
||||||
for( int i = 0; i < nDigi; i++){
|
for( int i = 0; i < nDigi; i++){
|
||||||
if( digi[i]->IsDummy () ) continue;
|
if( digi[i]->IsDummy () ) continue;
|
||||||
digi[i]->StopACQ();
|
digi[i]->StopACQ();
|
||||||
|
@ -301,7 +313,6 @@ void MainWindow::CloseDigitizers(){
|
||||||
if( digiSetting != NULL ) digiSetting->close();
|
if( digiSetting != NULL ) digiSetting->close();
|
||||||
|
|
||||||
if( readDataThread[i] != NULL ){
|
if( readDataThread[i] != NULL ){
|
||||||
readDataThread[i]->Stop();
|
|
||||||
readDataThread[i]->quit();
|
readDataThread[i]->quit();
|
||||||
readDataThread[i]->wait();
|
readDataThread[i]->wait();
|
||||||
delete readDataThread[i];
|
delete readDataThread[i];
|
||||||
|
@ -319,45 +330,54 @@ void MainWindow::CloseDigitizers(){
|
||||||
//^###################################################################### Open Scope
|
//^###################################################################### Open Scope
|
||||||
void MainWindow::OpenScope(){
|
void MainWindow::OpenScope(){
|
||||||
|
|
||||||
QMainWindow * scope = new QMainWindow(this);
|
|
||||||
scope->setWindowTitle("Scope");
|
|
||||||
scope->setGeometry(0, 0, 1000, 800);
|
|
||||||
|
|
||||||
QWidget * layoutWidget = new QWidget(scope);
|
QWidget * layoutWidget = new QWidget(scope);
|
||||||
scope->setCentralWidget(layoutWidget);
|
scope->setCentralWidget(layoutWidget);
|
||||||
QGridLayout * layout = new QGridLayout(layoutWidget);
|
QGridLayout * layout = new QGridLayout(layoutWidget);
|
||||||
layoutWidget->setLayout(layout);
|
layoutWidget->setLayout(layout);
|
||||||
|
|
||||||
|
|
||||||
plot->removeAllSeries();
|
|
||||||
|
|
||||||
QLineSeries * data = new QLineSeries(this);
|
|
||||||
data->setName("data");
|
|
||||||
|
|
||||||
//--------- add data
|
|
||||||
data->append(1, 2);
|
|
||||||
data->append(2, 2);
|
|
||||||
data->append(3, 5);
|
|
||||||
data->append(4, 2);
|
|
||||||
|
|
||||||
plot->addSeries(data);
|
|
||||||
|
|
||||||
|
|
||||||
plot->createDefaultAxes(); /// this must be after addSeries();
|
|
||||||
plot->axes(Qt::Vertical).first()->setRange(0, 10); /// this must be after createDefaultAxes();
|
|
||||||
plot->axes(Qt::Horizontal).first()->setRange(0, 5);
|
|
||||||
|
|
||||||
QChartView * plotView = new QChartView(plot);
|
QChartView * plotView = new QChartView(plot);
|
||||||
plotView->setRenderHints(QPainter::Antialiasing);
|
plotView->setRenderHints(QPainter::Antialiasing);
|
||||||
|
|
||||||
//scope->setCentralWidget(plotView);
|
//scope->setCentralWidget(plotView);
|
||||||
layout->addWidget(plotView);
|
layout->addWidget(plotView, 0, 0);
|
||||||
|
|
||||||
|
QPushButton * bnUpdate = new QPushButton("Random", scope);
|
||||||
|
layout->addWidget(bnUpdate, 1, 0);
|
||||||
|
connect(bnUpdate, &QPushButton::clicked, this, &MainWindow::UpdateScope);
|
||||||
|
|
||||||
scope->show();
|
scope->show();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::SetUpPlot(){ //@--- this function run at start up
|
||||||
|
scope = new QMainWindow(this);
|
||||||
|
scope->setWindowTitle("Scope");
|
||||||
|
scope->setGeometry(0, 0, 1000, 800);
|
||||||
|
|
||||||
|
plot = new QChart();
|
||||||
|
dataTrace = new QLineSeries();
|
||||||
|
dataTrace->setName("data");
|
||||||
|
for(int i = 0; i < 100; i ++) dataTrace->append(i, QRandomGenerator::global()->bounded(10));
|
||||||
|
plot->addSeries(dataTrace);
|
||||||
|
plot->createDefaultAxes(); /// this must be after addSeries();
|
||||||
|
plot->axes(Qt::Vertical).first()->setRange(-1, 11); /// this must be after createDefaultAxes();
|
||||||
|
plot->axes(Qt::Horizontal).first()->setRange(-1, 101);
|
||||||
|
|
||||||
|
updateTraceThread = new UpdateTraceThread();
|
||||||
|
connect(updateTraceThread, &UpdateTraceThread::updateTrace, this, &MainWindow::UpdateScope);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::UpdateScope(){
|
||||||
|
|
||||||
|
if( scope->isVisible() == false) return;
|
||||||
|
|
||||||
|
for( int i = 0 ; i < dataTrace->count(); i++){
|
||||||
|
dataTrace->replace(i, i, QRandomGenerator::global()->bounded(10));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
//^###################################################################### Open digitizer setting panel
|
//^###################################################################### Open digitizer setting panel
|
||||||
void MainWindow::OpenDigitizersSettings(){
|
void MainWindow::OpenDigitizersSettings(){
|
||||||
LogMsg("Open digitizers Settings Panel");
|
LogMsg("Open digitizers Settings Panel");
|
||||||
|
|
64
mainwindow.h
64
mainwindow.h
|
@ -12,6 +12,7 @@
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
#include <QChart>
|
#include <QChart>
|
||||||
|
#include <QLineSeries>
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <time.h> // time in nano-sec
|
#include <time.h> // time in nano-sec
|
||||||
|
@ -23,27 +24,15 @@
|
||||||
|
|
||||||
static QMutex digiMTX;
|
static QMutex digiMTX;
|
||||||
|
|
||||||
class ReadDataThread : public QThread{
|
//^#===================================================== ReadData Thread
|
||||||
|
class ReadDataThread : public QThread {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ReadDataThread(Digitizer2Gen * dig, QObject * parent = 0) : QThread(parent){
|
ReadDataThread(Digitizer2Gen * dig, QObject * parent = 0) : QThread(parent){
|
||||||
stop = false;
|
|
||||||
this->digi = dig;
|
this->digi = dig;
|
||||||
readCount = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Stop() {stop = true;}
|
|
||||||
|
|
||||||
void run(){
|
void run(){
|
||||||
clock_gettime(CLOCK_REALTIME, &ta);
|
clock_gettime(CLOCK_REALTIME, &ta);
|
||||||
readCount = 0;
|
|
||||||
|
|
||||||
//for( int i = 0; i < 10; i ++){
|
|
||||||
// emit sendMsg(QString::number(i));
|
|
||||||
// if( stop ) break;
|
|
||||||
//}
|
|
||||||
|
|
||||||
while(true){
|
while(true){
|
||||||
digiMTX.lock();
|
digiMTX.lock();
|
||||||
int ret = digi->ReadData();
|
int ret = digi->ReadData();
|
||||||
|
@ -59,32 +48,52 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
clock_gettime(CLOCK_REALTIME, &tb);
|
clock_gettime(CLOCK_REALTIME, &tb);
|
||||||
//if( readCount % 1000 == 0 ) {
|
|
||||||
if( tb.tv_sec - ta.tv_sec > 2 ) {
|
if( tb.tv_sec - ta.tv_sec > 2 ) {
|
||||||
emit sendMsg("FileSize : " + QString::number(digi->GetFileSize()/1024./1024.) + " MB");
|
emit sendMsg("FileSize : " + QString::number(digi->GetFileSize()/1024./1024.) + " MB");
|
||||||
|
|
||||||
//double duration = tb.tv_nsec-ta.tv_nsec + tb.tv_sec*1e+9 - ta.tv_sec*1e+9;
|
//double duration = tb.tv_nsec-ta.tv_nsec + tb.tv_sec*1e+9 - ta.tv_sec*1e+9;
|
||||||
//printf("%4d, duration : %10.0f, %6.1f\n", readCount, duration, 1e9/duration);
|
//printf("%4d, duration : %10.0f, %6.1f\n", readCount, duration, 1e9/duration);
|
||||||
ta = tb;
|
ta = tb;
|
||||||
}
|
}
|
||||||
readCount++;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void sendMsg(const QString &msg);
|
void sendMsg(const QString &msg);
|
||||||
|
private:
|
||||||
|
Digitizer2Gen * digi;
|
||||||
|
timespec ta, tb;
|
||||||
|
};
|
||||||
|
|
||||||
|
//^#===================================================== UpdateTrace Thread
|
||||||
|
class UpdateTraceThread : public QThread {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
UpdateTraceThread(QObject * parent = 0) : QThread(parent){
|
||||||
|
waitTime = 5;
|
||||||
|
stop = false;
|
||||||
|
}
|
||||||
|
void Stop() {this->stop = true;}
|
||||||
|
void run(){
|
||||||
|
unsigned int count = 0;
|
||||||
|
stop = false;
|
||||||
|
do{
|
||||||
|
usleep(100000);
|
||||||
|
count ++;
|
||||||
|
if( count % waitTime == 0){
|
||||||
|
emit updateTrace();
|
||||||
|
}
|
||||||
|
}while(!stop);
|
||||||
|
}
|
||||||
|
signals:
|
||||||
|
void updateTrace();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool stop;
|
bool stop;
|
||||||
Digitizer2Gen * digi;
|
unsigned int waitTime; //100 of milisec
|
||||||
timespec ta, tb;
|
|
||||||
unsigned int readCount;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//=================================================
|
|
||||||
|
|
||||||
|
//^#===================================================== MainWindow
|
||||||
class MainWindow : public QMainWindow{
|
class MainWindow : public QMainWindow{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
@ -99,10 +108,11 @@ private slots:
|
||||||
void CloseDigitizers();
|
void CloseDigitizers();
|
||||||
|
|
||||||
void OpenScope();
|
void OpenScope();
|
||||||
|
void SetUpPlot();
|
||||||
|
void UpdateScope();
|
||||||
|
|
||||||
void OpenDigitizersSettings();
|
void OpenDigitizersSettings();
|
||||||
|
|
||||||
|
|
||||||
void ProgramSettings();
|
void ProgramSettings();
|
||||||
bool OpenProgramSettings();
|
bool OpenProgramSettings();
|
||||||
void SaveProgramSettings();
|
void SaveProgramSettings();
|
||||||
|
@ -116,7 +126,6 @@ private slots:
|
||||||
|
|
||||||
signals :
|
signals :
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
QPushButton * bnProgramSettings;
|
QPushButton * bnProgramSettings;
|
||||||
|
@ -129,8 +138,11 @@ private:
|
||||||
QPushButton * bnDigiSettings;
|
QPushButton * bnDigiSettings;
|
||||||
QPushButton * bnSOLSettings;
|
QPushButton * bnSOLSettings;
|
||||||
|
|
||||||
|
QMainWindow * scope;
|
||||||
QPushButton * bnOpenScope;
|
QPushButton * bnOpenScope;
|
||||||
QChart * plot;
|
QChart * plot;
|
||||||
|
QLineSeries * dataTrace;
|
||||||
|
UpdateTraceThread * updateTraceThread;
|
||||||
|
|
||||||
QPushButton * bnStartACQ;
|
QPushButton * bnStartACQ;
|
||||||
QPushButton * bnStopACQ;
|
QPushButton * bnStopACQ;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user