Diag: use enum for dc-state (including warnings)

This commit is contained in:
Siegfried Siegert 2023-07-25 07:59:58 +02:00
parent 2a5a318c1a
commit 34ec52250b
Signed by: SiegfriedSiegert
GPG Key ID: 68371E015E8F0B03
2 changed files with 127 additions and 77 deletions

View File

@ -1,6 +1,7 @@
#include "DeviceControllerDiag.h"
#include <QCoreApplication>
#include <QMetaEnum>
#include <QUuid>
#include <QDebug>
@ -53,7 +54,7 @@ void DeviceControllerDiag::private_startDiag()
// check for DiagRequestTimeoutTimerTimeout:
if (this->flagInterruptDiag) {
qCritical() << "DeviceControllerDiag::private_startDiag() interrupted!";
this->private_finishedDiag(0xff);
this->private_finishedDiag(DeviceController::State::E255);
return;
}
@ -85,7 +86,7 @@ void DeviceControllerDiag::sys_superviseSystem()
// check for DiagRequestTimeoutTimerTimeout:
if (this->flagInterruptDiag) {
qCritical() << "DeviceControllerDiag::sys_superviseSystem() interrupted!";
this->private_finishedDiag(0xff);
this->private_finishedDiag(DeviceController::State::E255);
return;
}
@ -93,7 +94,7 @@ void DeviceControllerDiag::sys_superviseSystem()
{
// es gibt keinerlei gültige Daten vom DC
qCritical() << "DeviceControllerDiag::sys_superviseSystem() no valid data!";
this->private_finishedDiag(0xfe);
this->private_finishedDiag(DeviceController::State::E254);
return;
}
@ -120,34 +121,26 @@ void DeviceControllerDiag::sys_superviseSystem()
if (dynMaCond.lowerDoor || dynMaCond.upperDoor) {
// Service or battery door is open, goto INTRUSION MODE
qCritical() << "DeviceControllerDiag::sys_superviseSystem() Service or battery door is open, goto INTRUSION MODE";
this->private_finishedDiag(0xFD);
this->private_finishedDiag(DeviceController::State::E253);
return;
}
if (dynMaCond.middleDoor) {
// vault door is open, goto INTRUSION MODE
qCritical() << "DeviceControllerDiag::sys_superviseSystem() vault door is open, goto INTRUSION MODE";
this->private_finishedDiag(0xFC);
this->private_finishedDiag(DeviceController::State::E252);
return;
}
qCritical() << " --> call sub_componentAssessment()";
uint8_t proposedError = sub_componentAssessment();
if (proposedError) {
// All doors are closed but errors found, goto OOO MODE (out-of-order)
qCritical() << "DeviceControllerDiag::sys_superviseSystem() All doors are closed but errors found, goto OOO MODE (out-of-order)";
this->private_finishedDiag(proposedError);
return;
}
DeviceController::State proposedError = sub_componentAssessment();
// everything fine
qCritical() << "DeviceControllerDiag::sys_superviseSystem() everything fine";
this->private_finishedDiag(0x00);
this->private_finishedDiag(proposedError);
}
uint8_t DeviceControllerDiag::sub_componentAssessment()
DeviceController::State DeviceControllerDiag::sub_componentAssessment()
{
// this function decides if vending mode is possible, independant from door
// return >0 in case of error
@ -171,29 +164,29 @@ uint8_t DeviceControllerDiag::sub_componentAssessment()
// check for invalid states:
if (modCond.rtc>=200)
return 1;
return DeviceController::State::E001;
if (modCond.printer==200 || modCond.printer==201) // 200: not connected 201: printer-HW-error 202: no paper
return 2;
return DeviceController::State::E002;
if (modCond.printer==202)
return 3;
return DeviceController::State::E003;
if (modCond.coinBlocker>=200)
return 4;
return DeviceController::State::E004;
if (modCond.mdbBus>=200)
return 5;
return DeviceController::State::E005;
if (modCond.intEe>=200)
return 6;
return DeviceController::State::E006;
if (devPara.kindOfCoinChecker==1 || devPara.kindOfCoinChecker==2) // 0: without 1=EMP820 2=EMP900 3=currenza c² (MW)
{
if (modCond.coinChecker>=200 || modCond.coinEscrow>=200)
{
// Fehler Münzver.
return 7;
return DeviceController::State::E007;
}
if (modCond.coinSafe>200) // 200: kasse fehlt 201: voll 100:fast voll 1:ok
{
return 8;
return DeviceController::State::E008;
}
} else
if (devPara.kindOfCoinChecker==3)
@ -201,42 +194,45 @@ uint8_t DeviceControllerDiag::sub_componentAssessment()
if (modCond.changer>=200)
{
// Fehler Münzver.
return 7;
return DeviceController::State::E007;
}
if (modCond.coinSafe>200) // 200: kasse fehlt 201: voll 100:fast voll 1:ok
{
return 8;
return DeviceController::State::E008;
}
}
if ( modCond.billReader>=200 && devPara.BillAcceptor>0)
{
// Fehler BNA
return 9;
return DeviceController::State::E009;
}
if (dynMaCond.onAlarm>0)
return 10;
return DeviceController::State::E010;
if (dynMaCond.modeAbrech>0)
return 11;
return DeviceController::State::E011;
if (dynMaCond.nowCardTest>0)
return 12;
return DeviceController::State::E012;
if (dynMaCond.startupTestIsRunning>0)
return 13;
return DeviceController::State::E013;
if (modCond.voltage>=200)
return 14;
return DeviceController::State::E014;
if (modCond.temper>=200)
return 15;
return DeviceController::State::E015;
return 0;
// check for warnings
return DeviceController::State::O000;
}
uint8_t DeviceControllerDiag::sys_getSystemErrors()
DeviceController::State DeviceControllerDiag::sys_getSystemErrors()
{
// 0: everything fine 1..15: errors
/* 1: real time clock error
@ -267,7 +263,7 @@ uint8_t DeviceControllerDiag::sys_getSystemErrors()
* - 0xFD Service or battery door is open
* - 0xFE vault door is open
*/
void DeviceControllerDiag::private_finishedDiag(uint8_t result)
void DeviceControllerDiag::private_finishedDiag(DeviceController::State result)
{
this->diagRequestTimeoutTimer->stop();
this->isRequestRunning = false;
@ -281,99 +277,114 @@ void DeviceControllerDiag::private_finishedDiag(uint8_t result)
return;
}
if (result > 15 && result != 0xFE) return;
// Errors are in this range 1...15:
QString eventId = QUuid::createUuid().toString(QUuid::WithoutBraces).mid(0, 8);
QString eventName;
QString eventName = QMetaEnum::fromType<DeviceController::State>().valueToKey(result);;
EVENT_CLASS eventClass = EVENT_CLASS::STATE;
QString parameter;
switch (result) {
case 1: // real time clock error
eventName = "E001";
case DeviceController::State::E001: // real time clock error
eventClass = EVENT_CLASS::ERROR;
parameter = "real time clock error";
break;
case 2: // printer error
eventName = "E002";
case DeviceController::State::E002: // printer error
eventClass = EVENT_CLASS::ERROR;
parameter = "printer error";
break;
case 3: // no paper
eventName = "E003";
case DeviceController::State::E003: // no paper
eventClass = EVENT_CLASS::ERROR;
parameter = "no paper";
break;
case 4: // coin blocker
eventName = "E004";
case DeviceController::State::E004: // coin blocker
eventClass = EVENT_CLASS::ERROR;
parameter = "coin blocker";
break;
case 5: // mdb error
eventName = "E005";
case DeviceController::State::E005: // mdb error
eventClass = EVENT_CLASS::ERROR;
parameter = "mdb error";
break;
case 6: // mem error int.ee.
case DeviceController::State::E006: // mem error int.ee.
eventName = "E006";
eventClass = EVENT_CLASS::ERROR;
parameter = "mem error int.ee.";
break;
case 7: // error coin validator
eventName = "E007";
case DeviceController::State::E007: // error coin validator
eventClass = EVENT_CLASS::ERROR;
parameter = "error coin validator";
break;
case 8: // coin safe missed or full
eventName = "E008";
case DeviceController::State::E008: // coin safe missed or full
eventClass = EVENT_CLASS::ERROR;
parameter = "coin safe missed or full";
break;
case 9: // bill acceptor error
eventName = "E009";
case DeviceController::State::E009: // bill acceptor error
eventClass = EVENT_CLASS::ERROR;
parameter = "bill acceptor error";
break;
case 10: // alarm / intrusion
eventName = "E010";
eventClass = EVENT_CLASS::ERROR;
case DeviceController::State::E010: // alarm / intrusion
eventClass = EVENT_CLASS::ALARM;
parameter = "alarm / intrusion";
break;
case 11: // cash box change is ongoing
eventName = "E011";
case DeviceController::State::E011: // cash box change is ongoing
eventClass = EVENT_CLASS::STATE;
parameter = "cash box change is ongoing";
break;
case 12: // card test running
eventName = "E012";
case DeviceController::State::E012: // card test running
eventClass = EVENT_CLASS::STATE;
parameter = "card test running";
break;
case 13: // startup-test is running
eventName = "E013";
case DeviceController::State::E013: // startup-test is running
eventClass = EVENT_CLASS::STATE;
parameter = "startup-test is running";
break;
case 14: // voltage error
eventName = "E014";
case DeviceController::State::E014: // voltage error
eventClass = EVENT_CLASS::ERROR;
parameter = "voltage error";
break;
case 15: // temperature error
eventName = "E015";
case DeviceController::State::E015: // temperature error
eventClass = EVENT_CLASS::STATE;
parameter = "temperature error";
break;
case 0xFE: // no valid data from DeviceController
eventName = "E254";
case DeviceController::State::E252: // oper door / lower door open
eventClass = EVENT_CLASS::STATE;
parameter = "oper door / lower door open";
break;
case DeviceController::State::E253: // cash box door open
eventClass = EVENT_CLASS::STATE;
parameter = "cash box door open";
break;
case DeviceController::State::E254: // no valid data from DeviceController
eventClass = EVENT_CLASS::STATE;
parameter = "no valid data from DeviceController";
break;
case 0x00: // everything is fine
eventName = "O000";
case DeviceController::State::E255: // no valid data from DeviceController
eventClass = EVENT_CLASS::STATE;
parameter = "";
qCritical() << " ... ignore " << QMetaEnum::fromType<DeviceController::State>().valueToKey(result);
return;
break;
case DeviceController::State::O000: // everything is fine
eventClass = EVENT_CLASS::OPERATE;
parameter = "";
qCritical() << " ... everything fine";
break;
case DeviceController::State::W001: // paper low
eventClass = EVENT_CLASS::WARNING;
parameter = "paper low";
break;
case DeviceController::State::W002: // cashbox almost full
eventClass = EVENT_CLASS::WARNING;
parameter = "cashbox almost full";
break;
case DeviceController::State::W003: // voltage low
eventClass = EVENT_CLASS::WARNING;
parameter = "voltage low";
break;
case DeviceController::State::W004: // temperatur warning
eventClass = EVENT_CLASS::WARNING;
parameter = "temperatur warning";
break;
}
@ -393,3 +404,5 @@ void DeviceControllerDiag::private_finishedDiag(uint8_t result)
QCoreApplication::postEvent(eventReceiver, machineEvent);
}

View File

@ -7,6 +7,42 @@
#include "ATBMachineEvent.h"
#include "interfaces.h"
namespace DeviceController {
Q_NAMESPACE
enum State {
O000,
E001,
E002,
E003,
E004,
E005,
E006,
E007,
E008,
E009,
E010,
E011,
E012,
E013,
E014,
E015,
E252,
E253,
E254,
E255,
W001,
W002,
W003,
W004
};
Q_ENUM_NS(State)
}
class DeviceControllerDiag : public QObject
{
Q_OBJECT
@ -33,8 +69,9 @@ private:
QTimer *diagRequestTimeoutTimer;
uint8_t sub_componentAssessment();
uint8_t sys_getSystemErrors();
//uint8_t sub_componentAssessment();
DeviceController::State sub_componentAssessment();
DeviceController::State sys_getSystemErrors();
int lastVoltage;
@ -42,7 +79,7 @@ private slots:
void onDiagRequestTimeoutTimerTimeout();
void private_startDiag(); // diag entry method
void private_finishedDiag(uint8_t result); // diag exit method
void private_finishedDiag(DeviceController::State result); // diag exit method
void sys_superviseSystem();