#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; 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(100); // 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; } 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; if (myDCIF->isPortOpen()) { #ifdef USEHANDSHAKES if (myDCIF->isSerialFree()) #endif { // direct commands have highest prio (setting OUTPUTS) nxtAsCmd=sendWRcmd_getSendCommand0(); // command was stored by Gui if (nxtAsCmd>0) { 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) { 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) { 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) { qDebug() << "datif: sending 160 byte block, len: " << dataBufLen; datif_OUT_SendRandomData(dataSendBuf, dataBufLen); BlockCounter=0; return 0; } dbl=gpi_chk4remainingText(); if (dbl>0) { 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); break; case 18: if (indat_isMdbOn()) datif_sendIOrequest(0, CMD2DC_MDB_GET_STATE, 0); else dif_scanStep=24; break; case 19: datif_sendIOrequest(0, CMD2DC_GetAllInputs, 0); break; case 20: //if (indat_isMdbOn()) datif_sendIOrequest(0, CMD2DC_MDB_GETRESP, 0); 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); break; case 23: datif_sendIOrequest(0, CMD2DC_GetAllInputs, 0); break; case 24: //if (indat_isMdbOn()) // kein eigener Schalter für EMP datif_sendIOrequest(0, CMD2DC_EMP_GOTCOIN, 0); break; } dif_scanStep++; if (dif_scanStep>=25) dif_scanStep=5; return 0; } char T_datif::isPortOpen(void) { return (myDCIF->isPortOpen()); } // ############################################################################## // ############################################################################## // ############################################################################## // Empfangsdaten einsortieren // ---------------------------------------------------------------------------------------------- //void T_datif::StoredRecData(bool neu) 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(); } } char T_datif::loadRecDataFromFrame() { // necessary data in T_prot: uint16_t readSource, uitmp; 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 maxai; 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<4; ii++) haut hin :) for (int ii=0; ii0: 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: // 0x2A12 //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: // 0x2A40 gpi_storePrinterState(receivedData); // derzeit 10bytes ( 0x2A02) gpi_storePrinterFonts(&receivedData[10]); // derzeit 10bytes /* qDebug()<<"printer fonts stored " <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(); } // 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_OutCmdpara3; data[4]=0; data[5]=0; myDCIF->setUserWriteData(WRcmd, 0, nrOfWrData, data); myDCIF->setUserReadData(RDcmd); myDCIF->sendUserData(selectedSlaveAddr); } 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); } bool T_datif::verifyLineTestresponse(uint8_t RdDlen, uint8_t *receivedData) { if (RdDlen !=16) return false; QString myStr; myStr.clear(); myStr.append("< Slave Response"); for (int nn=0; nn<16; nn++) if (myStr[nn] !=receivedData[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 } // 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); 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); } 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); }