SOLARIS_QT6_DAQ/mainwindow.cpp

238 lines
5.7 KiB
C++
Raw Normal View History

2023-01-25 14:59:48 -05:00
#include "mainwindow.h"
#include <QLabel>
#include <QGridLayout>
2023-01-30 18:40:24 -05:00
#include <unistd.h>
//------ static memeber
Digitizer2Gen * MainWindow::digi = NULL;
2023-01-25 14:59:48 -05:00
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){
setWindowTitle("SOLARIS DAQ");
2023-01-30 18:40:24 -05:00
setGeometry(500, 100, 1000, 500);
2023-01-25 14:59:48 -05:00
QIcon icon("SOLARIS_favicon.png");
setWindowIcon(icon);
nDigi = 0;
2023-01-25 17:16:14 -05:00
digiSerialNum.clear();
digiSetting = NULL;
2023-01-25 14:59:48 -05:00
QWidget * mainLayoutWidget = new QWidget(this);
setCentralWidget(mainLayoutWidget);
2023-01-30 18:40:24 -05:00
QVBoxLayout * layoutMain = new QVBoxLayout(mainLayoutWidget);
mainLayoutWidget->setLayout(layoutMain);
2023-01-25 14:59:48 -05:00
2023-01-30 18:40:24 -05:00
{//====================== General
QGroupBox * box1 = new QGroupBox("General", mainLayoutWidget);
layoutMain->addWidget(box1);
QGridLayout * layout1 = new QGridLayout(box1);
2023-01-25 14:59:48 -05:00
bnProgramSettings = new QPushButton("Program Settings", this);
2023-01-30 18:40:24 -05:00
bnProgramSettings->setEnabled(false);
2023-01-25 14:59:48 -05:00
bnOpenDigitizers = new QPushButton("Open Digitizers", this);
connect(bnOpenDigitizers, SIGNAL(clicked()), this, SLOT(bnOpenDigitizers_clicked()));
bnCloseDigitizers = new QPushButton("Close Digitizers", this);
bnCloseDigitizers->setEnabled(false);
connect(bnCloseDigitizers, SIGNAL(clicked()), this, SLOT(bnCloseDigitizers_clicked()));
bnDigiSettings = new QPushButton("Digitizers Settings", this);
bnDigiSettings->setEnabled(false);
2023-01-25 17:16:14 -05:00
connect(bnDigiSettings, SIGNAL(clicked()), this, SLOT(OpenDigitizersSettings()));
2023-01-25 14:59:48 -05:00
2023-01-30 18:40:24 -05:00
layout1->addWidget(bnProgramSettings, 0, 0);
layout1->addWidget(bnOpenDigitizers, 0, 1);
layout1->addWidget(bnCloseDigitizers, 0, 2);
layout1->addWidget(bnDigiSettings, 1, 1);
}
{//====================== ACD control
QGroupBox * box2 = new QGroupBox("ACQ control", mainLayoutWidget);
layoutMain->addWidget(box2);
QGridLayout * layout2 = new QGridLayout(box2);
2023-01-25 14:59:48 -05:00
bnStartACQ = new QPushButton("Start ACQ", this);
bnStartACQ->setEnabled(false);
2023-01-30 18:40:24 -05:00
connect(bnStartACQ, &QPushButton::clicked, this, &MainWindow::StartACQ);
2023-01-25 14:59:48 -05:00
bnStopACQ = new QPushButton("Stop ACQ", this);
bnStopACQ->setEnabled(false);
2023-01-30 18:40:24 -05:00
connect(bnStopACQ, &QPushButton::clicked, this, &MainWindow::StopACQ);
2023-01-25 14:59:48 -05:00
2023-01-30 18:40:24 -05:00
layout2->addWidget(bnStartACQ, 0, 0);
layout2->addWidget(bnStopACQ, 0, 1);
2023-01-25 14:59:48 -05:00
}
2023-01-30 18:40:24 -05:00
layoutMain->addStretch();
2023-01-25 14:59:48 -05:00
2023-01-30 18:40:24 -05:00
{//===================== Log Msg
QGroupBox * box3 = new QGroupBox("Log Message", mainLayoutWidget);
layoutMain->addWidget(box3);
layoutMain->setStretchFactor(box3, 1);
2023-01-25 14:59:48 -05:00
2023-01-30 18:40:24 -05:00
QGridLayout * layout3 = new QGridLayout(box3);
2023-01-25 14:59:48 -05:00
2023-01-30 18:40:24 -05:00
logInfo = new QPlainTextEdit(this);
logInfo->isReadOnly();
logInfo->setGeometry(100, 200, 500, 100);
2023-01-25 14:59:48 -05:00
2023-01-30 18:40:24 -05:00
layout3->addWidget(logInfo);
2023-01-25 14:59:48 -05:00
2023-01-30 18:40:24 -05:00
}
2023-01-25 14:59:48 -05:00
LogMsg("Welcome to SOLARIS DAQ.");
2023-01-30 18:40:24 -05:00
//bnOpenDigitizers_clicked();
//OpenDigitizersSettings();
2023-01-25 17:16:14 -05:00
2023-01-25 14:59:48 -05:00
}
MainWindow::~MainWindow(){
2023-01-25 17:16:14 -05:00
delete digiSetting;
2023-01-25 14:59:48 -05:00
delete bnProgramSettings;
delete bnOpenDigitizers;
delete bnCloseDigitizers;
delete bnDigiSettings;
delete logInfo;
if( digi != NULL ){
digi->CloseDigitizer();
delete digi;
}
2023-01-30 18:40:24 -05:00
readDataThread->Stop();
readDataThread->quit();
readDataThread->wait();
delete readDataThread;
}
//################################################################
void MainWindow::StartACQ(){
digi->Reset();
digi->ProgramPHA(false);
digi->SetPHADataFormat(1);// only save 1 trace
remove("haha_000.sol"); // remove file
digi->OpenOutFile("haha");// haha_000.sol
digi->StartACQ();
LogMsg("Start Run....");
readDataThread->start();
bnStartACQ->setEnabled(false);
bnStopACQ->setEnabled(true);
LogMsg("end of " + QString::fromStdString(__func__));
}
void MainWindow::StopACQ(){
digi->StopACQ();
//readDataThread->Stop();
readDataThread->quit();
readDataThread->wait();
digi->CloseOutFile();
LogMsg("Stop Run");
bnStartACQ->setEnabled(true);
bnStopACQ->setEnabled(false);
2023-01-25 14:59:48 -05:00
}
void MainWindow::bnOpenDigitizers_clicked(){
LogMsg("Opening digitizer.....");
digi = new Digitizer2Gen();
digi->OpenDigitizer("dig2://192.168.0.100/");
if(digi->IsConnected()){
2023-01-25 17:16:14 -05:00
digiSerialNum.push_back(digi->GetSerialNumber());
nDigi ++;
LogMsg("Opened digitizer : " + QString::number(digi->GetSerialNumber()));
2023-01-25 14:59:48 -05:00
bnOpenDigitizers->setEnabled(false);
2023-01-25 17:16:14 -05:00
bnCloseDigitizers->setEnabled(true);
bnDigiSettings->setEnabled(true);
bnStartACQ->setEnabled(true);
2023-01-30 18:40:24 -05:00
bnStopACQ->setEnabled(false);
readDataThread = new ReadDataThread(digi, this);
connect(readDataThread, &ReadDataThread::sendMsg, this, &MainWindow::LogMsg);
2023-01-25 14:59:48 -05:00
}else{
LogMsg("Cannot open digitizer");
LogMsg("use a dummy.");
digi->SetDummy();
digiSerialNum.push_back(0000);
nDigi ++;
2023-01-25 14:59:48 -05:00
}
2023-01-30 18:40:24 -05:00
2023-01-25 14:59:48 -05:00
}
void MainWindow::bnCloseDigitizers_clicked(){
if( digi != NULL ){
digi->CloseDigitizer();
delete digi;
digi = NULL;
2023-01-25 17:16:14 -05:00
LogMsg("Closed Digitizer : " + QString::number(digiSerialNum[0]));
2023-01-25 14:59:48 -05:00
2023-01-25 17:16:14 -05:00
nDigi = 0;
digiSerialNum.clear();
2023-01-25 14:59:48 -05:00
bnOpenDigitizers->setEnabled(true);
2023-01-25 17:16:14 -05:00
bnCloseDigitizers->setEnabled(false);
bnDigiSettings->setEnabled(false);
bnStartACQ->setEnabled(false);
bnStopACQ->setEnabled(false);
2023-01-30 18:40:24 -05:00
if( digiSetting != NULL ) digiSetting->close();
2023-01-25 14:59:48 -05:00
}
}
2023-01-25 17:16:14 -05:00
void MainWindow::OpenDigitizersSettings(){
LogMsg("Open digitizers Settings Panel");
if( digiSetting == NULL){
digiSetting = new DigiSettings(digi, nDigi);
2023-01-30 18:40:24 -05:00
connect(digiSetting, &DigiSettings::sendLogMsg, this, &MainWindow::LogMsg);
2023-01-25 17:16:14 -05:00
digiSetting->show();
}else{
digiSetting->show();
}
}
2023-01-25 14:59:48 -05:00
void MainWindow::LogMsg(QString msg){
QString countStr = QStringLiteral("[%1] %2").arg(QDateTime::currentDateTime().toString("MM.dd hh:mm:ss"), msg);
logInfo->appendPlainText(countStr);
QScrollBar *v = logInfo->verticalScrollBar();
v->setValue(v->maximum());
2023-01-30 18:40:24 -05:00
//qDebug() << msg;
2023-01-25 14:59:48 -05:00
logInfo->repaint();
}