Compare commits
9 Commits
6176285b89
...
65163354bd
Author | SHA1 | Date | |
---|---|---|---|
65163354bd | |||
5f88c8f856 | |||
4efbbcbb5a | |||
1155b83ca9 | |||
631550b55e | |||
9e5c379e8a | |||
6b9e795206 | |||
b7ff6dcdbe | |||
2025a75d56 |
@ -1308,22 +1308,41 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
// download device controller
|
// download device controller
|
||||||
void dcDownloadStart() override;
|
bool dcDownloadRequest(QString const &fileToDownload) const override;
|
||||||
void dcDownloadRequest(QString const &fileToDownload) override;
|
|
||||||
bool dcDownloadRequested() const override;
|
bool dcDownloadRequested() const override;
|
||||||
QString dcDownloadFileName() const override;
|
bool dcDownloadResetRequest() const override;
|
||||||
void dcDownloadResetRequest() override;
|
bool dcDownloadRequestAck() const override;
|
||||||
void dcDownloadReportStart() override;
|
|
||||||
bool dcDownloadStarted() const override;
|
|
||||||
bool dcDownloadRunning() const override;
|
bool dcDownloadRunning() const override;
|
||||||
bool dcDownloadFinished() 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 dcDownloadSetTotalBlockNumber(uint16_t totalBlockNumber) override;
|
void dcDownloadSetTotalBlockNumber(uint16_t totalBlockNumber) override;
|
||||||
void dcDownloadSetCurrentBlockNumber(uint16_t currentBlockNumber) 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 dcDownloadGetTotalBlockNumber() const override;
|
||||||
uint16_t dcDownloadGetCurrentBlockNumber() const override;
|
uint16_t dcDownloadGetCurrentBlockNumber() const override;
|
||||||
|
|
||||||
virtual hwapi *getAPI() override;
|
virtual QObject const *getAPI() override;
|
||||||
|
|
||||||
signals: // for download
|
signals: // for download
|
||||||
void hwapi_reportDCDownloadStatus(QString const&) const;
|
void hwapi_reportDCDownloadStatus(QString const&) const;
|
||||||
|
@ -399,6 +399,7 @@ struct T_bna
|
|||||||
};
|
};
|
||||||
|
|
||||||
class hwapi;
|
class hwapi;
|
||||||
|
class DownloadThread;
|
||||||
class hwinf
|
class hwinf
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -2276,28 +2277,54 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
// download device controller
|
// download device controller
|
||||||
virtual void dcDownloadStart() {}
|
virtual bool dcDownloadRequest(QString const &fileToDownload) const {
|
||||||
virtual void dcDownloadRequest(QString const &fileToDownload) {
|
|
||||||
Q_UNUSED(fileToDownload);
|
Q_UNUSED(fileToDownload);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
virtual bool dcDownloadRequested() const { return false; }
|
virtual bool dcDownloadRequested() const { return false; }
|
||||||
virtual void dcDownloadResetRequest() {}
|
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 QString dcDownloadFileName() const { return ""; }
|
virtual QString dcDownloadFileName() const { return ""; }
|
||||||
virtual void dcDownloadReportStart() {}
|
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 dcDownloadSetTotalBlockNumber(uint16_t totalBlockNumber) {
|
virtual void dcDownloadSetTotalBlockNumber(uint16_t totalBlockNumber) {
|
||||||
Q_UNUSED(totalBlockNumber);
|
Q_UNUSED(totalBlockNumber);
|
||||||
}
|
}
|
||||||
virtual void dcDownloadSetCurrentBlockNumber(uint16_t currentBlockNumber) {
|
virtual void dcDownloadSetCurrentBlockNumber(uint16_t currentBlockNumber) {
|
||||||
Q_UNUSED(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 dcDownloadGetTotalBlockNumber() const { return 0; }
|
||||||
virtual uint16_t dcDownloadGetCurrentBlockNumber() const { return 0; }
|
virtual uint16_t dcDownloadGetCurrentBlockNumber() const { return 0; }
|
||||||
|
|
||||||
virtual bool dcDownloadStarted() const { return false; }
|
virtual QObject const *getAPI() { return nullptr; }
|
||||||
virtual bool dcDownloadRunning() const { return false; }
|
|
||||||
virtual bool dcDownloadFinished() const { return false; }
|
|
||||||
|
|
||||||
virtual hwapi *getAPI() { return nullptr; }
|
|
||||||
|
|
||||||
signals: // for download
|
signals: // for download
|
||||||
void hwapi_reportDCDownloadStatus(QString const&) const;
|
void hwapi_reportDCDownloadStatus(QString const&) const;
|
||||||
|
@ -4,12 +4,12 @@
|
|||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
class hwinf;
|
class hwapi;
|
||||||
class ReportingThread : public QThread {
|
class ReportingThread : public QThread {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ReportingThread(hwinf *hw);
|
ReportingThread(hwapi *hw);
|
||||||
~ReportingThread();
|
~ReportingThread();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -18,7 +18,7 @@ protected:
|
|||||||
void run() override;
|
void run() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
hwinf *m_hw;
|
hwapi *m_hw;
|
||||||
QString m_fileToDownload;
|
QString m_fileToDownload;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -304,14 +304,13 @@ struct SharedMem
|
|||||||
// download of device controller and json files
|
// download of device controller and json files
|
||||||
struct DCDownload {
|
struct DCDownload {
|
||||||
char m_filename[512];
|
char m_filename[512];
|
||||||
uint16_t m_totalBlocks;
|
std::atomic_ushort m_totalBlocks;
|
||||||
uint16_t m_currentblockNumber;
|
std::atomic_ushort m_currentblockNumber;
|
||||||
bool m_running;
|
std::atomic_bool m_requested{false};
|
||||||
bool m_started;
|
std::atomic_bool m_running{false};
|
||||||
bool m_finished;
|
std::atomic_bool m_finished{false};
|
||||||
} m_downLoadDC;
|
} m_downLoadDC;
|
||||||
|
|
||||||
|
|
||||||
static QSharedMemory *getShm(std::size_t s = 0);
|
static QSharedMemory *getShm(std::size_t s = 0);
|
||||||
|
|
||||||
static SharedMem *getData()
|
static SharedMem *getData()
|
||||||
|
@ -2,9 +2,15 @@
|
|||||||
#include "shared_mem_buffer.h"
|
#include "shared_mem_buffer.h"
|
||||||
#include "hwapi.h"
|
#include "hwapi.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QDateTime>
|
||||||
|
|
||||||
|
|
||||||
DownloadThread::DownloadThread(hwinf *hw)
|
DownloadThread::DownloadThread(hwinf *hw)
|
||||||
: m_hw(hw)
|
: m_hw(hw)
|
||||||
, m_fileToDownload(m_hw->dcDownloadFileName()) {
|
, m_fileToDownload(m_hw->dcDownloadFileName()) {
|
||||||
|
// connect(this, &QThread::finished,
|
||||||
|
// dynamic_cast<QObject const *>(m_hw), &QThread::deleteLater);
|
||||||
}
|
}
|
||||||
|
|
||||||
DownloadThread::~DownloadThread() {
|
DownloadThread::~DownloadThread() {
|
||||||
@ -12,10 +18,26 @@ DownloadThread::~DownloadThread() {
|
|||||||
|
|
||||||
// download thread running in ca-master sends the dc-file down to firmware
|
// download thread running in ca-master sends the dc-file down to firmware
|
||||||
void DownloadThread::run() {
|
void DownloadThread::run() {
|
||||||
// m_hw->dcDownloadInit(m_fileToDownload);
|
|
||||||
|
|
||||||
// hier dann den eigentlichen download-process eintragen
|
m_hw->dcDownloadRequestAck();
|
||||||
|
|
||||||
// m_hw->dcDownloadGetCurrentBlockNumber(currentBlockNumber);
|
qCritical() << QDateTime::currentDateTime().toString(Qt::ISODate) + "DOWNLOAD THREAD STARTED";
|
||||||
// m_hw->dcDownloadGetTotalBlockNumber(totalBlockNumber);
|
|
||||||
|
// 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);
|
||||||
}
|
}
|
||||||
|
253
src/hwapi.cpp
253
src/hwapi.cpp
@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <atomic>
|
||||||
|
|
||||||
static uint32_t hwapi_lastStartAmount;
|
static uint32_t hwapi_lastStartAmount;
|
||||||
static uint32_t hwapi_lastTotalAmount;
|
static uint32_t hwapi_lastTotalAmount;
|
||||||
@ -4376,46 +4377,232 @@ uint16_t hwapi::bna_getStackerLevel(uint32_t *amountInStacker, uint16_t *countOf
|
|||||||
return anzahl;
|
return anzahl;
|
||||||
}
|
}
|
||||||
|
|
||||||
hwapi *hwapi::getAPI() {
|
QObject const *hwapi::getAPI() {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void hwapi::dcDownloadRequest(QString const &dcFileToDownload) {
|
bool hwapi::dcDownloadRequest(QString const &dcFileToDownload) const {
|
||||||
char *fNameBuffer = SharedMem::getData()->m_downLoadDC.m_filename;
|
SharedMem *data = SharedMem::getData();
|
||||||
size_t const size = sizeof(SharedMem::getData()->m_downLoadDC.m_filename);
|
if (!data) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *fNameBuffer = data->m_downLoadDC.m_filename;
|
||||||
|
size_t const size = sizeof(data->m_downLoadDC.m_filename);
|
||||||
|
|
||||||
std::memset(fNameBuffer, 0x00, size);
|
std::memset(fNameBuffer, 0x00, size);
|
||||||
std::memcpy(fNameBuffer, dcFileToDownload.toStdString().c_str(),
|
std::memcpy(fNameBuffer, dcFileToDownload.toStdString().c_str(),
|
||||||
std::min(size, strlen(fNameBuffer)-1));
|
std::min(size, strlen(fNameBuffer)-1));
|
||||||
|
|
||||||
SharedMem::getData()->m_downLoadDC.m_totalBlocks = 0;
|
data->m_downLoadDC.m_totalBlocks = 0;
|
||||||
SharedMem::getData()->m_downLoadDC.m_currentblockNumber = 0;
|
data->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;
|
|
||||||
}
|
|
||||||
|
|
||||||
void hwapi::dcDownloadStart() {
|
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::dcDownloadReportStart() {
|
return true;
|
||||||
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 {
|
bool hwapi::dcDownloadRequested() const {
|
||||||
return SharedMem::getDataConst()->m_downLoadDC.m_started;
|
SharedMem const *data = SharedMem::getData();
|
||||||
|
// should be false at entry
|
||||||
|
return data ? data->m_downLoadDC.m_requested.load() : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void hwapi::dcDownloadResetRequest() {
|
bool hwapi::dcDownloadResetRequest() const {
|
||||||
SharedMem::getData()->m_downLoadDC.m_started = false;
|
SharedMem *data = SharedMem::getData();
|
||||||
|
if (data) {
|
||||||
|
data->m_downLoadDC.m_requested = 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 {
|
QString hwapi::dcDownloadFileName() const {
|
||||||
return SharedMem::getDataConst()->m_downLoadDC.m_filename;
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
void hwapi::dcDownloadSetTotalBlockNumber(uint16_t totalBlockNumber) {
|
void hwapi::dcDownloadSetTotalBlockNumber(uint16_t totalBlockNumber) {
|
||||||
@ -4427,22 +4614,26 @@ void hwapi::dcDownloadSetCurrentBlockNumber(uint16_t currentBlockNumber) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint16_t hwapi::dcDownloadGetTotalBlockNumber() const {
|
uint16_t hwapi::dcDownloadGetTotalBlockNumber() const {
|
||||||
return SharedMem::getDataConst()->m_downLoadDC.m_totalBlocks;
|
SharedMem const *data = SharedMem::getDataConst();
|
||||||
|
return data ? data->m_downLoadDC.m_totalBlocks.load() : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t hwapi::dcDownloadGetCurrentBlockNumber() const {
|
uint16_t hwapi::dcDownloadGetCurrentBlockNumber() const {
|
||||||
return SharedMem::getDataConst()->m_downLoadDC.m_currentblockNumber;
|
SharedMem const *data = SharedMem::getDataConst();
|
||||||
|
return data ? data->m_downLoadDC.m_currentblockNumber.load() : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hwapi::dcDownloadStarted() const {
|
bool hwapi::dcDownloadGetRequested() const {
|
||||||
return SharedMem::getDataConst()->m_downLoadDC.m_started;
|
SharedMem const *data = SharedMem::getDataConst();
|
||||||
|
return data ? data->m_downLoadDC.m_requested.load() : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hwapi::dcDownloadRunning() const {
|
bool hwapi::dcDownloadGetRunning() const {
|
||||||
return SharedMem::getDataConst()->m_downLoadDC.m_running;
|
SharedMem const *data = SharedMem::getDataConst();
|
||||||
|
return data ? data->m_downLoadDC.m_running.load() : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hwapi::dcDownloadFinished() const {
|
bool hwapi::dcDownloadGetFinished() const {
|
||||||
return SharedMem::getDataConst()->m_downLoadDC.m_finished;
|
SharedMem const *data = SharedMem::getDataConst();
|
||||||
|
return data ? data->m_downLoadDC.m_running.load() : 0;
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,10 @@
|
|||||||
#include "shared_mem_buffer.h"
|
#include "shared_mem_buffer.h"
|
||||||
#include "hwapi.h"
|
#include "hwapi.h"
|
||||||
|
|
||||||
ReportingThread::ReportingThread(hwinf *hw)
|
#include <QDateTime>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
ReportingThread::ReportingThread(hwapi *hw)
|
||||||
: m_hw(hw)
|
: m_hw(hw)
|
||||||
, m_fileToDownload(m_hw->dcDownloadFileName()) {
|
, m_fileToDownload(m_hw->dcDownloadFileName()) {
|
||||||
}
|
}
|
||||||
@ -10,46 +13,73 @@ ReportingThread::ReportingThread(hwinf *hw)
|
|||||||
ReportingThread::~ReportingThread() {
|
ReportingThread::~ReportingThread() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// download thread running in ca-slave sends reports download process to
|
// download thread running in ca-slave sends reports of download process to
|
||||||
// update tool
|
// each component which has connects for the corresponding signals.
|
||||||
void ReportingThread::run() {
|
void ReportingThread::run() {
|
||||||
hwapi *hw = m_hw->getAPI();
|
|
||||||
emit hw->hwapi_reportDCDownloadStatus("test");
|
|
||||||
|
|
||||||
qCritical() << "nach emit";
|
qCritical() << QDateTime::currentDateTime() << "START DOWNLOAD THREAD";
|
||||||
QThread::sleep(4);
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
int cnt = 10;
|
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;
|
||||||
while (!m_hw->dcDownloadRunning()) {
|
while (!m_hw->dcDownloadRunning()) {
|
||||||
if (--cnt > 0) {
|
if (--cnt > 0) {
|
||||||
QThread::sleep(1);
|
QThread::sleep(1);
|
||||||
|
} else break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (cnt == 0) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
while (m_hw->dcDownloadRunning()) {
|
uint16_t const tnr = 1750;
|
||||||
uint16_t const cnr = m_hw->dcDownloadGetCurrentBlockNumber();
|
uint16_t cnr = 0;
|
||||||
uint16_t const tnr = m_hw->dcDownloadGetTotalBlockNumber();
|
|
||||||
|
|
||||||
|
while (cnr <= tnr) {
|
||||||
|
QThread::msleep(100);
|
||||||
QString report("");
|
QString report("");
|
||||||
|
|
||||||
if (cnr > 0) {
|
if (cnr > 0) {
|
||||||
report = QString("total blocks %1, current block %2 [%3]")
|
double percent = ((double)cnr / (double)tnr) * 100.0;
|
||||||
.arg(tnr).arg(cnr).arg((double)(tnr)/(double(cnr)));
|
report = QString(": total blocks %1, current block %2 [%3]")
|
||||||
|
.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;
|
||||||
|
|
||||||
emit m_hw->hwapi_reportDCDownloadStatus(report);
|
qCritical() << "STATUS" << status;
|
||||||
|
|
||||||
|
emit m_hw->hwapi_reportDCDownloadStatus(status);
|
||||||
|
cnr += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t const cnr = m_hw->dcDownloadGetCurrentBlockNumber();
|
|
||||||
uint16_t const tnr = m_hw->dcDownloadGetTotalBlockNumber();
|
|
||||||
|
|
||||||
if (tnr == cnr) {
|
if (tnr == cnr) {
|
||||||
m_hw->hwapi_reportDCDownloadSuccess(
|
m_hw->hwapi_reportDCDownloadSuccess(
|
||||||
QString("SUCCESS DOWNLOADING") + m_fileToDownload);
|
QString("SUCCESS DOWNLOADING") + m_fileToDownload);
|
||||||
@ -58,5 +88,68 @@ void ReportingThread::run() {
|
|||||||
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(tnr).arg(cnr));
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#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