Send cashPaymentFinished() onCashChangerState() ...

This is for checking changer result and includes lot of debug code!
This commit is contained in:
Siegfried Siegert 2023-12-08 12:41:57 +01:00
parent 05113057b0
commit 25cb23a587
Signed by: SiegfriedSiegert
GPG Key ID: 68371E015E8F0B03
2 changed files with 187 additions and 4 deletions

View File

@ -224,8 +224,34 @@ void ATBDeviceControllerPlugin::requestStopCashInput()
void ATBDeviceControllerPlugin::cashCollect()
{
hw->vend_success();
// inserted amount
uint32_t amountInt = this->hw->getInsertedAmount();
QString amountString = QString::number(amountInt);
// inserted coins
uint32_t amountCoinsInt = CashUtils::getAmountOfInsertedCoins(this->hw);
QString amountCoinsString = QString::number(amountCoinsInt);
// inserted notes
uint32_t amountNotesInt = CashUtils::getAmountOfInsertedNotes(this->hw);
QString amountNotesString = QString::number(amountNotesInt);
if (this->coinProcessor() == nsDeviceControllerInterface::COIN_PROCESSOR::CHANGER) {
QTimer::singleShot(1000, this, &ATBDeviceControllerPlugin::onCashChangerState);
}
else {
emit this->cashPaymentFinished(nsDeviceControllerInterface::RESULT_STATE::SUCCESS,
amountString,
amountCoinsString, // coins
amountNotesString, // notes
0, // proposed change
"",
"");
this->currentCashState = CASH_STATE::CACHE_EMPTY;
}
}
void ATBDeviceControllerPlugin::cashAbort()
{
@ -1002,13 +1028,34 @@ void ATBDeviceControllerPlugin::onCashPayStopedSuccess()
QString amountNotesString = QString::number(amountNotesInt);
// amount due to change
uint32_t amountDueToChangeInt = this->cashStartAmountInt - amountInt;
uint32_t amountDueToChangeInt;
if (amountInt > this->cashStartAmountInt) {
amountDueToChangeInt = amountInt - this->cashStartAmountInt;
}
else {
amountDueToChangeInt = 0;
}
QString amountDueToChangeString = QString::number(amountDueToChangeInt);
// DEBUG
qCritical() << " insertedAmount (int) = " << amountInt;
qCritical() << " insertedAmount = " << amountString;
qCritical() << "---------------------------------------------------------";
qCritical() << "ATBDeviceControllerPlugin::onCashPayStopedSuccess()";
qCritical() << "";
qCritical() << " amountInt: " << amountInt;
qCritical() << " amountString: " << amountString;
qCritical() << "";
qCritical() << " amountNotesInt: " << amountNotesInt;
qCritical() << " amountNotesString: " << amountNotesString;
qCritical() << "";
qCritical() << " amountCoinsInt: " << amountCoinsInt;
qCritical() << " amountCoinsString: " << amountCoinsString;
qCritical() << "";
qCritical() << " this->cashStartAmountInt: " << this->cashStartAmountInt;
qCritical() << " amountDueToChangeInt: " << amountDueToChangeInt;
qCritical() << " amountDueToChangeString: " << amountDueToChangeString;
qCritical() << "---------------------------------------------------------";
emit this->cashInputFinished(nsDeviceControllerInterface::RESULT_STATE::SUCCESS,
amountString,
@ -1019,6 +1066,141 @@ void ATBDeviceControllerPlugin::onCashPayStopedSuccess()
"");
}
void ATBDeviceControllerPlugin::onCashChangerState()
{
uint32_t amountThatCouldNotBeChangedInt;
static int changerStateRequestCounter = 0;
static uint8_t lastChangerResult = 0;
// inserted amount
uint32_t amountInt = this->hw->getInsertedAmount();
QString amountString = QString::number(amountInt);
// inserted coins
uint32_t amountCoinsInt = CashUtils::getAmountOfInsertedCoins(this->hw);
QString amountCoinsString = QString::number(amountCoinsInt);
// inserted notes
uint32_t amountNotesInt = CashUtils::getAmountOfInsertedNotes(this->hw);
QString amountNotesString = QString::number(amountNotesInt);
// amount due to change
uint32_t amountCoinsChangedInt;
if (amountInt > this->cashStartAmountInt) {
amountCoinsChangedInt = amountInt - this->cashStartAmountInt;
}
else {
amountCoinsChangedInt = 0;
}
QString amountCoinsChangedString = QString::number(amountCoinsChangedInt);
// get changer state ------------------------------------------------
// Note: 'returnedAmount'-parameter is missleading here!
// 'returnedAmount' is the amount which could not be changed!
lastChangerResult = hw->changer_getChangeResult(&amountThatCouldNotBeChangedInt);
// DEBUG
qCritical() << "---------------------------------------------------------";
qCritical() << "ATBDeviceControllerPlugin::onCashChangerState()";
qCritical() << " changerStateRequestCounter: " << changerStateRequestCounter;
qCritical() << " lastChangerResult: " << lastChangerResult;
qCritical() << " amountThatCouldNotBeChangedInt: " << amountThatCouldNotBeChangedInt;
qCritical() << "";
qCritical() << " amountInt: " << amountInt;
qCritical() << " amountString: " << amountString;
qCritical() << "";
qCritical() << " amountCoinsInt: " << amountCoinsInt;
qCritical() << " amountCoinsString: " << amountCoinsString;
qCritical() << "";
qCritical() << " amountNotesInt: " << amountNotesInt;
qCritical() << " amountNotesString: " << amountNotesString;
qCritical() << "";
qCritical() << " this->cashStartAmountInt: " << this->cashStartAmountInt;
qCritical() << " amountCoinsChangedInt: " << amountCoinsChangedInt;
qCritical() << " amountCoinsChangedString: " << amountCoinsChangedString;
qCritical() << "---------------------------------------------------------";
if (lastChangerResult == 1) { // change is returned
QString amountCoinsChangedString = QString::number(amountCoinsChangedInt);
emit this->cashPaymentFinished(nsDeviceControllerInterface::RESULT_STATE::SUCCESS,
amountString,
amountCoinsString, // coins
amountNotesString, // notes
amountCoinsChangedString, // change
"",
"");
changerStateRequestCounter = 0;
lastChangerResult = 0;
return;
}
else
if (lastChangerResult == 0) { // not yet started
qCritical() << "ATBDeviceControllerPlugin::onCashChangerState(): ERROR: change not yet started: amount due to return: " << amountCoinsChangedString;
}
else
if (lastChangerResult == 2) { // only partial return
qCritical() << "ATBDeviceControllerPlugin::onCashChangerState(): ERROR: only partial return: amount due to return: " << amountCoinsChangedString;
}
else
if (lastChangerResult == 3) { // no return possible
qCritical() << "ATBDeviceControllerPlugin::onCashChangerState(): ERROR: no return possible: amount due to return: " << amountCoinsChangedString;
}
else {
qCritical() << "ATBDeviceControllerPlugin::onCashChangerState(): ERROR: invalid changerState (" << lastChangerResult << ")";
}
// handle timeout ------------------------------------------------
if (changerStateRequestCounter > 15) {
QString errorCode;
QString errorDescription;
switch (lastChangerResult) {
case 0: // not yet started
errorCode = "DC::CHANGER::START";
errorDescription = "Changer does not start";
break;
case 1: // amount returned
// This error should not occur!
errorCode = "DC::CHANGER::INVALID";
errorDescription = "Changer returned amount";
break;
case 2: // only partial return
errorCode = "DC::CHANGER::CHANGE";
errorDescription = "Changer does only partial return";
break;
case 3: // no return possible
errorCode = "DC::CHANGER::CHANGE_NOT_POSSIBLE";
errorDescription = "Changing not possible";
break;
default:
break;
}
emit this->cashPaymentFinished(nsDeviceControllerInterface::RESULT_STATE::ERROR_BACKEND,
amountString,
amountCoinsString,
amountNotesString,
0,
errorCode,
errorDescription);
changerStateRequestCounter = 0;
lastChangerResult = 0;
return;
}
// restart changer check:
changerStateRequestCounter++;
QTimer::singleShot(1000, this, &ATBDeviceControllerPlugin::onCashChangerState);
}
/**

View File

@ -151,6 +151,7 @@ private slots:
void onCashPayStopByEscrow();
void onCashPayStopByError();
void onCashPayStopByTimeout();
void onCashChangerState();
// doors and hardware contacts
void onServiceDoorOpened();