Compare commits
14 Commits
1.99.11-1
...
6176285b89
Author | SHA1 | Date | |
---|---|---|---|
6176285b89 | |||
0344150950 | |||
68813a49c5 | |||
8e287e3163 | |||
fd58f41c87 | |||
ece75887e2 | |||
cee4caf77d | |||
6b2830ee83 | |||
cd4bddd169 | |||
8a380c9845 | |||
23619543b2 | |||
be16fe4981 | |||
cf621c02bd | |||
ee26eef50f |
@@ -93,7 +93,9 @@ HEADERS += \
|
||||
$${PWD}/include/sendWRcmd.h \
|
||||
$${PWD}/include/storeINdata.h \
|
||||
$${PWD}/include/tslib.h \
|
||||
$${PWD}/include/shared_mem_buffer.h
|
||||
$${PWD}/include/shared_mem_buffer.h \
|
||||
$${PWD}/include/download_thread.h \
|
||||
$${PWD}/include/reporting_thread.h
|
||||
|
||||
SOURCES += \
|
||||
$${PWD}/src/com.cpp \
|
||||
@@ -107,7 +109,9 @@ SOURCES += \
|
||||
$${PWD}/src/sendWRcmd.cpp \
|
||||
$${PWD}/src/storeINdata.cpp \
|
||||
$${PWD}/src/tslib.cpp \
|
||||
$${PWD}/src/shared_mem_buffer.cpp
|
||||
$${PWD}/src/shared_mem_buffer.cpp \
|
||||
$${PWD}/src/download_thread.cpp \
|
||||
$${PWD}/src/reporting_thread.cpp
|
||||
|
||||
|
||||
# INTERFACE = DeviceController
|
||||
|
@@ -133,8 +133,8 @@
|
||||
#define SENDCOMBINED 0
|
||||
|
||||
|
||||
|
||||
|
||||
class hwinf;
|
||||
class DownloadThread;
|
||||
class T_datif : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -165,13 +165,15 @@ class T_datif : public QObject
|
||||
T_prot *myDCIF;
|
||||
QTimer *datif_trigger;
|
||||
uint8_t selectedSlaveAddr;
|
||||
DownloadThread *m_downloadThread;
|
||||
hwinf *m_hw;
|
||||
|
||||
private slots:
|
||||
char datif_cycleSend();
|
||||
void StoredRecData();
|
||||
|
||||
public:
|
||||
T_datif(QObject *parent = nullptr);
|
||||
T_datif(hwinf *hw, QObject *parent = nullptr);
|
||||
|
||||
void resetChain(void);
|
||||
char isPortOpen(void);
|
||||
|
25
include/download_thread.h
Normal file
25
include/download_thread.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef DOWNLOAD_THREAD_H_INCLUDED
|
||||
#define DOWNLOAD_THREAD_H_INCLUDED
|
||||
|
||||
#include <QThread>
|
||||
#include <QString>
|
||||
|
||||
class hwinf;
|
||||
class DownloadThread : public QThread {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
DownloadThread(hwinf *hw);
|
||||
~DownloadThread();
|
||||
|
||||
protected:
|
||||
// download thread does not have a running event queue, and therefore
|
||||
// no slots. signals work the usual way.
|
||||
void run() override;
|
||||
|
||||
private:
|
||||
hwinf *m_hw;
|
||||
QString m_fileToDownload;
|
||||
};
|
||||
|
||||
#endif // DOWNLOAD_THREAD_H_INCLUDED
|
@@ -40,7 +40,8 @@ V4.0 6.9.2023: activating DC-Bootloader in slve-lib (SM)
|
||||
#include "interfaces.h"
|
||||
#include "shared_mem_buffer.h"
|
||||
#include "runProc.h"
|
||||
|
||||
#include "download_thread.h"
|
||||
#include "reporting_thread.h"
|
||||
|
||||
/*
|
||||
* select Plugin Type here
|
||||
@@ -74,7 +75,8 @@ V4.0 6.9.2023: activating DC-Bootloader in slve-lib (SM)
|
||||
//for CAmaster:
|
||||
|
||||
class QSharedMemory;
|
||||
|
||||
class ReportingThread;
|
||||
class DownloadThread;
|
||||
class hwapi : public QObject,
|
||||
public hwinf
|
||||
{
|
||||
@@ -86,7 +88,8 @@ private:
|
||||
void sub_storeSendingText(QByteArray *buf) const;
|
||||
QTimer *hwapi_TimerPayment;
|
||||
QSharedMemory *m_sharedMem;
|
||||
//QTimer *hwapi_triggerBL;
|
||||
ReportingThread *m_reportingThread;
|
||||
DownloadThread *m_downloadThread;
|
||||
|
||||
public:
|
||||
explicit hwapi(QWidget *parent = nullptr);
|
||||
@@ -1304,8 +1307,28 @@ public:
|
||||
// countOfBills[1] for 10€ and so on
|
||||
|
||||
|
||||
// download device controller
|
||||
void dcDownloadStart() override;
|
||||
void dcDownloadRequest(QString const &fileToDownload) override;
|
||||
bool dcDownloadRequested() const override;
|
||||
QString dcDownloadFileName() const override;
|
||||
void dcDownloadResetRequest() override;
|
||||
void dcDownloadReportStart() override;
|
||||
bool dcDownloadStarted() const override;
|
||||
bool dcDownloadRunning() const override;
|
||||
bool dcDownloadFinished() const override;
|
||||
|
||||
signals:
|
||||
void dcDownloadSetTotalBlockNumber(uint16_t totalBlockNumber) override;
|
||||
void dcDownloadSetCurrentBlockNumber(uint16_t currentBlockNumber) override;
|
||||
uint16_t dcDownloadGetTotalBlockNumber() const override;
|
||||
uint16_t dcDownloadGetCurrentBlockNumber() const override;
|
||||
|
||||
virtual hwapi *getAPI() override;
|
||||
|
||||
signals: // for download
|
||||
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;
|
||||
|
@@ -2,6 +2,7 @@
|
||||
#define INTERFACE_H
|
||||
|
||||
#include <QtPlugin>
|
||||
#include <QString>
|
||||
|
||||
|
||||
|
||||
@@ -397,6 +398,7 @@ struct T_bna
|
||||
|
||||
};
|
||||
|
||||
class hwapi;
|
||||
class hwinf
|
||||
{
|
||||
|
||||
@@ -2273,9 +2275,35 @@ public:
|
||||
// countOfBills[1] for 10€ and so on
|
||||
|
||||
|
||||
// download device controller
|
||||
virtual void dcDownloadStart() {}
|
||||
virtual void dcDownloadRequest(QString const &fileToDownload) {
|
||||
Q_UNUSED(fileToDownload);
|
||||
}
|
||||
virtual bool dcDownloadRequested() const { return false; }
|
||||
virtual void dcDownloadResetRequest() {}
|
||||
virtual QString dcDownloadFileName() const { return ""; }
|
||||
virtual void dcDownloadReportStart() {}
|
||||
virtual void dcDownloadSetTotalBlockNumber(uint16_t totalBlockNumber) {
|
||||
Q_UNUSED(totalBlockNumber);
|
||||
}
|
||||
virtual void dcDownloadSetCurrentBlockNumber(uint16_t currentBlockNumber) {
|
||||
Q_UNUSED(currentBlockNumber);
|
||||
}
|
||||
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; }
|
||||
|
||||
signals: // for download
|
||||
void hwapi_reportDCDownloadStatus(QString const &) const;
|
||||
void hwapi_reportDCDownloadSuccess(QString const &) const;
|
||||
void hwapi_reportDCDownloadFailure(QString const &) const;
|
||||
|
||||
signals:
|
||||
// NOTE: declaring a "pure virtual" "signal" should be an error and thus not valid.
|
||||
void hwapi_templatePrintFinished_OK() const;
|
||||
void hwapi_templatePrintFinished_Err() const;
|
||||
|
25
include/reporting_thread.h
Normal file
25
include/reporting_thread.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef REPORTING_THREAD_H_INCLUDED
|
||||
#define REPORTING_THREAD_H_INCLUDED
|
||||
|
||||
#include <QThread>
|
||||
#include <QString>
|
||||
|
||||
class hwinf;
|
||||
class ReportingThread : public QThread {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ReportingThread(hwinf *hw);
|
||||
~ReportingThread();
|
||||
|
||||
protected:
|
||||
// reporting thread does not have a running event queue, and therefore
|
||||
// no slots. signals work the usual way.
|
||||
void run() override;
|
||||
|
||||
private:
|
||||
hwinf *m_hw;
|
||||
QString m_fileToDownload;
|
||||
};
|
||||
|
||||
#endif // REPORTING_THREAD_H_INCLUDED
|
@@ -301,8 +301,15 @@ struct SharedMem
|
||||
uint8_t p_nextFDcmdsInQueue;
|
||||
|
||||
|
||||
|
||||
|
||||
// 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;
|
||||
} m_downLoadDC;
|
||||
|
||||
|
||||
static QSharedMemory *getShm(std::size_t s = 0);
|
||||
|
@@ -5,6 +5,7 @@ VERSION="1.0.0"
|
||||
include(../DCLibraries.pri)
|
||||
|
||||
DEFINES+=THIS_IS_CA_MASTER
|
||||
DEFINES-=THIS_IS_CA_SLAVE
|
||||
DESTDIR=$${_PRO_FILE_PWD_}/../build
|
||||
|
||||
unix {
|
||||
|
@@ -5,6 +5,8 @@ VERSION="1.0.0"
|
||||
include(../DCLibraries.pri)
|
||||
|
||||
DEFINES+=THIS_IS_CA_SLAVE
|
||||
DEFINES-=THIS_IS_CA_MASTER
|
||||
|
||||
DESTDIR=$${_PRO_FILE_PWD_}/../build
|
||||
|
||||
unix {
|
||||
|
@@ -2,6 +2,9 @@
|
||||
#include "sendWRcmd.h"
|
||||
#include "controlBus.h"
|
||||
#include "storeINdata.h"
|
||||
#include "download_thread.h"
|
||||
#include "hwapi.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <datei.h>
|
||||
#include <QDir>
|
||||
@@ -47,8 +50,10 @@ static uint8_t datif_pNextCmd, datif_sendSlowCmd;
|
||||
//#define DATIF_CTR_GOTRESPVAL 100
|
||||
|
||||
|
||||
T_datif::T_datif(QObject *parent) : QObject(parent)
|
||||
T_datif::T_datif(hwinf *hw, QObject *parent) : QObject(parent)
|
||||
{
|
||||
m_hw = hw;
|
||||
|
||||
QByteArray myBA;
|
||||
QDir myDir("../dmd");
|
||||
|
||||
@@ -198,8 +203,21 @@ char T_datif::datif_cycleSend()
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (m_hw->dcDownloadRequested()) { // only happens in ca-master
|
||||
m_hw->dcDownloadResetRequest();
|
||||
|
||||
// start download-thread.
|
||||
m_downloadThread = new DownloadThread(m_hw);
|
||||
m_downloadThread->start();
|
||||
|
||||
int cnt = 10;
|
||||
while (--cnt > 0 && !m_downloadThread->isRunning()) {
|
||||
QThread::msleep(100);
|
||||
}
|
||||
if (cnt <= 0) {
|
||||
qCritical() << "DOWNLOAD-THREAD NOT RUNNING WITHIN 1000ms";
|
||||
}
|
||||
}
|
||||
|
||||
// 17.7.2023: repeat commands if result was !=OK -------------------------------------------------------------------
|
||||
if (datif_cmdWasPerformed==2 && doRepeat) // Cmd was not or false performed und Wiederholen erwuenscht
|
||||
|
21
src/download_thread.cpp
Normal file
21
src/download_thread.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#include "download_thread.h"
|
||||
#include "shared_mem_buffer.h"
|
||||
#include "hwapi.h"
|
||||
|
||||
DownloadThread::DownloadThread(hwinf *hw)
|
||||
: m_hw(hw)
|
||||
, m_fileToDownload(m_hw->dcDownloadFileName()) {
|
||||
}
|
||||
|
||||
DownloadThread::~DownloadThread() {
|
||||
}
|
||||
|
||||
// download thread running in ca-master sends the dc-file down to firmware
|
||||
void DownloadThread::run() {
|
||||
// m_hw->dcDownloadInit(m_fileToDownload);
|
||||
|
||||
// hier dann den eigentlichen download-process eintragen
|
||||
|
||||
// m_hw->dcDownloadGetCurrentBlockNumber(currentBlockNumber);
|
||||
// m_hw->dcDownloadGetTotalBlockNumber(totalBlockNumber);
|
||||
}
|
@@ -20,6 +20,11 @@
|
||||
*/
|
||||
|
||||
#include "hwapi.h"
|
||||
#include "reporting_thread.h"
|
||||
#include "download_thread.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
|
||||
static uint32_t hwapi_lastStartAmount;
|
||||
static uint32_t hwapi_lastTotalAmount;
|
||||
@@ -49,7 +54,7 @@ hwapi::hwapi(QWidget *parent) : QObject(parent)
|
||||
// {
|
||||
|
||||
#ifdef THIS_IS_CA_MASTER
|
||||
myDatif = new T_datif(); // für die CAslave-Lib auskommentieren!
|
||||
myDatif = new T_datif(this); // für die CAslave-Lib auskommentieren!
|
||||
#else
|
||||
qCritical()<<"hwapi: error CAslave cannot include T_datif";
|
||||
#endif
|
||||
@@ -4371,4 +4376,73 @@ uint16_t hwapi::bna_getStackerLevel(uint32_t *amountInStacker, uint16_t *countOf
|
||||
return anzahl;
|
||||
}
|
||||
|
||||
hwapi *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);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
bool hwapi::dcDownloadRequested() const {
|
||||
return SharedMem::getDataConst()->m_downLoadDC.m_started;
|
||||
}
|
||||
|
||||
void hwapi::dcDownloadResetRequest() {
|
||||
SharedMem::getData()->m_downLoadDC.m_started = false;
|
||||
}
|
||||
|
||||
QString hwapi::dcDownloadFileName() const {
|
||||
return SharedMem::getDataConst()->m_downLoadDC.m_filename;
|
||||
}
|
||||
|
||||
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 {
|
||||
return SharedMem::getDataConst()->m_downLoadDC.m_totalBlocks;
|
||||
}
|
||||
|
||||
uint16_t hwapi::dcDownloadGetCurrentBlockNumber() const {
|
||||
return SharedMem::getDataConst()->m_downLoadDC.m_currentblockNumber;
|
||||
}
|
||||
|
||||
bool hwapi::dcDownloadStarted() const {
|
||||
return SharedMem::getDataConst()->m_downLoadDC.m_started;
|
||||
}
|
||||
|
||||
bool hwapi::dcDownloadRunning() const {
|
||||
return SharedMem::getDataConst()->m_downLoadDC.m_running;
|
||||
|
||||
}
|
||||
|
||||
bool hwapi::dcDownloadFinished() const {
|
||||
return SharedMem::getDataConst()->m_downLoadDC.m_finished;
|
||||
}
|
||||
|
62
src/reporting_thread.cpp
Normal file
62
src/reporting_thread.cpp
Normal file
@@ -0,0 +1,62 @@
|
||||
#include "reporting_thread.h"
|
||||
#include "shared_mem_buffer.h"
|
||||
#include "hwapi.h"
|
||||
|
||||
ReportingThread::ReportingThread(hwinf *hw)
|
||||
: m_hw(hw)
|
||||
, m_fileToDownload(m_hw->dcDownloadFileName()) {
|
||||
}
|
||||
|
||||
ReportingThread::~ReportingThread() {
|
||||
}
|
||||
|
||||
// download thread running in ca-slave sends reports download process to
|
||||
// update tool
|
||||
void ReportingThread::run() {
|
||||
hwapi *hw = m_hw->getAPI();
|
||||
emit hw->hwapi_reportDCDownloadStatus("test");
|
||||
|
||||
qCritical() << "nach emit";
|
||||
QThread::sleep(4);
|
||||
|
||||
#if 0
|
||||
int cnt = 10;
|
||||
while (!m_hw->dcDownloadRunning()) {
|
||||
if (--cnt > 0) {
|
||||
QThread::sleep(1);
|
||||
}
|
||||
}
|
||||
if (cnt == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
while (m_hw->dcDownloadRunning()) {
|
||||
uint16_t const cnr = m_hw->dcDownloadGetCurrentBlockNumber();
|
||||
uint16_t const tnr = m_hw->dcDownloadGetTotalBlockNumber();
|
||||
|
||||
QString report("");
|
||||
|
||||
if (cnr > 0) {
|
||||
report = QString("total blocks %1, current block %2 [%3]")
|
||||
.arg(tnr).arg(cnr).arg((double)(tnr)/(double(cnr)));
|
||||
} else {
|
||||
report = QString("total blocks %1, current block %2 [0]")
|
||||
.arg(tnr).arg(cnr);
|
||||
}
|
||||
|
||||
emit m_hw->hwapi_reportDCDownloadStatus(report);
|
||||
}
|
||||
|
||||
uint16_t const cnr = m_hw->dcDownloadGetCurrentBlockNumber();
|
||||
uint16_t const tnr = m_hw->dcDownloadGetTotalBlockNumber();
|
||||
|
||||
if (tnr == cnr) {
|
||||
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(tnr).arg(cnr));
|
||||
}
|
||||
#endif
|
||||
}
|
Reference in New Issue
Block a user