Compare commits
No commits in common. "65163354bd6e0d09c1498b5e1da770c97046d38a" and "6176285b89196b5ba2cabba3d7fe5fb6132f4be7" have entirely different histories.
65163354bd
...
6176285b89
@ -1308,41 +1308,22 @@ public:
|
||||
|
||||
|
||||
// download device controller
|
||||
bool dcDownloadRequest(QString const &fileToDownload) const override;
|
||||
void dcDownloadStart() override;
|
||||
void dcDownloadRequest(QString const &fileToDownload) override;
|
||||
bool dcDownloadRequested() const override;
|
||||
bool dcDownloadResetRequest() const override;
|
||||
bool dcDownloadRequestAck() const override;
|
||||
bool dcDownloadRunning() const override;
|
||||
bool dcDownloadFinished() override;
|
||||
|
||||
bool dcDownloadReportStart() const override;
|
||||
bool dcDownloadReportRunning() const override;
|
||||
bool dcDownloadReportFinished() override;
|
||||
|
||||
|
||||
bool dcDownloadThreadStart() override;
|
||||
bool dcDownloadThreadRunning() const override;
|
||||
void dcDownloadThreadFinalize(DownloadThread *) override;
|
||||
bool dcDownloadThreadFinished() const override;
|
||||
bool dcDownloadReportThreadStart() override;
|
||||
bool dcDownloadReportThreadRunning() const override;
|
||||
void dcDownloadReportThreadFinalize() override;
|
||||
void dcDownloadReportThreadQuit() override;
|
||||
bool dcDownloadReportThreadFinished() const override;
|
||||
|
||||
QString dcDownloadFileName() const override;
|
||||
bool dcDownloadSetRequested(bool) override;
|
||||
bool dcDownloadSetRunning(bool) override;
|
||||
bool dcDownloadSetFinished(bool) override;
|
||||
void dcDownloadResetRequest() override;
|
||||
void dcDownloadReportStart() override;
|
||||
bool dcDownloadStarted() const override;
|
||||
bool dcDownloadRunning() const override;
|
||||
bool dcDownloadFinished() const override;
|
||||
|
||||
void dcDownloadSetTotalBlockNumber(uint16_t totalBlockNumber) override;
|
||||
void dcDownloadSetCurrentBlockNumber(uint16_t currentBlockNumber) override;
|
||||
bool dcDownloadGetRequested() const override;
|
||||
bool dcDownloadGetRunning() const override;
|
||||
bool dcDownloadGetFinished() const override;
|
||||
uint16_t dcDownloadGetTotalBlockNumber() const override;
|
||||
uint16_t dcDownloadGetCurrentBlockNumber() const override;
|
||||
|
||||
virtual QObject const *getAPI() override;
|
||||
virtual hwapi *getAPI() override;
|
||||
|
||||
signals: // for download
|
||||
void hwapi_reportDCDownloadStatus(QString const &) const;
|
||||
|
@ -399,7 +399,6 @@ struct T_bna
|
||||
};
|
||||
|
||||
class hwapi;
|
||||
class DownloadThread;
|
||||
class hwinf
|
||||
{
|
||||
|
||||
@ -2277,54 +2276,28 @@ public:
|
||||
|
||||
|
||||
// download device controller
|
||||
virtual bool dcDownloadRequest(QString const &fileToDownload) const {
|
||||
virtual void dcDownloadStart() {}
|
||||
virtual void dcDownloadRequest(QString const &fileToDownload) {
|
||||
Q_UNUSED(fileToDownload);
|
||||
return false;
|
||||
}
|
||||
virtual bool dcDownloadRequested() const { return false; }
|
||||
virtual bool dcDownloadResetRequest() const { return false; }
|
||||
virtual bool dcDownloadRequestAck() const { return false; }
|
||||
virtual bool dcDownloadRunning() const { return false; }
|
||||
virtual bool dcDownloadFinished() { return false; }
|
||||
|
||||
virtual bool dcDownloadReportStart() const { return false; }
|
||||
virtual bool dcDownloadReportRunning() const { return true; }
|
||||
virtual bool dcDownloadReportFinished() { return true; }
|
||||
|
||||
virtual bool dcDownloadThreadStart() { return false; }
|
||||
virtual bool dcDownloadThreadRunning() const { return true; }
|
||||
virtual void dcDownloadThreadFinalize(DownloadThread *) {}
|
||||
virtual bool dcDownloadThreadFinished() const { return true; }
|
||||
virtual bool dcDownloadReportThreadStart() { return false; }
|
||||
virtual bool dcDownloadReportThreadRunning() const { return true; }
|
||||
virtual void dcDownloadReportThreadFinalize() {}
|
||||
virtual void dcDownloadReportThreadQuit() {}
|
||||
virtual bool dcDownloadReportThreadFinished() const { return true; }
|
||||
|
||||
|
||||
virtual void dcDownloadResetRequest() {}
|
||||
virtual QString dcDownloadFileName() const { return ""; }
|
||||
virtual bool dcDownloadSetRequested(bool requested) {
|
||||
Q_UNUSED(requested); return false;
|
||||
}
|
||||
virtual bool dcDownloadSetRunning(bool running) {
|
||||
Q_UNUSED(running); return false;
|
||||
}
|
||||
virtual bool dcDownloadSetFinished(bool finished) {
|
||||
Q_UNUSED(finished); return false;
|
||||
}
|
||||
virtual void dcDownloadReportStart() {}
|
||||
virtual void dcDownloadSetTotalBlockNumber(uint16_t totalBlockNumber) {
|
||||
Q_UNUSED(totalBlockNumber);
|
||||
}
|
||||
virtual void dcDownloadSetCurrentBlockNumber(uint16_t currentBlockNumber) {
|
||||
Q_UNUSED(currentBlockNumber);
|
||||
}
|
||||
virtual bool dcDownloadGetRequested() const { return false; }
|
||||
virtual bool dcDownloadGetRunning() const { return false; }
|
||||
virtual bool dcDownloadGetFinished() const { return false; }
|
||||
virtual uint16_t dcDownloadGetTotalBlockNumber() const { return 0; }
|
||||
virtual uint16_t dcDownloadGetCurrentBlockNumber() const { return 0; }
|
||||
|
||||
virtual QObject const *getAPI() { return nullptr; }
|
||||
virtual bool dcDownloadStarted() const { return false; }
|
||||
virtual bool dcDownloadRunning() const { return false; }
|
||||
virtual bool dcDownloadFinished() const { return false; }
|
||||
|
||||
virtual hwapi *getAPI() { return nullptr; }
|
||||
|
||||
signals: // for download
|
||||
void hwapi_reportDCDownloadStatus(QString const &) const;
|
||||
|
@ -4,12 +4,12 @@
|
||||
#include <QThread>
|
||||
#include <QString>
|
||||
|
||||
class hwapi;
|
||||
class hwinf;
|
||||
class ReportingThread : public QThread {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ReportingThread(hwapi *hw);
|
||||
ReportingThread(hwinf *hw);
|
||||
~ReportingThread();
|
||||
|
||||
protected:
|
||||
@ -18,7 +18,7 @@ protected:
|
||||
void run() override;
|
||||
|
||||
private:
|
||||
hwapi *m_hw;
|
||||
hwinf *m_hw;
|
||||
QString m_fileToDownload;
|
||||
};
|
||||
|
||||
|
@ -304,13 +304,14 @@ struct SharedMem
|
||||
// download of device controller and json files
|
||||
struct DCDownload {
|
||||
char m_filename[512];
|
||||
std::atomic_ushort m_totalBlocks;
|
||||
std::atomic_ushort m_currentblockNumber;
|
||||
std::atomic_bool m_requested{false};
|
||||
std::atomic_bool m_running{false};
|
||||
std::atomic_bool m_finished{false};
|
||||
uint16_t m_totalBlocks;
|
||||
uint16_t m_currentblockNumber;
|
||||
bool m_running;
|
||||
bool m_started;
|
||||
bool m_finished;
|
||||
} m_downLoadDC;
|
||||
|
||||
|
||||
static QSharedMemory *getShm(std::size_t s = 0);
|
||||
|
||||
static SharedMem *getData()
|
||||
|
@ -2,15 +2,9 @@
|
||||
#include "shared_mem_buffer.h"
|
||||
#include "hwapi.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QDateTime>
|
||||
|
||||
|
||||
DownloadThread::DownloadThread(hwinf *hw)
|
||||
: m_hw(hw)
|
||||
, m_fileToDownload(m_hw->dcDownloadFileName()) {
|
||||
// connect(this, &QThread::finished,
|
||||
// dynamic_cast<QObject const *>(m_hw), &QThread::deleteLater);
|
||||
}
|
||||
|
||||
DownloadThread::~DownloadThread() {
|
||||
@ -18,26 +12,10 @@ DownloadThread::~DownloadThread() {
|
||||
|
||||
// download thread running in ca-master sends the dc-file down to firmware
|
||||
void DownloadThread::run() {
|
||||
// m_hw->dcDownloadInit(m_fileToDownload);
|
||||
|
||||
m_hw->dcDownloadRequestAck();
|
||||
// hier dann den eigentlichen download-process eintragen
|
||||
|
||||
qCritical() << QDateTime::currentDateTime().toString(Qt::ISODate) + "DOWNLOAD THREAD STARTED";
|
||||
|
||||
// test code:
|
||||
uint16_t const totalBlocks = 100;
|
||||
m_hw->dcDownloadSetTotalBlockNumber(totalBlocks);
|
||||
|
||||
for (uint16_t currentBlock = 0; currentBlock <= totalBlocks; ++currentBlock) {
|
||||
m_hw->dcDownloadSetCurrentBlockNumber(currentBlock);
|
||||
QThread::msleep(100);
|
||||
}
|
||||
|
||||
m_hw->dcDownloadSetRunning(false);
|
||||
m_hw->dcDownloadSetFinished(true);
|
||||
|
||||
qCritical() << QDateTime::currentDateTime().toString(Qt::ISODate) + "DOWNLOAD THREAD FINISHED";
|
||||
|
||||
// the object deletes itself ! This is the last line in run().
|
||||
// Never touch the object after this statement
|
||||
// m_hw->dcDownloadThreadFinalize(this);
|
||||
// m_hw->dcDownloadGetCurrentBlockNumber(currentBlockNumber);
|
||||
// m_hw->dcDownloadGetTotalBlockNumber(totalBlockNumber);
|
||||
}
|
||||
|
253
src/hwapi.cpp
253
src/hwapi.cpp
@ -25,7 +25,6 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <atomic>
|
||||
|
||||
static uint32_t hwapi_lastStartAmount;
|
||||
static uint32_t hwapi_lastTotalAmount;
|
||||
@ -4377,232 +4376,46 @@ uint16_t hwapi::bna_getStackerLevel(uint32_t *amountInStacker, uint16_t *countOf
|
||||
return anzahl;
|
||||
}
|
||||
|
||||
QObject const *hwapi::getAPI() {
|
||||
hwapi *hwapi::getAPI() {
|
||||
return this;
|
||||
}
|
||||
|
||||
bool hwapi::dcDownloadRequest(QString const &dcFileToDownload) const {
|
||||
SharedMem *data = SharedMem::getData();
|
||||
if (!data) {
|
||||
return false;
|
||||
}
|
||||
|
||||
char *fNameBuffer = data->m_downLoadDC.m_filename;
|
||||
size_t const size = sizeof(data->m_downLoadDC.m_filename);
|
||||
void hwapi::dcDownloadRequest(QString const &dcFileToDownload) {
|
||||
char *fNameBuffer = SharedMem::getData()->m_downLoadDC.m_filename;
|
||||
size_t const size = sizeof(SharedMem::getData()->m_downLoadDC.m_filename);
|
||||
|
||||
std::memset(fNameBuffer, 0x00, size);
|
||||
std::memcpy(fNameBuffer, dcFileToDownload.toStdString().c_str(),
|
||||
std::min(size, strlen(fNameBuffer)-1));
|
||||
|
||||
data->m_downLoadDC.m_totalBlocks = 0;
|
||||
data->m_downLoadDC.m_currentblockNumber = 0;
|
||||
SharedMem::getData()->m_downLoadDC.m_totalBlocks = 0;
|
||||
SharedMem::getData()->m_downLoadDC.m_currentblockNumber = 0;
|
||||
SharedMem::getData()->m_downLoadDC.m_started = true;
|
||||
SharedMem::getData()->m_downLoadDC.m_running = false;
|
||||
SharedMem::getData()->m_downLoadDC.m_finished = false;
|
||||
}
|
||||
|
||||
data->m_downLoadDC.m_requested = true;
|
||||
data->m_downLoadDC.m_running = false; // download thread is not running
|
||||
data->m_downLoadDC.m_finished = true;
|
||||
void hwapi::dcDownloadStart() {
|
||||
}
|
||||
|
||||
return true;
|
||||
void hwapi::dcDownloadReportStart() {
|
||||
if (SharedMem::getDataConst()->m_downLoadDC.m_started ||
|
||||
SharedMem::getDataConst()->m_downLoadDC.m_running) {
|
||||
m_reportingThread = new ReportingThread(this);
|
||||
m_reportingThread->start();
|
||||
}
|
||||
}
|
||||
|
||||
bool hwapi::dcDownloadRequested() const {
|
||||
SharedMem const *data = SharedMem::getData();
|
||||
// should be false at entry
|
||||
return data ? data->m_downLoadDC.m_requested.load() : false;
|
||||
return SharedMem::getDataConst()->m_downLoadDC.m_started;
|
||||
}
|
||||
|
||||
bool hwapi::dcDownloadResetRequest() const {
|
||||
SharedMem *data = SharedMem::getData();
|
||||
if (data) {
|
||||
data->m_downLoadDC.m_requested = false;
|
||||
void hwapi::dcDownloadResetRequest() {
|
||||
SharedMem::getData()->m_downLoadDC.m_started = false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool hwapi::dcDownloadRequestAck() const {
|
||||
SharedMem *data = SharedMem::getData();
|
||||
if (data) {
|
||||
if (data->m_downLoadDC.m_requested) {
|
||||
data->m_downLoadDC.m_requested = false;
|
||||
data->m_downLoadDC.m_running = true;
|
||||
data->m_downLoadDC.m_finished = false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool hwapi::dcDownloadRunning() const {
|
||||
SharedMem const *data = SharedMem::getDataConst();
|
||||
if (data) {
|
||||
int cnt = 10;
|
||||
while (--cnt > 0) {
|
||||
bool running = data->m_downLoadDC.m_running.load();
|
||||
bool finished = data->m_downLoadDC.m_finished.load();
|
||||
if (!running || finished) {
|
||||
if (cnt < 3) {
|
||||
qCritical() << "DOWNLOAD THREAD NOT RUNNING" << running << finished;
|
||||
}
|
||||
QThread::msleep(500);
|
||||
} else break;
|
||||
}
|
||||
// qCritical() << "DOWNLOAD RUNNING" << cnt << (cnt > 0);
|
||||
return (cnt > 0);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void hwapi::dcDownloadThreadFinalize(DownloadThread *dthread) {
|
||||
delete dthread;
|
||||
m_downloadThread = nullptr;
|
||||
}
|
||||
|
||||
bool hwapi::dcDownloadFinished() {
|
||||
SharedMem const *data = SharedMem::getDataConst();
|
||||
if (data) {
|
||||
int cnt = 10;
|
||||
while ((--cnt > 0) &&
|
||||
((data->m_downLoadDC.m_running.load() == true) &&
|
||||
(data->m_downLoadDC.m_finished.load() == false))) {
|
||||
QThread::sleep(1);
|
||||
}
|
||||
|
||||
//if (cnt > 0) {
|
||||
// delete m_downloadThread;
|
||||
// m_downloadThread = nullptr;
|
||||
// return true;
|
||||
//}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// download thread
|
||||
|
||||
bool hwapi::dcDownloadThreadStart() {
|
||||
m_downloadThread = new DownloadThread(this);
|
||||
if (m_downloadThread) {
|
||||
m_downloadThread->start();
|
||||
int cnt = 10;
|
||||
while (--cnt > 0 && !dcDownloadThreadRunning()) {
|
||||
QThread::msleep(200);
|
||||
}
|
||||
return (cnt > 0);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool hwapi::dcDownloadThreadRunning() const {
|
||||
return (dcDownloadGetRunning() == true)
|
||||
&& (dcDownloadGetFinished() == false);
|
||||
}
|
||||
|
||||
bool hwapi::dcDownloadThreadFinished() const {
|
||||
return (dcDownloadThreadRunning() == false);
|
||||
}
|
||||
|
||||
|
||||
// report thread
|
||||
bool hwapi::dcDownloadReportThreadStart() { // only start reporting thread
|
||||
int cnt = 10; // if download thread is running
|
||||
while (--cnt > 0 && !dcDownloadRunning()) {
|
||||
QThread::msleep(500);
|
||||
}
|
||||
if (cnt > 0) {
|
||||
m_reportingThread = new ReportingThread(this);
|
||||
if (m_reportingThread) {
|
||||
m_reportingThread->start();
|
||||
cnt = 10;
|
||||
while (--cnt > 0 && !dcDownloadReportThreadRunning()) {
|
||||
QThread::msleep(200);
|
||||
}
|
||||
return (cnt > 0);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool hwapi::dcDownloadReportThreadRunning() const {
|
||||
return m_reportingThread ? m_reportingThread->isRunning() : false;
|
||||
}
|
||||
|
||||
void hwapi::dcDownloadReportThreadFinalize() {
|
||||
if (m_reportingThread) {
|
||||
if (m_reportingThread->isFinished()) {
|
||||
delete m_reportingThread;
|
||||
m_reportingThread = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void hwapi::dcDownloadReportThreadQuit() {
|
||||
if (m_reportingThread) {
|
||||
m_reportingThread->quit();
|
||||
}
|
||||
}
|
||||
|
||||
bool hwapi::dcDownloadReportThreadFinished() const {
|
||||
return m_reportingThread ? m_reportingThread->isFinished() : false;
|
||||
}
|
||||
|
||||
bool hwapi::dcDownloadReportStart() const {
|
||||
int cnt = 10;
|
||||
while (--cnt > 0 && !dcDownloadRunning()) {
|
||||
QThread::msleep(200);
|
||||
}
|
||||
return (cnt == 0);
|
||||
}
|
||||
|
||||
bool hwapi::dcDownloadReportRunning() const {
|
||||
return dcDownloadReportThreadRunning();
|
||||
}
|
||||
|
||||
bool hwapi::dcDownloadReportFinished() {
|
||||
int cnt = 10;
|
||||
while (--cnt > 0 && !dcDownloadReportThreadFinished()) {
|
||||
QThread::sleep(1);
|
||||
}
|
||||
|
||||
if (cnt == 0 && !dcDownloadReportThreadFinished()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (dcDownloadReportThreadFinished()) {
|
||||
delete m_reportingThread;
|
||||
m_reportingThread = nullptr;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
QString hwapi::dcDownloadFileName() const {
|
||||
SharedMem const *data = SharedMem::getDataConst();
|
||||
return data ? data->m_downLoadDC.m_filename : "";
|
||||
}
|
||||
|
||||
bool hwapi::dcDownloadSetRequested(bool requested) {
|
||||
SharedMem *data = SharedMem::getData();
|
||||
if (data) {
|
||||
data->m_downLoadDC.m_requested = requested;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool hwapi::dcDownloadSetRunning(bool running) {
|
||||
SharedMem *data = SharedMem::getData();
|
||||
if (data) {
|
||||
data->m_downLoadDC.m_running = running;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool hwapi::dcDownloadSetFinished(bool finished) {
|
||||
SharedMem *data = SharedMem::getData();
|
||||
if (data) {
|
||||
data->m_downLoadDC.m_finished = finished;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return SharedMem::getDataConst()->m_downLoadDC.m_filename;
|
||||
}
|
||||
|
||||
void hwapi::dcDownloadSetTotalBlockNumber(uint16_t totalBlockNumber) {
|
||||
@ -4614,26 +4427,22 @@ void hwapi::dcDownloadSetCurrentBlockNumber(uint16_t currentBlockNumber) {
|
||||
}
|
||||
|
||||
uint16_t hwapi::dcDownloadGetTotalBlockNumber() const {
|
||||
SharedMem const *data = SharedMem::getDataConst();
|
||||
return data ? data->m_downLoadDC.m_totalBlocks.load() : 0;
|
||||
return SharedMem::getDataConst()->m_downLoadDC.m_totalBlocks;
|
||||
}
|
||||
|
||||
uint16_t hwapi::dcDownloadGetCurrentBlockNumber() const {
|
||||
SharedMem const *data = SharedMem::getDataConst();
|
||||
return data ? data->m_downLoadDC.m_currentblockNumber.load() : 0;
|
||||
return SharedMem::getDataConst()->m_downLoadDC.m_currentblockNumber;
|
||||
}
|
||||
|
||||
bool hwapi::dcDownloadGetRequested() const {
|
||||
SharedMem const *data = SharedMem::getDataConst();
|
||||
return data ? data->m_downLoadDC.m_requested.load() : 0;
|
||||
bool hwapi::dcDownloadStarted() const {
|
||||
return SharedMem::getDataConst()->m_downLoadDC.m_started;
|
||||
}
|
||||
|
||||
bool hwapi::dcDownloadGetRunning() const {
|
||||
SharedMem const *data = SharedMem::getDataConst();
|
||||
return data ? data->m_downLoadDC.m_running.load() : 0;
|
||||
bool hwapi::dcDownloadRunning() const {
|
||||
return SharedMem::getDataConst()->m_downLoadDC.m_running;
|
||||
|
||||
}
|
||||
|
||||
bool hwapi::dcDownloadGetFinished() const {
|
||||
SharedMem const *data = SharedMem::getDataConst();
|
||||
return data ? data->m_downLoadDC.m_running.load() : 0;
|
||||
bool hwapi::dcDownloadFinished() const {
|
||||
return SharedMem::getDataConst()->m_downLoadDC.m_finished;
|
||||
}
|
||||
|
@ -2,10 +2,7 @@
|
||||
#include "shared_mem_buffer.h"
|
||||
#include "hwapi.h"
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QDebug>
|
||||
|
||||
ReportingThread::ReportingThread(hwapi *hw)
|
||||
ReportingThread::ReportingThread(hwinf *hw)
|
||||
: m_hw(hw)
|
||||
, m_fileToDownload(m_hw->dcDownloadFileName()) {
|
||||
}
|
||||
@ -13,73 +10,46 @@ ReportingThread::ReportingThread(hwapi *hw)
|
||||
ReportingThread::~ReportingThread() {
|
||||
}
|
||||
|
||||
// download thread running in ca-slave sends reports of download process to
|
||||
// each component which has connects for the corresponding signals.
|
||||
// download thread running in ca-slave sends reports download process to
|
||||
// update tool
|
||||
void ReportingThread::run() {
|
||||
hwapi *hw = m_hw->getAPI();
|
||||
emit hw->hwapi_reportDCDownloadStatus("test");
|
||||
|
||||
qCritical() << QDateTime::currentDateTime() << "START DOWNLOAD THREAD";
|
||||
|
||||
static QString report("");
|
||||
|
||||
int cnt = 5;
|
||||
while (!m_hw->dcDownloadGetRunning()) {
|
||||
if (--cnt > 0) {
|
||||
report = QString("%1 waiting for download to start %2")
|
||||
.arg(QDateTime::currentDateTime().toString(Qt::ISODate))
|
||||
.arg(cnt);
|
||||
qCritical() << __LINE__ << "STATUS" << report;
|
||||
emit m_hw->hwapi_reportDCDownloadStatus(report);
|
||||
QThread::sleep(1);
|
||||
} else break;
|
||||
}
|
||||
qCritical() << "nach emit";
|
||||
QThread::sleep(4);
|
||||
|
||||
#if 0
|
||||
if (cnt == 0) {
|
||||
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;
|
||||
int cnt = 10;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t const tnr = 1750;
|
||||
uint16_t cnr = 0;
|
||||
while (m_hw->dcDownloadRunning()) {
|
||||
uint16_t const cnr = m_hw->dcDownloadGetCurrentBlockNumber();
|
||||
uint16_t const tnr = m_hw->dcDownloadGetTotalBlockNumber();
|
||||
|
||||
while (cnr <= tnr) {
|
||||
QThread::msleep(100);
|
||||
QString report("");
|
||||
|
||||
if (cnr > 0) {
|
||||
double percent = ((double)cnr / (double)tnr) * 100.0;
|
||||
report = QString(": total blocks %1, current block %2 [%3]")
|
||||
.arg(tnr).arg(cnr).arg(percent, 0, 'f', 2);
|
||||
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]")
|
||||
report = QString("total blocks %1, current block %2 [0]")
|
||||
.arg(tnr).arg(cnr);
|
||||
}
|
||||
status = QDateTime::currentDateTime().toString(Qt::ISODate) + report;
|
||||
|
||||
qCritical() << "STATUS" << status;
|
||||
|
||||
emit m_hw->hwapi_reportDCDownloadStatus(status);
|
||||
cnr += 1;
|
||||
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);
|
||||
@ -88,68 +58,5 @@ void ReportingThread::run() {
|
||||
QString("ERROR DOWNLOADING %1 (total blocks=%2, sent blocks=%3)")
|
||||
.arg(m_fileToDownload).arg(tnr).arg(cnr));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
uint16_t const totalBlocks = m_hw->dcDownloadGetTotalBlockNumber();
|
||||
|
||||
qCritical() << QDateTime::currentDateTime() << "TOTAL BLOCKS" << totalBlocks;
|
||||
|
||||
if (totalBlocks) {
|
||||
qint64 const start = QDateTime::currentMSecsSinceEpoch();
|
||||
double durationMillis = 0;
|
||||
uint16_t currentBlockNumber = 0;
|
||||
|
||||
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(report);
|
||||
QThread::msleep(100);
|
||||
}
|
||||
|
||||
QThread::msleep(100);
|
||||
|
||||
if (totalBlocks == currentBlockNumber) {
|
||||
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(totalBlocks).arg(currentBlockNumber));
|
||||
}
|
||||
}
|
||||
|
||||
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…
x
Reference in New Issue
Block a user