From 0fe6b074f3f3994d87af195f37e349a83e27882c Mon Sep 17 00:00:00 2001
From: QuakeGod <QuakeGod@sina.com>
Date: 星期六, 10 十二月 2022 16:55:40 +0800
Subject: [PATCH] FP0 fix utf8 char

---
 Src/KBus.c |  260 ++++++++++++++++++++++++++--------------------------
 1 files changed, 130 insertions(+), 130 deletions(-)

diff --git a/Src/KBus.c b/Src/KBus.c
index f41c30d..f51509d 100644
--- a/Src/KBus.c
+++ b/Src/KBus.c
@@ -17,22 +17,22 @@
 unsigned char BufferIn[16]={0};
 unsigned char BufferOut[16]={0};
 
-stChnStat ChnStats[8];
-unsigned char nAddr=0;
+stChnStat KBusChnStats[8];
+unsigned char nStationID=0;
 unsigned char nChilds;
 int ChildStat[16];
 unsigned char nCurPollId=0;
 unsigned char nSeq=0;
 
-volatile unsigned char MasterRecved=1;
-volatile unsigned char MasterRecvOK=1;
+volatile unsigned char KBusMasterRecved=1;
+volatile unsigned char KBusMasterRecvOK=1;
 
-volatile unsigned char SlaveRecved=1;
-unsigned int SendTimeuS=0;
-volatile int RecvTimeuS=0;
+volatile unsigned char KBusSlaveRecved=1;
+unsigned int KBusSendTimeuS=0;
+volatile int KBusRecvTimeuS=0;
 
-int DelayuS=0;
-int MaxDelayuS=0;
+int KBusDelayuS=0;
+int KBusMaxDelayuS=0;
 int ThisuS;
 volatile unsigned int nSlaveTick=0;
 
@@ -47,7 +47,7 @@
 unsigned char Datas[128];		
 volatile int PacketLength = 0;
 
-unsigned char BCC(void * pData, int nSize)
+unsigned char KBusBCC(void * pData, int nSize)
 {
 	unsigned char k;
 	k=0;
@@ -58,7 +58,7 @@
 	return k;	
 }
 
-int MakePacket(pPacket p1,unsigned char src, uchar dst, uchar nType,unsigned char nSEQ, unsigned char DataLen,void * pData )
+int KBusMakePacket(pKBPacket p1,unsigned char src, uchar dst, uchar nType,unsigned char nSEQ, unsigned char DataLen,void * pData )
 {
 	p1->Sign=StartSign;
 	p1->DstHost=dst;
@@ -73,17 +73,17 @@
 		case cmdPing:
 			p1->PacketLen=DataLen;
 			memcpy(p1->data,pData,DataLen);
-			p1->data[DataLen]=BCC(p1,sizeof(stPacket)+DataLen-1);
+			p1->data[DataLen]=KBusBCC(p1,sizeof(stKBPacket)+DataLen-1);
 			p1->data[DataLen+1]=EndSign;
 		
-			PacketLenth=sizeof(stPacket)+DataLen+1;
+			PacketLenth=sizeof(stKBPacket)+DataLen+1;
 			break;
 		case cmdPingReply:
 			p1->PacketLen=DataLen;
 			memcpy(p1->data,pData,DataLen);
-			p1->data[DataLen]=BCC(p1,sizeof(stPacket)+DataLen-1);
+			p1->data[DataLen]=KBusBCC(p1,sizeof(stKBPacket)+DataLen-1);
 			p1->data[DataLen+1]=EndSign;		
-			PacketLenth=sizeof(stPacket)+DataLen+1;		
+			PacketLenth=sizeof(stKBPacket)+DataLen+1;		
 			break;
 		case cmdRead:
 			break;
@@ -94,67 +94,67 @@
 		case cmdWriteReply:
 			p1->PacketLen=DataLen;
 		 if (DataLen !=0 )	memcpy(p1->data,pData,DataLen);
-			p1->data[DataLen]=BCC(p1,sizeof(stPacket)+DataLen-1);
+			p1->data[DataLen]=KBusBCC(p1,sizeof(stKBPacket)+DataLen-1);
 			p1->data[DataLen+1]=EndSign;
-			PacketLenth=sizeof(stPacket)+DataLen+1;					
+			PacketLenth=sizeof(stKBPacket)+DataLen+1;					
 			break;
 		case cmdGetVersion:
 			p1->PacketLen=DataLen;
 			memcpy(p1->data,pData,DataLen);
-			p1->data[DataLen]=BCC(p1,sizeof(stPacket)+DataLen-1);
+			p1->data[DataLen]=KBusBCC(p1,sizeof(stKBPacket)+DataLen-1);
 			p1->data[DataLen+1]=EndSign;
-			PacketLenth=sizeof(stPacket)+DataLen+1;			
+			PacketLenth=sizeof(stKBPacket)+DataLen+1;			
 			break;
 		case cmdVerInfo:
 			p1->PacketLen=DataLen;
 			memcpy(p1->data,pData,DataLen);
-			p1->data[DataLen]=BCC(p1,sizeof(stPacket)+DataLen-1);
+			p1->data[DataLen]=KBusBCC(p1,sizeof(stKBPacket)+DataLen-1);
 			p1->data[DataLen+1]=EndSign;
-			PacketLenth=sizeof(stPacket)+DataLen+1;			
+			PacketLenth=sizeof(stKBPacket)+DataLen+1;			
 			break;
 		case cmdExChgData:
 			p1->PacketLen=DataLen;
 			memcpy(p1->data,pData,DataLen);
-			p1->data[DataLen]=BCC(p1,sizeof(stPacket)+DataLen-1);
+			p1->data[DataLen]=KBusBCC(p1,sizeof(stKBPacket)+DataLen-1);
 			p1->data[DataLen+1]=EndSign;
-			PacketLenth=sizeof(stPacket)+DataLen+1;
+			PacketLenth=sizeof(stKBPacket)+DataLen+1;
 			break;
 		case cmdExChgDataReply:
 			p1->PacketLen=DataLen;
 			memcpy(p1->data,pData,DataLen);
-			p1->data[DataLen]=BCC(p1,sizeof(stPacket)+DataLen-1);
+			p1->data[DataLen]=KBusBCC(p1,sizeof(stKBPacket)+DataLen-1);
 			p1->data[DataLen+1]=EndSign;		
-			PacketLenth=sizeof(stPacket)+DataLen+1;		
+			PacketLenth=sizeof(stKBPacket)+DataLen+1;		
 			break;
 				
 		case cmdSyncRead:
 			p1->PacketLen=DataLen;
 			memcpy(p1->data,pData,DataLen);
-			p1->data[DataLen]=BCC(p1,sizeof(stPacket)+DataLen-1);
+			p1->data[DataLen]=KBusBCC(p1,sizeof(stKBPacket)+DataLen-1);
 			p1->data[DataLen+1]=EndSign;		
-			PacketLenth=sizeof(stPacket)+DataLen+1;		
+			PacketLenth=sizeof(stKBPacket)+DataLen+1;		
 			break;
 		case cmdSyncWrite:
 			p1->PacketLen=DataLen;
 			memcpy(p1->data,pData,DataLen);
-			p1->data[DataLen]=BCC(p1,sizeof(stPacket)+DataLen-1);
+			p1->data[DataLen]=KBusBCC(p1,sizeof(stKBPacket)+DataLen-1);
 			p1->data[DataLen+1]=EndSign;		
-			PacketLenth=sizeof(stPacket)+DataLen+1;		
+			PacketLenth=sizeof(stKBPacket)+DataLen+1;		
 			break;
 		case cmdSequenRead:
 			p1->PacketLen=DataLen;
 			memcpy(p1->data,pData,DataLen);
-			p1->data[DataLen]=BCC(p1,sizeof(stPacket)+DataLen-1);
+			p1->data[DataLen]=KBusBCC(p1,sizeof(stKBPacket)+DataLen-1);
 			p1->data[DataLen+1]=EndSign;		
-			PacketLenth=sizeof(stPacket)+DataLen+1;		
+			PacketLenth=sizeof(stKBPacket)+DataLen+1;		
 			break;		
 		
 		case cmdSyncTime:
 			p1->PacketLen=DataLen;
 			memcpy(p1->data,pData,DataLen);
-			p1->data[DataLen]=BCC(p1,sizeof(stPacket)+DataLen-1);
+			p1->data[DataLen]=KBusBCC(p1,sizeof(stKBPacket)+DataLen-1);
 			p1->data[DataLen+1]=EndSign;		
-			PacketLenth=sizeof(stPacket)+DataLen+1;		
+			PacketLenth=sizeof(stKBPacket)+DataLen+1;		
 			break;
 		
 		default:
@@ -164,90 +164,90 @@
 	return PacketLenth;
 }
 
-int CheckPacket(int nChn, pPacket p1, int nLen1)
+int KBusCheckPacket(int nChn, pKBPacket p1, int nLen1)
 {
 	if (p1->Sign != StartSign)
 	{
 		Uart2Stat.NotPacketErr++;
-		ChnStats[nCurPollId].NotPkgErr++;
+		KBusChnStats[nCurPollId].NotPkgErr++;
 		return -1;
 	}
 	int DataLen=p1->PacketLen;
 	if (DataLen>MaxPacketLength) 
 	{
 		Uart2Stat.LengthErr++;
-		ChnStats[nCurPollId].PkgLenErr++;
+		KBusChnStats[nCurPollId].PkgLenErr++;
 		return -1;
 	}
-	if (nLen1<DataLen+sizeof(stPacket)+1)
+	if (nLen1<DataLen+sizeof(stKBPacket)+1)
 	{
-		//len4=sprintf(str3,"%d < %d + %d \r\n",len2,DataLen,sizeof(stPacket));
+		//len4=sprintf(str3,"%d < %d + %d \r\n",len2,DataLen,sizeof(stKBPacket));
 		//PutStr(str3,len4);
-		ChnStats[nCurPollId].PkgLenErr++;
+		KBusChnStats[nCurPollId].PkgLenErr++;
 		Uart2Stat.LengthErr++;
 		return -3;	//not long enough					
 	}
 //	if (p1->data[DataLen+1] != EndSign)
 //	{
-//		ChnStats[nCurPollId].NoEndErr++;
+//		KBusChnStats[nCurPollId].NoEndErr++;
 //		Uart2Stat.LengthErr++;		
 //		return -2;
 //	}
-	unsigned char thisBCC=BCC(p1,sizeof(stPacket)+DataLen-1);
+	unsigned char thisBCC=KBusBCC(p1,sizeof(stKBPacket)+DataLen-1);
 	if (thisBCC != p1->data[DataLen]) 
 	{//BCC Error;
 		Uart2Stat.BCCerr++;
-		ChnStats[nCurPollId].BCCErr++;
+		KBusChnStats[nCurPollId].BCCErr++;
 		return -4;
 	} 		
 	return 0;
 }
 
-int SlaveCheckPacket(int nChn, pPacket p1, int nLen1)
+int KBusSlaveCheckPacket(int nChn, pKBPacket p1, int nLen1)
 {
 	if (p1->Sign != StartSign)
 	{
 		Uart2Stat.NotPacketErr++;
-		ChnStats[0].ClientNotPktErr++;
+		KBusChnStats[0].ClientNotPktErr++;
 		return -1;
 	}
 	int DataLen=p1->PacketLen;
 	if (DataLen>MaxPacketLength) 
 	{
 		Uart2Stat.LengthErr++;
-		ChnStats[0].ClientPkgLenErr++;
+		KBusChnStats[0].ClientPkgLenErr++;
 		return -1;
 	}
-	if (nLen1<DataLen+sizeof(stPacket)+1)
+	if (nLen1<DataLen+sizeof(stKBPacket)+1)
 	{
-		//len4=sprintf(str3,"%d < %d + %d \r\n",len2,DataLen,sizeof(stPacket));
+		//len4=sprintf(str3,"%d < %d + %d \r\n",len2,DataLen,sizeof(stKBPacket));
 		//PutStr(str3,len4);
-		ChnStats[0].ClientPkgLenErr++;
+		KBusChnStats[0].ClientPkgLenErr++;
 		Uart2Stat.LengthErr++;
 		return -3;	//not long enough					
 	}
 //	if (p1->data[DataLen+1] != EndSign)
 //	{
-//		ChnStats[nCurPollId].NoEndErr++;
+//		KBusChnStats[nCurPollId].NoEndErr++;
 //		Uart2Stat.LengthErr++;		
 //		return -2;
 //	}
-	unsigned char thisBCC=BCC(p1,sizeof(stPacket)+DataLen-1);
+	unsigned char thisBCC=KBusBCC(p1,sizeof(stKBPacket)+DataLen-1);
 	if (thisBCC != p1->data[DataLen]) 
 	{//BCC Error;
 		Uart2Stat.BCCerr++;
-		ChnStats[0].ClientBccErr++;
+		KBusChnStats[0].ClientBccErr++;
 		return -4;
 	} 		
 	return 0;
 }
 
-int MasterParsePacket(int nChn, pPacket p1, int Len1)
+int KBusMasterParsePacket(int nChn, pKBPacket p1, int Len1)
 {
 
 		int DataLen=p1->PacketLen;
-		ChnStats[nCurPollId].RecvPackets++;	
-		pPacket p2=(pPacket)PacketBuf2;		
+		KBusChnStats[nCurPollId].RecvPackets++;	
+		pKBPacket p2=(pKBPacket)PacketBuf2;		
 		int PacketLen=0;
 		//LL_GPIO_TogglePin(GPIOA,LL_GPIO_PIN_6);
 		int ChildId=p1->SrcAddr;
@@ -259,22 +259,22 @@
 				break;
 			case cmdPing:
 				BufferIn[ChildId]=p1->data[0];
-				PacketLen=MakePacket(p2,0,nCurPollId,cmdPingReply,p1->nSEQ,DataLen,p1->data);
+				PacketLen=KBusMakePacket(p2,0,nCurPollId,cmdPingReply,p1->nSEQ,DataLen,p1->data);
 				SendPacket(nChn, p2, PacketLen);
 				break;
 			case cmdPingReply:
-				DelayuS=ThisuS-SendTimeuS;
-				if (DelayuS > MaxDelayuS) MaxDelayuS = DelayuS;
+				KBusDelayuS=ThisuS-KBusSendTimeuS;
+				if (KBusDelayuS > KBusMaxDelayuS) KBusMaxDelayuS = KBusDelayuS;
 				
 				BufferIn[ChildId]=p1->data[0];
 				
 				//RunStat=100;
-				ChnStats[nCurPollId].CtnLstPkts=0;
-				ChnStats[nCurPollId].Delay=DelayuS;
-			if (DelayuS > ChnStats[nCurPollId].MaxDelay) 
-				ChnStats[nCurPollId].MaxDelay=DelayuS;
+				KBusChnStats[nCurPollId].CtnLstPkts=0;
+				KBusChnStats[nCurPollId].Delay=KBusDelayuS;
+			if (KBusDelayuS > KBusChnStats[nCurPollId].MaxDelay) 
+				KBusChnStats[nCurPollId].MaxDelay=KBusDelayuS;
 				//PutOutput(outputvalue);
-				MasterRecvOK=1;
+				KBusMasterRecvOK=1;
 				break;
 			case cmdRead:
 				break;
@@ -283,7 +283,7 @@
 			case cmdWrite:
 				break;
 			case cmdWriteReply:
-				MasterRecved=1;
+				KBusMasterRecved=1;
 				break;
 			case cmdGetVersion:
 				break;
@@ -294,12 +294,12 @@
 				//PutOutput(outputvalue);
 				//memcpy(DispBuf,p1->data+2,8);
 				p1->data[0]=BufferOut[0];
-				PacketLen=MakePacket(p2,nAddr,0,cmdExChgDataReply,p1->nSEQ,DataLen,p1->data);
+				PacketLen=KBusMakePacket(p2,nStationID,0,cmdExChgDataReply,p1->nSEQ,DataLen,p1->data);
 				SendPacket(nChn, p2, PacketLen);
 				break;
 			case cmdExChgDataReply:
-				DelayuS=ThisuS-SendTimeuS;
-				if (DelayuS > MaxDelayuS) MaxDelayuS = DelayuS;
+				KBusDelayuS=ThisuS-KBusSendTimeuS;
+				if (KBusDelayuS > KBusMaxDelayuS) KBusMaxDelayuS = KBusDelayuS;
 
 #if (BOARD_TYPE == 14)				
 				BufferIn[ChildId]=p1->data[0];
@@ -318,17 +318,17 @@
 #endif
 
 				//RunStat=100;
-				ChnStats[nCurPollId].CtnLstPkts=0;
-				ChnStats[nCurPollId].Delay=DelayuS;
-			if (DelayuS > ChnStats[nCurPollId].MaxDelay) 
-				ChnStats[nCurPollId].MaxDelay=DelayuS;
+				KBusChnStats[nCurPollId].CtnLstPkts=0;
+				KBusChnStats[nCurPollId].Delay=KBusDelayuS;
+			if (KBusDelayuS > KBusChnStats[nCurPollId].MaxDelay) 
+				KBusChnStats[nCurPollId].MaxDelay=KBusDelayuS;
 				//PutOutput(outputvalue);
 				
 			
 				nIndex=p1->data[3];
-				ChnStats[nCurPollId].ClientDatas[nIndex]=p1->data[4]|(p1->data[5]<<8)|(p1->data[6]<<16)|(p1->data[7]<<24);
+				KBusChnStats[nCurPollId].ClientDatas[nIndex]=p1->data[4]|(p1->data[5]<<8)|(p1->data[6]<<16)|(p1->data[7]<<24);
 			
-				MasterRecvOK=1;
+				KBusMasterRecvOK=1;
 				
 				break;
 					
@@ -343,28 +343,28 @@
 	return 0;
 }
 unsigned char nClientDataIndex=0;
-int SlaveParsePacket(int nChn, pPacket p1, int Len1)
+int KBusSlaveParsePacket(int nChn, pKBPacket p1, int Len1)
 {
 	Uart2Stat.OKPacket++;				
 	int DataLen=p1->PacketLen;	
 //int nSrcAddr=p1->SrcAddr;
 	int nDstHost=p1->DstHost;
 		
-//	RecvTimeuS=ThisuS;
-//	SlaveRecved=1;
+//	KBusRecvTimeuS=ThisuS;
+//	KBusSlaveRecved=1;
 	
-	pPacket p2=(pPacket)PacketBuf2;
+	pKBPacket p2=(pKBPacket)PacketBuf2;
 	int PacketLen=0;
 	unsigned char nIndex = p1->nSEQ & 0x07;
-	if (nDstHost!=nAddr && nDstHost != 0xff)
+	if (nDstHost!=nStationID && nDstHost != 0xff)
 	{
-		ChnStats[0].ClientMisIdPkts++;
+		KBusChnStats[0].ClientMisIdPkts++;
 		return -1;
 	}
-	if (nDstHost==nAddr || nDstHost==0xff)
+	if (nDstHost==nStationID || nDstHost==0xff)
 	{
-		RecvTimeuS=ThisuS;
-		SlaveRecved=1;
+		KBusRecvTimeuS=ThisuS;
+		KBusSlaveRecved=1;
 		switch (p1->nCMD)
 		{
 			case cmdNone:
@@ -374,9 +374,9 @@
 				//PutOutput(outputvalue);
 				//memcpy(DispBuf,p1->data+2,8);
 				p1->data[0]=BufferOut[0];
-				RecvTimeuS=ThisuS;
-				PacketLen=MakePacket(p2,nAddr,0,cmdPingReply,p1->nSEQ,DataLen,p1->data);
-				ChnStats[0].ClientSendPkts++;
+				KBusRecvTimeuS=ThisuS;
+				PacketLen=KBusMakePacket(p2,nStationID,0,cmdPingReply,p1->nSEQ,DataLen,p1->data);
+				KBusChnStats[0].ClientSendPkts++;
 				SendPacket(nChn, p2, PacketLen);
 				break;
 			case cmdPingReply:
@@ -387,8 +387,8 @@
 				break;
 			case cmdWrite:
 				//memcpy(DispBuf,p1->data,DataLen);
-				PacketLen=MakePacket(p2,1,0,cmdWriteReply,p1->nSEQ,0,0);
-				ChnStats[0].ClientSendPkts++;
+				PacketLen=KBusMakePacket(p2,1,0,cmdWriteReply,p1->nSEQ,0,0);
+				KBusChnStats[0].ClientSendPkts++;
 				SendPacket(nChn, p2, PacketLen);					
 				break;
 			case cmdWriteReply:
@@ -405,7 +405,7 @@
 				//PutOutput(outputvalue);
 				//memcpy(DispBuf,p1->data+2,8);
 				nIndex=nClientDataIndex;
-		//		ChnStats[0].ClientDatas[7]++;
+		//		KBusChnStats[0].ClientDatas[7]++;
 //				BufferOut[0]=GetInput();
 		//		BufferOut[0]=GetInput();
 #else
@@ -413,20 +413,20 @@
 				//PutOutput(outputvalue);
 				//memcpy(DispBuf,p1->data+2,8);
 				nIndex=nClientDataIndex;
-		//		ChnStats[0].ClientDatas[7]++;
+		//		KBusChnStats[0].ClientDatas[7]++;
 //				BufferOut[0]=GetInput();
 				BufferOut[0]=GetInput();
 #endif
 				p1->data[0]=BufferOut[0];
 				p1->data[3]=nIndex;
-				p1->data[4]=ChnStats[0].ClientDatas[nIndex];
-				p1->data[5]=ChnStats[0].ClientDatas[nIndex]>>8;
-				p1->data[6]=ChnStats[0].ClientDatas[nIndex]>>16;
-				p1->data[7]=ChnStats[0].ClientDatas[nIndex]>>24;
+				p1->data[4]=KBusChnStats[0].ClientDatas[nIndex];
+				p1->data[5]=KBusChnStats[0].ClientDatas[nIndex]>>8;
+				p1->data[6]=KBusChnStats[0].ClientDatas[nIndex]>>16;
+				p1->data[7]=KBusChnStats[0].ClientDatas[nIndex]>>24;
 				nClientDataIndex++;
 				if (nClientDataIndex >= 10) { nClientDataIndex=0;}
-				PacketLen=MakePacket(p2,nAddr,0,cmdExChgDataReply,p1->nSEQ,DataLen,p1->data);
-				ChnStats[0].ClientSendPkts++;
+				PacketLen=KBusMakePacket(p2,nStationID,0,cmdExChgDataReply,p1->nSEQ,DataLen,p1->data);
+				KBusChnStats[0].ClientSendPkts++;
 				SendPacket(nChn, p2, PacketLen);
 				break;
 			case cmdExChgDataReply:
@@ -448,42 +448,42 @@
 	}	
 	return 0;
 }
-int ParsePacket(int nChn, pPacket p1, int Len1)
+int KBusParsePacket(int nChn, pKBPacket p1, int Len1)
 {
 	ThisuS=GetuS();
 	int Result=0;
 	if (bKBusMaster)
 	{
-			MasterRecved=1;
-			Result=CheckPacket(nChn, p1, Len1);
+			KBusMasterRecved=1;
+			Result=KBusCheckPacket(nChn, p1, Len1);
 			if (Result != S_OK)
 			{
 				return Result;
 			}
-			MasterRecvOK=1;
-			Result=MasterParsePacket(nChn, p1, Len1);			
+			KBusMasterRecvOK=1;
+			Result=KBusMasterParsePacket(nChn, p1, Len1);			
 			return Result;
 	}
 	if (bKBusSlave)
 	{
-			ChnStats[0].ClientRecvPkts++;
-			Result=SlaveCheckPacket(nChn, p1, Len1);
+			KBusChnStats[0].ClientRecvPkts++;
+			Result=KBusSlaveCheckPacket(nChn, p1, Len1);
 			if (Result != S_OK)
 			{
 				return Result;
 			}
-			ChnStats[0].ClientTimeOutErr=KMem.RunStat;
-			Result=SlaveParsePacket(nChn, p1, Len1);
+			KBusChnStats[0].ClientTimeOutErr=KMem.RunStat;
+			Result=KBusSlaveParsePacket(nChn, p1, Len1);
 			return Result;
 	}
 	//int len1=p1->PacketLen;
 //	if (p1->DstHost!=255&&p1->DstHost!=2) return -3;
-//	pPacket p2=(pPacket)PacketBuf2;
+//	pKBPacket p2=(pKBPacket)PacketBuf2;
 //			Uart2Stat.OKPacket++;
 
 	return Result;
 }
-
+/*
 int InitMachine(stMachineConfig * pConfig)
 {
 	return S_OK;
@@ -523,7 +523,7 @@
 {
 	return S_OK;
 }
-
+*/
 int KBusRepeaterFunc(int nChn)
 {
 		KMem.WY[0]=KMem.WX[0];
@@ -544,20 +544,20 @@
 
 		int len1=0;
 
-		if ((MasterRecved && MasterRecvOK && thisuS-SendTimeuS>50) || thisuS-SendTimeuS>1000u)
+		if ((KBusMasterRecved && KBusMasterRecvOK && thisuS-KBusSendTimeuS>50) || thisuS-KBusSendTimeuS>1000u)
 		{
-			if (!MasterRecvOK) 
+			if (!KBusMasterRecvOK) 
 			{
 				TimeOutCount++;
 				Uart2Stat.TimeOutErr++; 
-				ChnStats[nCurPollId].LostPackets++;
-				ChnStats[nCurPollId].CtnLstPkts++;
-				if (!MasterRecved) {ChnStats[nCurPollId].TimeOutErr++;}
-				if (ChnStats[nCurPollId].CtnLstPkts>ChnStats[nCurPollId].MaxCtnLstPkts)
-				{ChnStats[nCurPollId].MaxCtnLstPkts=ChnStats[nCurPollId].CtnLstPkts;}
-				if (ChnStats[nCurPollId].CtnLstPkts>3)
+				KBusChnStats[nCurPollId].LostPackets++;
+				KBusChnStats[nCurPollId].CtnLstPkts++;
+				if (!KBusMasterRecved) {KBusChnStats[nCurPollId].TimeOutErr++;}
+				if (KBusChnStats[nCurPollId].CtnLstPkts>KBusChnStats[nCurPollId].MaxCtnLstPkts)
+				{KBusChnStats[nCurPollId].MaxCtnLstPkts=KBusChnStats[nCurPollId].CtnLstPkts;}
+				if (KBusChnStats[nCurPollId].CtnLstPkts>3)
 				{
-					ChnStats[nCurPollId].Stat=0;
+					KBusChnStats[nCurPollId].Stat=0;
 					KMem.ErrStat=200;
 					 
 					{BufferIn[nCurPollId]=0;}
@@ -565,7 +565,7 @@
 			//	LL_GPIO_SetOutputPin(GPIOA,LL_GPIO_PIN_7);
 			}else
 			{
-				ChnStats[nCurPollId].Stat=1;
+				KBusChnStats[nCurPollId].Stat=1;
 				
 				KMem.RunStat=100;
 			}
@@ -599,24 +599,24 @@
 
 			Datas[0]=BufferOut[nCurPollId];
 			Datas[1]=BufferOut[nCurPollId+1];;
-			Datas[2]=ChnStats[nCurPollId].Stat;
+			Datas[2]=KBusChnStats[nCurPollId].Stat;
 			Datas[3]=0;
 			Datas[4]=tick1&0xff;
 			Datas[5]=(tick1>>8)&0xff;
 			Datas[6]=(tick1>>16)&0xff;
 			Datas[7]=(tick1>>24)&0xff;
 			
-			SendTimeuS=thisuS;				
-			len1=MakePacket((pPacket)PacketBuf1,0,nCurPollId,cmdExChgData,nSeq,8,Datas);
-			SendPacket(nChn, (pPacket)PacketBuf1, len1);
-			ChnStats[nCurPollId].SendPackets++;
-			ChnStats[nCurPollId].SendTimeInterval=SendTimeuS-ChnStats[nCurPollId].LastSentTimeuS;
-			ChnStats[nCurPollId].LastSentTimeuS=SendTimeuS;
+			KBusSendTimeuS=thisuS;				
+			len1=KBusMakePacket((pKBPacket)PacketBuf1,0,nCurPollId,cmdExChgData,nSeq,8,Datas);
+			SendPacket(nChn, (pKBPacket)PacketBuf1, len1);
+			KBusChnStats[nCurPollId].SendPackets++;
+			KBusChnStats[nCurPollId].SendTimeInterval=KBusSendTimeuS-KBusChnStats[nCurPollId].LastSentTimeuS;
+			KBusChnStats[nCurPollId].LastSentTimeuS=KBusSendTimeuS;
 //			PacketLength = len1;
 			SendTime=tick1;
 
-			MasterRecved=0;
-			MasterRecvOK=0;
+			KBusMasterRecved=0;
+			KBusMasterRecvOK=0;
 		//	LL_GPIO_TogglePin(GPIOA,LL_GPIO_PIN_5);		
 			//ToggleErrLed();
 //				ToggleOut8();
@@ -632,23 +632,23 @@
 int KBusSlaveFunc(int nChn)
 {
 		int ThisuS=GetuS();
-		int thisRecvTime=RecvTimeuS;
-		if (SlaveRecved)
+		int thisRecvTime=KBusRecvTimeuS;
+		if (KBusSlaveRecved)
 		{
 			KMem.RunStat=8000;
-			SlaveRecved=0;
+			KBusSlaveRecved=0;
 		}else if ((ThisuS - thisRecvTime) >12000u)
 		{
 			KMem.ErrStat=8000;
 			KMem.SDD[17]=1;
 			KMem.SDD[18]=ThisuS;
-			KMem.SDD[19]=RecvTimeuS;
+			KMem.SDD[19]=KBusRecvTimeuS;
 		}else if ( ThisuS > (thisRecvTime + 12000u))
 		{
 			KMem.ErrStat=8000;
 			KMem.SDD[17]=2;
 			KMem.SDD[18]=ThisuS;
-			KMem.SDD[19]=RecvTimeuS;
+			KMem.SDD[19]=KBusRecvTimeuS;
 		}
 		
 	return 0;

--
Gitblit v1.9.1