forked from GerhardHoffmann/DCLibraries
First draft implementation of reporting thread sending reports to ATBUpdateTool, which
contains the necessary connects.
This commit is contained in:
parent
5f88c8f856
commit
65163354bd
@ -17,23 +17,23 @@ ReportingThread::~ReportingThread() {
|
|||||||
// each component which has connects for the corresponding signals.
|
// each component which has connects for the corresponding signals.
|
||||||
void ReportingThread::run() {
|
void ReportingThread::run() {
|
||||||
|
|
||||||
qCritical() << "START DOWNLOAD THREAD";
|
qCritical() << QDateTime::currentDateTime() << "START DOWNLOAD THREAD";
|
||||||
|
|
||||||
static QString status;
|
static QString report("");
|
||||||
|
|
||||||
#if 0
|
|
||||||
int cnt = 5;
|
int cnt = 5;
|
||||||
while (!m_hw->dcDownloadRunning()) {
|
while (!m_hw->dcDownloadGetRunning()) {
|
||||||
if (--cnt > 0) {
|
if (--cnt > 0) {
|
||||||
status = QString("%1 waiting for download to start %2")
|
report = QString("%1 waiting for download to start %2")
|
||||||
.arg(QDateTime::currentDateTime().toString(Qt::ISODate))
|
.arg(QDateTime::currentDateTime().toString(Qt::ISODate))
|
||||||
.arg(cnt);
|
.arg(cnt);
|
||||||
qCritical() << __LINE__ << "STATUS" << status;
|
qCritical() << __LINE__ << "STATUS" << report;
|
||||||
emit m_hw->hwapi_reportDCDownloadStatus(status);
|
emit m_hw->hwapi_reportDCDownloadStatus(report);
|
||||||
QThread::sleep(1);
|
QThread::sleep(1);
|
||||||
} else break;
|
} else break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
if (cnt == 0) {
|
if (cnt == 0) {
|
||||||
m_hw->dcDownloadResetRequest();
|
m_hw->dcDownloadResetRequest();
|
||||||
status = QString("%1 reset download request")
|
status = QString("%1 reset download request")
|
||||||
@ -56,7 +56,6 @@ void ReportingThread::run() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
uint16_t const tnr = 1750;
|
uint16_t const tnr = 1750;
|
||||||
uint16_t cnr = 0;
|
uint16_t cnr = 0;
|
||||||
@ -66,11 +65,11 @@ void ReportingThread::run() {
|
|||||||
QString report("");
|
QString report("");
|
||||||
|
|
||||||
if (cnr > 0) {
|
if (cnr > 0) {
|
||||||
double percent = (double)cnr / (double)tnr;
|
double percent = ((double)cnr / (double)tnr) * 100.0;
|
||||||
report = QString("total blocks %1, current block %2 [%3%]")
|
report = QString(": total blocks %1, current block %2 [%3]")
|
||||||
.arg(tnr).arg(cnr).arg(percent, 0, 'f', 2);
|
.arg(tnr).arg(cnr).arg(percent, 0, 'f', 2);
|
||||||
} else {
|
} else {
|
||||||
report = QString("total blocks %1, current block %2 [0]")
|
report = QString(": total blocks %1, current block %2 [0]")
|
||||||
.arg(tnr).arg(cnr);
|
.arg(tnr).arg(cnr);
|
||||||
}
|
}
|
||||||
status = QDateTime::currentDateTime().toString(Qt::ISODate) + report;
|
status = QDateTime::currentDateTime().toString(Qt::ISODate) + report;
|
||||||
@ -90,38 +89,67 @@ void ReportingThread::run() {
|
|||||||
.arg(m_fileToDownload).arg(tnr).arg(cnr));
|
.arg(m_fileToDownload).arg(tnr).arg(cnr));
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#endif
|
||||||
|
|
||||||
while (m_hw->dcDownloadRunning()) {
|
uint16_t const totalBlocks = m_hw->dcDownloadGetTotalBlockNumber();
|
||||||
uint16_t const cnr = m_hw->dcDownloadGetCurrentBlockNumber();
|
|
||||||
uint16_t const tnr = m_hw->dcDownloadGetTotalBlockNumber();
|
|
||||||
|
|
||||||
QString report("");
|
qCritical() << QDateTime::currentDateTime() << "TOTAL BLOCKS" << totalBlocks;
|
||||||
|
|
||||||
if (cnr > 0) {
|
if (totalBlocks) {
|
||||||
report = QString("total blocks %1, current block %2 [%3]")
|
qint64 const start = QDateTime::currentMSecsSinceEpoch();
|
||||||
.arg(tnr).arg(cnr).arg((double)(tnr)/(double(cnr)));
|
double durationMillis = 0;
|
||||||
} else {
|
uint16_t currentBlockNumber = 0;
|
||||||
report = QString("total blocks %1, current block %2 [0]")
|
|
||||||
.arg(tnr).arg(cnr);
|
while (m_hw->dcDownloadGetRunning()) {
|
||||||
}
|
currentBlockNumber = m_hw->dcDownloadGetCurrentBlockNumber();
|
||||||
|
|
||||||
|
durationMillis += QDateTime::currentMSecsSinceEpoch() - start;
|
||||||
|
|
||||||
|
double const timeAveragePerBlock = (currentBlockNumber > 0) ? (durationMillis / currentBlockNumber) : durationMillis;
|
||||||
|
double const estimatedSecondsLeft = (timeAveragePerBlock * (totalBlocks - currentBlockNumber)) / 1000.0;
|
||||||
|
|
||||||
|
double percent = ((double)currentBlockNumber / (double)totalBlocks) * 100.0;
|
||||||
|
report = QString(": total blocks %1, current block %2 [%3] (est. time left: %4s)")
|
||||||
|
.arg(totalBlocks)
|
||||||
|
.arg(currentBlockNumber)
|
||||||
|
.arg(percent, 0, 'f', 2)
|
||||||
|
.arg(estimatedSecondsLeft, 0, 'f', 2);
|
||||||
|
|
||||||
|
qCritical() << "RT report" << report;
|
||||||
|
|
||||||
emit m_hw->hwapi_reportDCDownloadStatus(QString("XXXXX") + QDateTime::currentDateTime().toString(Qt::ISODate));
|
|
||||||
emit m_hw->hwapi_reportDCDownloadStatus(report);
|
emit m_hw->hwapi_reportDCDownloadStatus(report);
|
||||||
|
QThread::msleep(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t const cnr = m_hw->dcDownloadGetCurrentBlockNumber();
|
QThread::msleep(100);
|
||||||
uint16_t const tnr = m_hw->dcDownloadGetTotalBlockNumber();
|
|
||||||
|
|
||||||
if (tnr == cnr) {
|
if (totalBlocks == currentBlockNumber) {
|
||||||
m_hw->hwapi_reportDCDownloadSuccess(
|
m_hw->hwapi_reportDCDownloadSuccess(
|
||||||
QString("SUCCESS DOWNLOADING") + m_fileToDownload);
|
QString("SUCCESS DOWNLOADING") + m_fileToDownload);
|
||||||
} else {
|
} else {
|
||||||
m_hw->hwapi_reportDCDownloadFailure(
|
m_hw->hwapi_reportDCDownloadFailure(
|
||||||
QString("ERROR DOWNLOADING %1 (total blocks=%2, sent blocks=%3)")
|
QString("ERROR DOWNLOADING %1 (total blocks=%2, sent blocks=%3)")
|
||||||
.arg(m_fileToDownload).arg(tnr).arg(cnr));
|
.arg(m_fileToDownload).arg(totalBlocks).arg(currentBlockNumber));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
qCritical() << "FINISH DOWNLOAD THREAD";
|
qCritical() << QDateTime::currentDateTime() << __PRETTY_FUNCTION__
|
||||||
|
<< QString("line=%1 REPORT THREAD ABOUT TO FINISH").arg(__LINE__);
|
||||||
|
|
||||||
|
cnt = 10;
|
||||||
|
|
||||||
|
bool running = m_hw->dcDownloadGetRunning();
|
||||||
|
bool finished = m_hw->dcDownloadGetFinished();
|
||||||
|
|
||||||
|
while (--cnt > 0 && (running && !finished)) {
|
||||||
|
qCritical() << QDateTime::currentDateTime() << __PRETTY_FUNCTION__
|
||||||
|
<< QString("line=%1 REPORT THREAD: WAIT FOR END OF DOWNLOAD THREAD %2 %3 (%4)")
|
||||||
|
.arg(__LINE__).arg(running).arg(finished).arg(cnt);
|
||||||
|
QThread::sleep(1);
|
||||||
|
running = m_hw->dcDownloadGetRunning();
|
||||||
|
finished = m_hw->dcDownloadGetFinished();
|
||||||
|
}
|
||||||
|
|
||||||
|
qCritical() << QDateTime::currentDateTime() << __PRETTY_FUNCTION__
|
||||||
|
<< QString("line=%1 FINISH REPORT THREAD").arg(__LINE__);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user