Proposal for getting account data from CAlib/DeviceController
This commit is contained in:
parent
74753ce644
commit
414dda009e
@ -1,5 +1,6 @@
|
|||||||
#include "src/ATBAPP/ATBDeviceControllerPlugin.h"
|
#include "src/ATBAPP/ATBDeviceControllerPlugin.h"
|
||||||
#include "src/ATBAPP/ATBHealthEvent.h"
|
#include "src/ATBAPP/ATBHealthEvent.h"
|
||||||
|
#include "src/ATBAPP/Utils.h"
|
||||||
|
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QTextCodec>
|
#include <QTextCodec>
|
||||||
@ -9,6 +10,9 @@
|
|||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
|
|
||||||
|
#include <cstdlib>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ATBDeviceControllerPlugin::ATBDeviceControllerPlugin(QObject *parent) : QObject(parent),
|
ATBDeviceControllerPlugin::ATBDeviceControllerPlugin(QObject *parent) : QObject(parent),
|
||||||
pluginState(PLUGIN_STATE::NOT_INITIALIZED)
|
pluginState(PLUGIN_STATE::NOT_INITIALIZED)
|
||||||
@ -135,7 +139,65 @@ void ATBDeviceControllerPlugin::cashAbort()
|
|||||||
// for an external account request, e.g. by an ui-button:
|
// for an external account request, e.g. by an ui-button:
|
||||||
void ATBDeviceControllerPlugin::requestAccount()
|
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<QString, QVariant> 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()
|
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()";
|
qCritical() << "ATBDeviceControllerPlugin::onCoinBoxRemoved()";
|
||||||
|
|
||||||
|
this->private_startAccount();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ATBDeviceControllerPlugin::onCoinBoxInserted()
|
void ATBDeviceControllerPlugin::onCoinBoxInserted()
|
||||||
@ -603,8 +654,6 @@ const QString ATBDeviceControllerPlugin::getString(nsDeviceControllerInterface::
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/************************************************************************************************
|
/************************************************************************************************
|
||||||
* ... end
|
* ... end
|
||||||
*/
|
*/
|
||||||
|
@ -129,6 +129,10 @@ private:
|
|||||||
|
|
||||||
nsDeviceControllerInterface::CASH_STATE currentCashState;
|
nsDeviceControllerInterface::CASH_STATE currentCashState;
|
||||||
|
|
||||||
|
// counts failed hw->log_chkIfVaultRecordAvailable()
|
||||||
|
int accountCheckCounter;
|
||||||
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
// printer
|
// printer
|
||||||
|
|
||||||
@ -152,6 +156,11 @@ private slots:
|
|||||||
void onCoinBoxRemoved();
|
void onCoinBoxRemoved();
|
||||||
void onCoinBoxInserted();
|
void onCoinBoxInserted();
|
||||||
void onAllDoorsClosed();
|
void onAllDoorsClosed();
|
||||||
|
|
||||||
|
// account handling
|
||||||
|
void private_startAccount();
|
||||||
|
void private_checkAccountData();
|
||||||
|
void private_getAccountData();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ATBDEVICECONTROLLERPLUGIN_H
|
#endif // ATBDEVICECONTROLLERPLUGIN_H
|
||||||
|
Loading…
Reference in New Issue
Block a user