#include #include #include #include "tslib.h" #include "sendWRcmd.h" void indat_PrnPwr(void); void sendWRcmd_INI(void) { sendWRcmd_clrCmdStack(); sendWRcmd_clrCmd4Stack(); sendFDcmd_clrStack(); longFDcmd_clrStack(); } // Command Stack for commands without parameters static uint16_t nextAsynchsendCmd0[CMDSTACKDEPTH]; static uint8_t nrOfCmdsInQueue; /* convention: use simple (not rotating) FIFO Stack: Example: nrOfCmdsInQueue=4 then nextAsynchsendCmd0[0]=cmd1 // was stored as first nextAsynchsendCmd0[1]=cmd2 nextAsynchsendCmd0[2]=cmd3 nextAsynchsendCmd0[3]=cmd4 // came in as last Send: [0] first, then move buffer 1 down: nextAsynchsendCmd0[0]=cmd2 nextAsynchsendCmd0[1]=cmd3 nextAsynchsendCmd0[2]=cmd4 nextAsynchsendCmd0[3]=0; nrOfCmdsInQueue=3 now */ void sendWRcmd_clrCmdStack(void) { uint8_t nn; for (nn=0; nn=CMDSTACKDEPTH) { qDebug() << "cannot save cmd because stack is full"; return false; // not possible } nextAsynchsendCmd0[nrOfCmdsInQueue++]=nextCmd; //qDebug() << "PI cmd queued:"<< nextCmd << ", saved, pp=" << nrOfCmdsInQueue; return true; // ok, will be sent } uint16_t sendWRcmd_getSendCommand0(void) { uint16_t nxtAsynchCmd; uint8_t nn, ll; if (nrOfCmdsInQueue==0 || nrOfCmdsInQueue>CMDSTACKDEPTH) return 0; // error nxtAsynchCmd=nextAsynchsendCmd0[0]; // move Puffer down by one element if (CMDSTACKDEPTH>0) ll=CMDSTACKDEPTH-1; else ll=0; for (nn=0; nn0) nrOfCmdsInQueue--; //qDebug() << "PI cmd queued:"<< nxtAsynchCmd << ", restored, pp now =" << nrOfCmdsInQueue; return nxtAsynchCmd; } //--------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------- // Command Stack for commands with 4 parameters static uint16_t nextAsynchsendCmd4[CMD4STACKDEPTH]; static uint8_t nextCmd4para1[CMD4STACKDEPTH]; static uint8_t nextCmd4para2[CMD4STACKDEPTH]; static uint8_t nextCmd4para3[CMD4STACKDEPTH]; static uint8_t nextCmd4para4[CMD4STACKDEPTH]; static uint8_t nrOfCmds4InQueue; /* convention: use simple (not rotating) FIFO Stack: Example: nrOfCmdsInQueue=4 then nextAsynchsendCmd0[0]=cmd1 // was stored as first nextAsynchsendCmd0[1]=cmd2 nextAsynchsendCmd0[2]=cmd3 nextAsynchsendCmd0[3]=cmd4 // came in as last Send: [0] first, then move buffer 1 down: nextAsynchsendCmd0[0]=cmd2 nextAsynchsendCmd0[1]=cmd3 nextAsynchsendCmd0[2]=cmd4 nextAsynchsendCmd0[3]=0; nrOfCmdsInQueue=3 now */ void sendWRcmd_clrCmd4Stack(void) { uint8_t nn; for (nn=0; nn=CMD4STACKDEPTH) { qDebug() << "cannot save cmd because stack is full"; return false; // not possible } nextAsynchsendCmd4[nrOfCmds4InQueue]=nextCmd; nextCmd4para1[nrOfCmds4InQueue]=dat1; nextCmd4para2[nrOfCmds4InQueue]=dat2; nextCmd4para3[nrOfCmds4InQueue]=dat3; nextCmd4para4[nrOfCmds4InQueue]=dat4; //qDebug() << "data with 4 data byte saved, pp=" << nrOfCmds4InQueue; //qDebug() << " dat1=" << nextCmd4para1[nrOfCmds4InQueue] << " dat2=" << nextCmd4para2[nrOfCmds4InQueue] // << " dat3=" << nextCmd4para3[nrOfCmds4InQueue] << " dat4=" << nextCmd4para4[nrOfCmds4InQueue]; nrOfCmds4InQueue++; return true; // ok, will be sent } uint16_t sendWRcmd_getSendCommand4(uint8_t *dat1, uint8_t *dat2, uint8_t *dat3, uint8_t *dat4) { uint16_t nxtAsynchCmd; uint8_t nn, ll; if (nrOfCmds4InQueue==0 || nrOfCmds4InQueue>CMD4STACKDEPTH) return 0; // error nxtAsynchCmd=nextAsynchsendCmd4[0]; *dat1=nextCmd4para1[0]; *dat2=nextCmd4para2[0]; *dat3=nextCmd4para3[0]; *dat4=nextCmd4para4[0]; //qDebug() << "cmd4 restored to send from [0]; pp=" << nrOfCmds4InQueue; //qDebug() << " data1: " << nextCmd4para1[0] << " data2: " << nextCmd4para2[0] << // " data3: " << nextCmd4para3[0] << " data4: " << nextCmd4para4[0]; // move Puffer down by one element if (CMD4STACKDEPTH>0) ll=CMD4STACKDEPTH-1; else ll=0; for (nn=0; nn0) nrOfCmds4InQueue--; //qDebug() << "cmd4 after push down: pp=" << nrOfCmds4InQueue; return nxtAsynchCmd; } static uint16_t nextAsynchsendCmd8[CMD8STACKDEPTH]; static uint8_t nextCmd8para1[CMD8STACKDEPTH]; static uint8_t nextCmd8para2[CMD8STACKDEPTH]; static uint16_t nextCmd8para3[CMD8STACKDEPTH]; static uint32_t nextCmd8para4[CMD8STACKDEPTH]; static uint8_t nrOfCmds8InQueue; void sendWRcmd_clrCmd8Stack(void) { uint8_t nn; for (nn=0; nn=CMD8STACKDEPTH) { qDebug() << "cannot save cmd because stack is full"; return false; // not possible } nextAsynchsendCmd8[nrOfCmds8InQueue]=nextCmd; nextCmd8para1[nrOfCmds8InQueue]=dat1; nextCmd8para2[nrOfCmds8InQueue]=dat2; nextCmd8para3[nrOfCmds8InQueue]=dat3; nextCmd8para4[nrOfCmds8InQueue]=dat4; nrOfCmds8InQueue++; return true; // ok, will be sent } uint16_t sendWRcmd_getSendCommand8(uint8_t *dat1, uint8_t *dat2, uint16_t *dat3, uint32_t *dat4) { uint16_t nxtAsynchCmd; uint8_t nn, ll; if (nrOfCmds8InQueue==0 || nrOfCmds8InQueue>CMD8STACKDEPTH) return 0; // error nxtAsynchCmd=nextAsynchsendCmd8[0]; *dat1=nextCmd8para1[0]; *dat2=nextCmd8para2[0]; *dat3=nextCmd8para3[0]; *dat4=nextCmd8para4[0]; // move buffer down by one element if (CMD8STACKDEPTH>0) ll=CMD8STACKDEPTH-1; else ll=0; for (nn=0; nn0) nrOfCmds8InQueue--; return nxtAsynchCmd; } static uint8_t sendAsynchDataBuf[160]; // no stack, only ONE buffer static uint8_t sendAsyDatLen; bool sendWRcmd_setSendBlock160(uint8_t leng, uint8_t *buf) { //qDebug() << "pi epi: storing send data"; if (leng>160) leng=160; sendAsyDatLen=leng; tslib_strclr(sendAsynchDataBuf, 0, 160); for (uint8_t nn=0; nn=MAXNROF_PRNBLOCKS) return 1; // not possible, no free mem //len=tslib_strlen(buf); // kennt keine Binärzeichen!!!!!! len=leng; if (len>MAXNROF_PRNBYTES) len=MAXNROF_PRNBYTES; tslib_strclr(Sdata_PRN_TEXT[pp], 0, MAXNROF_PRNBYTES); for (nn=0; nn0) pPrnDataBuff--; pp=pPrnDataBuff; // example: pp=4: then buffers [0...3] are still occupied, pp=0: all buffers empty // now clear highest copyed line (which got free now) tslib_strclr(Sdata_PRN_TEXT[pp], 0, MAXNROF_PRNBYTES); // optionally: clear all remaining higher lines: for (nn=(pp+1); nn0: nr of 64byte-blocks return (pPrnDataBuff); } // --------------------------------------------------------------------------------- // 11.4.23 neu, Kommando direkt an "FastDevice"-protokoll senden, nicht mehr umsetzen // --------------------------------------------------------------------------------- // short command, 4 data bytes static uint8_t nextFDwrCmd[FDCMD_STACKDEPTH]; static uint8_t nextFDrdCmd[FDCMD_STACKDEPTH]; static uint8_t nextFDblkNr[FDCMD_STACKDEPTH]; static uint8_t nextFDpara1[FDCMD_STACKDEPTH]; static uint8_t nextFDpara2[FDCMD_STACKDEPTH]; static uint8_t nextFDpara3[FDCMD_STACKDEPTH]; static uint8_t nextFDpara4[FDCMD_STACKDEPTH]; static uint8_t p_nextFDcmdsInQueue; /* convention: use simple (not rotating) FIFO Stack: Example: nrOfCmdsInQueue=4 then nextAsynchsendCmd0[0]=cmd1 // was stored as first nextAsynchsendCmd0[1]=cmd2 nextAsynchsendCmd0[2]=cmd3 nextAsynchsendCmd0[3]=cmd4 // came in as last Send: [0] first, then move buffer 1 down: nextAsynchsendCmd0[0]=cmd2 nextAsynchsendCmd0[1]=cmd3 nextAsynchsendCmd0[2]=cmd4 nextAsynchsendCmd0[3]=0; nrOfCmdsInQueue=3 now */ void sendFDcmd_clrStack(void) { uint8_t nn; for (nn=0; nn=FDCMD_STACKDEPTH) { qDebug() << "cannot save cmd because stack is full"; return false; // not possible } nextFDwrCmd[p_nextFDcmdsInQueue]=nextWrCmd; nextFDrdCmd[p_nextFDcmdsInQueue]=nextRdCmd; nextFDblkNr[p_nextFDcmdsInQueue]=blockNum; nextFDpara1[p_nextFDcmdsInQueue]=dat1; nextFDpara2[p_nextFDcmdsInQueue]=dat2; nextFDpara3[p_nextFDcmdsInQueue]=dat3; nextFDpara4[p_nextFDcmdsInQueue]=dat4; //qDebug() << "data with 4 data byte saved, pp=" << nrOfCmds4InQueue; //qDebug() << " dat1=" << nextCmd4para1[nrOfCmds4InQueue] << " dat2=" << nextCmd4para2[nrOfCmds4InQueue] // << " dat3=" << nextCmd4para3[nrOfCmds4InQueue] << " dat4=" << nextCmd4para4[nrOfCmds4InQueue]; p_nextFDcmdsInQueue++; return true; // ok, will be sent } bool sendFDcmd_get(uint8_t *nextWrCmd, uint8_t *nextRdCmd, uint8_t *blockNum, uint8_t *dat1, uint8_t *dat2, uint8_t *dat3, uint8_t *dat4) { uint8_t nn, ll; if (p_nextFDcmdsInQueue==0 || p_nextFDcmdsInQueue>FDCMD_STACKDEPTH) return false; // not possible *nextWrCmd=nextFDwrCmd[0]; *nextRdCmd=nextFDrdCmd[0]; *blockNum=nextFDblkNr[0]; *dat1=nextFDpara1[0]; *dat2=nextFDpara2[0]; *dat3=nextFDpara3[0]; *dat4=nextFDpara4[0]; //qDebug() << "cmd4 restored to send from [0]; pp=" << nrOfCmds4InQueue; //qDebug() << " data1: " << nextCmd4para1[0] << " data2: " << nextCmd4para2[0] << // " data3: " << nextCmd4para3[0] << " data4: " << nextCmd4para4[0]; // move Puffer down by one element if (FDCMD_STACKDEPTH>0) ll=FDCMD_STACKDEPTH-1; else ll=0; for (nn=0; nn0) p_nextFDcmdsInQueue--; //qDebug() << "cmd4 after push down: pp=" << nrOfCmds4InQueue; return true; // ok, will be sent } uint8_t check4FDshortCmd(void) { // returns number of waiting command return p_nextFDcmdsInQueue; } // long command, 64 data bytes static uint8_t longFDwrCmd[FDLONG_STACKDEPTH]; static uint8_t longFDrdCmd[FDLONG_STACKDEPTH]; static uint8_t longFDblkNr[FDLONG_STACKDEPTH]; static uint8_t longFDlength[FDLONG_STACKDEPTH]; static uint8_t longFDpara[FDLONG_STACKDEPTH][64]; static uint8_t p_longFDcmdsInQueue; void longFDcmd_clrStack(void) { uint8_t nn, mm; for (nn=0; nn=FDLONG_STACKDEPTH) { qCritical() << "cannot save cmd because stack is full"; return false; // not possible } longFDwrCmd[p_longFDcmdsInQueue]=nextWrCmd; longFDrdCmd[p_longFDcmdsInQueue]=nextRdCmd; longFDblkNr[p_longFDcmdsInQueue]=blockNum; longFDlength[p_longFDcmdsInQueue]=length; for (nn=0; nn<64; nn++) longFDpara[p_longFDcmdsInQueue][nn]=data[nn]; p_longFDcmdsInQueue++; return true; // ok, will be sent } bool longFDcmd_get(uint8_t *nextWrCmd, uint8_t *nextRdCmd, uint8_t *blockNum, uint8_t *length, uint8_t *data) { uint8_t nn, mm, ll; if (p_longFDcmdsInQueue==0 || p_longFDcmdsInQueue>FDLONG_STACKDEPTH) return false; // not possible *nextWrCmd= longFDwrCmd[0]; *nextRdCmd= longFDrdCmd[0]; *blockNum = longFDblkNr[0]; *length = longFDlength[0]; for (mm=0; mm<64; mm++) data[mm] = longFDpara[0][mm]; // move Puffer down by one element if (FDLONG_STACKDEPTH>0) ll=FDLONG_STACKDEPTH-1; else ll=0; for (nn=0; nn0) p_longFDcmdsInQueue--; return true; // ok, will be sent } uint8_t check4FDlongCmd(void) { // returns number of waiting command return p_longFDcmdsInQueue; }