forked from GerhardHoffmann/DCLibraries
Save as changing to master.
This commit is contained in:
parent
6176285b89
commit
2025a75d56
@ -1309,12 +1309,14 @@ public:
|
|||||||
|
|
||||||
// download device controller
|
// download device controller
|
||||||
void dcDownloadStart() override;
|
void dcDownloadStart() override;
|
||||||
void dcDownloadRequest(QString const &fileToDownload) override;
|
bool dcDownloadFinished() override;
|
||||||
|
bool dcDownloadRequest(QString const &fileToDownload) override;
|
||||||
bool dcDownloadRequested() const override;
|
bool dcDownloadRequested() const override;
|
||||||
QString dcDownloadFileName() const override;
|
QString dcDownloadFileName() const override;
|
||||||
void dcDownloadResetRequest() override;
|
bool dcDownloadResetRequest() override;
|
||||||
void dcDownloadReportStart() override;
|
void dcDownloadReportStart() override;
|
||||||
bool dcDownloadStarted() const override;
|
bool dcDownloadReportRunning() override;
|
||||||
|
bool dcDownloadReportFinished() override;
|
||||||
bool dcDownloadRunning() const override;
|
bool dcDownloadRunning() const override;
|
||||||
bool dcDownloadFinished() const override;
|
bool dcDownloadFinished() const override;
|
||||||
|
|
||||||
@ -1323,12 +1325,12 @@ public:
|
|||||||
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;
|
||||||
void hwapi_reportDCDownloadSuccess(QString const &) const;
|
void hwapi_reportDCDownloadSuccess(QString const&) const;
|
||||||
void hwapi_reportDCDownloadFailure(QString const &) const;
|
void hwapi_reportDCDownloadFailure(QString const&) const;
|
||||||
// already declared in interfaces.h
|
// already declared in interfaces.h
|
||||||
void hwapi_templatePrintFinished_OK(void) const;
|
void hwapi_templatePrintFinished_OK(void) const;
|
||||||
void hwapi_templatePrintFinished_Err(void) const;
|
void hwapi_templatePrintFinished_Err(void) const;
|
||||||
|
@ -2277,13 +2277,17 @@ public:
|
|||||||
|
|
||||||
// download device controller
|
// download device controller
|
||||||
virtual void dcDownloadStart() {}
|
virtual void dcDownloadStart() {}
|
||||||
virtual void dcDownloadRequest(QString const &fileToDownload) {
|
virtual bool dcDownloadFinished() { return true; }
|
||||||
Q_UNUSED(fileToDownload);
|
virtual bool dcDownloadRequest(QString const &fileToDownload) {
|
||||||
|
Q_UNUSED(fileToDownload);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
virtual bool dcDownloadRequested() const { return false; }
|
virtual bool dcDownloadRequested() const { return false; }
|
||||||
virtual void dcDownloadResetRequest() {}
|
virtual bool dcDownloadResetRequest() { return false; }
|
||||||
virtual QString dcDownloadFileName() const { return ""; }
|
virtual QString dcDownloadFileName() const { return ""; }
|
||||||
virtual void dcDownloadReportStart() {}
|
virtual void dcDownloadReportStart() {}
|
||||||
|
virtual bool dcDownloadReportRunning() { return true; }
|
||||||
|
virtual bool dcDownloadReportFinished() { return true; }
|
||||||
virtual void dcDownloadSetTotalBlockNumber(uint16_t totalBlockNumber) {
|
virtual void dcDownloadSetTotalBlockNumber(uint16_t totalBlockNumber) {
|
||||||
Q_UNUSED(totalBlockNumber);
|
Q_UNUSED(totalBlockNumber);
|
||||||
}
|
}
|
||||||
@ -2293,16 +2297,15 @@ public:
|
|||||||
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 bool dcDownloadRunning() const { return false; }
|
virtual bool dcDownloadRunning() const { return false; }
|
||||||
virtual bool dcDownloadFinished() const { return false; }
|
virtual bool dcDownloadFinished() const { return false; }
|
||||||
|
|
||||||
virtual hwapi *getAPI() { return nullptr; }
|
virtual QObject const *getAPI() { return nullptr; }
|
||||||
|
|
||||||
signals: // for download
|
signals: // for download
|
||||||
void hwapi_reportDCDownloadStatus(QString const &) const;
|
void hwapi_reportDCDownloadStatus(QString const&) const;
|
||||||
void hwapi_reportDCDownloadSuccess(QString const &) const;
|
void hwapi_reportDCDownloadSuccess(QString const&) const;
|
||||||
void hwapi_reportDCDownloadFailure(QString const &) const;
|
void hwapi_reportDCDownloadFailure(QString const&) const;
|
||||||
|
|
||||||
// NOTE: declaring a "pure virtual" "signal" should be an error and thus not valid.
|
// NOTE: declaring a "pure virtual" "signal" should be an error and thus not valid.
|
||||||
void hwapi_templatePrintFinished_OK() const;
|
void hwapi_templatePrintFinished_OK() 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()
|
||||||
|
109
src/hwapi.cpp
109
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,94 @@ 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) {
|
||||||
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;
|
data->m_downLoadDC.m_requested = true;
|
||||||
SharedMem::getData()->m_downLoadDC.m_finished = false;
|
data->m_downLoadDC.m_running = false;
|
||||||
|
data->m_downLoadDC.m_finished = false;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void hwapi::dcDownloadStart() {
|
void hwapi::dcDownloadStart() {
|
||||||
}
|
SharedMem *data = SharedMem::getData();
|
||||||
|
if (data) {
|
||||||
void hwapi::dcDownloadReportStart() {
|
data->m_downLoadDC.m_requested = false;
|
||||||
if (SharedMem::getDataConst()->m_downLoadDC.m_started ||
|
data->m_downLoadDC.m_running = true;
|
||||||
SharedMem::getDataConst()->m_downLoadDC.m_running) {
|
|
||||||
m_reportingThread = new ReportingThread(this);
|
|
||||||
m_reportingThread->start();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hwapi::dcDownloadRequested() const {
|
bool hwapi::dcDownloadFinished() {
|
||||||
return SharedMem::getDataConst()->m_downLoadDC.m_started;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void hwapi::dcDownloadResetRequest() {
|
void hwapi::dcDownloadReportStart() {
|
||||||
SharedMem::getData()->m_downLoadDC.m_started = false;
|
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 {
|
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) {
|
void hwapi::dcDownloadSetTotalBlockNumber(uint16_t totalBlockNumber) {
|
||||||
@ -4427,22 +4476,22 @@ 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 {
|
|
||||||
return SharedMem::getDataConst()->m_downLoadDC.m_started;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hwapi::dcDownloadRunning() const {
|
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 {
|
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 "shared_mem_buffer.h"
|
||||||
#include "hwapi.h"
|
#include "hwapi.h"
|
||||||
|
|
||||||
ReportingThread::ReportingThread(hwinf *hw)
|
#include <QDateTime>
|
||||||
|
|
||||||
|
ReportingThread::ReportingThread(hwapi *hw)
|
||||||
: m_hw(hw)
|
: m_hw(hw)
|
||||||
, m_fileToDownload(m_hw->dcDownloadFileName()) {
|
, m_fileToDownload(m_hw->dcDownloadFileName()) {
|
||||||
}
|
}
|
||||||
@ -10,25 +12,47 @@ 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();
|
static QString status;
|
||||||
emit hw->hwapi_reportDCDownloadStatus("test");
|
|
||||||
|
|
||||||
qCritical() << "nach emit";
|
int cnt = 5;
|
||||||
QThread::sleep(4);
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
int cnt = 10;
|
|
||||||
while (!m_hw->dcDownloadRunning()) {
|
while (!m_hw->dcDownloadRunning()) {
|
||||||
if (--cnt > 0) {
|
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);
|
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()) {
|
while (m_hw->dcDownloadRunning()) {
|
||||||
uint16_t const cnr = m_hw->dcDownloadGetCurrentBlockNumber();
|
uint16_t const cnr = m_hw->dcDownloadGetCurrentBlockNumber();
|
||||||
@ -44,6 +68,7 @@ void ReportingThread::run() {
|
|||||||
.arg(tnr).arg(cnr);
|
.arg(tnr).arg(cnr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
emit m_hw->hwapi_reportDCDownloadStatus(QString("XXXXX") + QDateTime::currentDateTime().toString(Qt::ISODate));
|
||||||
emit m_hw->hwapi_reportDCDownloadStatus(report);
|
emit m_hw->hwapi_reportDCDownloadStatus(report);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user