From d0445949d248f8ce1f7d365e6c5a3fc73277c44d Mon Sep 17 00:00:00 2001 From: Siegfried Siegert Date: Fri, 19 May 2023 13:57:17 +0200 Subject: [PATCH] Merge changes from T.Sax DC_plugin 18.5.23 --- include/datIf.h | 2 + include/hwapi.h | 63 +++++++++- include/interfaces.h | 19 ++- include/shared_mem_buffer.h | 2 +- src/datIf.cpp | 36 +++++- src/hwapi.cpp | 230 ++++++++++++++++++++++++++++++++++-- src/storeINdata.cpp | 44 ++++++- 7 files changed, 374 insertions(+), 22 deletions(-) diff --git a/include/datIf.h b/include/datIf.h index 0b173e2..465691f 100644 --- a/include/datIf.h +++ b/include/datIf.h @@ -308,6 +308,8 @@ class T_datif : public QMainWindow QTimer *datif_trigger; uint8_t selectedSlaveAddr; + int datif_noResponseCtr; + private slots: char datif_cycleSend(); void StoredRecData(); diff --git a/include/hwapi.h b/include/hwapi.h index 9489e08..8be320c 100644 --- a/include/hwapi.h +++ b/include/hwapi.h @@ -1,8 +1,30 @@ +/* +matching interfaces.h: + +// History +// 11.10.2021: V1.0 222 functions +// 23.12.2021: V1.1 added block-parameter to function "read mifare data" +// 30.12.2021: V1.2 added function: mif_clearDataBuffer(), mif_isBlockAvailable(uint8_t blkNr) and mif_getAvailableDataBlocks() +// 1.1.2022: V1.3 Mifare extended. ( background: read 16 x 48byte from card to DC, read 12 x 64byte from DC to CA) +// new: read full card with 768bytes from HWapi without block borders +// added: mif_getNrOfAvailableDataBytes mif_getCardData768byteDec(uint8_t *buf, uint16_t bufferSize) +// mif_getCardDataDec(uint16_t fromAddr, uint16_t toAddr, uint8_t *buf, uint16_t bufferSize) +// mif_getCardDataStr(bool useHexFormat, char seperator) +// 29.03.2023: V3.1 some extensions for PSA1256_ptu5, +// V3.2 Bootloader improvement +// 12.04.2023: V3.3 new features extended: loading and using Json-files, cash-collection, cash-data-logging + +//#define HWINF_iid "Atb.Psa2020.software.HWapi/3.1" +//#define HWINF_iid "Atb.Psa1256ptu5.software.HWapi/3.1" +#define HWINF_iid "Atb.Psa1256ptu5.software.HWapi/3.3" +*/ + #ifndef hwapi_H #define hwapi_H #include +#include #include #include "interfaces.h" #include "datIf.h" @@ -15,6 +37,7 @@ class hwapi : public QObject, Q_INTERFACES(hwinf) private: void sub_storeSendingText(QByteArray *buf) const; + QTimer *hwapi_TimerPayment; DownloadResult sendNextAddress(int bNum) const; DownloadResult sendNextDataBlock(QByteArray const &b, int bNum) const; @@ -161,6 +184,13 @@ public: uint8_t bl_exitBL(uint8_t *sendData) const override; // minimum size of sendData-buffer: 5byte retval: length + + + + + + + // ------------------------------------------------------------------------------ // Level 2 DC2-onboard devices // WR: set time @@ -963,6 +993,17 @@ public: bool cash_startPayment(uint32_t amount) const override; // 17.4.23TS: extended to 32bit + uint8_t cash_paymentProcessing(void) const override; + // run this function periodically while coin payment process to generate necessary signals + // return value: + // 0: stopped 1: starting up 2: coin collection + // 3: finished by User (Push button) 4: finished, Max-Value collected + // 5: finished by escrow + // 10,11: error cannot start + // 12: timeout while payment, coins returned + // 13: stopped by unexpected error + + bool cash_cancelPayment(void) const override; // and return coins @@ -1032,6 +1073,7 @@ public: void sys_restoreDeviceParameter(struct T_devices *deviceSettings) const override; + bool sys_areDCdataValid(void) const override; /* --------------------------------------------------------------------------------------------- // ------------ supervise all hardware components @@ -1076,14 +1118,31 @@ public: signals: void hwapi_templatePrintFinished_OK(void) const override; void hwapi_templatePrintFinished_Err(void) const override; + + void hwapi_coinCollectionJustStarted(void) const override; + void hwapi_coinCollectionAborted(void) const override; + void hwapi_gotNewCoin(void) const override; - void hwapi_vendStopByMax(void) const override; - void hwapi_vendStopByPushbutton(void) const override; + void hwapi_payStopByMax(void) const override; + void hwapi_payStopByPushbutton(void) const override; + + void hwapi_payStopByEscrow(void) const override; + void hwapi_payStopByError(void) const override; + void hwapi_payStopByTimeout(void) const override; + void hwapi_payCancelled(void) const override; + + void hwapi_coinProcessJustStopped(void) const override; + + + + + private slots: void hwapi_slotPrintFinished_OK(void); void hwapi_slotPrintFinished_Err(void); void hwapi_slotGotCoin(void); + void hwapi_slotPayProc(void); }; diff --git a/include/interfaces.h b/include/interfaces.h index 31856ce..43c683d 100644 --- a/include/interfaces.h +++ b/include/interfaces.h @@ -1452,6 +1452,8 @@ public: virtual bool cash_startPayment(uint32_t amount) const=0; // 17.4.23TS: extended to 32bit + virtual uint8_t cash_paymentProcessing(void) const=0; + virtual uint32_t getInsertedAmount(void) const=0; virtual uint16_t getLastInsertedCoin(void) const=0; @@ -1616,6 +1618,8 @@ public: virtual void sys_restoreDeviceParameter(struct T_devices *deviceSettings) const=0; + virtual bool sys_areDCdataValid(void) const=0; + /* --------------------------------------------------------------------------------------------- // ------------ supervise all hardware components // ------------ assess the machine state @@ -1669,9 +1673,20 @@ public: signals: virtual void hwapi_templatePrintFinished_OK(void) const=0; virtual void hwapi_templatePrintFinished_Err(void) const=0; + + virtual void hwapi_coinCollectionJustStarted(void) const=0; + virtual void hwapi_coinCollectionAborted(void) const=0; + virtual void hwapi_gotNewCoin(void) const=0; - virtual void hwapi_vendStopByMax(void) const=0; - virtual void hwapi_vendStopByPushbutton(void) const=0; + virtual void hwapi_payStopByMax(void) const=0; + virtual void hwapi_payStopByPushbutton(void) const=0; + + virtual void hwapi_payStopByEscrow(void) const=0; + virtual void hwapi_payStopByError(void) const=0; + virtual void hwapi_payStopByTimeout(void) const=0; + virtual void hwapi_payCancelled(void) const=0; + + virtual void hwapi_coinProcessJustStopped(void) const=0; }; diff --git a/include/shared_mem_buffer.h b/include/shared_mem_buffer.h index 07cc2b8..d45841f 100644 --- a/include/shared_mem_buffer.h +++ b/include/shared_mem_buffer.h @@ -227,7 +227,7 @@ struct SharedMemBuffer { uint16_t nrOfCoins; bool dcDataValid; uint8_t wakeReason; - + char curPayNewCoin; } store; struct T_globTime { diff --git a/src/datIf.cpp b/src/datIf.cpp index ddc9bc1..14709de 100644 --- a/src/datIf.cpp +++ b/src/datIf.cpp @@ -50,6 +50,7 @@ T_datif::T_datif(QWidget *parent) : QMainWindow(parent) cycl_running=0; //datif_DCdataValid=0; gpi_storeDcDataValid(0); + datif_noResponseCtr=0; } void T_datif::resetChain(void) @@ -69,6 +70,11 @@ char T_datif::datif_cycleSend() uint8_t length, data[66]; bool b_ret; + datif_noResponseCtr++; // inc every 10ms fehlt noch in SysCont + if (datif_noResponseCtr>500) // seit 5s kein Lebenszeichen von DC2 + gpi_storeDcDataValid(0); // fehlt in SysCont + + if (cycl_running) { // request is still running, wait for response before next sending @@ -214,7 +220,10 @@ char T_datif::datif_cycleSend() sendINrequestsAutomatic(); // sendCyclicCmd(); // request all cyclic data sequential } else + { dif_scanStep=0; // always start from beginning + gpi_storeDcDataValid(0); // fehlt in SysCont + } } #ifdef USEHANDSHAKES else @@ -225,6 +234,7 @@ char T_datif::datif_cycleSend() } else { //qDebug() << "com port not available"; // wird ununterbrochen ausgegeben + gpi_storeDcDataValid(0); // fehlt in SysCont } return 0; @@ -842,6 +852,7 @@ char T_datif::isPortOpen(void) void T_datif::StoredRecData() { + datif_noResponseCtr=0; //qDebug() << "StoreRecData called"; // call automatically by T_prot //if (myDCIF->ifDataReceived()) @@ -1210,6 +1221,15 @@ char T_datif::loadRecDataFromFrame() // DB1: last coin signal (value / scale) // DB2,3: last coin value // DB4: lastError from Emp + + // 0: nr of stored coins + // 1: got 2:type 3:err 4=valL 5=valH + +// qDebug() << "got emp coin "<< " " << receivedData[0] <<" " << receivedData[1] +// << " " << receivedData[2]<< " " << receivedData[3] +// << " " << receivedData[4]<< " " << receivedData[5] +// << " " << receivedData[6]<< " " << receivedData[7]; + gpi_storeEmpCoinSignal(receivedData[0], &receivedData[1]); break; @@ -1365,11 +1385,18 @@ char T_datif::loadRecDataFromFrame() newInsertedAmount=uchar2ulong(receivedData[3],receivedData[2],receivedData[1],receivedData[0]); uitmp=uchar2uint(receivedData[5],receivedData[4]); uit2=uchar2uint(receivedData[7],receivedData[6]); - gpi_storeCurrentPayment(newInsertedAmount, uitmp, uit2); - if (newInsertedAmount != lastInsertedAmount) + if (uitmp>0) // nur 1x bei neuer Münze { - emit datif_gotNewCoin(); - lastInsertedAmount=newInsertedAmount; + gpi_storeCurrentPayment(newInsertedAmount, uitmp, uit2); + //void gpi_storeCurrentPayment(uint32_t insertedAmount, uint16_t lastCoinType, uint16_t lastCoinValue) + if (newInsertedAmount != lastInsertedAmount) + { + emit datif_gotNewCoin(); +//qDebug()<<"emit new coin"; + + lastInsertedAmount=newInsertedAmount; + } +qDebug()<<" store new coin"< baudrateMap = { {"1200" , 0}, {"9600" , 1}, {"19200" , 2}, {"38400" , 3}, @@ -51,6 +53,18 @@ hwapi::hwapi(QObject *parent) : QObject(parent) { connect(myDatif, SIGNAL(datif_templatePrintFinished_OK()), this, SLOT(hwapi_slotPrintFinished_OK())); connect(myDatif, SIGNAL(datif_templatePrintFinished_Err()), this, SLOT(hwapi_slotPrintFinished_Err())); connect(myDatif, SIGNAL(datif_gotNewCoin()), this, SLOT(hwapi_slotGotCoin())); + + hwapi_TimerPayment = new QTimer(); + hwapi_TimerPayment->setSingleShot(true); + + QTimer *hwapi_callPayProc = new QTimer(); + connect(hwapi_callPayProc, SIGNAL(timeout()), this, SLOT(hwapi_slotPayProc())); + hwapi_callPayProc->setSingleShot(false); + hwapi_callPayProc->start(100); // in ms + + hwapi_lastStartAmount=0; + hwapi_cash_lastCollectionState=0; + hwapi_paymentStarted=0; } hwapi::~hwapi() { @@ -59,6 +73,12 @@ hwapi::~hwapi() { } } + +void hwapi::hwapi_slotPayProc(void) +{ + cash_paymentProcessing(); +} + void hwapi::hwapi_slotPrintFinished_OK(void) { emit hwapi_templatePrintFinished_OK(); } @@ -74,7 +94,7 @@ void hwapi::hwapi_slotGotCoin(void) { uint32_t newSum=epi_CurrentPaymentGetAmount(); if (newSum>=hwapi_lastStartAmount) - emit hwapi_vendStopByMax(); + emit hwapi_payStopByMax(); } @@ -1636,6 +1656,20 @@ uint8_t hwapi::coin_escrowFlapOpened(void) const + + + + + +// ------------------------------------------------------------------------------ +// Level4 devices are operated by DC +// processes with more then one devices +// timer controlled or long term processes +// ------------------------------------------------------------------------------ + + + + void hwapi::sendDeviceSettings(uint8_t kindOfPrinter, uint8_t kindOfCoinChecker, uint8_t kindOfMifareReader, uint8_t suppressSleep, uint8_t kindOfModem, uint8_t kindOfCredit) const @@ -3507,11 +3541,7 @@ bool hwapi::prn_printTemplate(uint8_t nrOftemplate) const // nr = 1..32 { // return true if sending, false if cmd-stack is full - - // 3.5.23: die dynVals und alle templates sollen am stück gesendet - uint8_t data[64]; - data[0]=nrOftemplate; - return longFDcmd_set(152, 0,0, 1, data); + return sendFDcmd_set(152, 0,0, nrOftemplate,0,0,0); } void hwapi::log_getHoldAccountNumbers(uint8_t *nrOfVals, uint16_t *accNr ) const @@ -3608,11 +3638,190 @@ bool hwapi::cash_startPayment(uint32_t amount) const dat2=ulong2uchar(amount, 1); dat3=ulong2uchar(amount, 2); dat4=ulong2uchar(amount, 3); + hwapi_cash_lastCollectionState=0; + sendFDcmd_set(155, 0,0, dat1,dat2,dat3,dat4); - return sendFDcmd_set(155, 0,0, dat1,dat2,dat3,dat4); + hwapi_paymentStarted=1; + hwapi_TimerPayment->start(5000); // in ms + + return true; } + +uint8_t hwapi::cash_paymentProcessing(void) const +{ + // run this function periodically while coin payment process to generate necessary signals: + // virtual void hwapi_coinCollectionJustStarted(void) const=0; + // virtual void hwapi_coinCollectionAborted(void) const=0; + // virtual void hwapi_gotNewCoin(void) const=0; // comes from: hwapi_slotGotCoin() + // virtual void hwapi_payStopByMax(void) const=0; // comes from: hwapi_slotGotCoin() + // virtual void hwapi_payStopByPushbutton(void) const=0; // comes from cash_stopPayment() + // virtual void hwapi_payStopByEscrow(void) const=0; + // virtual void hwapi_payStopByError(void) const=0; + // virtual void hwapi_payStopByTimeout(void) const=0; + // virtual void hwapi_payCancelled(void) const=0; + + // virtual void hwapi_coinProcessJustStopped(void) const=0; + + // return value: + // 0: stopped 1: starting up 2: coin collection + // 3: finished by User (Push button) 4: finished, Max-Value collected + // 5: finished by escrow + // 6: money encashed + // 7: cancelled + // 10,11: error cannot start + // 12: timeout while payment, coins returned + // 13: stopped by unexpected error + + + + struct T_emp empStat; + struct T_dynamicCondition myDynMachCond; + uint8_t collActiv=0, payInProg, empState; + + if (hwapi_paymentStarted<1) + return 0; // off + + collActiv=1; // starting up payment + emp_getAllParameters(&empStat); + //collActiv=empStat.paymentRunning; + + empState=empStat.state; + // 0=start command + // 1=powered, do emp ini, send reset + // 2=delay + // 3=wait for response, requesting status after response + // 4,5 through, startup + // 6: wait for status + // 7: through, startup + // 8: IDLE state. EMP is up and ready, polling is running + // 9: polling on, payment not yet on + // 10: payment, check coins + // 11: through + // 12: wait 1s for last coin + // 90: stop all, 1s delay + // 99: off, all stopped + + sys_getDynMachineConditions(&myDynMachCond); + payInProg= myDynMachCond.paymentInProgress; + // 0: stopped by timeout + // 1: running 2: wait4lastCoin + // 3: payment stopped manually, coins in Escrow + // 4: payment stopped autom, amount collected, coins in Escrow + // 5: payment stopped, escrow full, coins in Escrow + // 6: coins encashed 7:coins returned + // 8: CoinChecker or MDB on Error + + + if (payInProg==8) + { + // coin checker faulty, cannot start + if (hwapi_paymentStarted==1) + { + hwapi_paymentStarted=90; // stop due to error + emit hwapi_coinCollectionAborted(); + //sendFDcmd_set(156, 0,0, 2,0,0,0); // cancel payment + collActiv=10; // error cannot start + } + } else + + if (empState>=10 && empState<=12) + { + // coin acceptance is active now: + hwapi_TimerPayment->stop(); // to avoid error signal + if (hwapi_paymentStarted==1) // 1=wait for coin checker being ready + { + hwapi_paymentStarted=2; // coins can be inserted no + emit hwapi_coinCollectionJustStarted(); + } + } else + { + // EMP not (yet) ready + + if (!hwapi_TimerPayment->isActive()) + { + // 5s after start-payment the coin-checker is still not ready + hwapi_TimerPayment->stop(); + if (hwapi_paymentStarted==1) + { + hwapi_paymentStarted=90; // stop due to error + emit hwapi_coinCollectionAborted(); // error cannot start + //sendFDcmd_set(156, 0,0, 2,0,0,0); // cancel payment + collActiv=11; // error cannot start + } + } + } + + if (hwapi_paymentStarted==2) + { + collActiv=2; // coin collection active + + // coins can be inserted now, wait for end + if (payInProg==0) // timeout + { + hwapi_paymentStarted++; + collActiv=12; // stop by timeout + emit hwapi_payStopByTimeout(); + } else + if (payInProg==3) // user pressed "Next/Continue" + { + hwapi_paymentStarted++; + collActiv=3; + emit hwapi_payStopByPushbutton(); + } else + if (payInProg==4) // max achieved + { + hwapi_paymentStarted++; + collActiv=4; + emit hwapi_payStopByMax(); + } else + if (payInProg==5) // escrow full + { + hwapi_paymentStarted++; + collActiv=5; + emit hwapi_payStopByEscrow(); + } else + if (payInProg==6) // encashed + { + hwapi_paymentStarted++; + collActiv=6; + + } else + if (payInProg==7) // returned, user pressed Cancel button + { + hwapi_paymentStarted++; + collActiv=7; + emit hwapi_payCancelled(); + } else + + if (empState<9 || payInProg==8) + { + hwapi_paymentStarted++; + collActiv=13; // stopped by unexpected error + emit hwapi_payStopByError(); + } + } + + if (empState<8 || empState>12) + epi_clearCurrentPayment(); // to avoid wrong "got-coin" messages + + + if (hwapi_paymentStarted==90 || hwapi_paymentStarted==3 ) + { + // EMP error, wait till process finished + if (empState==99 && (payInProg==0 || payInProg>5) ) + { + // everything stopped, no more coins in escrow + hwapi_paymentStarted=0; + emit hwapi_coinProcessJustStopped(); + } + } + + return collActiv; +} + + uint32_t hwapi::getInsertedAmount(void) const { return epi_CurrentPaymentGetAmount(); @@ -3643,7 +3852,7 @@ bool hwapi::cash_stopPayment(void) const { // DB1: 1=encash 2=cancel & return coins // 3=stop and keep coins in escrow - emit hwapi_vendStopByPushbutton(); + emit hwapi_payStopByPushbutton(); return sendFDcmd_set(156, 0,0, 3,0,0,0); } @@ -3666,6 +3875,11 @@ bool hwapi::vend_failed(void) const } + + + + + uint8_t hwapi::mif_getCardType(QString *cardholder) const // return 1,2,3,4 = upper, lower access card, printer test, coin test // cardholder: 7byte Name-String diff --git a/src/storeINdata.cpp b/src/storeINdata.cpp index 4f4035b..dca481f 100644 --- a/src/storeINdata.cpp +++ b/src/storeINdata.cpp @@ -24,6 +24,7 @@ bool indat_isPrinterOn() { return indat_savePrnPwr; } + static bool indat_saveMifPwr; void indat_storeMifarePower(bool isOn) { @@ -34,6 +35,7 @@ bool indat_isMifareOn() { return indat_saveMifPwr; } + static bool indat_MdbIsOn; void indat_storeMDBisOn(bool isOn) { @@ -44,6 +46,11 @@ bool indat_isMdbOn() { return indat_MdbIsOn; } + +// ////////////////////////////////////////////////////////////////////////// + + + void gpi_storeSlaveSerParams(uint8_t slaveBaudRate, uint8_t NrDataBits, uint8_t parity, uint8_t NrStopBits) { // store numbers @@ -95,6 +102,7 @@ void gpi_storeGenerals(uint8_t genNr, QString text) { text.toStdString().c_str(), sizeof(SharedMemBuffer::getDataConst()->genStrings[0])); } + } QString epi_loadGenerals(uint8_t genNr) { @@ -108,6 +116,9 @@ QString epi_loadGenerals(uint8_t genNr) { return " "; } + + + // ------------------------------- void gpi_storeUID(uint8_t const *buf8byteUid) { @@ -282,6 +293,7 @@ QString epi_getSlaveTimeDateStr() { } + // /////////////////////////////////////////////////////////////////////////////////// // analog values // /////////////////////////////////////////////////////////////////////////////////// @@ -310,6 +322,7 @@ uint16_t epi_loadAIs(uint8_t aiNr) { // ADC0: temp // 1: voltage // 2: brightness +#define MAXNROF_MEASURE 4 uint32_t epi_loadMeasureValue(uint8_t ValueNr) { // ValueNr 0=ADC0, 1=ADC1 aso... @@ -989,6 +1002,15 @@ void gpi_storePrinterFonts(uint8_t const *buf) { sizeof(SharedMemBuffer::getData()->Sdata.PRN_FONTS)); } +/* + qDebug()<<"printer fonts stored " <store.insertedAmount = 0; p_lastCoin = 0; + memset((char *)&SharedMemBuffer::getData()->store.lastCoinType[0], + 0x00, sizeof(SharedMemBuffer::getData()->store.lastCoinType)); + memset((char *)&SharedMemBuffer::getData()->store.lastCoinValue[0], + 0x00, sizeof(SharedMemBuffer::getData()->store.lastCoinValue)); + SharedMemBuffer::getData()->store.curPayNewCoin = 0; } void gpi_storeCurrentPayment(uint32_t insertedAmount, @@ -1140,7 +1171,9 @@ void gpi_storeCurrentPayment(uint32_t insertedAmount, SharedMemBuffer::getData()->store.insertedAmount = insertedAmount; SharedMemBuffer::getData()->store.lastCoinType[p_lastCoin] = lastCoinType; SharedMemBuffer::getData()->store.lastCoinValue[p_lastCoin] = lastCoinValue; + p_lastCoin++; + SharedMemBuffer::getData()->store.curPayNewCoin++; } uint32_t epi_CurrentPaymentGetAmount(void) { @@ -1225,6 +1258,8 @@ void epi_restoreDeviceConditions(uint8_t *leng, uint8_t *data) { *leng); } + + // store dynamic machine conditions void gpi_storeDynMachineConditions(uint8_t leng, uint8_t const *data) { SharedMemBuffer::getData()->store.machCondLen = leng; @@ -1329,8 +1364,7 @@ bool gpi_areDcDataValid() } - - - - - +bool epi_areDcDataValid() +{ + return SharedMemBuffer::getData()->store.dcDataValid; +}