/** ****************************************************************************** * @file : FPx.c * @brief : FPx funcstions program body ****************************************************************************** */ #include "globaldef.h" #include "FPx.h" #include "string.h" #include "functions.h" // uint8_t PktBuf1[64]; uint8_t PktBuf2[64]; uint8_t PktLen1=0; uint8_t PktLen2=0; /* uint8_t bReceiving; uint8_t nReceivedLen; uint8_t bSending; uint8_t bSentLen; uint8_t bConfiged=0; uint8_t nConfigStationId=0; uint8_t nInputBytes=8; uint8_t nOutputBytes=8; uint8_t nIndex=0; volatile uint8_t oldSYN=0; int RSTCount0; uint8_t bFirstReq = 0; FPxCBFuncDef FPxCBFunc; uint8_t bFPxCallBackFuncSet = 0; */ stFPxStat FPxStat; stFPxMem FPxMem; uint8_t FPx_Init(int nChilds) { bSPI1Sending=0; bSPI1Recving=0; if (nChilds==0) { FPxStat.nInputBytes=1; //根据子机数量,报告扩展容量 FPxStat.nOutputBytes=1; } else if (nChilds ==1) { FPxStat.nInputBytes=3; //只有一个子机也分配一个完整DT FPxStat.nOutputBytes=2; } else { FPxStat.nInputBytes=nChilds; //根据子机数量,报告扩展容量 FPxStat.nOutputBytes=nChilds; } SetACKPin_0(); SetACKPin_0(); SetFPxDEPin_0(); HAL_Delay(10); FPxStat.RSTCount0=GetuS(); return 0; } uint8_t FPx_SetIOCount(int nInputBytes, int nOutputBytes) { FPxStat.nInputBytes=nInputBytes; //设置扩展容量,字节单位 FPxStat.nOutputBytes=nOutputBytes; return 0; } int FPxSetCallBackFunc(FPxEvCBFuncDef func1) { FPxStat.FPxEvCBFunc = func1; // FPxStat.bFPxCallBackFuncSet = 1; return 0; } uint8_t FPx_Proc() { uchar CurRST=GetRSTPin(); uchar CurSEL=GetSELPin(); uchar CurSYN=GetSYNPin(); uchar CurACK=GetACKPin(); uchar CurOE=GetOEPin(); // KMem.WY[4]=CurRST; // KMem.WY[5]=CurSEL; // KMem.WY[6]=CurSYN; // KMem.WY[7]=CurACK; if (CurOE) { // disable output for (int j=0;j=1000) { logData(0x11); SetACKPin_1(); FPxStat.bFirstReq=1; // RSTCount=0; // bSPI1Recving=1; // KMem.WX[7]=RSTCount/1000; LL_SPI_Disable(SPI2); LL_SPI_Enable(SPI2); nSPI1RecvPos=0; } } if (CurSYN ==0 && FPxStat.oldSYN != 0) { KMem.WDT[121] = KMem.WDT[122]; KMem.WDT[122]=0; nSPI1RecvPos=0; logData(0x12); } if (CurSEL && CurSYN !=0 && FPxStat.oldSYN == 0){ bSPI1Recving=1; // nSPI1RecvPos=0; LL_SPI_Disable(SPI2); // nSPI1RecvPos=0; LL_SPI_Enable(SPI2); logData(0x13); } if (CurSEL && CurSYN && !bSPI1Sending && !bSPI1Recving) { bSPI1Recving=1; nSPI1RecvPos=0; logData(0x14); } if (CurSYN == 0){ bSPI1Recving=0; nSPI1RecvPos=0; } FPxStat.oldSYN=CurSYN; /* if (bSPI1RecvDone) { bSPI1RecvDone=0; ParsePkt(SPI1RecvBuf,nSPI1RecvLenInBuf); } // */ return 0; } uint8_t FPxBCC(uint8_t* pBuf, uint8_t len1) { uint8_t BCC=0; for (int i=0;iHdr1=nST; p1->nInputBytes=0x30|FPxStat.nInputBytes; p1->nOutputBytes=0x30|FPxStat.nOutputBytes; p1->nParam1=0x30|0x05; p1->nBCC= 0x30|FPxBCC(PktBuf2,4); p1->End1=0x0d; logData(0x22); FPxSendPkt(PktBuf2,sizeof(stFPxQuRplyPkt)); FPxStat.nConfigStationId=nStationID; FPxStat.bConfiged=1; if (FPxStat.FPxEvCBFunc) FPxStat.FPxEvCBFunc(evFPxStateChange,0,0); } bSPI1Recving=1; break; case CMD_1: KMem.WDT[9]++; // bSPI1Recving=1; break; case CMD_2: KMem.WDT[10]++; // bSPI1Recving=1; break; case CMD_3_EXCHG: if (!FPxStat.bConfiged || FPxStat.nConfigStationId != nStationID) { bSPI1Recving=1; break; } KMem.WDT[11]++; { for (int j=0;jHdr1=nST; for (int j=0;jnInputBytes[j*2 + 0]=0x30|HiHofB(FPxMem.WLXB[j]); //((KMem.DT[0]>>4)&0x0f); p1->nInputBytes[j*2 + 1]=0x30|LoHofB(FPxMem.WLXB[j]); //((KMem.DT[0]>>0)&0x0f); } //p1->nInputBytes[0]=0x30|HiHofB(LoBofW(KMem.DT[0])); //((KMem.DT[0]>>4)&0x0f); //p1->nInputBytes[1]=0x30|LoHofB(LoBofW(KMem.DT[0])); //((KMem.DT[0]>>0)&0x0f); //p1->nInputBytes[2]=0x30|HiHofB(HiBofW(KMem.DT[0])); //((KMem.DT[0]>>12)&0x0f); //p1->nInputBytes[3]=0x30|LoHofB(HiBofW(KMem.DT[0])); //((KMem.DT[0]>>8)&0x0f); //p1->nInputBytes[4]=0x30|((KMem.DT[1]>>4)&0x0f); //p1->nInputBytes[5]=0x30|((KMem.DT[1]>>0)&0x0f); PktBuf2[FPxStat.nInputBytes*2 + 1 ]=0x30|FPxBCC(PktBuf2,FPxStat.nInputBytes*2+1); // p1->nBCC= 0x30|CalBCC(PktBuf2,7); PktBuf2[FPxStat.nInputBytes*2 + 2 ]=0x0d; // p1->End1=0x0d; FPxSendPkt(PktBuf2,FPxStat.nInputBytes*2 + 3); } bSPI1Recving=1; break; case CMD_4: KMem.WDT[12]++; // bSPI1Recving=1; break; case CMD_5: KMem.WDT[13]++; // bSPI1Recving=1; break; case CMD_6: KMem.WDT[14]++; // bSPI1Recving=1; break; case CMD_7_END: KMem.WDT[15]++; if (FPxStat.bConfiged && FPxStat.nConfigStationId == nStationID) { //SetFPxDEPin_0(); SetACKPin_1(); } bSPI1Recving=1; break; default: KMem.WDT[18]++; bSPI1Recving=1; break; } KMem.WDT[24+(len1&0x0f)]++; return res; } uint8_t FPxSendPkt(uint8_t * pBuf, uint8_t len1) { uint8_t res=0; KMem.WR[len1&0x0f]++; if (!bSPI1Sending) { uint8_t value; memcpy(SPI1SendBuf,pBuf,len1); nSPI1ToSendLen=len1; nSPI1SentLen=0; // SetFPxDEPin_1(); // SetACKPin_0(); value = SPI1SendBuf[nSPI1SentLen]; LL_SPI_TransmitData8(SPI1,value); bSPI1Sending=1; logData(value); // passive mode SetFPxDEPin_1(); SetACKPin_0(); } return res; }