DCLibraries/src/reporting_thread.cpp

88 lines
2.8 KiB
C++
Raw Normal View History

2023-12-01 14:28:07 +01:00
#include "reporting_thread.h"
#include "shared_mem_buffer.h"
#include "hwapi.h"
2023-12-06 14:53:52 +01:00
#include <QDateTime>
ReportingThread::ReportingThread(hwapi *hw)
2023-12-01 14:28:07 +01:00
: m_hw(hw)
2023-12-02 09:44:59 +01:00
, m_fileToDownload(m_hw->dcDownloadFileName()) {
2023-12-01 14:28:07 +01:00
}
ReportingThread::~ReportingThread() {
}
2023-12-06 14:53:52 +01:00
// download thread running in ca-slave sends reports of download process to
// each component which has connects for the corresponding signals.
2023-12-01 14:28:07 +01:00
void ReportingThread::run() {
2023-12-06 14:53:52 +01:00
static QString status;
2023-12-03 19:55:23 +01:00
2023-12-06 14:53:52 +01:00
int cnt = 5;
2023-12-01 14:28:07 +01:00
while (!m_hw->dcDownloadRunning()) {
if (--cnt > 0) {
2023-12-06 14:53:52 +01:00
status = QString("%1 waiting for download to start %2")
.arg(QDateTime::currentDateTime().toString(Qt::ISODate))
.arg(cnt);
qCritical() << __LINE__ << "STATUS" << status;
emit m_hw->hwapi_reportDCDownloadStatus(status);
2023-12-01 14:28:07 +01:00
QThread::sleep(1);
2023-12-06 14:53:52 +01:00
} else break;
2023-12-01 14:28:07 +01:00
}
2023-12-06 14:53:52 +01:00
2023-12-01 14:28:07 +01:00
if (cnt == 0) {
2023-12-06 14:53:52 +01:00
m_hw->dcDownloadResetRequest();
status = QString("%1 reset download request")
.arg(QDateTime::currentDateTime().toString(Qt::ISODate));
qCritical() << __LINE__ << "STATUS" << status;
emit m_hw->hwapi_reportDCDownloadStatus(status);
cnt = 5;
while (!m_hw->dcDownloadRunning()) {
if (--cnt > 0) {
QThread::sleep(1);
} else break;
}
if (cnt == 0) {
status = QString("%1 download request failure")
.arg(QDateTime::currentDateTime().toString(Qt::ISODate));
qCritical() << __LINE__ << "STATUS" << status;
emit m_hw->hwapi_reportDCDownloadFailure(status);
return;
}
2023-12-01 14:28:07 +01:00
}
2023-12-06 14:53:52 +01:00
#if 0
2023-12-01 14:28:07 +01:00
while (m_hw->dcDownloadRunning()) {
uint16_t const cnr = m_hw->dcDownloadGetCurrentBlockNumber();
uint16_t const tnr = m_hw->dcDownloadGetTotalBlockNumber();
QString report("");
if (cnr > 0) {
report = QString("total blocks %1, current block %2 [%3]")
.arg(tnr).arg(cnr).arg((double)(tnr)/(double(cnr)));
} else {
report = QString("total blocks %1, current block %2 [0]")
.arg(tnr).arg(cnr);
}
2023-12-06 14:53:52 +01:00
emit m_hw->hwapi_reportDCDownloadStatus(QString("XXXXX") + QDateTime::currentDateTime().toString(Qt::ISODate));
2023-12-01 14:28:07 +01:00
emit m_hw->hwapi_reportDCDownloadStatus(report);
}
uint16_t const cnr = m_hw->dcDownloadGetCurrentBlockNumber();
uint16_t const tnr = m_hw->dcDownloadGetTotalBlockNumber();
if (tnr == cnr) {
m_hw->hwapi_reportDCDownloadSuccess(
QString("SUCCESS DOWNLOADING") + m_fileToDownload);
} else {
m_hw->hwapi_reportDCDownloadFailure(
QString("ERROR DOWNLOADING %1 (total blocks=%2, sent blocks=%3)")
.arg(m_fileToDownload).arg(tnr).arg(cnr));
}
2023-12-03 19:55:23 +01:00
#endif
2023-12-01 14:28:07 +01:00
}