Save as changing to master.
This commit is contained in:
parent
6176285b89
commit
2025a75d56
@ -1309,12 +1309,14 @@ public:
|
||||
|
||||
// download device controller
|
||||
void dcDownloadStart() override;
|
||||
void dcDownloadRequest(QString const &fileToDownload) override;
|
||||
bool dcDownloadFinished() override;
|
||||
bool dcDownloadRequest(QString const &fileToDownload) override;
|
||||
bool dcDownloadRequested() const override;
|
||||
QString dcDownloadFileName() const override;
|
||||
void dcDownloadResetRequest() override;
|
||||
bool dcDownloadResetRequest() override;
|
||||
void dcDownloadReportStart() override;
|
||||
bool dcDownloadStarted() const override;
|
||||
bool dcDownloadReportRunning() override;
|
||||
bool dcDownloadReportFinished() override;
|
||||
bool dcDownloadRunning() const override;
|
||||
bool dcDownloadFinished() const override;
|
||||
|
||||
@ -1323,12 +1325,12 @@ public:
|
||||
uint16_t dcDownloadGetTotalBlockNumber() const override;
|
||||
uint16_t dcDownloadGetCurrentBlockNumber() const override;
|
||||
|
||||
virtual hwapi *getAPI() override;
|
||||
virtual QObject const *getAPI() override;
|
||||
|
||||
signals: // for download
|
||||
void hwapi_reportDCDownloadStatus(QString const &) const;
|
||||
void hwapi_reportDCDownloadSuccess(QString const &) const;
|
||||
void hwapi_reportDCDownloadFailure(QString const &) const;
|
||||
void hwapi_reportDCDownloadStatus(QString const&) const;
|
||||
void hwapi_reportDCDownloadSuccess(QString const&) const;
|
||||
void hwapi_reportDCDownloadFailure(QString const&) const;
|
||||
// already declared in interfaces.h
|
||||
void hwapi_templatePrintFinished_OK(void) const;
|
||||
void hwapi_templatePrintFinished_Err(void) const;
|
||||
|
@ -2277,13 +2277,17 @@ public:
|
||||
|
||||
// download device controller
|
||||
virtual void dcDownloadStart() {}
|
||||
virtual void dcDownloadRequest(QString const &fileToDownload) {
|
||||
Q_UNUSED(fileToDownload);
|
||||
virtual bool dcDownloadFinished() { return true; }
|
||||
virtual bool dcDownloadRequest(QString const &fileToDownload) {
|
||||
Q_UNUSED(fileToDownload);
|
||||
return false;
|
||||
}
|
||||
virtual bool dcDownloadRequested() const { return false; }
|
||||
virtual void dcDownloadResetRequest() {}
|
||||
virtual bool dcDownloadResetRequest() { return false; }
|
||||
virtual QString dcDownloadFileName() const { return ""; }
|
||||
virtual void dcDownloadReportStart() {}
|
||||
virtual bool dcDownloadReportRunning() { return true; }
|
||||
virtual bool dcDownloadReportFinished() { return true; }
|
||||
virtual void dcDownloadSetTotalBlockNumber(uint16_t totalBlockNumber) {
|
||||
Q_UNUSED(totalBlockNumber);
|
||||
}
|
||||
@ -2293,16 +2297,15 @@ public:
|
||||
virtual uint16_t dcDownloadGetTotalBlockNumber() const { return 0; }
|
||||
virtual uint16_t dcDownloadGetCurrentBlockNumber() const { return 0; }
|
||||
|
||||
virtual bool dcDownloadStarted() const { return false; }
|
||||
virtual bool dcDownloadRunning() const { return false; }
|
||||
virtual bool dcDownloadFinished() const { return false; }
|
||||
|
||||
virtual hwapi *getAPI() { return nullptr; }
|
||||
virtual QObject const *getAPI() { return nullptr; }
|
||||
|
||||
signals: // for download
|
||||
void hwapi_reportDCDownloadStatus(QString const &) const;
|
||||
void hwapi_reportDCDownloadSuccess(QString const &) const;
|
||||
void hwapi_reportDCDownloadFailure(QString const &) const;
|
||||
void hwapi_reportDCDownloadStatus(QString const&) const;
|
||||
void hwapi_reportDCDownloadSuccess(QString const&) const;
|
||||
void hwapi_reportDCDownloadFailure(QString const&) const;
|
||||
|
||||
// NOTE: declaring a "pure virtual" "signal" should be an error and thus not valid.
|
||||
void hwapi_templatePrintFinished_OK() const;
|
||||
|
@ -4,12 +4,12 @@
|
||||
#include <QThread>
|
||||
#include <QString>
|
||||
|
||||
class hwinf;
|
||||
class hwapi;
|
||||
class ReportingThread : public QThread {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ReportingThread(hwinf *hw);
|
||||
ReportingThread(hwapi *hw);
|
||||
~ReportingThread();
|
||||
|
||||
protected:
|
||||
@ -18,7 +18,7 @@ protected:
|
||||
void run() override;
|
||||
|
||||
private:
|
||||
hwinf *m_hw;
|
||||
hwapi *m_hw;
|
||||
QString m_fileToDownload;
|
||||
};
|
||||
|
||||
|
@ -304,14 +304,13 @@ struct SharedMem
|
||||
// download of device controller and json files
|
||||
struct DCDownload {
|
||||
char m_filename[512];
|
||||
uint16_t m_totalBlocks;
|
||||
uint16_t m_currentblockNumber;
|
||||
bool m_running;
|
||||
bool m_started;
|
||||
bool m_finished;
|
||||
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};
|
||||
} m_downLoadDC;
|
||||
|
||||
|
||||
static QSharedMemory *getShm(std::size_t s = 0);
|
||||
|
||||
static SharedMem *getData()
|
||||
|
109
src/hwapi.cpp
109
src/hwapi.cpp
@ -25,6 +25,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <atomic>
|
||||
|
||||
static uint32_t hwapi_lastStartAmount;
|
||||
static uint32_t hwapi_lastTotalAmount;
|
||||
@ -4376,46 +4377,94 @@ uint16_t hwapi::bna_getStackerLevel(uint32_t *amountInStacker, uint16_t *countOf
|
||||
return anzahl;
|
||||
}
|
||||
|
||||
hwapi *hwapi::getAPI() {
|
||||
QObject const *hwapi::getAPI() {
|
||||
return this;
|
||||
}
|
||||
|
||||
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);
|
||||
bool hwapi::dcDownloadRequest(QString const &dcFileToDownload) {
|
||||
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);
|
||||
|
||||
std::memset(fNameBuffer, 0x00, size);
|
||||
std::memcpy(fNameBuffer, dcFileToDownload.toStdString().c_str(),
|
||||
std::min(size, strlen(fNameBuffer)-1));
|
||||
|
||||
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_totalBlocks = 0;
|
||||
data->m_downLoadDC.m_currentblockNumber = 0;
|
||||
|
||||
data->m_downLoadDC.m_requested = true;
|
||||
data->m_downLoadDC.m_running = false;
|
||||
data->m_downLoadDC.m_finished = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void hwapi::dcDownloadStart() {
|
||||
}
|
||||
|
||||
void hwapi::dcDownloadReportStart() {
|
||||
if (SharedMem::getDataConst()->m_downLoadDC.m_started ||
|
||||
SharedMem::getDataConst()->m_downLoadDC.m_running) {
|
||||
m_reportingThread = new ReportingThread(this);
|
||||
m_reportingThread->start();
|
||||
SharedMem *data = SharedMem::getData();
|
||||
if (data) {
|
||||
data->m_downLoadDC.m_requested = false;
|
||||
data->m_downLoadDC.m_running = true;
|
||||
}
|
||||
}
|
||||
|
||||
bool hwapi::dcDownloadRequested() const {
|
||||
return SharedMem::getDataConst()->m_downLoadDC.m_started;
|
||||
bool hwapi::dcDownloadFinished() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void hwapi::dcDownloadResetRequest() {
|
||||
SharedMem::getData()->m_downLoadDC.m_started = false;
|
||||
void hwapi::dcDownloadReportStart() {
|
||||
SharedMem const *data = SharedMem::getData();
|
||||
if (data) {
|
||||
if (data->m_downLoadDC.m_requested) {
|
||||
m_reportingThread = new ReportingThread(this);
|
||||
m_reportingThread->start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool hwapi::dcDownloadReportRunning() {
|
||||
if (m_reportingThread) {
|
||||
return m_reportingThread->isRunning();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool hwapi::dcDownloadReportFinished() {
|
||||
if (m_reportingThread) {
|
||||
int cnt = 10;
|
||||
while (--cnt > 0 && !m_reportingThread->isFinished()) {
|
||||
QThread::sleep(1);
|
||||
}
|
||||
if (!m_reportingThread->isFinished()) {
|
||||
return false;
|
||||
}
|
||||
delete m_reportingThread;
|
||||
m_reportingThread = nullptr;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool hwapi::dcDownloadRequested() const {
|
||||
SharedMem const *data = SharedMem::getData();
|
||||
// should be false at entry
|
||||
return data ? data->m_downLoadDC.m_requested.load() : false;
|
||||
}
|
||||
|
||||
bool hwapi::dcDownloadResetRequest() {
|
||||
SharedMem *data = SharedMem::getData();
|
||||
if (data) {
|
||||
data->m_downLoadDC.m_requested = false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
QString hwapi::dcDownloadFileName() const {
|
||||
return SharedMem::getDataConst()->m_downLoadDC.m_filename;
|
||||
SharedMem const *data = SharedMem::getDataConst();
|
||||
return data ? data->m_downLoadDC.m_filename : "";
|
||||
}
|
||||
|
||||
void hwapi::dcDownloadSetTotalBlockNumber(uint16_t totalBlockNumber) {
|
||||
@ -4427,22 +4476,22 @@ void hwapi::dcDownloadSetCurrentBlockNumber(uint16_t currentBlockNumber) {
|
||||
}
|
||||
|
||||
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 {
|
||||
return SharedMem::getDataConst()->m_downLoadDC.m_currentblockNumber;
|
||||
}
|
||||
|
||||
bool hwapi::dcDownloadStarted() const {
|
||||
return SharedMem::getDataConst()->m_downLoadDC.m_started;
|
||||
SharedMem const *data = SharedMem::getDataConst();
|
||||
return data ? data->m_downLoadDC.m_currentblockNumber.load() : 0;
|
||||
}
|
||||
|
||||
bool hwapi::dcDownloadRunning() const {
|
||||
return SharedMem::getDataConst()->m_downLoadDC.m_running;
|
||||
|
||||
SharedMem const *data = SharedMem::getData();
|
||||
return data ? data->m_downLoadDC.m_running.load() : false;
|
||||
}
|
||||
|
||||
bool hwapi::dcDownloadFinished() const {
|
||||
return SharedMem::getDataConst()->m_downLoadDC.m_finished;
|
||||
SharedMem const *data = SharedMem::getData();
|
||||
return data ? data->m_downLoadDC.m_finished.load() : false;
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,9 @@
|
||||
#include "shared_mem_buffer.h"
|
||||
#include "hwapi.h"
|
||||
|
||||
ReportingThread::ReportingThread(hwinf *hw)
|
||||
#include <QDateTime>
|
||||
|
||||
ReportingThread::ReportingThread(hwapi *hw)
|
||||
: m_hw(hw)
|
||||
, m_fileToDownload(m_hw->dcDownloadFileName()) {
|
||||
}
|
||||
@ -10,25 +12,47 @@ ReportingThread::ReportingThread(hwinf *hw)
|
||||
ReportingThread::~ReportingThread() {
|
||||
}
|
||||
|
||||
// download thread running in ca-slave sends reports download process to
|
||||
// update tool
|
||||
// download thread running in ca-slave sends reports of download process to
|
||||
// each component which has connects for the corresponding signals.
|
||||
void ReportingThread::run() {
|
||||
hwapi *hw = m_hw->getAPI();
|
||||
emit hw->hwapi_reportDCDownloadStatus("test");
|
||||
static QString status;
|
||||
|
||||
qCritical() << "nach emit";
|
||||
QThread::sleep(4);
|
||||
|
||||
#if 0
|
||||
int cnt = 10;
|
||||
int cnt = 5;
|
||||
while (!m_hw->dcDownloadRunning()) {
|
||||
if (--cnt > 0) {
|
||||
status = QString("%1 waiting for download to start %2")
|
||||
.arg(QDateTime::currentDateTime().toString(Qt::ISODate))
|
||||
.arg(cnt);
|
||||
qCritical() << __LINE__ << "STATUS" << status;
|
||||
emit m_hw->hwapi_reportDCDownloadStatus(status);
|
||||
QThread::sleep(1);
|
||||
} else break;
|
||||
}
|
||||
|
||||
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()) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
if (cnt == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
while (m_hw->dcDownloadRunning()) {
|
||||
uint16_t const cnr = m_hw->dcDownloadGetCurrentBlockNumber();
|
||||
@ -44,6 +68,7 @@ void ReportingThread::run() {
|
||||
.arg(tnr).arg(cnr);
|
||||
}
|
||||
|
||||
emit m_hw->hwapi_reportDCDownloadStatus(QString("XXXXX") + QDateTime::currentDateTime().toString(Qt::ISODate));
|
||||
emit m_hw->hwapi_reportDCDownloadStatus(report);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user