APservice/win08_mif.cpp

424 lines
13 KiB
C++
Raw Permalink Normal View History

2023-11-14 09:32:56 +01:00
#include "win08_mif.h"
T_win08::T_win08(hwinf *HWaccess, QWidget *parent) : QWidget(parent)
{
this->HWaccess = HWaccess;
myLayout = new QGridLayout;
QFont myTabFont;
myTabFont.setPixelSize(18);
/*
lab1 =new QLabel(tr("Mifare Card\n Reader"));
lab1->setFont(myTabFont);
myLayout->addWidget(lab1,0,0);
lab2 =new QLabel(tr(" "));
lab2->setFont(myTabFont);
myLayout->addWidget(lab2,2,1);
*/
pbMifPwr = new QPushButton("Power");
pbMifPwr->setCheckable(true); // true = toggle button
pbMifPwr->setAutoDefault(false); // beim start aus
pbMifPwr->setFont(myTabFont);
pbMifPwr->setStyleSheet("background-color: white");
myLayout->addWidget(pbMifPwr, 2, 4);
connect(pbMifPwr, SIGNAL(clicked()), this, SLOT(pbMifPower()));
QLabel *lab3 =new QLabel("Mifare Card\n Reader");
// QLabel *lab3 =new QLabel(tr("Reader State:"));
lab3->setFont(myTabFont);
myLayout->addWidget(lab3,2,0);
myTabFont.setPixelSize(18);
labReaderState =new QLabel(); //QListWidget();
labReaderState->setFont(myTabFont);
//labReaderState->setMinimumWidth(300);
//labReaderState->setMinimumHeight(150);
labReaderState->setLineWidth(3); // 1,2,3
labReaderState->setStyleSheet("background-color: white");
labReaderState->setFont(myTabFont);
myLayout->addWidget(labReaderState,2,2);
myTabFont.setPixelSize(18);
QLabel *lab6 =new QLabel(tr("Card tapped?"));
lab6->setFont(myTabFont);
myLayout->addWidget(lab6,4,0);
labCardTap =new QLabel(tr(" "));
labCardTap->setFont(myTabFont);
labCardTap->setMinimumWidth(300);
labCardTap->setLineWidth(3); // 1,2,3
labCardTap->setStyleSheet("background-color: white");
myLayout->addWidget(labCardTap,4,2);
QLabel *lab4 =new QLabel(tr("Card ID: "));
lab4->setFont(myTabFont);
myLayout->addWidget(lab4,6,0);
labCardUid =new QLabel(" ");
labCardUid->setFont(myTabFont);
labCardUid->setMinimumWidth(300);
labCardUid->setLineWidth(3); // 1,2,3
labCardUid->setStyleSheet("background-color: white");
myLayout->addWidget(labCardUid,6,2);
QLabel *lab10 =new QLabel(tr(" card size: "));
lab10->setFont(myTabFont);
myLayout->addWidget(lab10,8,0);
labCardSiz =new QLabel(" ");
labCardSiz->setFont(myTabFont);
labCardSiz->setMinimumWidth(300);
labCardSiz->setLineWidth(3); // 1,2,3
labCardSiz->setStyleSheet("background-color: white");
myLayout->addWidget(labCardSiz,8,2);
QLabel *lab11 =new QLabel(tr("ATBcard CuNu: "));
lab11->setFont(myTabFont);
myLayout->addWidget(lab11,10,0);
labCardCunu =new QLabel(" ");
labCardCunu->setFont(myTabFont);
labCardCunu->setMinimumWidth(300);
labCardCunu->setLineWidth(3); // 1,2,3
labCardCunu->setStyleSheet("background-color: white");
myLayout->addWidget(labCardCunu,10,2);
// kind of card and card valid:
QLabel *lab12 =new QLabel(tr("ATB Type\n and validty: "));
lab12->setFont(myTabFont);
myLayout->addWidget(lab12,12,0);
labCardValid =new QLabel(" ");
labCardValid->setFont(myTabFont);
labCardValid->setMinimumWidth(300);
labCardValid->setLineWidth(3); // 1,2,3
labCardValid->setStyleSheet("background-color: white");
myLayout->addWidget(labCardValid,12,2);
QLabel *lab13 =new QLabel(tr("personal code:"));
lab13->setFont(myTabFont);
myLayout->addWidget(lab13,14,0);
labCardPerso =new QLabel(" ");
labCardPerso->setFont(myTabFont);
labCardPerso->setMinimumWidth(300);
labCardPerso->setLineWidth(3); // 1,2,3
labCardPerso->setStyleSheet("background-color: white");
myLayout->addWidget(labCardPerso,14,2);
QLabel *lab14 =new QLabel(tr("expire time:"));
lab14->setFont(myTabFont);
myLayout->addWidget(lab14,16,0);
labCardExpire =new QLabel(" ");
labCardExpire->setFont(myTabFont);
labCardExpire->setMinimumWidth(300);
labCardExpire->setLineWidth(3); // 1,2,3
labCardExpire->setStyleSheet("background-color: white");
myLayout->addWidget(labCardExpire,16,2);
/*
QLabel *lab5 =new QLabel(tr("Seg.0 binary:"));
lab5->setFont(myTabFont);
myLayout->addWidget(lab5,8,0);
myTabFont.setPixelSize(16);
dispCardData =new QListWidget();
dispCardData->setFont(myTabFont);
dispCardData->setMinimumWidth(300);
dispCardData->setLineWidth(3); // 1,2,3
dispCardData->setStyleSheet("background-color: white");
myLayout->addWidget(dispCardData,8,2);
QLabel *lab7 =new QLabel(tr("ATB Card Data:"));
lab7->setFont(myTabFont);
myLayout->addWidget(lab7,9,0);
myTabFont.setPixelSize(16);
dispATBdata =new QListWidget();
dispATBdata->setFont(myTabFont);
dispATBdata->setMinimumWidth(300);
dispATBdata->setLineWidth(3); // 1,2,3
dispATBdata->setStyleSheet("background-color: white");
myLayout->addWidget(dispATBdata,9,2);
*/
/*
pbMiftest = new QPushButton(" TEST");
pbMiftest->setCheckable(false); // true = toggle button
pbMiftest->setAutoDefault(false); // beim start aus
pbMiftest->setFont(myTabFont);
pbMiftest->setStyleSheet("background-color: white");
myLayout->addWidget(pbMiftest, 9, 4);
connect(pbMiftest, SIGNAL(clicked()), this, SLOT(pbMifTest()));
*/
setLayout(myLayout);
myNextStep=0;
myStep=0;
myTO = new QTimer();
myTO->setSingleShot(true);
myTO->start(2000);
}
T_win08::~T_win08()
{
close();
}
void T_win08::pbMifPower(void)
{
if (pbMifPwr->isChecked())
{
HWaccess->mif_readerOn(1);
} else
HWaccess->mif_readerOn(0);
}
//void T_win08::pbMifTest(void)
//{
// HWaccess->prn_sendPrnSysCmd(0x12, 0x34, 0x56789012);
//}
void T_win08::Nav_back(void)
{
myNextStep=WCS_WIN08BAK;
}
void T_win08::Nav_home(void)
{
myNextStep=WCS_WIN08MID;
}
void T_win08::Nav_next(void)
{
myNextStep=WCS_WIN08FWD;
}
static UCHAR sendingOrder;
bool T_win08::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;
sendingOrder=0;
return false;
}
bool T_win08::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 mifData[66];
QString myStr;
//char myChr;
*nextScreen=0; // 0=no change
*useNavi=0;
if (myNextStep)
{
*nextScreen=myNextStep;
myNextStep=0;
}
// Power Taste
if (HWaccess->mif_isMifarePowerOn())
{
pbMifPwr->setStyleSheet("background-color: green");
} else
{
pbMifPwr->setStyleSheet("background-color: white");
labReaderState->clear();
labCardTap->clear();
labCardUid->clear();
//dispCardData->clear();
//dispATBdata->clear();
labCardTap->setStyleSheet("background-color: white");
labCardSiz->clear();
labCardCunu->clear();
labCardValid->clear();
labCardPerso->clear();
labCardExpire->clear();
return 0;
}
struct T_moduleCondition myDevCond;
HWaccess->sys_getDeviceConditions(&myDevCond);
uint8_t readerState=myDevCond.mifareReader; // 0: unknown 1=OK 200=no response 201=wrong response 202: Reader reports HW-error
// request Mifare data. As we need all this data just for test it's not requested automatically
sendingOrder++; // inc every 100ms
if (sendingOrder==10)
sendingOrder=1;
else if (sendingOrder==2)
HWaccess->request_MifareID();
else if (sendingOrder==6)
HWaccess->request_MifareAtbType();
switch (readerState)
{
case 0: labReaderState->setText(" state unknown"); break;
case 1: labReaderState->setText(" reader OK"); break;
case 200: labReaderState->setText(" no response from reader"); break;
case 201: labReaderState->setText(" wrong response from reader"); break;
case 202: labReaderState->setText(" reader HW error"); break;
}
if (HWaccess->mif_readerIsOK())
{
labReaderState->setStyleSheet("background-color: green");
} else
{
labReaderState->setStyleSheet("background-color: red");
labCardUid->clear();
labCardTap->clear();
//dispCardData->clear();
//dispATBdata->clear();
labCardSiz->clear();
labCardCunu->clear();
labCardValid->clear();
labCardPerso->clear();
labCardExpire->clear();
}
if (readerState==1)
{
// myStr.clear();
// myStr.append(" reader OK, Type="); // besser nicht anzeigen, gefaerdet Ersatzteil-business
// myStr.append(HWaccess->mif_getReaderType());
// labReaderState->setText(myStr);
// Type anzeigen
} else
{
labCardTap->clear();
labCardTap->setStyleSheet("background-color: white");
labCardUid->clear();
//dispCardData->clear();
//dispATBdata->clear();
labCardSiz->clear();
labCardCunu->clear();
labCardValid->clear();
labCardPerso->clear();
labCardExpire->clear();
return 0;
}
// Card-attached?
if (HWaccess->mif_cardIsAttached())
{
labCardTap->setText(" CARD attached");
if (HWaccess->mif_readResult()>0)
labCardTap->setStyleSheet("background-color: green");
else
labCardTap->setStyleSheet("background-color: yellow");
} else
{
labCardTap->setText("-no card-");
labCardTap->setStyleSheet("background-color: white");
labCardUid->clear();
//dispCardData->clear();
labCardUid->clear();
//dispATBdata->clear();
labCardSiz->clear();
labCardCunu->clear();
labCardValid->clear();
labCardPerso->clear();
labCardExpire->clear();
return false;
}
labCardUid->setText(HWaccess->mif_cardUID());
uint8_t cardSize, idLeng;
HWaccess->mif_getCardSize(&cardSize, &idLeng);
//cardSize=1k or 4kByte idLeng =4Byte or 7 byte
myStr.clear();
myStr.append(" memSize: ");
myStr.append(QString::number(cardSize,10));
myStr.append(" length_of_ID: ");
myStr.append(QString::number(idLeng));
myStr.append(" byte");
labCardSiz->setText(myStr);
labCardCunu->setText(QString::number(HWaccess->mif_getAtbCardCuNu()));
if (HWaccess->mif_isValidAtbCard())
{
labCardValid->setStyleSheet("background-color: green");
} else
{
labCardValid->setStyleSheet("background-color: yellow");
}
uint8_t ret=HWaccess->mif_getAtbCardTyp();
// return 1=upper door card 1=lower door 3=printer-test 4=coin-test
// 0: not a valid atb2020 card
switch (ret)
{
case 1: labCardValid->setText(" upper door "); break;
case 2: labCardValid->setText(" lower door "); break;
case 3: labCardValid->setText(" printer test"); break;
case 4: labCardValid->setText(" coin test "); break;
default: labCardValid->setText(" --- no atb card ---"); break;
}
labCardPerso->setText(HWaccess->mif_getAtbCardPerso());
uint8_t year, month, day, hour, minute;
HWaccess->mif_getAtbCardExpire(&year, &month, &day, &hour, &minute);
//mif_getAtbCardExpire(uint8_t *year, uint8_t *month, uint8_t *day, uint8_t *hour, uint8_t *minute)
myStr.clear();
myStr.append(" expires at (d.m.y h:m): ");
myStr.append(QString::number(day,10));
myStr.append(".");
myStr.append(QString::number(month,10));
myStr.append(".");
myStr.append(QString::number(year,10));
myStr.append(" ");
myStr.append(QString::number(hour,10));
myStr.append(":");
myStr.append(QString::number(minute,10));
labCardExpire->setText(myStr);
return false;
}