Merge branch 'pu/accountRequest' into pu/integration
This commit is contained in:
		@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,6 @@
 | 
			
		||||
#include "src/ATBAPP/ATBDeviceControllerPlugin.h"
 | 
			
		||||
#include "src/ATBAPP/ATBHealthEvent.h"
 | 
			
		||||
#include "src/ATBAPP/Utils.h"
 | 
			
		||||
 | 
			
		||||
#include <QTimer>
 | 
			
		||||
#include <QTextCodec>
 | 
			
		||||
@@ -9,10 +10,15 @@
 | 
			
		||||
#include <QDateTime>
 | 
			
		||||
#include <QFileInfo>
 | 
			
		||||
 | 
			
		||||
#include <cstdlib>
 | 
			
		||||
 | 
			
		||||
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<QObject*>(hw), SIGNAL(hwapi_doorVaultDoorOpened()),       this, SLOT(onVaultDoorOpened()),   Qt::QueuedConnection);    // Screen?? with message
 | 
			
		||||
    connect(dynamic_cast<QObject*>(hw), SIGNAL(hwapi_doorCoinBoxRemoved()),        this, SLOT(onCoinBoxRemoved()),    Qt::QueuedConnection);     // Create/Send Account
 | 
			
		||||
    connect(dynamic_cast<QObject*>(hw), SIGNAL(hwapi_doorCoinBoxInserted()),       this, SLOT(onCoinBoxInserted()),   Qt::QueuedConnection);
 | 
			
		||||
    //connect(dynamic_cast<QObject*>(hw), SIGNAL(hwapi_doorCBinAndAllDoorsClosed()), this, SLOT( ??? )), Qt::QueuedConnection);
 | 
			
		||||
    connect(dynamic_cast<QObject*>(hw), SIGNAL(hwapi_doorCBinAndAllDoorsClosed()), this, SLOT(onCBinAndAllDoorsClosed()), Qt::QueuedConnection);
 | 
			
		||||
    connect(dynamic_cast<QObject*>(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<nrOfVals; ++i) {
 | 
			
		||||
        qCritical() << "      backupedAccNumbers[" << i << "] = " << backupedAccNumbers[0];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    qsort( backupedAccNumbers, nrOfVals, sizeof (uint16_t), Utils::compare );
 | 
			
		||||
 | 
			
		||||
    uint16_t latestAccountNumber = backupedAccNumbers[nrOfVals-1];
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    // DEBUG
 | 
			
		||||
    qCritical() << "       latestAccountNumber = " << latestAccountNumber;
 | 
			
		||||
 | 
			
		||||
    hw->log_selectVaultRecord(latestAccountNumber);
 | 
			
		||||
 | 
			
		||||
    this->accountCheckCounter = 0;
 | 
			
		||||
    QTimer::singleShot(500, this, SLOT(private_checkAccountData()));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ATBDeviceControllerPlugin::private_checkAccountData()
 | 
			
		||||
{
 | 
			
		||||
    // DEBUG
 | 
			
		||||
    qCritical() << "      --> 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<QString, QVariant> 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<QString, QVariant> 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
 | 
			
		||||
 */
 | 
			
		||||
 
 | 
			
		||||
@@ -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<QString, QVariant> & 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
 | 
			
		||||
 
 | 
			
		||||
@@ -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<QString, QVariant> & accountData) = 0;
 | 
			
		||||
    void requestAccountResponse(const QHash<QString, QVariant> & 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);
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										18
									
								
								src/ATBAPP/Utils.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								src/ATBAPP/Utils.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -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;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										23
									
								
								src/ATBAPP/Utils.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								src/ATBAPP/Utils.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,23 @@
 | 
			
		||||
#ifndef UTILS_H
 | 
			
		||||
#define UTILS_H
 | 
			
		||||
 | 
			
		||||
#include <QObject>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
		Reference in New Issue
	
	Block a user