Compare commits

..

10 Commits

8 changed files with 458 additions and 15 deletions

View File

@ -21,14 +21,15 @@ INCLUDEPATH += ../include
win32 {
BUILD_DATE=$$system("date /t")
BUILD_TIME=$$system("time /t")
GIT_COMMIT=""
EXTENDED_VERSION=""
} else {
BUILD_DATE=$$system("date +%d-%m-%y")
BUILD_TIME=$$system("date +%H:%M:%S")
GIT_COMMIT=$$system("git log -1 --format=oneline | cut -d' ' -f1")
EXTENDED_VERSION="$${VERSION}-$${GIT_COMMIT}"
}
GIT_COMMIT=$$system("git log -1 --format=oneline | cut -d' ' -f1")
EXTENDED_VERSION="$${VERSION}-$${GIT_COMMIT}"
DEFINES+=APP_VERSION=\\\"$$VERSION\\\"
DEFINES+=APP_BUILD_DATE=\\\"$$BUILD_DATE\\\"

View File

@ -25,15 +25,16 @@ INCLUDEPATH += ../include
win32 {
BUILD_DATE=$$system("date /t")
BUILD_TIME=$$system("time /t")
GIT_COMMIT=""
EXTENDED_VERSION=""
} else {
BUILD_DATE=$$system("date +%d-%m-%y")
BUILD_TIME=$$system("date +%H:%M:%S")
GIT_COMMIT=$$system("git log -1 --format=oneline | cut -d' ' -f1")
EXTENDED_VERSION="$${VERSION}-$${GIT_COMMIT}"
}
GIT_COMMIT=$$system("git log -1 --format=oneline | cut -d' ' -f1")
EXTENDED_VERSION="$${VERSION}-$${GIT_COMMIT}"
DEFINES+=APP_VERSION=\\\"$$VERSION\\\"
DEFINES+=APP_BUILD_DATE=\\\"$$BUILD_DATE\\\"
DEFINES+=APP_BUILD_TIME=\\\"$$BUILD_TIME\\\"

View File

@ -80,7 +80,8 @@ V4.0 6.9.2023: activating DC-Bootloader in slve-lib (SM)
class QSharedMemory;
class DownloadThread;
class ReportingThread;
class hwapi : public QObject,
public hwinf
{
@ -92,6 +93,8 @@ private:
void sub_storeSendingText(QByteArray *buf) const;
QTimer *hwapi_TimerPayment;
QSharedMemory *m_sharedMem;
ReportingThread *m_reportingThread;
DownloadThread *m_downloadThread;
//QTimer *hwapi_triggerBL;
public:
@ -1316,10 +1319,47 @@ public:
// countOfBills: array of up to 16 sums, countOfBills[0]=nr of 5€-bills in stacker
// countOfBills[1] for 10€ and so on
// download device controller
bool dcDownloadRequest(QString const &fileToDownload) const override;
bool dcDownloadRequested() const override;
bool dcDownloadResetRequest() const override;
bool dcDownloadRequestAck() const override;
bool dcDownloadRunning() const override;
bool dcDownloadFinished() override;
bool dcDownloadReportStart() const override;
bool dcDownloadReportRunning() const override;
bool dcDownloadReportFinished() override;
bool dcDownloadThreadStart() override;
bool dcDownloadThreadRunning() const override;
void dcDownloadThreadFinalize(DownloadThread *) override;
bool dcDownloadThreadFinished() const override;
bool dcDownloadReportThreadStart() override;
bool dcDownloadReportThreadRunning() const override;
void dcDownloadReportThreadFinalize() override;
void dcDownloadReportThreadQuit() override;
bool dcDownloadReportThreadFinished() const override;
QString dcDownloadFileName() const override;
bool dcDownloadSetRequested(bool) override;
bool dcDownloadSetRunning(bool) override;
bool dcDownloadSetFinished(bool) override;
void dcDownloadSetTotalBlockNumber(uint16_t totalBlockNumber) override;
void dcDownloadSetCurrentBlockNumber(uint16_t currentBlockNumber) override;
bool dcDownloadGetRequested() const override;
bool dcDownloadGetRunning() const override;
bool dcDownloadGetFinished() const override;
uint16_t dcDownloadGetTotalBlockNumber() const override;
uint16_t dcDownloadGetCurrentBlockNumber() const override;
virtual QObject const *getAPI() override;
signals:
void hwapi_reportDCDownloadStatus(QString const&) const;
void hwapi_reportDCDownloadSuccess(QString const&) const;
void hwapi_reportDCDownloadFailure(QString const&) const;
void hwapi_templatePrintFinished_OK(void) const override;
void hwapi_templatePrintFinished_Err(void) const override;

View File

@ -414,6 +414,7 @@ struct T_bna
};
class DownloadThread;
class hwinf
{
@ -2299,9 +2300,73 @@ public:
// countOfBills[1] for 10€ and so on
// download device controller
virtual bool dcDownloadRequest(QString const &fileToDownload) const {
Q_UNUSED(fileToDownload);
return false;
}
virtual bool dcDownloadRequested() const { return false; }
virtual bool dcDownloadResetRequest() const { return false; }
virtual bool dcDownloadRequestAck() const { return false; }
virtual bool dcDownloadRunning() const { return false; }
virtual bool dcDownloadFinished() { return false; }
virtual bool dcDownloadReportStart() const { return false; }
virtual bool dcDownloadReportRunning() const { return true; }
virtual bool dcDownloadReportFinished() { return true; }
virtual bool dcDownloadThreadStart() { return false; }
virtual bool dcDownloadThreadRunning() const { return true; }
virtual void dcDownloadThreadFinalize(DownloadThread *) {}
virtual bool dcDownloadThreadFinished() const { return true; }
virtual bool dcDownloadReportThreadStart() { return false; }
virtual bool dcDownloadReportThreadRunning() const { return true; }
virtual void dcDownloadReportThreadFinalize() {}
virtual void dcDownloadReportThreadQuit() {}
virtual bool dcDownloadReportThreadFinished() const { return true; }
virtual QString dcDownloadFileName() const { return ""; }
virtual bool dcDownloadSetRequested(bool requested) {
Q_UNUSED(requested); return false;
}
virtual bool dcDownloadSetRunning(bool running) {
Q_UNUSED(running); return false;
}
virtual bool dcDownloadSetFinished(bool finished) {
Q_UNUSED(finished); return false;
}
virtual void dcDownloadSetTotalBlockNumber(uint16_t totalBlockNumber) {
Q_UNUSED(totalBlockNumber);
}
virtual void dcDownloadSetCurrentBlockNumber(uint16_t currentBlockNumber) {
Q_UNUSED(currentBlockNumber);
}
virtual bool dcDownloadGetRequested() const { return false; }
virtual bool dcDownloadGetRunning() const { return false; }
virtual bool dcDownloadGetFinished() const { return false; }
virtual uint16_t dcDownloadGetTotalBlockNumber() const { return 0; }
virtual uint16_t dcDownloadGetCurrentBlockNumber() const { return 0; }
virtual QObject const *getAPI() { return nullptr; }
signals:
/*
NOTE: the difference between a virtual Qt signal and a normal Qt signal:
A Qt virtual signal is a connection that is established using a pointer
or reference and is not connected to an object or data. It is therefore
not bound to a particular object, but to a specific class (object type).
Qt virtual signals are useful because they allow you to create
connections without worrying about whether an object or a specific data
element has been destroyed.
https://www.youtube.com/watch?v=HTH3VFfqsXw
*/
virtual void hwapi_reportDCDownloadStatus(QString const&) const {}
virtual void hwapi_reportDCDownloadSuccess(QString const&) const {}
virtual void hwapi_reportDCDownloadFailure(QString const&) const {}
virtual void hwapi_templatePrintFinished_OK(void) const=0;
virtual void hwapi_templatePrintFinished_Err(void) const=0;

View File

@ -300,9 +300,26 @@ struct SharedMem
uint8_t p_nextFDcmdsInQueue;
// download of device controller and json files
struct DCDownload {
enum class FILE_INDEX {
DC_BINARY = 0, DC2C_CASH = 1, DC2C_CONF = 2, DC2C_SERIAL=3,
DC2C_PRINT_01, DC2C_PRINT_02, DC2C_PRINT_03, DC2C_PRINT_04,
DC2C_PRINT_05, DC2C_PRINT_06, DC2C_PRINT_07, DC2C_PRINT_08,
DC2C_PRINT_09, DC2C_PRINT_10, DC2C_PRINT_11, DC2C_PRINT_12,
DC2C_PRINT_13, DC2C_PRINT_14, DC2C_PRINT_15, DC2C_PRINT_16,
DC2C_PRINT_17, DC2C_PRINT_18, DC2C_PRINT_19, DC2C_PRINT_20,
DC2C_PRINT_21, DC2C_PRINT_22, DC2C_PRINT_23, DC2C_PRINT_24,
DC2C_PRINT_25, DC2C_PRINT_26, DC2C_PRINT_27, DC2C_PRINT_28,
DC2C_PRINT_29, DC2C_PRINT_30, DC2C_PRINT_31, DC2C_PRINT_32
};
char m_filename[(int)FILE_INDEX::DC2C_PRINT_32][512];
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);

View File

@ -1,19 +1,40 @@
TEMPLATE = lib
TARGET = CAmaster
VERSION="1.0.0"
VERSION="1.0.1"
HEADERS += \
../include/com.h \
../include/datIf.h \
../include/prot.h
../include/prot.h \
../include/download_thread.h
SOURCES += \
../src/com.cpp \
../src/datIf.cpp \
../src/prot.cpp
../src/prot.cpp \
../src/download_thread.cpp
include(../DCLibraries.pri)
win32 {
BUILD_DATE=$$system("date /t")
BUILD_TIME=$$system("time /t")
GIT_COMMIT=""
EXTENDED_VERSION=""
EXTENDED_VERSION_LIB=""
} else {
BUILD_DATE=$$system("date +%d-%m-%y")
BUILD_TIME=$$system("date +%H:%M:%S")
GIT_COMMIT=$$system("git log -1 --format=oneline . | cut -d' ' -f1")
EXTENDED_VERSION_LIB="libCAmaster-$${VERSION}-$${GIT_COMMIT}"
}
DEFINES+=APP_VERSION=\\\"$$VERSION\\\"
DEFINES+=APP_BUILD_DATE=\\\"$$BUILD_DATE\\\"
DEFINES+=APP_BUILD_TIME=\\\"$$BUILD_TIME\\\"
DEFINES+=APP_EXTENDED_VERSION=\\\"$$EXTENDED_VERSION\\\"
DEFINES+=APP_EXTENDED_VERSION_LIB=\\\"$$EXTENDED_VERSION_LIB\\\"
DEFINES+=THIS_IS_CA_MASTER
DESTDIR=$${_PRO_FILE_PWD_}/../build

View File

@ -1,9 +1,35 @@
TEMPLATE = lib
TARGET = CAslave
VERSION="1.0.0"
VERSION="1.0.1"
HEADERS += \
../include/reporting_thread.h
SOURCES += \
../src/reporting_thread.cpp
include(../DCLibraries.pri)
win32 {
BUILD_DATE=$$system("date /t")
BUILD_TIME=$$system("time /t")
GIT_COMMIT=""
EXTENDED_VERSION=""
EXTENDED_VERSION_LIB=""
} else {
BUILD_DATE=$$system("date +%d-%m-%y")
BUILD_TIME=$$system("date +%H:%M:%S")
GIT_COMMIT=$$system("git log -1 --format=oneline . | cut -d' ' -f1")
EXTENDED_VERSION_LIB_="libCAslave-$${VERSION}-$${GIT_COMMIT}"
}
DEFINES+=APP_VERSION=\\\"$$VERSION\\\"
DEFINES+=APP_BUILD_DATE=\\\"$$BUILD_DATE\\\"
DEFINES+=APP_BUILD_TIME=\\\"$$BUILD_TIME\\\"
DEFINES+=APP_EXTENDED_VERSION=\\\"$$EXTENDED_VERSION\\\"
DEFINES+=APP_EXTENDED_VERSION_LIB=\\\"$$EXTENDED_VERSION_LIB\\\"
DEFINES+=THIS_IS_CA_SLAVE
DESTDIR=$${_PRO_FILE_PWD_}/../build

View File

@ -20,6 +20,13 @@
*/
#include "hwapi.h"
#include "download_thread.h"
#include "reporting_thread.h"
#include <cstring>
#include <QThread>
#include <QDebug>
static uint32_t hwapi_lastStartAmount;
static uint32_t hwapi_lastTotalAmount;
@ -33,6 +40,12 @@ static uint8_t bl_startupStep;
hwapi::hwapi(QWidget *parent) : QObject(parent)
{
// constructor
qCritical() << " hwapi::hwapi() APP_VERSION:" << APP_VERSION;
qCritical() << " hwapi::hwapi() APP_BUILD_DATE:" << APP_BUILD_DATE;
qCritical() << " hwapi::hwapi() APP_BUILD_TIME:" << APP_BUILD_TIME;
qCritical() << " hwapi::hwapi() APP_EXTENDED_VERSION:" << APP_EXTENDED_VERSION;
qCritical() << "hwapi::hwapi() APP_EXTENDED_VERSION_LIB:" << APP_EXTENDED_VERSION_LIB;
// create or attach shared memory segment
m_sharedMem = SharedMem::getShm(sizeof(SharedMem));
@ -4394,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;
}