#include #include #include #include "tslib.h" #include "sendWRcmd.h" void indat_PrnPwr(void); void sendWRcmd_INI(void) { sendWRcmd_clrCmdStack(); sendWRcmd_clrCmd4Stack(); } // 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; if (nrOfCmdsInQueue==0 || nrOfCmdsInQueue>CMDSTACKDEPTH) return 0; // error nxtAsynchCmd=nextAsynchsendCmd0[0]; // move Puffer down by one element 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; 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 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; if (nrOfCmds8InQueue==0 || nrOfCmds8InQueue>CMD4STACKDEPTH) return 0; // error nxtAsynchCmd=nextAsynchsendCmd8[0]; *dat1=nextCmd8para1[0]; *dat2=nextCmd8para2[0]; *dat3=nextCmd8para3[0]; *dat4=nextCmd8para4[0]; // move buffer down by one element 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); }