diff --git a/DCPlugin.pro b/DCPlugin.pro index 4379416..412637f 100644 --- a/DCPlugin.pro +++ b/DCPlugin.pro @@ -77,6 +77,7 @@ HEADERS += \ src/ATBAPP/ATBMachineEvent.h \ src/ATBAPP/ATBDeviceControllerPlugin.h \ src/ATBAPP/Utils.h \ + src/ATBAPP/support/CashUtils.h \ src/ATBAPP/support/DBusControllerInterface.h \ src/ATBAPP/support/JSON.h \ src/ATBAPP/support/PTUSystem.h @@ -87,6 +88,7 @@ SOURCES += \ src/ATBAPP/ATBDeviceControllerPlugin.cpp \ src/ATBAPP/DeviceControllerDiag.cpp \ src/ATBAPP/Utils.cpp \ + src/ATBAPP/support/CashUtils.cpp \ src/ATBAPP/support/DBusControllerInterface.cpp \ src/ATBAPP/support/JSON.cpp \ src/ATBAPP/support/PTUSystem.cpp diff --git a/src/ATBAPP/ATBDeviceControllerPlugin.cpp b/src/ATBAPP/ATBDeviceControllerPlugin.cpp index aef35e9..76ecb26 100644 --- a/src/ATBAPP/ATBDeviceControllerPlugin.cpp +++ b/src/ATBAPP/ATBDeviceControllerPlugin.cpp @@ -5,6 +5,7 @@ #include "src/ATBAPP/support/JSON.h" #include "src/ATBAPP/support/DBusControllerInterface.h" #include "src/ATBAPP/support/PTUSystem.h" +#include "src/ATBAPP/support/CashUtils.h" #include #include diff --git a/src/ATBAPP/support/CashUtils.cpp b/src/ATBAPP/support/CashUtils.cpp new file mode 100644 index 0000000..2785e02 --- /dev/null +++ b/src/ATBAPP/support/CashUtils.cpp @@ -0,0 +1,74 @@ +#include "CashUtils.h" + +CashUtils::CashUtils(QObject *parent) : QObject(parent){} + +#define MAX_COINS 64 +#define MAX_NOTES 16 + +/***************************************************************************** +* Get current inserted coins +* +* getAllInsertedCoins(uint16_t *types, uint16_t *values) +* all inserted coins of this past transaction are stored, max 64 +*/ +uint32_t getAmountOfInsertedCoins(hwinf* hw) +{ + uint32_t result = 0; + + uint16_t types[MAX_COINS]; + uint16_t values[MAX_COINS]; + hw->getAllInsertedCoins(types, values); + + for (int i = 0; i < MAX_COINS; i++) { + result += (types[i] * values[i]); + } + + return result; +} + + +/***************************************************************************** + * Get current inserted notes + * + * virtual uint8_t bna_getCurrentNotes(uint16_t latestBill, uint16_t *currentNotes) const =0; + * returns number of collected bank notes since start-command (current transaction) + * latestBill: not used + * currentNotes[0] = last bill value + * currentNotes[1] = 0/1 1 if bill in escrow 0 if bill in cash box (stacker) + * currentNotes[2,3] = total sum of collected bills within this transaction + * + */ +uint32_t getAmountOfInsertedNotes(hwinf* hw) +{ + uint32_t result = 0; + + uint16_t currentNotes[MAX_NOTES]; + hw->bna_getCurrentNotes(0, currentNotes); + + result = currentNotes[2] + ( currentNotes[3] >> 16); + + return result; +} + + + +/***************************************************************************** + * Get changer result + * + * virtual uint8_t changer_getChangeResult(uint32_t *returnedAmount) const =0; + * get result of coin dispensing + * receivedData[0]: 0: not yet started + * 1:amount returned + * 2:only partial return + * 3: no return possible + * receivedData[2,3,4,5]: returned amount + * + * Note: to get changed amount this method must be called after changing! + */ + +uint32_t getAmountDueToChange(hwinf* hw) +{ + Q_UNUSED(hw) + + return 0; +} diff --git a/src/ATBAPP/support/CashUtils.h b/src/ATBAPP/support/CashUtils.h new file mode 100644 index 0000000..a856821 --- /dev/null +++ b/src/ATBAPP/support/CashUtils.h @@ -0,0 +1,23 @@ +#ifndef CASHUTILS_H +#define CASHUTILS_H + +#include +#include "interfaces.h" + +class CashUtils : public QObject +{ + Q_OBJECT + +public: + static uint32_t getAmountOfInsertedCoins(hwinf* hw); + static uint32_t getAmountOfInsertedNotes(hwinf* hw); + static uint32_t getAmountDueToChange(hwinf* hw); + +private: + explicit CashUtils(QObject *parent = nullptr); + +signals: + +}; + +#endif // CASHUTILS_H