Compare commits

...

4 Commits

4 changed files with 46 additions and 19 deletions

View File

@@ -134,7 +134,8 @@
class DownloadThread;
class hwinf;
class T_datif : public QObject
{
Q_OBJECT
@@ -165,13 +166,14 @@ class T_datif : public QObject
T_prot *myDCIF;
QTimer *datif_trigger;
uint8_t selectedSlaveAddr;
hwinf *m_hw = nullptr;
private slots:
char datif_cycleSend();
void StoredRecData();
public:
T_datif(QObject *parent = nullptr);
T_datif(hwinf *hw, QObject *parent = nullptr);
void resetChain(void);
char isPortOpen(void);

View File

@@ -93,14 +93,13 @@ private:
void sub_storeSendingText(QByteArray *buf) const;
QTimer *hwapi_TimerPayment;
QSharedMemory *m_sharedMem;
ReportingThread *m_reportingThread;
DownloadThread *m_downloadThread;
ReportingThread *m_reportingThread = nullptr;
DownloadThread *m_downloadThread = nullptr;
//QTimer *hwapi_triggerBL;
public:
explicit hwapi(QWidget *parent = nullptr);
#ifdef THIS_IS_CA_MASTER
T_datif *myDatif;
#endif

View File

@@ -3,6 +3,7 @@
#include <QThread>
#include <QString>
// #include <functional>
class hwapi;
class ReportingThread : public QThread {
@@ -12,6 +13,14 @@ public:
ReportingThread(hwapi *hw);
~ReportingThread();
//void setFunction(std::function<void(QString const&)> f) {
// m_f = f;
//}
//std::function<void(QString const&)> function() {
// return m_f;
//}
protected:
// reporting thread does not have a running event queue, and therefore
// no slots. signals work the usual way.
@@ -20,6 +29,7 @@ protected:
private:
hwapi *m_hw;
QString m_fileToDownload;
//std::function<void(QString const&)> m_f;
};
#endif // REPORTING_THREAD_H_INCLUDED

View File

@@ -4,10 +4,15 @@
#include <QDateTime>
#include <QDebug>
#include <QApplication>
#include <QCoreApplication>
#include <cmath>
ReportingThread::ReportingThread(hwapi *hw)
: m_hw(hw)
, m_fileToDownload(m_hw->dcDownloadFileName()) {
// , m_f([](QString const&){}) {
}
ReportingThread::~ReportingThread() {
@@ -17,7 +22,9 @@ ReportingThread::~ReportingThread() {
// each component which has connects for the corresponding signals.
void ReportingThread::run() {
qCritical() << QDateTime::currentDateTime() << "START DOWNLOAD THREAD";
qCritical()
<< QDateTime::currentDateTime() << "START REPORT THREAD"
<< "(PART OF APPLICATION" << QCoreApplication::applicationName() << ")";
static QString report("");
@@ -96,28 +103,37 @@ void ReportingThread::run() {
qCritical() << QDateTime::currentDateTime() << "TOTAL BLOCKS" << totalBlocks;
if (totalBlocks) {
qint64 const start = QDateTime::currentMSecsSinceEpoch();
double durationMillis = 0;
QDateTime const start = QDateTime::currentDateTime();
uint16_t currentBlockNumber = 0;
uint16_t prevBlockNumber = ~0;
while (m_hw->dcDownloadGetRunning()) {
currentBlockNumber = m_hw->dcDownloadGetCurrentBlockNumber();
if (prevBlockNumber != currentBlockNumber) {
double durationSecs = start.secsTo(QDateTime::currentDateTime());
durationMillis += QDateTime::currentMSecsSinceEpoch() - start;
double const timeAveragePerBlock = (currentBlockNumber > 0) ? (durationSecs / currentBlockNumber) : durationSecs;
long estimatedSecondsLeft = lround((timeAveragePerBlock * (totalBlocks - currentBlockNumber)));
long estimatedMinutesLeft =
((estimatedSecondsLeft % 60) == 0) ?
(estimatedSecondsLeft / 60) :
((estimatedSecondsLeft + 60) / 60);
estimatedSecondsLeft = (estimatedSecondsLeft % 60);
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: %4min %5s)")
.arg(totalBlocks)
.arg(currentBlockNumber)
.arg(percent, 0, 'f', 2)
.arg(estimatedMinutesLeft)
.arg(estimatedSecondsLeft, 2);
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() << m_hw << "RT report" << report;
qCritical() << "RT report" << report;
emit m_hw->hwapi_reportDCDownloadStatus(report);
emit m_hw->hwapi_reportDCDownloadStatus(report);
prevBlockNumber = currentBlockNumber;
}
QThread::msleep(100);
}