forked from GerhardHoffmann/DCLibraries
Add implementations for helpers for downloading device controller.
NOTE : They are not called at the moment.
This commit is contained in:
parent
490fdd9209
commit
a344ba1b7d
259
src/hwapi.cpp
259
src/hwapi.cpp
@ -4407,4 +4407,263 @@ uint16_t hwapi::bna_getStackerLevel(uint32_t *amountInStacker, uint16_t *countOf
|
||||
return anzahl;
|
||||
}
|
||||
|
||||
QObject const *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[(int)SharedMem::DCDownload::FILE_INDEX::DC_BINARY];
|
||||
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));
|
||||
|
||||
data->m_downLoadDC.m_totalBlocks = 0;
|
||||
data->m_downLoadDC.m_currentblockNumber = 0;
|
||||
|
||||
data->m_downLoadDC.m_requested = true;
|
||||
data->m_downLoadDC.m_running = false; // download thread is not running
|
||||
data->m_downLoadDC.m_finished = true;
|
||||
|
||||
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() const {
|
||||
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 {
|
||||
SharedMem const *data = SharedMem::getDataConst();
|
||||
return data ? data->m_downLoadDC.m_filename[(int)SharedMem::DCDownload::FILE_INDEX::DC_BINARY] : "";
|
||||
}
|
||||
|
||||
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) {
|
||||
SharedMem::getData()->m_downLoadDC.m_totalBlocks = totalBlockNumber;
|
||||
}
|
||||
|
||||
void hwapi::dcDownloadSetCurrentBlockNumber(uint16_t currentBlockNumber) {
|
||||
SharedMem::getData()->m_downLoadDC.m_currentblockNumber = currentBlockNumber;
|
||||
}
|
||||
|
||||
uint16_t hwapi::dcDownloadGetTotalBlockNumber() const {
|
||||
SharedMem const *data = SharedMem::getDataConst();
|
||||
return data ? data->m_downLoadDC.m_totalBlocks.load() : 0;
|
||||
}
|
||||
|
||||
uint16_t hwapi::dcDownloadGetCurrentBlockNumber() const {
|
||||
SharedMem const *data = SharedMem::getDataConst();
|
||||
return data ? data->m_downLoadDC.m_currentblockNumber.load() : 0;
|
||||
}
|
||||
|
||||
bool hwapi::dcDownloadGetRequested() const {
|
||||
SharedMem const *data = SharedMem::getDataConst();
|
||||
return data ? data->m_downLoadDC.m_requested.load() : 0;
|
||||
}
|
||||
|
||||
bool hwapi::dcDownloadGetRunning() const {
|
||||
SharedMem const *data = SharedMem::getDataConst();
|
||||
return data ? data->m_downLoadDC.m_running.load() : 0;
|
||||
}
|
||||
|
||||
bool hwapi::dcDownloadGetFinished() const {
|
||||
SharedMem const *data = SharedMem::getDataConst();
|
||||
return data ? data->m_downLoadDC.m_running.load() : 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user