From 74753ce644dd4b0b1a10c51f2d2bb221c2205404 Mon Sep 17 00:00:00 2001 From: Siegfried Siegert Date: Mon, 19 Jun 2023 15:06:04 +0200 Subject: [PATCH 1/6] Add utils-class for static utils methods --- DCPlugin.pro | 6 ++++-- src/ATBAPP/Utils.cpp | 18 ++++++++++++++++++ src/ATBAPP/Utils.h | 23 +++++++++++++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 src/ATBAPP/Utils.cpp create mode 100644 src/ATBAPP/Utils.h diff --git a/DCPlugin.pro b/DCPlugin.pro index eeead9b..ee20c98 100644 --- a/DCPlugin.pro +++ b/DCPlugin.pro @@ -73,11 +73,13 @@ HEADERS += \ src/ATBAPP/ATBAPPplugin.h \ src/ATBAPP/DeviceControllerInterface.h \ src/ATBAPP/ATBHealthEvent.h \ - src/ATBAPP/ATBDeviceControllerPlugin.h + src/ATBAPP/ATBDeviceControllerPlugin.h \ + src/ATBAPP/Utils.h SOURCES += \ src/ATBAPP/ATBHealthEvent.cpp \ - src/ATBAPP/ATBDeviceControllerPlugin.cpp + src/ATBAPP/ATBDeviceControllerPlugin.cpp \ + src/ATBAPP/Utils.cpp DISTFILES += \ generate-version.sh diff --git a/src/ATBAPP/Utils.cpp b/src/ATBAPP/Utils.cpp new file mode 100644 index 0000000..1280441 --- /dev/null +++ b/src/ATBAPP/Utils.cpp @@ -0,0 +1,18 @@ +#include "Utils.h" + +Utils::Utils(QObject *parent) : QObject(parent) +{ + +} + + + +int Utils::compare(const void* a, const void* b) +{ + int int_a = * ( (int*) a ); + int int_b = * ( (int*) b ); + + if ( int_a == int_b ) return 0; + else if ( int_a < int_b ) return -1; + else return 1; +} diff --git a/src/ATBAPP/Utils.h b/src/ATBAPP/Utils.h new file mode 100644 index 0000000..be71871 --- /dev/null +++ b/src/ATBAPP/Utils.h @@ -0,0 +1,23 @@ +#ifndef UTILS_H +#define UTILS_H + +#include + + +class Utils : public QObject +{ + Q_OBJECT +public: + static int compare(const void* a, const void* b); + +private: + explicit Utils(QObject *parent = nullptr); + + + + +signals: + +}; + +#endif // UTILS_H From 414dda009e1fee52d44cdbaf051fada7b856b1f3 Mon Sep 17 00:00:00 2001 From: Siegfried Siegert Date: Mon, 19 Jun 2023 16:26:33 +0200 Subject: [PATCH 2/6] Proposal for getting account data from CAlib/DeviceController --- src/ATBAPP/ATBDeviceControllerPlugin.cpp | 81 +++++++++++++++++++----- src/ATBAPP/ATBDeviceControllerPlugin.h | 9 +++ 2 files changed, 74 insertions(+), 16 deletions(-) diff --git a/src/ATBAPP/ATBDeviceControllerPlugin.cpp b/src/ATBAPP/ATBDeviceControllerPlugin.cpp index 46eeba9..d17d84b 100644 --- a/src/ATBAPP/ATBDeviceControllerPlugin.cpp +++ b/src/ATBAPP/ATBDeviceControllerPlugin.cpp @@ -1,5 +1,6 @@ #include "src/ATBAPP/ATBDeviceControllerPlugin.h" #include "src/ATBAPP/ATBHealthEvent.h" +#include "src/ATBAPP/Utils.h" #include #include @@ -9,6 +10,9 @@ #include #include +#include + + ATBDeviceControllerPlugin::ATBDeviceControllerPlugin(QObject *parent) : QObject(parent), pluginState(PLUGIN_STATE::NOT_INITIALIZED) @@ -135,7 +139,65 @@ void ATBDeviceControllerPlugin::cashAbort() // for an external account request, e.g. by an ui-button: void ATBDeviceControllerPlugin::requestAccount() { - qCritical() << "TODO: implement ATBDeviceControllerPlugin::requestAccount()"; + qCritical() << "ATBDeviceControllerPlugin::requestAccount()"; + + this->private_startAccount(); +} + +void ATBDeviceControllerPlugin::private_startAccount() +{ + uint16_t backupedAccNumbers[8]; // array of account numbers + uint8_t nrOfVals; // number of saved accounts + + // it is not defined which one is the latest account + hw->log_getHoldAccountNumbers(&nrOfVals, backupedAccNumbers); + + qsort( backupedAccNumbers, nrOfVals, sizeof (uint16_t), Utils::compare ); + + uint16_t latestAccountNumber = backupedAccNumbers[nrOfVals-1]; + + hw->log_selectVaultRecord(latestAccountNumber); + + this->accountCheckCounter = 0; + QTimer::singleShot(500, this, SLOT(private_checkAccountData())); +} + +void ATBDeviceControllerPlugin::private_checkAccountData() +{ + if (hw->log_chkIfVaultRecordAvailable()) { + this->private_getAccountData(); + } + else { + if (this->accountCheckCounter < 10) { + this->accountCheckCounter++; + QTimer::singleShot(500, this, SLOT(private_checkAccountData())); + } + else { + // cannot get accountData within ~10*500ms + qCritical() << "checkAccountData() failed"; + + // TODO: create and send an HealthEvent... + } + } +} + + +void ATBDeviceControllerPlugin::private_getAccountData() +{ + struct T_vaultRecord retVR; + + hw->log_getVaultRecord(&retVR); + + QHash accountData; + + accountData.insert("AccountingNumber", QString::number(retVR.AccountingNumber)); + + for (uint i = 0; i < sizeof(retVR.coinsInVault); ++i) { + accountData.insert("COIN_" + QString::number(i) + "_Quantity", retVR.coinsInVault[i]); + accountData.insert("COIN_" + QString::number(i) + "_Value", retVR.coinDenomination[i]); + } + + emit requestAccountResponse(accountData); } @@ -161,20 +223,9 @@ void ATBDeviceControllerPlugin::onVaultDoorOpened() void ATBDeviceControllerPlugin::onCoinBoxRemoved() { - hw->log_selectVaultRecord(0); - - // TODO: - // - create and send account (-> requestAccountResponse()) - - // account: - // collect account data - QHash accountData; - - // send account - // -> currently skipped: emit this->requestAccountResponse(accountData); - - qCritical() << "ATBDeviceControllerPlugin::onCoinBoxRemoved()"; + + this->private_startAccount(); } void ATBDeviceControllerPlugin::onCoinBoxInserted() @@ -603,8 +654,6 @@ const QString ATBDeviceControllerPlugin::getString(nsDeviceControllerInterface:: } - - /************************************************************************************************ * ... end */ diff --git a/src/ATBAPP/ATBDeviceControllerPlugin.h b/src/ATBAPP/ATBDeviceControllerPlugin.h index c48b6cb..7ffc9bd 100644 --- a/src/ATBAPP/ATBDeviceControllerPlugin.h +++ b/src/ATBAPP/ATBDeviceControllerPlugin.h @@ -129,6 +129,10 @@ private: nsDeviceControllerInterface::CASH_STATE currentCashState; + // counts failed hw->log_chkIfVaultRecordAvailable() + int accountCheckCounter; + + private slots: // printer @@ -152,6 +156,11 @@ private slots: void onCoinBoxRemoved(); void onCoinBoxInserted(); void onAllDoorsClosed(); + + // account handling + void private_startAccount(); + void private_checkAccountData(); + void private_getAccountData(); }; #endif // ATBDEVICECONTROLLERPLUGIN_H From 1467530e3c469404bca4778ef5aae4ef8c394a3d Mon Sep 17 00:00:00 2001 From: Siegfried Siegert Date: Mon, 19 Jun 2023 16:27:20 +0200 Subject: [PATCH 3/6] Add debug output for account request --- src/ATBAPP/ATBDeviceControllerPlugin.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/ATBAPP/ATBDeviceControllerPlugin.cpp b/src/ATBAPP/ATBDeviceControllerPlugin.cpp index d17d84b..6e5b546 100644 --- a/src/ATBAPP/ATBDeviceControllerPlugin.cpp +++ b/src/ATBAPP/ATBDeviceControllerPlugin.cpp @@ -152,10 +152,21 @@ void ATBDeviceControllerPlugin::private_startAccount() // it is not defined which one is the latest account hw->log_getHoldAccountNumbers(&nrOfVals, backupedAccNumbers); + // DEBUG + qCritical() << "Start account: "; + qCritical() << " nrOfVals = " << nrOfVals; + for (int i=0; i private_checkAccountData()"; + if (hw->log_chkIfVaultRecordAvailable()) { this->private_getAccountData(); } @@ -184,6 +198,9 @@ void ATBDeviceControllerPlugin::private_checkAccountData() void ATBDeviceControllerPlugin::private_getAccountData() { + // DEBUG + qCritical() << " --> private_getAccountData()"; + struct T_vaultRecord retVR; hw->log_getVaultRecord(&retVR); @@ -195,6 +212,10 @@ void ATBDeviceControllerPlugin::private_getAccountData() for (uint i = 0; i < sizeof(retVR.coinsInVault); ++i) { accountData.insert("COIN_" + QString::number(i) + "_Quantity", retVR.coinsInVault[i]); accountData.insert("COIN_" + QString::number(i) + "_Value", retVR.coinDenomination[i]); + + // DEBUG + qCritical() << "COIN_" + QString::number(i) + "_Quantity = " << accountData["COIN_" + QString::number(i) + "_Quantity"]; + qCritical() << "COIN_" + QString::number(i) + "_Value = " << accountData["COIN_" + QString::number(i) + "_Value"]; } emit requestAccountResponse(accountData); From 2b71705c81c64eacc14edb3d9de6d1340ccd518c Mon Sep 17 00:00:00 2001 From: Siegfried Siegert Date: Tue, 20 Jun 2023 13:11:40 +0200 Subject: [PATCH 4/6] Update interface: DeviceControllerInterface is derived from QObject: This is for using new connect()-syntax in main application. Note: - signals in interface must not be defined virtual - signals in implementation must not override signals defined in interface. --- src/ATBAPP/ATBDeviceControllerPlugin.cpp | 4 +++- src/ATBAPP/ATBDeviceControllerPlugin.h | 29 +----------------------- src/ATBAPP/DeviceControllerInterface.h | 28 ++++++++++++----------- 3 files changed, 19 insertions(+), 42 deletions(-) diff --git a/src/ATBAPP/ATBDeviceControllerPlugin.cpp b/src/ATBAPP/ATBDeviceControllerPlugin.cpp index 6e5b546..88083e0 100644 --- a/src/ATBAPP/ATBDeviceControllerPlugin.cpp +++ b/src/ATBAPP/ATBDeviceControllerPlugin.cpp @@ -14,9 +14,11 @@ -ATBDeviceControllerPlugin::ATBDeviceControllerPlugin(QObject *parent) : QObject(parent), +ATBDeviceControllerPlugin::ATBDeviceControllerPlugin(QObject *parent) : pluginState(PLUGIN_STATE::NOT_INITIALIZED) { + this->setParent(parent); + this->pluginInfo = QString::fromUtf8(pluginInfoString.c_str()); if (!this->private_loadCashAgentLib("")) { diff --git a/src/ATBAPP/ATBDeviceControllerPlugin.h b/src/ATBAPP/ATBDeviceControllerPlugin.h index 7ffc9bd..3e36777 100644 --- a/src/ATBAPP/ATBDeviceControllerPlugin.h +++ b/src/ATBAPP/ATBDeviceControllerPlugin.h @@ -24,7 +24,7 @@ using namespace nsDeviceControllerInterface; class QSettings; -class ATBDeviceControllerPlugin : public QObject, +class ATBDeviceControllerPlugin : public DeviceControllerInterface { Q_OBJECT @@ -75,33 +75,6 @@ public slots: signals: - void printTicketFinished(nsDeviceControllerInterface::RESULT_STATE resultState, - const QString & errorCode, - const QString & errorDescription); - - void cashInputEvent(nsDeviceControllerInterface::RESULT_STATE resultState, - nsDeviceControllerInterface::CASH_STATE cashState, - const QString & newCashValue, - const QString & errorCode, - const QString & errorDescription); - - void cashInputFinished(nsDeviceControllerInterface::RESULT_STATE resultState, - const QString & newCashValue, - const QString & errorCode, - const QString & errorDescription); - - void requestModeSERVICE(); - void requestModeIDLE(); - void requestModeOOO(); - - void requestAccountResponse(const QHash & accountData); - - - - void Error( - const QString & errorCode, - const QString & errorDescription); - diff --git a/src/ATBAPP/DeviceControllerInterface.h b/src/ATBAPP/DeviceControllerInterface.h index 094f2ad..72278ab 100644 --- a/src/ATBAPP/DeviceControllerInterface.h +++ b/src/ATBAPP/DeviceControllerInterface.h @@ -15,8 +15,10 @@ namespace nsDeviceControllerInterface { } -class DeviceControllerInterface : public ATBAPPplugin +class DeviceControllerInterface : public QObject + , public ATBAPPplugin { + Q_OBJECT Q_INTERFACES(ATBAPPplugin) public: @@ -71,19 +73,19 @@ public slots: virtual void onChangedProgramModeToOOO() = 0; signals: - virtual void printTicketFinished(nsDeviceControllerInterface::RESULT_STATE resultState, + void printTicketFinished(nsDeviceControllerInterface::RESULT_STATE resultState, const QString & errorCode, - const QString & errorDescription) = 0; + const QString & errorDescription); /** * emitted on e.g. a coin input */ - virtual void cashInputEvent(nsDeviceControllerInterface::RESULT_STATE resultState, + void cashInputEvent(nsDeviceControllerInterface::RESULT_STATE resultState, nsDeviceControllerInterface::CASH_STATE cashState, const QString & newCashValue, /* additional variables? */ const QString & errorCode, - const QString & errorDescription) = 0; + const QString & errorDescription); /** * emitted if cashInput has been stopped, e.g. in result to task requestStopCashInput(): @@ -91,32 +93,32 @@ signals: * -> no cash input is possible * -> coins are in cache */ - virtual void cashInputFinished(nsDeviceControllerInterface::RESULT_STATE resultState, + void cashInputFinished(nsDeviceControllerInterface::RESULT_STATE resultState, const QString & newCashValue, /* additional variables? */ const QString & errorCode, - const QString & errorDescription) = 0; + const QString & errorDescription); /** * emitted e.g. if service door is opened */ - virtual void requestModeSERVICE() = 0; + void requestModeSERVICE(); /** * emitted e.g. if doors are closed */ - virtual void requestModeIDLE() = 0; + void requestModeIDLE(); /** * emitted e.g. on severe errors */ - virtual void requestModeOOO() = 0; + void requestModeOOO(); /** * emitted e.g. if service door is opened */ - virtual void requestAccountResponse(const QHash & accountData) = 0; + void requestAccountResponse(const QHash & accountData); /** * emitted on error @@ -126,10 +128,10 @@ signals: * -> send error event to ISMAS * -> ... */ - virtual void Error( + void Error( /* additional variables? */ const QString & errorCode, - const QString & errorDescription) = 0; + const QString & errorDescription); }; From 7c3bc484af212c005ff45f6f5f392c29aec8134d Mon Sep 17 00:00:00 2001 From: Siegfried Siegert Date: Tue, 20 Jun 2023 13:23:36 +0200 Subject: [PATCH 5/6] Handle door events (note) This events come somtimes very unreliably. --- src/ATBAPP/ATBDeviceControllerPlugin.cpp | 19 +++++++++++++++---- src/ATBAPP/ATBDeviceControllerPlugin.h | 1 + 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/ATBAPP/ATBDeviceControllerPlugin.cpp b/src/ATBAPP/ATBDeviceControllerPlugin.cpp index 88083e0..8dc29c3 100644 --- a/src/ATBAPP/ATBDeviceControllerPlugin.cpp +++ b/src/ATBAPP/ATBDeviceControllerPlugin.cpp @@ -41,7 +41,7 @@ ATBDeviceControllerPlugin::ATBDeviceControllerPlugin(QObject *parent) : connect(dynamic_cast(hw), SIGNAL(hwapi_doorVaultDoorOpened()), this, SLOT(onVaultDoorOpened()), Qt::QueuedConnection); // Screen?? with message connect(dynamic_cast(hw), SIGNAL(hwapi_doorCoinBoxRemoved()), this, SLOT(onCoinBoxRemoved()), Qt::QueuedConnection); // Create/Send Account connect(dynamic_cast(hw), SIGNAL(hwapi_doorCoinBoxInserted()), this, SLOT(onCoinBoxInserted()), Qt::QueuedConnection); - //connect(dynamic_cast(hw), SIGNAL(hwapi_doorCBinAndAllDoorsClosed()), this, SLOT( ??? )), Qt::QueuedConnection); + connect(dynamic_cast(hw), SIGNAL(hwapi_doorCBinAndAllDoorsClosed()), this, SLOT(onCBinAndAllDoorsClosed()), Qt::QueuedConnection); connect(dynamic_cast(hw), SIGNAL(hwapi_doorAllDoorsClosed()), this, SLOT(onAllDoorsClosed()), Qt::QueuedConnection); // check for errors, switch to mode IDLE @@ -242,6 +242,10 @@ void ATBDeviceControllerPlugin::onVaultDoorOpened() // - show special screen / message on screen // - create an HealthEvent (-> ISMAS-Event) qCritical() << "ATBDeviceControllerPlugin::onVaultDoorOpened()"; + + // TODO: Start background task "ACCOUNT" + + // do not: emit this->requestModeSERVICE(); } void ATBDeviceControllerPlugin::onCoinBoxRemoved() @@ -256,11 +260,18 @@ void ATBDeviceControllerPlugin::onCoinBoxInserted() qCritical() << "ATBDeviceControllerPlugin::onCoinBoxInserted()"; } +void ATBDeviceControllerPlugin::onCBinAndAllDoorsClosed() +{ + qCritical() << "ATBDeviceControllerPlugin::onCBinAndAllDoorsClosed()"; + + // TODO: Stop background task "ACCOUNT" + + QTimer::singleShot(2000, this, SIGNAL(requestModeIDLE())); +} + + void ATBDeviceControllerPlugin::onAllDoorsClosed() { - // TODO: - // - check for errors, switch to mode IDLE - qCritical() << "ATBDeviceControllerPlugin::onAllDoorsClosed()"; emit this->requestModeIDLE(); diff --git a/src/ATBAPP/ATBDeviceControllerPlugin.h b/src/ATBAPP/ATBDeviceControllerPlugin.h index 3e36777..177bbdd 100644 --- a/src/ATBAPP/ATBDeviceControllerPlugin.h +++ b/src/ATBAPP/ATBDeviceControllerPlugin.h @@ -129,6 +129,7 @@ private slots: void onCoinBoxRemoved(); void onCoinBoxInserted(); void onAllDoorsClosed(); + void onCBinAndAllDoorsClosed(); // account handling void private_startAccount(); From b39bbcfad534c7bf4cc947a7b4f2d0f370492505 Mon Sep 17 00:00:00 2001 From: Siegfried Siegert Date: Tue, 20 Jun 2023 13:26:43 +0200 Subject: [PATCH 6/6] Account: set accountData "NumberOfCoinVariants" --- src/ATBAPP/ATBDeviceControllerPlugin.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/ATBAPP/ATBDeviceControllerPlugin.cpp b/src/ATBAPP/ATBDeviceControllerPlugin.cpp index 8dc29c3..e026cab 100644 --- a/src/ATBAPP/ATBDeviceControllerPlugin.cpp +++ b/src/ATBAPP/ATBDeviceControllerPlugin.cpp @@ -211,7 +211,13 @@ void ATBDeviceControllerPlugin::private_getAccountData() accountData.insert("AccountingNumber", QString::number(retVR.AccountingNumber)); - for (uint i = 0; i < sizeof(retVR.coinsInVault); ++i) { + int numberOfCoinVariants = sizeof(retVR.coinsInVault); + + // limit numberOfCoinVariants: + if (numberOfCoinVariants > 16) { numberOfCoinVariants = 16; } + + accountData.insert("NumberOfCoinVariants", numberOfCoinVariants); + for (int i = 0; i < numberOfCoinVariants; ++i) { accountData.insert("COIN_" + QString::number(i) + "_Quantity", retVR.coinsInVault[i]); accountData.insert("COIN_" + QString::number(i) + "_Value", retVR.coinDenomination[i]);