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

View File

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

View File

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

View File

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