| | |
| | | unsigned char Datas[128]; |
| | | volatile int PacketLength = 0; |
| | | |
| | | stClientInfo ClientInfo[16]; |
| | | |
| | | |
| | | |
| | | unsigned char KBusBCC(void * pData, int nSize) |
| | | { |
| | | unsigned char k; |
| | |
| | | case cmdNone: |
| | | break; |
| | | case cmdPing: |
| | | p1->PacketLen=DataLen; |
| | | p1->DataLen=DataLen; |
| | | memcpy(p1->data,pData,DataLen); |
| | | p1->data[DataLen]=KBusBCC(p1,sizeof(stKBPacket)+DataLen-1); |
| | | p1->data[DataLen+1]=EndSign; |
| | |
| | | PacketLenth=sizeof(stKBPacket)+DataLen+1; |
| | | break; |
| | | case cmdPingReply: |
| | | p1->PacketLen=DataLen; |
| | | p1->DataLen=DataLen; |
| | | memcpy(p1->data,pData,DataLen); |
| | | p1->data[DataLen]=KBusBCC(p1,sizeof(stKBPacket)+DataLen-1); |
| | | p1->data[DataLen+1]=EndSign; |
| | |
| | | case cmdWrite: |
| | | break; |
| | | case cmdWriteReply: |
| | | p1->PacketLen=DataLen; |
| | | p1->DataLen=DataLen; |
| | | if (DataLen !=0 ) memcpy(p1->data,pData,DataLen); |
| | | p1->data[DataLen]=KBusBCC(p1,sizeof(stKBPacket)+DataLen-1); |
| | | p1->data[DataLen+1]=EndSign; |
| | | PacketLenth=sizeof(stKBPacket)+DataLen+1; |
| | | break; |
| | | case cmdGetVersion: |
| | | p1->PacketLen=DataLen; |
| | | p1->DataLen=DataLen; |
| | | memcpy(p1->data,pData,DataLen); |
| | | p1->data[DataLen]=KBusBCC(p1,sizeof(stKBPacket)+DataLen-1); |
| | | p1->data[DataLen+1]=EndSign; |
| | | PacketLenth=sizeof(stKBPacket)+DataLen+1; |
| | | break; |
| | | case cmdVerInfo: |
| | | p1->PacketLen=DataLen; |
| | | p1->DataLen=DataLen; |
| | | memcpy(p1->data,pData,DataLen); |
| | | p1->data[DataLen]=KBusBCC(p1,sizeof(stKBPacket)+DataLen-1); |
| | | p1->data[DataLen+1]=EndSign; |
| | | PacketLenth=sizeof(stKBPacket)+DataLen+1; |
| | | break; |
| | | case cmdExChgData: |
| | | p1->PacketLen=DataLen; |
| | | p1->DataLen=DataLen; |
| | | memcpy(p1->data,pData,DataLen); |
| | | p1->data[DataLen]=KBusBCC(p1,sizeof(stKBPacket)+DataLen-1); |
| | | p1->data[DataLen+1]=EndSign; |
| | | PacketLenth=sizeof(stKBPacket)+DataLen+1; |
| | | break; |
| | | case cmdExChgDataReply: |
| | | p1->PacketLen=DataLen; |
| | | p1->DataLen=DataLen; |
| | | memcpy(p1->data,pData,DataLen); |
| | | p1->data[DataLen]=KBusBCC(p1,sizeof(stKBPacket)+DataLen-1); |
| | | p1->data[DataLen+1]=EndSign; |
| | |
| | | break; |
| | | |
| | | case cmdSyncRead: |
| | | p1->PacketLen=DataLen; |
| | | p1->DataLen=DataLen; |
| | | memcpy(p1->data,pData,DataLen); |
| | | p1->data[DataLen]=KBusBCC(p1,sizeof(stKBPacket)+DataLen-1); |
| | | p1->data[DataLen+1]=EndSign; |
| | | PacketLenth=sizeof(stKBPacket)+DataLen+1; |
| | | break; |
| | | case cmdSyncWrite: |
| | | p1->PacketLen=DataLen; |
| | | p1->DataLen=DataLen; |
| | | memcpy(p1->data,pData,DataLen); |
| | | p1->data[DataLen]=KBusBCC(p1,sizeof(stKBPacket)+DataLen-1); |
| | | p1->data[DataLen+1]=EndSign; |
| | | PacketLenth=sizeof(stKBPacket)+DataLen+1; |
| | | break; |
| | | case cmdSequenRead: |
| | | p1->PacketLen=DataLen; |
| | | p1->DataLen=DataLen; |
| | | memcpy(p1->data,pData,DataLen); |
| | | p1->data[DataLen]=KBusBCC(p1,sizeof(stKBPacket)+DataLen-1); |
| | | p1->data[DataLen+1]=EndSign; |
| | |
| | | break; |
| | | |
| | | case cmdSyncTime: |
| | | p1->PacketLen=DataLen; |
| | | p1->DataLen=DataLen; |
| | | memcpy(p1->data,pData,DataLen); |
| | | p1->data[DataLen]=KBusBCC(p1,sizeof(stKBPacket)+DataLen-1); |
| | | p1->data[DataLen+1]=EndSign; |
| | |
| | | } |
| | | return -1; |
| | | } |
| | | int DataLen=p3->PacketLen; |
| | | int DataLen=p3->DataLen; |
| | | if (DataLen>MaxPacketLength) |
| | | { |
| | | Uart2Stat.LengthErr++; |
| | |
| | | KBusChnStats[0].ClientNotPktErr++; |
| | | return -1; |
| | | } |
| | | int DataLen=p3->PacketLen; |
| | | int DataLen=p3->DataLen; |
| | | if (DataLen>MaxPacketLength) |
| | | { |
| | | Uart2Stat.LengthErr++; |
| | |
| | | Len1--; |
| | | } |
| | | |
| | | int DataLen=p1->PacketLen; |
| | | int DataLen=p1->DataLen; |
| | | KBusChnStats[nCurPollId].RecvPackets++; |
| | | pKBPacket p2=(pKBPacket)PacketBuf2; |
| | | int PacketLen=0; |
| | |
| | | |
| | | #if (BOARD_TYPE == 14) |
| | | BufferIn[ChildId]=p1->data[0]; |
| | | BufferIn[ChildId + 1] = p1->data[1]; |
| | | BufferIn[ChildId + 2 ] = p1->data[2]; |
| | | |
| | | KMem.WXB[ChildId-1]=BufferIn[ChildId]; |
| | | KMem.WXB[ChildId]=BufferIn[ChildId+1]; |
| | | KMem.WXB[ChildId+1]=BufferIn[ChildId+2]; |
| | | |
| | | if (KMRunStat.WorkMode==0) { |
| | | // KMem.WY[0]= KMem.WX[1]+(KMem.WX[2]<<8) ; |
| | | // PutOutput (KMem.WY[0]); |
| | |
| | | } |
| | | |
| | | Uart2Stat.OKPacket++; |
| | | int DataLen=p1->PacketLen; |
| | | int DataLen=p1->DataLen; |
| | | //int nSrcAddr=p1->SrcAddr; |
| | | int nDstHost=p1->DstHost; |
| | | |
| | |
| | | break; |
| | | case cmdExChgData: |
| | | BufferIn[0]=p1->data[0]; |
| | | BufferIn[1]=p1->data[1]; |
| | | // KMem.WLYB[1] = BufferIn[1]; |
| | | |
| | | KMem.WYB[1] = BufferIn[1]; |
| | | nSlaveTick=p1->data[4]+(p1->data[5]<<8);//+(p1->data[6]<<16)+(p1->data[7]<<24); |
| | | #if (BOARD_TYPE == 14) |
| | | // PutOutput(BufferIn[0]); |
| | |
| | | // KBusChnStats[0].ClientDatas[7]++; |
| | | // BufferOut[0]=GetInput(); |
| | | BufferOut[0]=GetInput(); |
| | | BufferOut[1]=KMem.WXB[1]; |
| | | #endif |
| | | p1->data[0]=BufferOut[0]; |
| | | p1->data[1]=BufferOut[1]; |
| | | |
| | | p1->data[3]=nIndex; |
| | | p1->data[4]=KBusChnStats[0].ClientDatas[nIndex]; |
| | | p1->data[5]=KBusChnStats[0].ClientDatas[nIndex]>>8; |
| | |
| | | { |
| | | KBusChnStats[nCurPollId].Stat=0; |
| | | KMem.ErrStat=200; |
| | | |
| | | {BufferIn[nCurPollId]=0;} |
| | | #if (BOARD_TYPE == 14) |
| | | BufferIn[nCurPollId]=0; |
| | | KMem.WXB[nCurPollId-1]=BufferIn[nCurPollId]; |
| | | #else |
| | | {BufferIn[nCurPollId]=0; |
| | | KMem.WLX[nCurPollId]=BufferIn[nCurPollId]; |
| | | } |
| | | #endif |
| | | } |
| | | // LL_GPIO_SetOutputPin(GPIOA,LL_GPIO_PIN_7); |
| | | }else |