diff --git a/classes/loggerthread.cpp b/classes/loggerthread.cpp index 9eb0eaf..ffee9c8 100644 --- a/classes/loggerthread.cpp +++ b/classes/loggerthread.cpp @@ -3,6 +3,7 @@ chnlClass_Simple chnlArray[TOTAL_CHANNEL]; loggerThread::loggerThread(QObject *parent) : QObject(parent) { + //qDebug()<<" debug LoggerThread start "; initializeHWAddresses(); for(int i = 0; i< TOTAL_CHANNEL; i++) { @@ -10,33 +11,60 @@ loggerThread::loggerThread(QObject *parent) : QObject(parent) chnlArray[i].setChannelAddress(i); } + //qDebug()<<" debug LoggerThread 1 "; + //qDebug()<<" before timer_logger initialize "; timer_logger = new QTimer(this); connect(timer_logger, SIGNAL(timeout()), SLOT(on_timer_logger_elapsed())); timer_logger->start(sampleRate_MS); + local_logging = false; + local_logTime_MS = 0; + local_log_sec = 0; + local_log_min = 0; + local_log_hours = 0; + //qDebug()<<" debug LoggerThread 2 "; //qDebug()<<" before timer_graph initialize "; timer_graphValue = new QTimer(this); connect(timer_graphValue, SIGNAL(timeout()), SLOT(on_timer_graphValue_elapsed())); timer_graphValue->start(100); + //qDebug()<<" debug LoggerThread 3 "; timer_elapser = new QElapsedTimer(); + timer_elapser2 = new QElapsedTimer(); + timer_elapser2->start(); + + //qDebug()<<" debug LoggerThread 4 "; } void loggerThread::on_timer_logger_elapsed() { - if(graphWindowIsOpen) return; timer_elapser->start(); + logStr = QString(QString::number(logSerialNumber)+","); + logStr += QString(QTime::currentTime().toString("HH:mm:ss")+","); for(int i=0; insecsElapsed(); sampleRate_MS_Calculated = (sampleRate_MS - (elapsed_timeNanoSec/1000000.0)); timer_logger->setInterval(sampleRate_MS_Calculated); @@ -44,6 +72,7 @@ void loggerThread::on_timer_logger_elapsed() } void loggerThread::on_timer_graphValue_elapsed() { + timer_elapser2->restart(); for(int i=0; i<4; i++) { if(graphChannels_idxBool[i]) @@ -51,6 +80,49 @@ void loggerThread::on_timer_graphValue_elapsed() emit tx_GraphChannelValue(i, graphChannels_idx[i], chnlArray[graphChannels_idx[i]].giveCurrentValue()); } } + + + if(local_logging) + { + if(local_logTime_MS >= 1000) + { + local_logTime_MS -= 1000; + local_log_sec++; + if(local_log_hours<100) + local_LogTime_Str = QString("00"+QString::number(local_log_hours)+ ":"); + else if(local_log_hours<10) + local_LogTime_Str = QString("0"+QString::number(local_log_hours)+ ":"); + else + local_LogTime_Str = QString(QString::number(local_log_hours)+ ":"); + + if(local_log_min<10) + local_LogTime_Str += QString("0"+QString::number(local_log_min)+ ":"); + else + local_LogTime_Str += QString(QString::number(local_log_min)+ ":"); + + if(local_log_sec<10) + local_LogTime_Str += QString("0"+QString::number(local_log_sec)); + else + local_LogTime_Str += QString(QString::number(local_log_sec)); + + emit tx_ramdomOP(1, 1.0, local_LogTime_Str); + } + if(local_log_sec > 59) + { + local_log_sec = 0; + local_log_min++; + } + if(local_log_min > 59) + { + local_log_min = 0; + local_log_hours++; + } + + local_logTime_MS += (timer_graphValue->interval()+timer_elapser2->elapsed()); + + //qDebug()<<" local_logTime_MS:: "<givemeaddr(7); } + +void loggerThread::initialize_Dir_FileName() +{ + //qDebug()<<"Home Directory String:: "<open(QIODevice::ReadWrite)) + { + logFile->write(str.toUtf8()); + logFile->close(); + } + else + { + qDebug()<<"Error in open File"; + } + //qDebug()<<" initial Log File Path is: "<open(QIODevice::Append)) + { + logFile->write(str.toUtf8()); + logFile->close(); + } + else + { + qDebug()<<"Error in Writing str to File in Append mode"; + } +} diff --git a/classes/loggerthread.h b/classes/loggerthread.h index 1dfc637..acbcde9 100644 --- a/classes/loggerthread.h +++ b/classes/loggerthread.h @@ -24,6 +24,8 @@ class loggerThread : public QObject void tx_EnableChannelsAre(int chnlID); void tx_GraphChannelValue(int indx, int chnl, float val); + void tx_ramdomOP(int idx, float val, QString str); + public slots: void rx_setChannelEnableDisable(int chnlIndex, bool enable); @@ -43,6 +45,7 @@ public slots: private: QTimer *timer_logger; QElapsedTimer *timer_elapser; + QElapsedTimer *timer_elapser2; QTimer *timer_graphValue; Addressing *addrss_Obj; @@ -70,8 +73,28 @@ public slots: bool local_logging = false; qint64 elapsed_timeNanoSec = 0; int elapsed_timeMS = 0; + QString logStr = ""; + long logSerialNumber = 0; + + int local_logTime_MS = 0; + + + + void initialize_Dir_FileName(); + QString folderPath = QString(QDir::homePath()+"/DAQ_Logs"); + QString filePath = ""; + int LogFileNumber = 0; + QString logFileExtension = ".csv"; + QFile *logFile; + void writeThisToLogFile(QString str); + + // ---------- Log Time spend + long local_log_sec = 0; + int local_log_min = 0; + int local_log_hours = 0; + QString local_LogTime_Str = ""; }; #endif // LOGGERTHREAD_H diff --git a/graphwin.cpp b/graphwin.cpp index 95cfdd1..9675a38 100644 --- a/graphwin.cpp +++ b/graphwin.cpp @@ -73,7 +73,6 @@ void graphWin::on_timer_singleShot_Elapsed() ui->pb_RemoveGraph_3->setEnabled(false); } - void graphWin::rx_EnableChannelsAre(int chnlID) { //qDebug()<<" enable channel is :"<cmb_AddList->addItem(QString::number(chnlID, 10)); } } - void graphWin::rx_GraphChannelValue(int indx, int chnl, float val) { //qDebug()<<" index:"<cmb_AddList->currentText().toInt(); @@ -220,8 +217,6 @@ void graphWin::on_pb_Add_toGraph_clicked() update_cmbBoxItems(); } } - - void graphWin::on_pb_RemoveGraph_0_clicked() { availIndex[0] = false; @@ -306,7 +301,19 @@ void graphWin::update_cmbBoxItems() } ui->cmb_AddList->setCurrentIndex(currentIndex); } - +void graphWin::rx_ramdomOP(int idx, float val, QString str) +{ + switch (idx) { + case 0: { + ui->lbl_FilePath->setText(QString("PATH: "+str)); + break; + } + case 1: { + ui->lbl_Time->setText(str); + break; + } + } +} void graphWin::on_pb_CloseWindow_clicked() { @@ -314,3 +321,13 @@ void graphWin::on_pb_CloseWindow_clicked() this->close(); } +void graphWin::on_pb_StartLog_clicked() +{ + local_loggingStarted = !local_loggingStarted; + emit tx_loggingStartStop(local_loggingStarted); + + ui->pb_StartLog->setText(QString(local_loggingStarted? "Started":"Stoped")); + ui->pb_StartLog->setStyleSheet(QString(local_loggingStarted? styleLogStart : styleLogStop)); +} + + diff --git a/graphwin.h b/graphwin.h index 18f43bb..f120b24 100644 --- a/graphwin.h +++ b/graphwin.h @@ -19,16 +19,19 @@ class graphWin : public QDialog signals: void tx_GraphWindowIsOpen(bool windOpen); - void tx_AddNewChannelToGraph(int idx, int chnlID); void tx_RemoveChannelToGraph(int idx, int chnlID); - void tx_giveMeEnablesChannels(); + void tx_loggingStartStop(bool started); public slots: void rx_EnableChannelsAre(int chnlID); void rx_GraphChannelValue(int indx, int chnl, float val); + void rx_ramdomOP(int idx, float val, QString str); + + + // ------------ Timer Slots void on_timer_singleShot_Elapsed(); private slots: @@ -37,13 +40,11 @@ private slots: void on_pb_RemoveGraph_1_clicked(); void on_pb_RemoveGraph_2_clicked(); void on_pb_RemoveGraph_3_clicked(); + void on_pb_CloseWindow_clicked(); + void on_pb_StartLog_clicked(); - - - void on_pb_CloseWindow_clicked(); - private: Ui::graphWin *ui; QTimer *timer_singleShot; @@ -51,7 +52,7 @@ private slots: QVector qv_EnablChannels; QVector qv_availableList; int graphedChannels[4] = {123, 123, 123, 123}; - + bool local_loggingStarted = false; bool initial_bool = false; bool chnl4thIsEnable = false; bool chnl4thIsAppliable = false; @@ -62,6 +63,10 @@ private slots: QColor plot2_Color = QColor(40, 222, 255); QColor plot3_Color = QColor(222, 110, 255); + + QString styleLogStop = "font: 600 20pt 'Times New Roman'; padding: 5px; background-color: rgb(255, 255, 255); border: 1px solid black; border-radius:5px; color:red;"; + QString styleLogStart = "font: 600 20pt 'Times New Roman'; padding: 5px; background-color: lime; border: 1px solid black; border-radius:5px; color:white;"; + QString style_removBtn_0 = "font: 500 16pt 'Times New Roman'; padding: 5px; color:white; background-color:"+ plot0_Color.name()+"; border: 1px solid black; border-radius:5px;"; QString style_removBtn_1 = "font: 500 16pt 'Times New Roman'; padding: 5px; color:white; background-color:"+ plot1_Color.name()+"; border: 1px solid black; border-radius:5px;"; QString style_removBtn_2 = "font: 500 16pt 'Times New Roman'; padding: 5px; color:white; background-color:"+ plot2_Color.name()+"; border: 1px solid black; border-radius:5px;"; diff --git a/mainwindow.cpp b/mainwindow.cpp index 78a8e8d..47fcb10 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -13,13 +13,14 @@ MainWindow::MainWindow(QWidget *parent) //this->setWindowFlag(Qt::WindowStaysOnTopHint); this->setAttribute(Qt::WA_DeleteOnClose, true); //so that it will be deleted when closed - + //qDebug()<<" debug 1"; timer_singleShot= new QTimer(this); connect(timer_singleShot, SIGNAL(timeout()), SLOT(on_timer_singleShot_elapsed())); timer_singleShot->setSingleShot(true); index_SingleShotTimer = 0; timer_singleShot->start(50); + //qDebug()<<" debug 2"; loggerClass = new loggerThread(); thrd = new QThread(loggerClass); loggerClass->moveToThread(thrd); @@ -29,19 +30,20 @@ MainWindow::MainWindow(QWidget *parent) thrd->start(); + //qDebug()<<" debug 3"; timer_enabler = new QTimer(this); connect(timer_enabler, SIGNAL(timeout()), SLOT(on_timer_enabler_elapsed())); timer_enabler->setInterval(100); timer_enabler->start(); index_SingleShotTimer = 0; + + + //qDebug()<<" debug 4"; for(int i=0; itxt_SampleTime->toPlainText().toInt()); grphW = new graphWin(); connect(grphW, SIGNAL(tx_GraphWindowIsOpen(bool)), loggerClass, SLOT(rx_GraphWindowIsOpen(bool))); connect(grphW, SIGNAL(tx_AddNewChannelToGraph(int, int)), loggerClass, SLOT(rx_AddNewChannelToGraph(int, int))); connect(grphW, SIGNAL(tx_RemoveChannelToGraph(int, int)), loggerClass, SLOT(rx_RemoveChannelToGraph(int, int))); connect(grphW, SIGNAL(tx_giveMeEnablesChannels()), loggerClass, SLOT(rx_giveMeEnablesChannels())); + connect(grphW, SIGNAL(tx_loggingStartStop(bool)), loggerClass, SLOT(rx_loggingStartStop(bool))); + connect(loggerClass, SIGNAL(tx_EnableChannelsAre(int)), grphW, SLOT(rx_EnableChannelsAre(int))); connect(loggerClass, SIGNAL(tx_GraphChannelValue(int,int,float)), grphW, SLOT(rx_GraphChannelValue(int,int,float))); - - - + connect(loggerClass, SIGNAL(tx_ramdomOP(int,float, QString)), grphW, SLOT(rx_ramdomOP(int,float, QString))); grphW->setModal(true); grphW->exec(); diff --git a/mainwindow.ui b/mainwindow.ui index 0e9714d..16f08c2 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -1775,7 +1775,7 @@ text-decoration:underline; <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } </style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> -<p align="center" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:18pt; font-weight:600;">5</span></p></body></html> +<p align="center" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:18pt; font-weight:600;">1</span></p></body></html>