#include "datIf.h" #include "sendWRcmd.h" #include "controlBus.h" #include "storeINdata.h" #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; T_datif::T_datif(QWidget *parent) : QMainWindow(parent) { 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(10); // in ms, 80 gut, default 100 50....200 // 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; } void T_datif::resetChain(void) { dif_scanStep=0; } char T_datif::datif_cycleSend() { // cyclic transmission of INPUT-Requests // call cyclic to send next request every 100ms, then wait for response before sending again!!! uint16_t nxtAsCmd; uint8_t dataSendBuf[160], dataBufLen, dbl, who; static uint8_t BlockCounter; uint8_t nextWrCmd, nextRdCmd, blockNum, dat1, dat2, dat3, dat4; uint8_t length, data[66]; bool b_ret; if (cycl_running) { // request is still running, wait for response before next sending datif_trigger->stop(); datif_trigger->start(10); cycl_running++; if (cycl_running>10) cycl_running=0; return 0; } if (myDCIF->isPortOpen()) { #ifdef USEHANDSHAKES if (myDCIF->isSerialFree()) #endif { // new, from 11.4.23: direkt access to fastDevice Interface // 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, uint16_t RdAddr, uint16_t reserv); //void myDCIF->setUserReadData( uint16_t ReadCmd, uint16_t RdAddr); //void myDCIF->setUserReadData( uint16_t ReadCmd); //void myDCIF->sendUserData(uint16_t slaveAdr); if (check4FDshortCmd()) { b_ret=sendFDcmd_get(&nextWrCmd, &nextRdCmd, &blockNum, &dat1, &dat2, &dat3, &dat4); if (b_ret) { data[0]=dat1; data[1]=dat2; data[2]=dat3; data[3]=dat4; data[4]=0; myDCIF->setUserWriteData(nextWrCmd, blockNum, 4, data); myDCIF->setUserReadData(nextRdCmd); myDCIF->sendUserData(selectedSlaveAddr); } } if (check4FDlongCmd()) { b_ret=longFDcmd_get(&nextWrCmd, &nextRdCmd, &blockNum, &length, data); if (b_ret) { myDCIF->setUserWriteData(nextWrCmd, blockNum, length, data); myDCIF->setUserReadData(nextRdCmd); myDCIF->sendUserData(selectedSlaveAddr); } } // direct commands have highest prio (setting OUTPUTS) nxtAsCmd=sendWRcmd_getSendCommand0(); // command was stored by Gui if (nxtAsCmd>0) { cycl_running=1; // qDebug() << "datif: send next cmd0"; sendWRcommand(nxtAsCmd); send_requests(nxtAsCmd); sendHighLevel(nxtAsCmd); BlockCounter=0; return 0; } nxtAsCmd=sendWRcmd_getSendCommand4(&datif_OutCmdpara1, &datif_OutCmdpara2, &datif_OutCmdpara3, &datif_OutCmdpara4); // command was stored by Gui if (nxtAsCmd>0) { cycl_running=1; //qDebug() << "datif: send next cmd4"; sendWRcommand(nxtAsCmd); send_requests(nxtAsCmd); sendHighLevel(nxtAsCmd); BlockCounter=0; return 0; } nxtAsCmd=sendWRcmd_getSendCommand8(&datif_OutCmdpara1, &datif_OutCmdpara2, &datif_OutCmdpara5, &datif_OutCmdpara6); // command was stored by Gui if (nxtAsCmd>0) { cycl_running=1; //qDebug() << "datif: send next cmd8"; sendWRcommand(nxtAsCmd); send_requests(nxtAsCmd); sendHighLevel(nxtAsCmd); BlockCounter=0; return 0; } dbl=sendWRcmd_getSendBlock160(&dataBufLen, dataSendBuf); // used for bootloader if (dbl>0) { cycl_running=1; //qDebug() << "datif: sending 160 byte block, len: " << dataBufLen; datif_OUT_SendRandomData(dataSendBuf, dataBufLen); BlockCounter=0; return 0; } dbl=gpi_chk4remainingText(); if (dbl>0) { cycl_running=1; //qDebug() << "datif: sending printer text "; gpi_restorePrnText(&dataSendBuf[0]); // can hold 1280 byte, get next 64 //for (uint8_t nn=0; nn<64; nn++) // qDebug() << dataSendBuf[nn] << " "; who=gpi_getUserOfSendingTextBuffer(&datif_OutCmdpara1, &datif_OutCmdpara2, &datif_OutCmdpara3, &datif_OutCmdpara4); if (who==1) { epi_store64ByteSendData(64, dataSendBuf); // "dueway", copy this 64 back to pi, used by datif_ send64byteOutCmd datif_send64byteOutCmd(CMD2DC_PRI_PRINT_TXT, 0, 0); } else if (who==2) { epi_store64ByteSendData(64, dataSendBuf); // "dueway", copy this 64 back to pi, used by datif_ send64byteOutCmd datif_send64byteOutCmd(CMD2DC_STOR_QR_DATA, 0, 0); } else if (who==3) { //qDebug() << "datif: sending printer text, docnr: " <11) RDBLKNR=0; datif_OutCmdpara1=RDBLKNR; } break; case 17: //datif_sendIOrequest(0, CMD2DC_GetAllInputs, 0); datif_sendIOrequest(0, 19, 0); break; case 18: if (indat_isMdbOn()) datif_sendIOrequest(0, CMD2DC_MDB_GET_STATE, 0); // 107 //else // dif_scanStep=24; unsinn break; case 19: datif_sendIOrequest(0, 30, 0); break; case 20: //if (indat_isMdbOn()) datif_sendIOrequest(0, CMD2DC_MDB_GETRESP, 0); // 22 break; case 21: datif_sendIOrequest(0, CMD2DC_GetAllInputs, 0); break; case 22: //if (indat_isMdbOn()) // kein eigener Schalter für EMP datif_sendIOrequest(0, CMD2DC_EMP_GET_ALL, 0); // 23 break; case 23: datif_sendIOrequest(0, 31, 0); break; case 24: //if (indat_isMdbOn()) // kein eigener Schalter für EMP datif_sendIOrequest(0, CMD2DC_EMP_GOTCOIN, 0); // 108 break; case 25: datif_sendIOrequest(0, 32, 0); break; case 26: datif_sendIOrequest(0, 33, 0); break; } dif_scanStep++; if (dif_scanStep>26) dif_scanStep=5; return 0; } char T_datif::isPortOpen(void) { return (myDCIF->isPortOpen()); } // ############################################################################## // ############################################################################## // ############################################################################## // Empfangsdaten einsortieren // ---------------------------------------------------------------------------------------------- void T_datif::StoredRecData() { //qDebug() << "StoreRecData called"; // call automatically by T_prot //if (myDCIF->ifDataReceived()) //if (neu) { // just a wrapper as we need a retval // "neu" is the same as "INdataValid" loadRecDataFromFrame(); } cycl_running=0; } char T_datif::loadRecDataFromFrame() { // 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; // maxai char ctmp; static uint8_t lastResult; uint8_t prnResult; static uint32_t lastInsertedAmount; uint32_t newInsertedAmount; ret=myDCIF->getReceivedInData(&SlaveAdr, &readSource, &readAddress, &RdDleng, receivedData); // retval: data valid, only one time true, true if CommandState OK and readState OK gpi_storeResultOfLastRequest(ret); if (ret==false) { // qDebug() << "datif: rec data not valid"; return 0; } gpi_storeRecPayLoad(RdDleng, receivedData); // save for host (user of hwapi) //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_storeMdbState(uctmp&4, uctmp&128, uctmp&4); // hat ein eigenes Cmd weiter unten! 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 CMD2DC_RdBk_MifState: //109 // get reader status and card type //gpi_storeMifReaderStateAndCardType(receivedData); gpi_storeNewMifareCard(receivedData[0], &receivedData[1]); break; case CMD2DC_RdBk_MifData: //24 // one block of data (64byte) comes in // blkNr 0...11 in "Addr" gpi_storeMifCardData(readAddress, receivedData); //qDebug()<<"datif storing mif data: (adr/data) "<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 " < // never move or change this 1st entry UINT AccountingNumber; UINT CUNU; UINT MANU; UINT resint1; //UINT resint2; UCHAR label1buffer[4]; // tim> UCHAR year; UCHAR month; UCHAR dom; UCHAR hour; UCHAR min; UCHAR sec; UCHAR DoW; UCHAR reschar3; UCHAR label2buffer[4]; // abs> ULONG AbsIncome1; ULONG AbsReserve; ULONG AbsNrOfCuts; //16 UCHAR label3buffer[4]; // mw > // Verkauf, Tür zu: ULONG VKcoinsInserted[16]; // nur für Wechsler, soviel wurde eingeworfen ULONG VKcoinsReturned[6]; // nur für Wechsler, Anzahl Münzen pro Typ, soviel wurde zurückgegeben //88 // Service, Tür offen: UINT ServCoinsInserted[16]; // nur für Wechsler, soviel wurde eingeworfen UINT ServCoinsReturned[6]; // nur für Wechsler, Anzahl Münzen pro Typ, soviel wurde zurückgegeben UINT resint3; UINT resint4; UINT currentTubeContent[6]; // nur für Wechsler, aktueller Füllstand UINT resint5; UINT resint6; // 56 UCHAR label4buffer[4]; // box> UINT coinsInVault[16]; UINT billsInStacker[8]; // 48 UCHAR label5buffer[4]; // val> // actually constant unless exchange rate is changed UINT coinDenomination[16]; // 5..50000 (z.B. 2€ sind in Ungarn 760Ft) UINT billDenom[8]; UINT tubeDenom[6]; UINT exchangeRate; UINT resint9; // 64 UCHAR endofblock[4]; // end> // 316 byte Block im Speicher */ // readAddress, &RdDleng, receivedData gpi_storeVaultRecord(readAddress, receivedData ); // always 64byte break; } return 0; } // fehlen: 112, 113,14,17, 19, 30,31,32,33, // 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, uint16_t RdAddr, uint16_t reserv); //void myDCIF->setUserReadData( uint16_t ReadCmd, uint16_t RdAddr); //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]; 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; 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; }