| | |
| | | stFPxStat FPxStat; |
| | | stFPxMem FPxMem; |
| | | |
| | | |
| | | |
| | | uint8_t FPx_Init(int nChilds) |
| | | { |
| | | bSPI1Sending=0; |
| | |
| | | FPxStat.nOutputBytes=2; |
| | | } else |
| | | { |
| | | FPxStat.nInputBytes=nChilds+1; //根据子机数量,报告扩展容量 |
| | | FPxStat.nInputBytes=nChilds; //根据子机数量,报告扩展容量 |
| | | FPxStat.nOutputBytes=nChilds; |
| | | } |
| | | SetACKPin_0(); |
| | |
| | | return 0; |
| | | } |
| | | |
| | | int FPxSetCallBackFunc(FPxCBFuncDef func1) |
| | | int FPxSetCallBackFunc(FPxEvCBFuncDef func1) |
| | | { |
| | | FPxStat.FPxCBFunc = func1; |
| | | FPxStat.bFPxCallBackFuncSet = 1; |
| | | FPxStat.FPxEvCBFunc = func1; |
| | | // FPxStat.bFPxCallBackFuncSet = 1; |
| | | return 0; |
| | | } |
| | | |
| | |
| | | // KMem.WY[5]=CurSEL; |
| | | // KMem.WY[6]=CurSYN; |
| | | // KMem.WY[7]=CurACK; |
| | | if (CurOE) { |
| | | if (CurOE) { // disable output |
| | | for (int j=0;j<FPxStat.nOutputBytes;j++) |
| | | { |
| | | FPxMem.WLYB[j]=0; |
| | | } |
| | | if (FPxStat.bFPxCallBackFuncSet) FPxStat.FPxCBFunc(evFPxStateChange,0,0); |
| | | if (FPxStat.bFPxCallBackFuncSet) FPxStat.FPxCBFunc(evFPxDataUpdate,0,0); |
| | | if (FPxStat.FPxEvCBFunc) FPxStat.FPxEvCBFunc(evFPxStateChange,0,0); |
| | | if (FPxStat.FPxEvCBFunc) FPxStat.FPxEvCBFunc(evFPxDataUpdate,0,0); |
| | | } |
| | | |
| | | if (!CurRST) {FPxStat.RSTCount0=GetuS();} |
| | | if (!CurRST) { // in reset |
| | | FPxStat.RSTCount0=GetuS(); |
| | | SetACKPin_0(); |
| | | FPxStat.bFirstReq=0; |
| | | LL_SPI_Disable(SPI2); |
| | | FPxStat.bConfiged = 0; |
| | | nSPI1RecvPos=0; |
| | | |
| | | } |
| | | if (!FPxStat.bFirstReq && CurRST) |
| | | { |
| | | { // after Reset; |
| | | int RSTCount = GetuS() - FPxStat.RSTCount0 ; |
| | | if (RSTCount>=10000) |
| | | if (RSTCount>=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; |
| | | // nSPI1RecvPos=0; |
| | | LL_SPI_Disable(SPI2); |
| | | nSPI1RecvPos=0; |
| | | // nSPI1RecvPos=0; |
| | | LL_SPI_Enable(SPI2); |
| | | logData(0x13); |
| | | } |
| | | if (CurSEL && CurSYN && !bSPI1Sending && !bSPI1Recving) |
| | | { |
| | | bSPI1Recving=1; |
| | | nSPI1RecvPos=0; |
| | | logData(0x14); |
| | | } |
| | | |
| | | if (CurSYN == 0){ |
| | |
| | | return 0; |
| | | } |
| | | |
| | | uint8_t FPxCalBCC(uint8_t* pBuf, uint8_t len1) |
| | | uint8_t FPxBCC(uint8_t* pBuf, uint8_t len1) |
| | | { |
| | | uint8_t BCC=0; |
| | | for (int i=0;i<len1;i++) |
| | |
| | | if (!FPxStat.bConfiged || (FPxStat.bConfiged && nStationID == FPxStat.nConfigStationId)) |
| | | { |
| | | KMem.WDT[8]++; |
| | | |
| | | KMem.WDT[0]= nST; |
| | | KMem.WDT[1]= len1; |
| | | KMem.WDT[2] = FPxStat.nConfigStationId; |
| | | |
| | | KMem.WDT[4]= FPxStat.nInputBytes; |
| | | KMem.WDT[5]= FPxStat.nOutputBytes; |
| | | |
| | | pFPxQuRplyPkt p1 = (pFPxQuRplyPkt)PktBuf2; |
| | | p1->Hdr1=nST; |
| | | p1->nInputBytes=0x30|FPxStat.nInputBytes; |
| | | p1->nOutputBytes=0x30|FPxStat.nOutputBytes; |
| | | p1->nParam1=0x30|0x05; |
| | | p1->nBCC= 0x30|FPxCalBCC(PktBuf2,4); |
| | | p1->nBCC= 0x30|FPxBCC(PktBuf2,4); |
| | | p1->End1=0x0d; |
| | | |
| | | logData(0x11); |
| | | logData(0x22); |
| | | |
| | | FPxSendPkt(PktBuf2,sizeof(stFPxQuRplyPkt)); |
| | | FPxStat.nConfigStationId=nStationID; |
| | | FPxStat.bConfiged=1; |
| | | if (FPxStat.bFPxCallBackFuncSet) FPxStat.FPxCBFunc(evFPxStateChange,0,0); |
| | | if (FPxStat.FPxEvCBFunc) FPxStat.FPxEvCBFunc(evFPxStateChange,0,0); |
| | | } |
| | | bSPI1Recving=1; |
| | | break; |
| | |
| | | KMem.WYB[j]=(0xff); |
| | | } |
| | | // */ |
| | | if (FPxStat.bFPxCallBackFuncSet) FPxStat.FPxCBFunc(evFPxDataUpdate,0,0); |
| | | if (FPxStat.FPxEvCBFunc) FPxStat.FPxEvCBFunc(evFPxDataUpdate,0,0); |
| | | |
| | | // KMem.WDT[2]=((pBuf[1]&0xf)<<4) + ((pBuf[2]&0xf)<<0) + ((pBuf[3]&0xf)<<12) + ((pBuf[4]&0xf)<<8); |
| | | pFPxEXGRplyPkt p1 = (pFPxEXGRplyPkt)PktBuf2; |
| | |
| | | //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|FPxCalBCC(PktBuf2,FPxStat.nInputBytes*2+1); // p1->nBCC= 0x30|CalBCC(PktBuf2,7); |
| | | 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); |
| | | } |