APservice/win11_abr.cpp

664 lines
20 KiB
C++
Raw Permalink Normal View History

2023-11-14 09:32:56 +01:00
#include "win11_abr.h"
#define BUTTONCOLOR0 "background-color: white"
#define BUTTONCOLORWAIT "background-color: yellow"
#define BUTTONCOLORGOT "background-color: green"
#define BUTTONCOLORBAD "background-color: red"
#define BUTTONCOLORGOOD "background-color: green"
static char updateList, wait4data;
static uint8_t pwreq;
/*
void log_getHoldAccountNumbers(uint8_t *nrOfVals, uint16_t *accNr ) const override;
// returns all acc nrs of the backuped vault records
// use: uint16_t backupedAccNumbers[8]
// will be requested automatically
bool log_selectVaultRecord(uint16_t accountNr ) const override;
// return true if sending, false if cmd-stack is full
// and trigger transfer
bool log_chkIfVaultRecordAvailable(void) const override;
// return true if completly received
bool log_getVaultRecord(struct T_vaultRecord *retVR) const override;
// which was selected by: log_selectVaultRecord()
// to be forwarded to Ismas
bool prn_printAccountReceipt(void) const override;
// return true if sending to DC OK, false if cmd-stack is full
*/
T_win11::T_win11(hwinf *HWaccess, QWidget *parent) : QWidget(parent)
{
this->HWaccess = HWaccess;
//myLayout = new QGridLayout;
mainHLayout = new QHBoxLayout;
leftLayout = new QVBoxLayout;
RightLayout = new QVBoxLayout;
QFont myTabFont;
myTabFont.setPixelSize(20);
// availAccNrList.append("1");
// availAccNrList.append("2");
// availAccNrList.append("3");
// availAccNrList.append("4");
// availAccNrList.append("5");
// availAccNrList.append("6");
// availAccNrList.append("7");
// availAccNrList.append("8");
availAccNrList.clear();
// left side: big ListWindow to show accounting record
but2 = new QPushButton(" Load Data");
leftLayout->addWidget(but2);
connect(but2, SIGNAL(clicked()), this, SLOT(slot_loadData()));
but2->setStyleSheet(BUTTONCOLOR0); // BUTTONCOLORWAIT BUTTONCOLORGOT
but2->setFont(myTabFont);
QLabel *lab1 =new QLabel("accounting data:");
leftLayout->addWidget(lab1);
lab1->setFont(myTabFont);
myTabFont.setPixelSize(16);
win11_showVaultRecord = new QListWidget;
win11_showVaultRecord->setFont(myTabFont);
//win11_showVaultRecord->setMinimumHeight(200);
win11_showVaultRecord->setMinimumWidth(500);
leftLayout->addWidget(win11_showVaultRecord);
//win11_showVaultRecord->addItem("data 123");
win11_showVaultRecord->setLineWidth(3);
// right side:
myTabFont.setPixelSize(20);
but1 = new QPushButton(" Reload Acc. Nrs");
RightLayout->addWidget(but1);
connect(but1, SIGNAL(clicked()), this, SLOT(slot_loadNumbers()));
but1->setFont(myTabFont);
but1->setStyleSheet(BUTTONCOLOR0); // BUTTONCOLORWAIT BUTTONCOLORGOT
//QLabel *lab6 =new QLabel(" ");
//RightLayout->addWidget(lab6);
QLabel *lab4 =new QLabel("select Acc. Nr.:");
RightLayout->addWidget(lab4);
lab4->setFont(myTabFont);
QFont myCBfont;
myCBfont.setPixelSize(16);
//myCBfont.setPointSize(16);
myCBfont.setPointSize(myCBfont.pixelSize() - 5);
cb_selAccNr = new QComboBox();
cb_selAccNr->addItems(availAccNrList);
//cb_selAccNr->setFont(myCBfont); // aendert nur die Liste, Eingabezeile bleibt klein
//cb_selAccNr->setCurrentIndex(7);
cb_selAccNr->setEditable(true);
cb_selAccNr->setMaxVisibleItems(8);
cb_selAccNr->setStyleSheet("QComboBox { font-size: 20px; }"); // gilt fuer Liste und Eingabezeile
//cb_selAccNr->setStyleSheet("QScrollBar:vertical { width: 30px; }");
RightLayout->addWidget(cb_selAccNr);
//myTabFont.setPixelSize(16);
//QLabel *lab5 =new QLabel(" ");
//RightLayout->addWidget(lab5);
//lab5->setFont(myTabFont);
/*
myTabFont.setPixelSize(16);
QLabel *lab2 =new QLabel("available AccNrs.:");
lab2->setFont(myTabFont);
RightLayout->addWidget(lab2);
myTabFont.setPixelSize(16);
win11_showAccNrs = new QListWidget;
win11_showAccNrs->setFont(myTabFont);
//win11_showAccNrs->setMinimumHeight(200);
//win11_showAccNrs->setMinimumWidth(100);
win11_showAccNrs->setLineWidth(3);
win11_showAccNrs->clear();
win11_showAccNrs->addItems(availAccNrList);
RightLayout->addWidget(win11_showAccNrs);
*/
//QLabel *lab3 =new QLabel(" ");
//RightLayout->addWidget(lab3);
but3 = new QPushButton(" print ");
RightLayout->addWidget(but3);
connect(but3, SIGNAL(clicked()), this, SLOT(slot_printSel()));
but3->setStyleSheet(BUTTONCOLOR0);
but3->setFont(myTabFont);
but4 = new QPushButton(" verify ");
RightLayout->addWidget(but4);
connect(but4, SIGNAL(clicked()), this, SLOT(slot_crc()));
but4->setStyleSheet(BUTTONCOLOR0);
but4->setFont(myTabFont);
but5 = new QPushButton("read acc-nr");
RightLayout->addWidget(but5);
connect(but5, SIGNAL(clicked()), this, SLOT(slot_readNr()));
but5->setStyleSheet(BUTTONCOLOR0);
but5->setFont(myTabFont);
//disp_CurrentAccNr=new QLabel();
disp_CurrentAccNr=new QLineEdit(); // mit Eingabemoeglichkeit!
RightLayout->addWidget(disp_CurrentAccNr);
disp_CurrentAccNr->setFont(myTabFont);
//disp_CurrentAccNr->setLineWidth(3);
disp_CurrentAccNr->setStyleSheet(BUTTONCOLOR0);
disp_CurrentAccNr->setEnabled(true);
myTabFont.setPixelSize(16);
//QLabel *lab5 =new QLabel(" ");
//RightLayout->addWidget(lab5);
//lab5->setFont(myTabFont);
myKeypad = new T_keypad();
leftLayout->addWidget(myKeypad);
connect(myKeypad, SIGNAL(keyEntryFinished()), this, SLOT(valueIsSet()));
but6 = new QPushButton("set acc-nr");
RightLayout->addWidget(but6);
connect(but6, SIGNAL(clicked()), this, SLOT(slot_setAccNr()));
but6->setStyleSheet(BUTTONCOLOR0);
but6->setFont(myTabFont);
but7 = new QPushButton("delete all DC-data");
RightLayout->addWidget(but7);
connect(but7, SIGNAL(clicked()), this, SLOT(slot_deleteAccData()));
but7->setStyleSheet(BUTTONCOLOR0);
but7->setFont(myTabFont);
but8 = new QPushButton("delete all Totals");
RightLayout->addWidget(but8);
connect(but8, SIGNAL(clicked()), this, SLOT(slot_deleteTotals()));
but8->setStyleSheet(BUTTONCOLOR0);
but8->setFont(myTabFont);
mainHLayout->addLayout(leftLayout);
mainHLayout->addLayout(RightLayout);
setLayout(mainHLayout);
updateList=1;
wait4data=0;
myNextStep=0;
myStep=0;
pwreq=0;
myTO = new QTimer();
myTO->setSingleShot(true);
myTO->stop();
}
T_win11::~T_win11()
{
close();
}
void T_win11::Nav_back(void)
{
myNextStep=WCS_WIN11BAK;
}
void T_win11::Nav_home(void)
{
myNextStep=WCS_WIN11MID;
}
void T_win11::Nav_next(void)
{
myNextStep=WCS_WIN11FWD;
}
void T_win11::slot_loadData(void)
{
bool ok=0;
int selNr;
QString anStr;
but3->setStyleSheet(BUTTONCOLOR0);
but2->setStyleSheet(BUTTONCOLORWAIT); // BUTTONCOLORGOT
but2->setText("loading...");
//int anInt=cb_selAccNr->currentIndex();
anStr=cb_selAccNr->currentText();
selNr=anStr.toUInt(&ok);
if (ok)
{
if (selNr==0)
{
sub_displayCurrentCashbox();
} else
{
HWaccess->log_selectVaultRecord(uint16_t(selNr));
win11_showVaultRecord->clear();
wait4data=1;
}
}
myStep++;
}
void T_win11::slot_loadNumbers(void)
{
updateList=1;
}
void T_win11::slot_printSel(void)
{
bool ok=0;
QString anStr=cb_selAccNr->currentText();
uint16_t selNr=anStr.toUInt(&ok);
if (ok && selNr>0)
{
HWaccess->prn_printOneAccountReceipt(selNr);
myTO->start(3000);
}
}
void T_win11::slot_crc(void)
{
bool ret=0;
ret=HWaccess->log_verifyVaultRecordByCrc();
if (ret)
but4->setStyleSheet(BUTTONCOLORGOOD);
else
but4->setStyleSheet(BUTTONCOLORBAD);
}
void T_win11::slot_readNr(void)
{
uint16_t nxtAn=0;
nxtAn= HWaccess->log_DC_getNextAccountNumber();
QString myStr;
myStr.clear();
myStr.append(QString::number(nxtAn));
disp_CurrentAccNr->setText(myStr);
}
void T_win11::slot_setAccNr(void)
{
// set new accouning number
// request password before
pwreq=1;
myKeypad->keysVisible(2);
myKeypad->show(); // display pinpad for password entry
}
void T_win11::slot_deleteAccData(void)
{
pwreq=2;
myKeypad->keysVisible(2);
myKeypad->show();
}
void T_win11::slot_deleteTotals(void)
{
pwreq=3;
myKeypad->keysVisible(2);
myKeypad->show();
}
void T_win11::valueIsSet(void)
{
// password was entered
bool ok=0;
QString myPW, myStr;
myPW=myKeypad->getValueString(); // get entered password
if (pwreq==1) // pw-entry requested for acc-nr
{
if (myPW=="92706") // compare password
{
//qDebug()<<"PW correct";
myStr=disp_CurrentAccNr->text(); // new value was set before PW
uint16_t nxtAn=myStr.toUInt(&ok,10);
if (ok)
{
HWaccess->log_DC_setNextAccountNumber(nxtAn);
disp_CurrentAccNr->setText("->new acc.nr set");
}
}
} else
if (pwreq==2) // pw-entry requested for deleteAccData
{
if (myPW=="92637") // compare password
{
HWaccess->log_DC_deleteAllVaultrecordsInDc();
disp_CurrentAccNr->setText("->all acc.data deleted");
}
} else
if (pwreq==3) // pw-entry requested for delete totals
{
if (myPW=="92702") // compare password
{
HWaccess->log_DC_deleteAllTotalCounters();
disp_CurrentAccNr->setText("->all totals deleted");
}
}
pwreq=0;
}
void T_win11::enterAccData(QString label, uint32_t val)
{
QString myStr;
myStr.clear();
myStr.append(label);
myStr.append(QString::number(val));
win11_showVaultRecord->addItem(myStr);
}
void T_win11::enterString(QString label, char *buff, int len)
{
QString myStr;
char myChar;
int nn, LL=len;
myStr.clear();
myStr.append(label);
for (nn=0; nn<LL; nn++)
{
myChar=buff[nn];
myStr.append(myChar);
}
win11_showVaultRecord->addItem(myStr);
}
void T_win11::enterArray(QString label, uint16_t *buff, int len)
{
QString myStr;
int nn, LL=len;
uint16_t val;
myStr.clear();
myStr.append(label);
for (nn=0; nn<LL; nn++)
{
val=buff[nn];
myStr.append(QString::number(val));
myStr.append(", ");
}
win11_showVaultRecord->addItem(myStr);
}
void T_win11::enterArray(QString label, uint32_t *buff, int len)
{
QString myStr;
int nn, LL=len;
uint32_t val;
myStr.clear();
myStr.append(label);
for (nn=0; nn<LL; nn++)
{
val=buff[nn];
myStr.append(QString::number(val));
myStr.append(", ");
}
win11_showVaultRecord->addItem(myStr);
}
bool T_win11::work_ini(uint16_t *nextScreen, uint8_t *useNavi)
{
// one state of the vending/operating FSM
// called ONE time after selecting this state (initialization)
// useNavi=0: no change
// bit0,1: enable/disable button "next"
// bit2,3: enable/disable button "home"
// bit4,5: enable/disable button "back"
*nextScreen=0; // needed 0=no change
*useNavi=SWITCH_BACK_ON | SWITCH_HOME_ON | SWITCH_NEXT_ON;
myNextStep=0;
return false;
}
bool T_win11::working(uint16_t *nextScreen, uint8_t *useNavi)
{
// one state of the vending/operating FSM
// called cyclic until this state changes intentionally to another state
// display informations for human operator, react on operators inputs or wait for payment media
// useNavi=0: no change
// bit0,1: enable/disable button "next"
// bit2,3: enable/disable button "home"
// bit4,5: enable/disable button "back"
uint8_t nrOfVals, nn;
uint16_t accNr[34], val;
QString myStr;
struct T_vaultRecord retVR;
//uint8_t temp[400];
if (updateList)
{
HWaccess->log_getHoldAccountNumbers(&nrOfVals, &accNr[0] );
//void log_getHoldAccountNumbers(uint8_t *nrOfVals, uint16_t *accNr ) const override;
// returns all acc nrs of the backuped vault records
// use: uint16_t backupedAccNumbers[8]
// will be requested automatically
if (nrOfVals>32) nrOfVals=32;
availAccNrList.clear();
availAccNrList.append("0"); // 0 = immer akt. Kasseninhalt
for (nn=0; nn< nrOfVals; nn++)
{
myStr.clear();
val=accNr[nn];
myStr.append( QString::number(val,10) );
availAccNrList.append(myStr);
}
if (nrOfVals>0)
{
cb_selAccNr->clear();
cb_selAccNr->addItems(availAccNrList);
//win11_showAccNrs->clear();
//win11_showAccNrs->addItems(availAccNrList);
updateList=0;
}
}
//blksRdy=HWaccess->log_getAvailableVaultBlocks();
// return 0x0011 1111 if all 6 blocks arer loaded (one bit per block)
//if (blksRdy==0x3F && wait4data)
if (HWaccess->log_chkIfVaultRecordAvailable() && wait4data)
{
wait4data=0;
win11_showVaultRecord->clear();
but2->setStyleSheet(BUTTONCOLORGOT);
but2->setText("loaded");
// get data from local memory and display to left window
HWaccess->log_getVaultRecord(&retVR);
enterString ("Start : ", retVR.startbuffer, 4);
enterAccData("Acc.Nr. : ", retVR.AccountingNumber );
enterAccData("Cu.Nr. : ", retVR.CUNU );
enterAccData("MachNr. : ", retVR.MANU );
enterAccData("reserve : ", retVR.resint1 );
enterString ("--- : ", retVR.label1buffer, 4 );
enterAccData("Year : ", retVR.year );
enterAccData("Month : ", retVR.month );
enterAccData("Day : ", retVR.dom );
enterAccData("Hour : ", retVR.hour );
enterAccData("Min : ", retVR.min );
enterAccData("Sec : ", retVR.sec );
enterAccData("Weekday : ", retVR.DoW );
enterAccData("reserve : ", retVR.reschar3 );
enterString ("--- : ", retVR.label2buffer, 4 );
enterAccData("Total : ", retVR.AbsIncome1 );
enterAccData("abs.Res : ", retVR.AbsReserve );
enterAccData("abs.Cut : ", retVR.AbsNrOfCuts );
enterString ("--- : ", retVR.label3buffer, 4 );
enterArray ("ins.Coins: ", retVR.VKcoinsInserted, 16 );
enterArray ("ret Coins: ", retVR.VKcoinsReturned, 6 );
enterArray ("fillCoins: ", retVR.ServCoinsInserted, 16 );
enterArray ("takeCoins: ", retVR.ServCoinsReturned, 6 );
enterAccData("reserve : ", retVR.resint3 );
enterAccData("reserve : ", retVR.resint4 );
enterArray ("tubeCont.: ", retVR.currentTubeContent,6 );
enterAccData("reserve : ", retVR.resint5 );
enterAccData("reserve : ", retVR.resint6 );
enterString("--- : ", retVR.label4buffer, 4 );
enterArray ("nr.Coins : ", retVR.coinsInVault, 16 );
enterArray ("nr.Bills : ", retVR.billsInStacker, 8 );
enterString("--- : ", retVR.label5buffer, 4 );
enterArray ("coinDenom: ", retVR.coinDenomination, 16 );
enterArray ("billDenom: ", retVR.billDenom, 8 );
enterArray ("tubeDenom: ", retVR.tubeDenom, 6 );
enterAccData("exchgRate: ", retVR.exchangeRate );
enterAccData("reserve : ", retVR.resint9 );
enterAccData("Cuts CB : ", retVR.cutsSinceCBchange);
enterAccData("Amount CB: ", retVR.CBcontent_cent);
enterAccData("Coins CB : ", retVR.CBnrofCoins);
enterString("End : ", retVR.endofblock, 4 );
// 332 bytes
enterAccData("CRC : ", retVR.CRC16);
enterAccData("res : ", retVR.resint11);
enterString("End : ", retVR.endofRecord, 4 );
}
if (myTO->isActive())
{
uint8_t uctmp=HWaccess->prn_getPrintResult();
// return: 0: unknown
// 1: OK - last template was printed succesful
// 2: error - last template was not printed
if (uctmp==2)
but3->setStyleSheet(BUTTONCOLORBAD);
else if (uctmp==1)
but3->setStyleSheet(BUTTONCOLORGOOD);
else
but3->setStyleSheet(BUTTONCOLOR0);
}
if (myStep==0)
{
//myStep++;
} else
if (myStep==1)
{
if (!myTO->isActive())
{
myStep++;
myTO->start(200);
HWaccess->bna_requestStackerLevel();
//qDebug()<<"win11 requ bills";
}
} else
if (myStep==2)
{
if (!myTO->isActive())
{
myStep++;
myTO->start(200);
}
} else
if (myStep==3)
{
if (!myTO->isActive())
{
myStep=1; // nur 1x auf Tastendruck anfordern
myTO->start(200);
HWaccess->changer_requestTubelevel();
//qDebug()<<"win11 requ tubes";
}
}
if (myNextStep)
{
*nextScreen=myNextStep;
myNextStep=0;
}
*useNavi=0;
return false;
}
void T_win11::sub_displayCurrentCashbox(void)
{
// "Daily" anzeigen, also akt. Kasseninhalt
wait4data=0;
but2->setStyleSheet(BUTTONCOLORGOOD);
but2->setText("loaded");
win11_showVaultRecord->clear();
win11_showVaultRecord->addItem("\nCurrent cashbox content\n");
struct T_dynamicCondition myDynMachCond;
HWaccess->sys_getDynMachineConditions(&myDynMachCond);
enterAccData("nr of coins in Box: ", myDynMachCond.nrCoinsInBox);
enterAccData("Amount in coin Box: ", myDynMachCond.amountInBox);
win11_showVaultRecord->addItem(" ");
uint32_t amountInStacker;
uint16_t countOfBills[16], totalBills;
totalBills=HWaccess->bna_getStackerLevel(&amountInStacker, countOfBills);
// countOfBills[0...7]=Anzahl der jew. Werte countOfBills[8...15]=Wertigkeit
enterAccData("nr of bills in Box: ", totalBills);
enterAccData("Amount of bills : ", (amountInStacker/100) );
enterAccData("Nr of 5€ Bills: ", countOfBills[0]);
enterAccData("Nr of 10€ Bills: ", countOfBills[1]);
enterAccData("Nr of 20€ Bills: ", countOfBills[2]);
enterAccData("Nr of 50€ Bills: ", countOfBills[3]);
enterAccData("Nr of 100€ Bills: ", countOfBills[4]);
win11_showVaultRecord->addItem(" ");
struct T_chg_Tub changer;
HWaccess->changer_getTubelevel(&changer);
// don't use tubeDispens[], it's not yet correct!
QString myStr;
win11_showVaultRecord->addItem("\n Coin changer content: ");
for (int nn=0; nn<6; nn++)
{
myStr.clear();
if (changer.tubeValues[nn]>0)
{
myStr.append(swl_long2str(changer.tubeValues[nn]));
myStr.append(" : ");
myStr.append(swl_long2str(changer.tubeLevel[nn]));
if (changer.tubeFull[nn]>0)
myStr.append(" F");
win11_showVaultRecord->addItem(myStr);
}
}
}