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/ATBDeviceControllerPlugin.cpp b/src/ATBAPP/ATBDeviceControllerPlugin.cpp index 46eeba9..e026cab 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,10 +10,15 @@ #include #include +#include -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("")) { @@ -35,7 +41,7 @@ ATBDeviceControllerPlugin::ATBDeviceControllerPlugin(QObject *parent) : QObject( 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 @@ -135,7 +141,92 @@ 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); + + // DEBUG + qCritical() << "Start account: "; + qCritical() << " nrOfVals = " << nrOfVals; + for (int i=0; i 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() +{ + // DEBUG + qCritical() << " --> private_getAccountData()"; + + struct T_vaultRecord retVR; + + hw->log_getVaultRecord(&retVR); + + QHash accountData; + + accountData.insert("AccountingNumber", QString::number(retVR.AccountingNumber)); + + 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]); + + // 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); } @@ -157,24 +248,17 @@ 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() { - 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() @@ -182,11 +266,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(); @@ -603,8 +694,6 @@ const QString ATBDeviceControllerPlugin::getString(nsDeviceControllerInterface:: } - - /************************************************************************************************ * ... end */ diff --git a/src/ATBAPP/ATBDeviceControllerPlugin.h b/src/ATBAPP/ATBDeviceControllerPlugin.h index c48b6cb..177bbdd 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); - @@ -129,6 +102,10 @@ private: nsDeviceControllerInterface::CASH_STATE currentCashState; + // counts failed hw->log_chkIfVaultRecordAvailable() + int accountCheckCounter; + + private slots: // printer @@ -152,6 +129,12 @@ private slots: void onCoinBoxRemoved(); void onCoinBoxInserted(); void onAllDoorsClosed(); + void onCBinAndAllDoorsClosed(); + + // account handling + void private_startAccount(); + void private_checkAccountData(); + void private_getAccountData(); }; #endif // ATBDEVICECONTROLLERPLUGIN_H 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); }; 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