Skip to content

Commit

Permalink
Saving progress of CSV Log File. Now Some graph creation and image/Icon
Browse files Browse the repository at this point in the history
integration work is pending.
  • Loading branch information
Mubshr07 committed Jun 3, 2021
1 parent 6654255 commit 02977a2
Show file tree
Hide file tree
Showing 6 changed files with 210 additions and 24 deletions.
142 changes: 140 additions & 2 deletions classes/loggerthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,126 @@
chnlClass_Simple chnlArray[TOTAL_CHANNEL];
loggerThread::loggerThread(QObject *parent) : QObject(parent)
{
//qDebug()<<" debug LoggerThread start ";
initializeHWAddresses();
for(int i = 0; i< TOTAL_CHANNEL; i++)
{
chnlArray[i].setChannelEnableDisable(false);
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; i<TOTAL_CHANNEL; i++)
{
if(chnlArray[i].isChnlEnable())
{
emit tx_channel_Value(i, chnlArray[i].giveCurrentValue());
if(!graphWindowIsOpen) {
emit tx_channel_Value(i, chnlArray[i].giveCurrentValue());
} else if(graphWindowIsOpen && local_logging) {
logStr += QString(QString::number(chnlArray[i].giveCurrentValue(), 'f', 3)+",");
}
}
}

if(local_logging)
{
logStr += "\n";
writeThisToLogFile(logStr);
logSerialNumber++;
}



elapsed_timeNanoSec = timer_elapser->nsecsElapsed();
sampleRate_MS_Calculated = (sampleRate_MS - (elapsed_timeNanoSec/1000000.0));
timer_logger->setInterval(sampleRate_MS_Calculated);
//qDebug()<<" 2222222222 ";
}
void loggerThread::on_timer_graphValue_elapsed()
{
timer_elapser2->restart();
for(int i=0; i<4; i++)
{
if(graphChannels_idxBool[i])
{
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:: "<<local_logTime_MS;
}

}


Expand All @@ -65,6 +137,7 @@ void loggerThread::rx_setSampleTime(int sec)
}
void loggerThread::rx_loggingStartStop(bool start)
{
//qDebug()<<" Logging Status : "<<start;
local_logging = start;
emit tx_loggingStarted(local_logging);
}
Expand All @@ -85,6 +158,7 @@ void loggerThread::rx_giveMeEnablesChannels()
emit tx_EnableChannelsAre(i);
}
}
emit tx_ramdomOP(0, 0.0, filePath);
}
void loggerThread::rx_AddNewChannelToGraph(int idx, int chnlID)
{
Expand All @@ -100,6 +174,8 @@ void loggerThread::rx_GraphWindowIsOpen(bool windOpen)
{
//qDebug()<<" Graph Window is Open : "<<windOpen;
graphWindowIsOpen = windOpen;
if(windOpen)
initialize_Dir_FileName();
}


Expand All @@ -120,3 +196,65 @@ void loggerThread::initializeHWAddresses()
local_ADC7_ADDRESS = addrss_Obj->givemeaddr(7);

}

void loggerThread::initialize_Dir_FileName()
{
//qDebug()<<"Home Directory String:: "<<LogDirPath;
QDir mainDir(folderPath);
if (!mainDir.exists())
{
mainDir.mkdir(folderPath);
}
LogFileNumber = 0;

while (true)
{
if(!(QFileInfo::exists(folderPath +"/LogFile_"+ QString::number(LogFileNumber) + logFileExtension))) {
filePath = QString(folderPath +"/LogFile_"+ QString::number(LogFileNumber) + logFileExtension);
break;
} else {
LogFileNumber++;
}
}

qDebug()<<" File Path : "<<filePath;

QString str = "S/N,";
str += "Log Time,";
//str += "Log Time,";


for(int i=0; i<TOTAL_CHANNEL;i++)
{
if(chnlArray[i].isChnlEnable())
{
str += QString("Ch#"+QString::number(i)+",");
}
}
//qDebug()<<" initialFile: "<<str;

str += "\n";
logFile = new QFile(filePath);
if(logFile->open(QIODevice::ReadWrite))
{
logFile->write(str.toUtf8());
logFile->close();
}
else
{
qDebug()<<"Error in open File";
}
//qDebug()<<" initial Log File Path is: "<<localFilePath;
}
void loggerThread::writeThisToLogFile(QString str)
{
if(logFile->open(QIODevice::Append))
{
logFile->write(str.toUtf8());
logFile->close();
}
else
{
qDebug()<<"Error in Writing str to File in Append mode";
}
}
23 changes: 23 additions & 0 deletions classes/loggerthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -43,6 +45,7 @@ public slots:
private:
QTimer *timer_logger;
QElapsedTimer *timer_elapser;
QElapsedTimer *timer_elapser2;
QTimer *timer_graphValue;

Addressing *addrss_Obj;
Expand Down Expand Up @@ -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
29 changes: 23 additions & 6 deletions graphwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 :"<<chnlID;
Expand All @@ -92,7 +91,6 @@ void graphWin::rx_EnableChannelsAre(int chnlID)
ui->cmb_AddList->addItem(QString::number(chnlID, 10));
}
}

void graphWin::rx_GraphChannelValue(int indx, int chnl, float val)
{
//qDebug()<<" index:"<<indx<<" chnlID:"<<chnl<<" value:"<<val;
Expand Down Expand Up @@ -142,7 +140,6 @@ void graphWin::rx_GraphChannelValue(int indx, int chnl, float val)
}
}


void graphWin::on_pb_Add_toGraph_clicked()
{
int chnlInt = ui->cmb_AddList->currentText().toInt();
Expand Down Expand Up @@ -220,8 +217,6 @@ void graphWin::on_pb_Add_toGraph_clicked()
update_cmbBoxItems();
}
}


void graphWin::on_pb_RemoveGraph_0_clicked()
{
availIndex[0] = false;
Expand Down Expand Up @@ -306,11 +301,33 @@ 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()
{
emit tx_GraphWindowIsOpen(false);

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));
}


19 changes: 12 additions & 7 deletions graphwin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -37,21 +40,19 @@ 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;

QVector<int> qv_EnablChannels;
QVector<int> qv_availableList;
int graphedChannels[4] = {123, 123, 123, 123};

bool local_loggingStarted = false;
bool initial_bool = false;
bool chnl4thIsEnable = false;
bool chnl4thIsAppliable = false;
Expand All @@ -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;";
Expand Down
Loading

0 comments on commit 02977a2

Please sign in to comment.