#include "datIf.h" #include "sendWRcmd.h" #include "controlBus.h" #include "storeINdata.h" #include #include #include // called from MainWindow() #define DATIF_MAXCMDS 16 static uint8_t dif_dataStep; static uint8_t dif_scanStep; //, RDBLKNR; static uint8_t datif_OutCmdpara1, datif_OutCmdpara2, datif_OutCmdpara3, datif_OutCmdpara4; static uint16_t datif_OutCmdpara5; static uint32_t datif_OutCmdpara6; static uint8_t cycl_running; static bool doRepeat; static uint8_t keepLastWrCmd, keepLastRdCmd; static uint8_t keepLastblockNum, keepLastdat1, keepLastdat2, keepLastdat3, keepLastdat4; static uint8_t keepLastlength, keepLastdata64[66]; // new, 17.7.23: static uint8_t datif_cmdWasPerformed; static uint8_t datif_repeatCtr; static uint8_t datif_kindOfCmd; static uint8_t datif_pNextCmd, datif_sendSlowCmd; //#define DATIF_MAXTO_WAIT4RESP 80 //20 erhöht am 17.7 geht viel besser // höchster gemessener Wert (bei 20ms): 6 //#define DATIF_GAP4RESP 1 // weniger als 1 geht nicht. erzeugt eine Lücke zw. 20..65ms (2 Programmzyklen) //#define DATIF_CTR_GOTRESPVAL 100 T_datif::T_datif(QObject *parent) : QObject(parent) { QByteArray myBA; QDir myDir("../dmd"); if (!myDir.exists()) myDir.mkdir("../dmd"); myDCIF = new T_prot(); // valid data was received, storing connect(myDCIF, SIGNAL(framerecieved()), this, SLOT(StoredRecData())); // new, 9.11.20 data for DC-bootloader received not matchind Pprot //connect(myDCIF, SIGNAL(rawDataRecieved()), this, SLOT(BLdataRecData())); // cyclic transmission of INPUT-Requests datif_trigger = new QTimer(); connect(datif_trigger, SIGNAL(timeout()), this, SLOT(datif_cycleSend())); datif_trigger->setSingleShot(false); datif_trigger->start(20); // in ms, // passing Signal through //connect(myDCIF, SIGNAL(framerecieved()), this, SLOT( ResponseRecieved() )); datif_OutCmdpara1=0; datif_OutCmdpara2=0; datif_OutCmdpara3=0; datif_OutCmdpara4=0; dif_dataStep=1; dif_scanStep=0; selectedSlaveAddr=FIX_SLAVE_ADDR; cycl_running=0; gpi_storeDcDataValid(0); // data are not yet valid, no response from DC by now datif_noResponseCtr=0; datif_repeatCtr=0; datif_cmdWasPerformed=0; // 0: no response by now datif_kindOfCmd=0; gpi_storeOverallResult(0xFF); // neu, 24.5.23: Alle Daten zusätzlich in Datei speichern // if (datei_ifFileExists(FILENAME_SHAREDDATA)) // { // myBA.clear(); // myBA=datei_readFromFile(FILENAME_SHAREDDATA); // } /* // Testfile ereugen: csv_startCreatingFile(); csv_addUintToFile(0); csv_addUintToFile(1); csv_addUintToFile(2); csv_addUintToFile(3); csv_addUintToFile(4); csv_addUintToFile(5); myBA=csv_readbackArray(); datei_clearFile(FILENAME_SHAREDDATA); datei_writeToFile(FILENAME_SHAREDDATA, myBA); */ doRepeat=true; datif_pNextCmd=0; datif_sendSlowCmd=0; } void T_datif::resetChain(void) { dif_scanStep=0; } char T_datif::datif_cycleSend() { // cyclic transmission of INPUT-Requests // call cyclic every 20ms to send next request , then wait for response before sending again!!! //uint16_t nxtAsCmd; uint8_t dataSendBuf[160], dataBufLen, dbl; //static uint8_t BlockCounter; uint8_t nextWrCmd, nextRdCmd, blockNum, dat1, dat2, dat3, dat4; uint8_t length, data[66]; bool b_ret; // send next command if ( !myDCIF->isPortOpen()) { //qDebug() << "com port not available"; // wird ununterbrochen ausgegeben gpi_storeDcDataValid(0); // DC data not valid return 0; } // supervise if DC data are valid datif_noResponseCtr++; // inc every 20ms if (datif_noResponseCtr>250) // no life sign from device controller (DC) for about 3s gpi_storeDcDataValid(0); // DC data has not updated for >=5s -> no longer valid! // Ueberwachung ob ein oder mehrere Commands am Stueck erfolgreich waren if (gpi_wantToResetSupervision()) { gpi_storeOverallResult(0xFF); } // wait for response ---------------------------------------------------------------------------- // "cycl_running" entscheidet ob ein neues Kommando gesendet werden darf oder ob wir noch auf die Antwort des letzten warten // bei der Antwort gibt's drei Faelle: // a) Antwort OK --> nach einer Luecke von 10ms neues Kommando schicken // b) Antwort meldet Fehler -> 2x wiederholen (nach einer Luecke von 10ms ) // c) gar keine Antwort, Timeout nach 100ms -> 2x wiederholen (nach einer Luecke von 10ms ) // cycl_running=0: nichts zu tun 1: Mitteilung: Kommando wurde soeben abgesendet, 2,3,4 = Wiederholung if (cycl_running) // 21.9.23 doRepeat hier raus sonst gehts warten auch nicht mehr (BL) // if (cycl_running && doRepeat) { // request is still running, wait for response before next sending //qDebug()<< "datif wait for response"; datif_trigger->stop(); datif_trigger->start(20); // ruft "this" (datif_cycleSend) erneut in 20ms auf // mit 10 kein Unterscheid weil Zykluszeit grösser cycl_running++; // inc every 20...30ms // warte max 100ms auf Antwort if (cycl_running >80 && cycl_running <95) // neu 13.9.23 mind. 40 damit Templates // in Folge gedruckt werden koennen // 95: muss nur kleiner sein als die 100 fuer die Luecke // 17.10.23: 50--> 80 { // 100ms vergangen, bisher keine Antwort, also Kommando wiederholen qDebug()<< "datif timeout no response for wr/rd cmd "<< keepLastWrCmd << " " << keepLastRdCmd; cycl_running = 0; // gleich wiederholen weil ja schon ewig nichts mehr reinkam datif_cmdWasPerformed=2; // NO :(( gpi_storeLastResult(8); } if (cycl_running>=101) // 100 + 1 { // Antwort ist gekommen, also nach kurzer Luecke naechstes (datif_cmdWasPerformed==1) // oder nochmal gleiches (datif_cmdWasPerformed==2) Kommando senden //qDebug()<< "datif got any response"; cycl_running=0; } // hier stoppen, weil Antwort des letzten Cmds noch nicht da return 0; } // 17.7.2023: repeat commands if result was !=OK ------------------------------------------------------------------- if (datif_cmdWasPerformed==2 && doRepeat) // Cmd was not or false performed und Wiederholen erwuenscht { //qDebug()<<"datif: repeating..."; datif_repeatCtr++; if (datif_repeatCtr>3) { // give in, 3x no or wrong response datif_cmdWasPerformed=0; datif_kindOfCmd=0; cycl_running=0; gpi_storeOverallResult(2); return 0; } // repeat last command as we got no or bad result (error) if (datif_kindOfCmd==2) { //qDebug() << "datif: repeat long FDcmd (wr/rd): " <setUserWriteData(keepLastWrCmd, keepLastblockNum, keepLastlength, keepLastdata64); myDCIF->setUserReadData(keepLastRdCmd); myDCIF->sendUserData(selectedSlaveAddr); cycl_running=1; // 1: start transmission and reset TOcounter datif_cmdWasPerformed=0; } else if (datif_kindOfCmd==1) { //qDebug() << "datif: repeat short FDcmd (wr/rd): " <setUserWriteData(keepLastWrCmd, keepLastblockNum, 4, data); myDCIF->setUserReadData(keepLastRdCmd); myDCIF->sendUserData(selectedSlaveAddr); cycl_running=1; // 1: start transmission datif_cmdWasPerformed=0; } else { qDebug() << "datif: unknown cmd, stop repeating wr/rd:" << keepLastWrCmd << " " << keepLastRdCmd; datif_cmdWasPerformed=0; cycl_running=0; datif_kindOfCmd=0; } return 0; } // end of repeat commands // Send new command --------------------------------------------------------------- // from 11.4.23: direkt access to fastDevice Interface // send long fast direct command if (checkNextFDcmd()==2) { // return 0: no command waiting // 1: short cmd // 2: long cmd gpi_storeOverallResult(0); b_ret=longFDcmd_get(&nextWrCmd, &nextRdCmd, &blockNum, &length, data); if (b_ret) { keepLastWrCmd=nextWrCmd; keepLastRdCmd=nextRdCmd; keepLastblockNum=blockNum; keepLastlength=length; for (int ii=0; ii<66; ii++) keepLastdata64[ii]=data[ii]; myDCIF->setUserWriteData(nextWrCmd, blockNum, length, data); myDCIF->setUserReadData(nextRdCmd); myDCIF->sendUserData(selectedSlaveAddr); //qDebug()<<"Datif send long FD cmd (wr/rd): "<setUserWriteData(nextWrCmd, blockNum, 4, data); myDCIF->setUserReadData(nextRdCmd); myDCIF->sendUserData(selectedSlaveAddr); //qDebug()<<"Datif send short FD cmd (wr/rd): "<0) { cycl_running=1; // 1: start transmission //qDebug() << "datif: sending " << dataBufLen << " bytes to BL: " // << QTime::currentTime().toString(Qt::ISODateWithMs) <<" " // << QByteArray((const char*)dataSendBuf,dataBufLen).toHex(':'); datif_OUT_SendRandomData(dataSendBuf, dataBufLen); datif_kindOfCmd=0; datif_repeatCtr=0; doRepeat=false; return 0; } // if no direct comands need to be sent then send input requests if (gpi_isEmmisionOn()) // auto send button is pressed { //qDebug() << "auto request is on"; datif_kindOfCmd=0; sendINrequestsAutomatic(); // request all cyclic data sequential } else { dif_scanStep=0; // always start from beginning gpi_storeDcDataValid(0); } datif_cmdWasPerformed=0; // 0: no response by now return 0; } // ############################################################################## // sende alle Befehle um die Eingangsdaten abzufragen der Reihe nach: char T_datif::sendINrequestsAutomatic(void) { //qDebug() << "send IN request " << dif_scanStep; // uint8_t datif_autoRequCommandList[50]={11, 12, 18, 104, 106, 103, 14, 27, 109, 17, 19, 23, 30, 31, 32, 33, 114, 35}; uint8_t datif_autoRequCommandList[30]={11, 12, 14, 17, 18, 19, 22, 23, 27, 30, 31, 32, 33, 35, 102, 103, 104, 106, 107, 109, 114,0,0,0,0,0,0,0,0,0}; uint8_t datif_maxNrCommands=21, datif_sendNow; // special commands: // 102: get IOs run constantly!!! // 108, 112: get inserted amount in cent in sum, quick while purchase // 113: get wake source, can be requested one time by Master after wake. Not here // 19: get time and date and Extra values. poll occasionally and if needed // 107, 22: MDB: poll if needed doRepeat=true; // 20.9.23 15uhr (after release) if (datif_sendSlowCmd>0) { // send special command, slowly datif_sendNow=datif_autoRequCommandList[datif_pNextCmd++]; if (datif_pNextCmd >= datif_maxNrCommands) datif_pNextCmd=0; if (datif_sendNow>0) // never send Command 0 datif_sendIOrequest(0, datif_sendNow, 0); else datif_pNextCmd=0; // falls in der Liste 0 vorkommt dann von vorne beginnen //qDebug()<< "datif send request " << datif_sendNow; } else { if (gpi_getNowCoinPay()) { // request coin input, high priority datif_sendIOrequest(0, 112, 0); //qDebug()<< "datif send request 112 get coins"; } else { // request inputs, high priority datif_sendIOrequest(0, 31, 0); // 102 // while coin collection DIs are polled slowly with datif_autoRequCommandList[] //qDebug()<< "datif send request 102 get DIs"; } } if (++datif_sendSlowCmd>1) datif_sendSlowCmd=0; // 0,1,0,1,0,1,0.... return 0; // 25.9.2023, wichtig sonst bleibt die komplette PTU stehen!!!! } char T_datif::isPortOpen(void) { return (myDCIF->isPortOpen()); } // ############################################################################## // Empfangsdaten einsortieren // ---------------------------------------------------------------------------------------------- void T_datif::StoredRecData() { // got response from slave on last request // call automatically by T_prot uint8_t res; datif_noResponseCtr=0; loadRecDataFromFrame(); res=myDCIF->ifDataReceived(); // return: 0xFF: result unknown 0=OK // 1= wrong length 2=wrong start sign 5= wrong crc // 6= slave: master cmd was wrong 7: slave: could not write/read data gpi_storeLastResult(res); } char T_datif::loadRecDataFromFrame() { // is called even with wrong received data in order to speed up the process (stop waiting for response) // necessary data in T_prot: uint16_t readSource, uitmp,uit2; uint16_t readAddress; //uint8_t pp; uint8_t SlaveAdr, RdDleng; uint8_t receivedData[FRAME_DATALEN]; QString localStr; uint32_t ultmp; //int portNr; bool ret; uint8_t uctmp; //, res; // maxai char ctmp; //static uint8_t lastResult; //uint8_t prnResult; static uint32_t lastInsertedAmount; uint32_t newInsertedAmount; // uint32_t mifatb_cunu, mifatb_cardnu, mifatb_creditAmount, mifatb_creditTime; // QString mifatb_cardTyp, mifatb_lpr, mifatb_group, mifatb_zone; // uint8_t nn; char cc; // uint8_t mifatb_times[10]; if (gpi_getNowIsBootload()) { datif_cmdWasPerformed=1; cycl_running=100; // stop waiting for response and wait 1cycle till next sending return 0; } ret=myDCIF->getReceivedInData(&SlaveAdr, &readSource, &readAddress, &RdDleng, receivedData); // nur true wenn CommandState OK und readState OK // retval: data valid, only one time true, true if CommandState OK and readState OK gpi_storeResultOfLastRequest(ret); if (ret==false) { // Details anzeigen: //res= myDCIF->ifDataReceived(); // return: 0xFF: result unknown 0=OK // 1= wrong length 2=wrong start sign 5= wrong crc // 6= slave: master cmd was wrong 7: slave: could not write/read data /* qDebug() << "datif: bad response, error: " << res << " " << " lastWR: " << keepLastWrCmd << " lastRd: " << keepLastRdCmd; qDebug("datif_recData: %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d ", receivedData[0], receivedData[1], receivedData[2], receivedData[3], receivedData[4], receivedData[5], receivedData[6], receivedData[7], receivedData[8], receivedData[9], receivedData[10], receivedData[11], receivedData[12], receivedData[13], receivedData[14], receivedData[15]); */ datif_cmdWasPerformed=2; // NO :(( cycl_running=100; // stop waiting for response and wait 1cycle till next sending return 0; } datif_cmdWasPerformed=1; // YES :), stop repeating cycl_running=100; // stop waiting for response //qDebug() << "datif: got valid response "; gpi_storeRecPayLoad(RdDleng, receivedData); // save for host (user of hwapi) // uint8_t nn; //qDebug() << "\n datif: got valid data, rdsrc:" << readSource << " rdadd:" << readAddress // << " rdlen:" << RdDleng; // qDebug("datif_recData: %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d ", // receivedData[0], receivedData[1], receivedData[2], receivedData[3], // receivedData[4], receivedData[5], receivedData[6], receivedData[7], // receivedData[8], receivedData[9], receivedData[10], receivedData[11], // receivedData[12], receivedData[13], receivedData[14], receivedData[15]); // readSource: reflects the READ Command if possible // readAddress: reflects the requested read/write address if slave could perform // lastWakeSrc: if Slave wakes master, this ist the reason for it (e.g. button pressed) // RdDataLength: number of bytes in receivedData //firstDB=receivedData[0]; // just shorter, is used very often //scndDB=receivedData[1]; //thrdDB=receivedData[2]; localStr.clear(); // receivedData[0]='a'; // receivedData[1]='B'; // receivedData[2]='1'; // receivedData[3]='-'; for (int ii=0; ii>2)&3)); uctmp=receivedData[1]; gpi_storeDI_contactPowerIsOn(uctmp&0x10); gpi_storeDI_optos((uctmp>>5)&3); uctmp=receivedData[2]; gpi_storeDI_auxIn(uctmp); uctmp=receivedData[3]; gpi_storeDI_ptuWake(uctmp&1); gpi_storeDI_readbackMdbTxD(uctmp&2); gpi_storeDI_prnReady(uctmp&4); gpi_storeDI_CoinAttach(uctmp&8); gpi_storeDI_CoinEscrow(uctmp&16); gpi_storeDI_mifareCardTapped(uctmp&32); gpi_storeDI_rejMot_home(uctmp&64); uctmp=receivedData[4]; //gpi_storeDI_modemWake(0); // gibt's gar nicht! gpi_storeDI_mbdWake(uctmp&1); gpi_storeDI_MifarePowerIsOn(uctmp&2); gpi_storeDI_AuxPowerIsOn(uctmp&8); gpi_storeDI_GsmPowerIsOn(uctmp&16); gpi_storeDI_CreditPowerIsOn(uctmp&32); gpi_storeDI_PrinterPowerIsOn(uctmp&64); gpi_storeDI_MdbPowerIsOn(uctmp&128); gpi_storeDI_paperLow(receivedData[5]); break; case CMD2DC_RdBkAllOutputs: //103 /* // alle DO's in einen 8byte Puffer zusammenstellen, werden in einen Rutsch zum Master gesendet outBuf[0]: bit 0: TestMdbInput 1: RS1 drv enabled 2: RS1switch: 1=GSM 0=printer 3: RS2switch: H: mifare L: credit 4: Vbarcode=Vaux is on outBuf[1]: bit 0: coin led 1: 0 2: paper led 3: pinpad led 4: start led 5: service led outBuf[2]: bit 0: siren 1: relay 2: ptu wake 3: shutter 4: shutter test 5: escrowGive 6: escrowTake 7: prn power outBuf[3]: Motor 1: 0:off 1=vorwärts / öffnen 2=rückw./zu 3: beide ein outBuf[4]: Motor 2: 0:off 1=vorwärts / öffnen 2=rückw./zu 3: beide ein */ uctmp=receivedData[0]; gpi_storeDO_mdbRxTst(uctmp&1); gpi_storeDO_auxPower(uctmp&0x10); gpi_storeDO_serialSwitch((uctmp>>1)&7); // serial drv 0:on/off, 1:Serial mux1, 2:Serial mux2 uctmp=receivedData[1]; gpi_storeDO_ledsAndFan(uctmp); // bit0: coinled 1:front_illu 2: paper-led 3:pinpad-led 4:start-led 5:service-led 6:fan uctmp=receivedData[2]; gpi_storeDO_sirenAndRelay(uctmp&3); // bit0: siren 1:relay gpi_storeDO_ptuWake(uctmp&4); gpi_storeDO_coinShutter(uctmp>>3); // bit0: Coin shutter output, bit1: input-test-output gpi_storeDO_coinEscrow(uctmp>>5); // retval: 1:return flap is open 2:take flap is open 0:closed gpi_storeDO_printerPwrOn(uctmp&0x80); uctmp=(receivedData[4] & 3); uctmp<<=2; if (receivedData[3] & 1) uctmp |=1; if (receivedData[3] & 2) uctmp |=2; gpi_storeDO_motorOutputs(uctmp); // bit0: upper lock forw bit 1 backw bit2: lowLock forw bit3: LL backw break; case 109: // get reader status and card type //gpi_storeMifReaderStateAndCardType(receivedData); //gpi_storeNewMifareCard(receivedData[0], &receivedData[1]); break; case 24: gpi_storeMifHwData(receivedData); /* struct T_Mifare { UCHAR ReaderState; // 1: OK 0: not OK UCHAR res1; UCHAR ReaderVersion[10]; UCHAR CardPresent; UCHAR CardSelected; UCHAR Cardtype; UCHAR CardAllowed; // 0,1 nur Mifare Classic 1k und 4k zugelassen UCHAR CardSize; // 1 or 4 (kB) UCHAR LengOfUid; // 4 or 7 (byte) UCHAR UID[8]; // 4 byte oder 7 byte, Format binär // 26 byte bis hier UCHAR res2; UCHAR res3; ULONG UidH; // bei 4byte Uid alles 0 ULONG UidL; UCHAR SectorLogged; // result of loggin: 2=success 3=failed 1=no_tag 8=addr overflow F0=wrongCmd UCHAR CurrentSector; UCHAR RD_WR_Result; UCHAR res4; // 40byte lang }; */ break; case CMD2DC_RdBk_AtbCardType: //25 // DC reports the type of mif-card (valid ATB card?) gpi_storeMifAtbData(receivedData); /* mifatb_cunu=uchar2ulong(receivedData[3], receivedData[2],receivedData[1],receivedData[0]); mifatb_cardnu=uchar2ulong(receivedData[7], receivedData[6],receivedData[5],receivedData[4]); mifatb_cardTyp.clear(); for (nn=0; nn<4; nn++) mifatb_cardTyp.append(char(receivedData[8+nn])); mifatb_lpr.clear(); for (nn=0; nn<16; nn++) mifatb_lpr.append(char(receivedData[12+nn])); mifatb_group.clear(); for (nn=0; nn<8; nn++) mifatb_group.append(char(receivedData[28+nn])); mifatb_zone.clear(); for (nn=0; nn<8; nn++) mifatb_zone.append(char(receivedData[36+nn])); for (nn=0; nn<10; nn++) mifatb_times[nn]=receivedData[44+nn]; // 0..9: (Start) day, month, year, hh, min (Stop) day, month, year, hh, min, mifatb_creditAmount= uchar2ulong(receivedData[57], receivedData[56],receivedData[55],receivedData[54]); mifatb_creditTime = uchar2ulong(receivedData[61], receivedData[60],receivedData[59],receivedData[58]); // for the 2020 cards the field "mifatb_creditAmount" is used as expire date/time: //for (nn=0; nn<5; nn++) // mifatb_times[nn]=receivedData[54+nn]; falsch ultmp=mifatb_creditAmount; mifatb_times[4]=ultmp%100; ultmp/=100; mifatb_times[3]=ultmp%100; ultmp/=100; mifatb_times[2]=ultmp%100; ultmp/=100; mifatb_times[1]=ultmp%100; ultmp/=100; mifatb_times[0]=ultmp%100; qDebug()<<"got MifAtbData: "<0: error // bit0: paper low 1: no paper 2: temperature error // 3: head open 4: paper jam in cutter // 6: no response 7: bad response from printer gpi_storePrinterState(receivedData); // derzeit 10bytes ( 0x2A02) break; case CMD2DC_RdBk_PrnFonts: // 26 //D0: font table/type //D1: size //D2: height //D3: width //D4: bold //D5: invers //D6: underlined //D7: density //D8: speed //D9: Alignment gpi_storePrinterFonts(receivedData); // derzeit 10bytes break; case CMD2DC_RdBk_AllPrnData: // 27 gpi_storePrinterState(receivedData); // derzeit 10bytes ( 0x2A02) gpi_storePrinterFonts(&receivedData[10]); // derzeit 10bytes /* qDebug()<<"printer fonts stored " <0) // nur 1x bei neuer Münze 6.10.23 aendern: beim Wechsler hat die kleinste Muenze immer coin type 0! if (uit2>0) { 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()<<"datif store new coin"<28) { gpi_storeDeviceConditions(RdDleng, receivedData); } break; case 31: // Get dynamic machine conditions (doors, voltage, alarm….) if (RdDleng>50) { gpi_storeDcDataValid(1); // DC-Data are valid as DC responded. // Could be set to every response but this (31) // is a very common and very important request gpi_storeDynMachineConditions(RdDleng, receivedData); } /* funktioniert, ist aber nicht nötig. Signal wird nach dem shared memory erzeugt prnResult=receivedData[52]; if (prnResult != lastResult) { // new result if (prnResult==1) { emit datif_templatePrintFinished_OK(); } else if (prnResult==2) { emit datif_templatePrintFinished_Err(); } lastResult=prnResult; }*/ break; case 32: // Get current cash level (in vault) // bytes 0..3: amount bytes 4,5=Nr.ofCoins in vault ultmp=uchar2ulong(receivedData[3],receivedData[2],receivedData[1],receivedData[0]); uitmp=uchar2uint(receivedData[5],receivedData[4]); gpi_storeCBlevel(ultmp, uitmp); break; case 33: // Get all backuped acc. Numbers // 8 UINTs with acc-nr gpi_storeDCbackupAccNr(RdDleng, receivedData); break; case 35: gpi_storeMifCardType(RdDleng, receivedData); break; case 38: // Get stored account record backup // readAddress, &RdDleng, receivedData //if (RdDleng>50) // 1.8.23 nach Verlängerung des Datensatzes um 20byte falsch!!! //{ gpi_storeVaultRecord(readAddress, receivedData ); // always/max 64byte /* qDebug()<<"datif cmd38 got vault data. blockNr: "<60) { gpi_storeDynData(receivedData); } break; case 40: //qDebug()<<"datif got response 40 bytes: " << RdDleng; if (RdDleng>60) { gpi_storeTubeLevel(receivedData); } break; case 41: // get BNA parameters if (RdDleng>50) { gpi_storeBnaParams(receivedData); } break; case 21: // readback version strings of all Json-File in DC // gpi_storeJsonVersion(readAddress, receivedData); break; case 116: // get BNA current collection if (RdDleng>7) { gpi_storeBnaCollection(receivedData); } break; case 42: // get BNA box content and value of types // qDebug()<< "CAmaster datif_got 42 "; // for (uctmp=0; uctmp<64; uctmp++) // qDebug()<60) { gpi_storeBnaContent(receivedData); } break; } readSource=0; // 17.05.2023: to avoid multiple recording return 0; } // subs: // ---------------------------------------------------------------------------------------------- // erstelle WRITE Datensätze // ---------------------------------------------------------------------------------------------- // always use this three functions to send data: //void myDCIF->setUserWriteData(uint16_t WriteCmd, uint16_t WrAddr, uint8_t WrDatLen, uint8_t *data); //void myDCIF->setUserWriteData(uint16_t WriteCmd, uint16_t WrAddr); //void myDCIF->setUserWriteData(uint16_t WriteCmd); //void myDCIF->setUserWrite1DB (uint16_t WriteCmd, uint16_t WrAddr, uint8_t val); //void myDCIF->setUserWrite2DB (uint16_t WriteCmd, uint16_t WrAddr, uint8_t val0, uint8_t val1); //void myDCIF->setUserReadData( uint16_t ReadCmd); //void myDCIF->sendUserData(uint16_t slaveAdr); void T_datif::datif_startSending(void) { // egal ob WR und RD Daten gesetzt wurden myDCIF->sendUserData(selectedSlaveAddr); // starte Sendung gpi_startNewRequest(); cycl_running=1; } // allgemeine Schreib/Lese-Funktion void T_datif::datif_sendIOrequest(uint16_t WRcmd, uint16_t RDcmd, uint8_t nrOfWrData) { uint8_t data[6]; //, who; if (nrOfWrData>4) nrOfWrData=0; tslib_strclr(data,0,6); if (nrOfWrData>0) data[0]=datif_OutCmdpara1; if (nrOfWrData>1) data[1]=datif_OutCmdpara2; if (nrOfWrData>2) data[2]=datif_OutCmdpara3; if (nrOfWrData>3) data[3]=datif_OutCmdpara4; data[4]=0; data[5]=0; keepLastWrCmd=WRcmd; keepLastRdCmd=RDcmd; //if (RDcmd==101) //{ // who=0; //} myDCIF->setUserWriteData(WRcmd, 0, nrOfWrData, data); myDCIF->setUserReadData(RDcmd); myDCIF->sendUserData(selectedSlaveAddr); cycl_running=1; } void T_datif::datif_send8byteOutCmd(uint16_t WRcmd, uint16_t RDcmd) { uint8_t data[10]; uint16_t uitmp; uint32_t ultmp; tslib_strclr(data,0,10); // 8 used data[0]=datif_OutCmdpara1; data[1]=datif_OutCmdpara2; uitmp=datif_OutCmdpara5; ultmp=datif_OutCmdpara6; data[2]=uint8_t(uitmp); uitmp>>=8; data[3]=uint8_t(uitmp); data[4]=uint8_t(ultmp); ultmp>>=8; data[5]=uint8_t(ultmp); ultmp>>=8; data[6]=uint8_t(ultmp); ultmp>>=8; data[7]=uint8_t(ultmp); data[8]=0; data[9]=0; myDCIF->setUserWriteData(WRcmd, 0, 8, data); myDCIF->setUserReadData(RDcmd); myDCIF->sendUserData(selectedSlaveAddr); cycl_running=1; } bool T_datif::verifyLineTestresponse(uint8_t RdDlen, uint8_t *receivedData) { if (RdDlen < 16) return false; QString myStr; char ctmp; myStr.clear(); myStr.append("< Slave Response"); for (int nn=0; nn<16; nn++) { ctmp=receivedData[nn]; if (myStr[nn] != ctmp) { //qDebug() << " datif cmd 10: got wrong string "; //qDebug() << myStr; //qDebug() << receivedData; //qDebug() << nn; return false; } } return true; } // RTC ---------------------------------------------------------------------- /* void T_datif::datif_OUT_setTime(void) { // send PC time/date to slave //uint8_t hour,min, sec, year, month, day, dayOfWeek, //uint8_t dayOfYear, isLeap, weekOfYear; uint8_t buff[15]; uint16_t uitmp; QTime *systTime = new QTime(); // qDebug() << systTime->currentTime().hour() <<":" // << systTime->currentTime().minute() <<":" // << systTime->currentTime().second(); buff[0]=uint8_t(systTime->currentTime().hour()); buff[1]=uint8_t(systTime->currentTime().minute()); buff[2]=uint8_t(systTime->currentTime().second()); QDate *systDate = new QDate(); systDate->currentDate(); uitmp= uint16_t(systDate->currentDate().year()); buff[3]=uint8_t(uitmp); buff[4]=uint8_t(uitmp>>8); buff[5]=uint8_t(systDate->currentDate().month()); buff[6]=uint8_t(systDate->currentDate().day()); buff[7]=uint8_t(systDate->currentDate().dayOfWeek()); // uitmp=systDate->currentDate().dayOfYear(); // buff[8]=uint8_t(uitmp); // buff[9]=uint8_t(uitmp>>8); // buff[10]=uint8_t(systDate->currentDate().isLeapYear(systDate->currentDate().year())); // buff[11]=uint8_t(systDate->currentDate().weekNumber()); //weekOfYear // buff[12]=0; //myDCIF->setUserWriteData(0x1310,0,8, buff); myDCIF->setUserWriteData(CMD2DC_sendTime,0,8, buff); myDCIF->setUserReadData(0); myDCIF->sendUserData(selectedSlaveAddr); // jetzt wegsckicken cycl_running=1; } */ // 0x2311: set time to RTC // 0x2312: set date to RTC uint8_t T_datif::datif_OUT_SendRandomData(uint8_t *buf, uint8_t Length) { uint8_t len=Length; myDCIF->setBLsendData(len, buf ); myDCIF->setUserReadData(0); myDCIF->sendUserData(selectedSlaveAddr); cycl_running=1; return 0; } /* void T_datif::datif_send64byteOutCmd(uint16_t WRcmd, uint16_t addr, uint16_t RDcmd) { // sending length is already defined by stored data // not batched! don't use twice within 100ms uint8_t LL; uint8_t data[66]; tslib_strclr(data,0,66); // up to 64 used gpi_restore64ByteSendData(&LL, data); // LL bytes was stored to be sent myDCIF->setUserWriteData(WRcmd, addr, LL, data); myDCIF->setUserReadData(RDcmd); myDCIF->sendUserData(selectedSlaveAddr); cycl_running=1; }*/ void T_datif::datif_sendToMemory(uint16_t WRcmd, uint16_t docNr, uint16_t blockNr, uint8_t *data64) { // send printer documents to DC2 memory // docNr: 0...15(31) with 1280 byte each (20 blocks a 64byte) // blockNr=0...19 with 64byte each // docNr =transmitted in WRITEADDRESS high byte // blockNr=transmitted in WRITEADDRESS low byte uint16_t aa=0; aa=docNr; aa<<=8; aa |=blockNr; myDCIF->setUserWriteData(WRcmd, aa, 64, data64); myDCIF->setUserReadData(0); myDCIF->sendUserData(selectedSlaveAddr); cycl_running=1; } void T_datif::startSupervision(void) { gpi_storeOverallResult(0xFF); }