Save as changing to master.

This commit is contained in:
2023-12-06 14:53:52 +01:00
parent 6176285b89
commit 2025a75d56
6 changed files with 145 additions and 67 deletions

View File

@@ -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;
}

View File

@@ -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);
}