From 2364f06313efb8eb97d4ae741a31cdd2efc175d2 Mon Sep 17 00:00:00 2001
From: QuakeGod <QuakeGod@sina.com>
Date: 星期三, 01 二月 2023 16:05:50 +0800
Subject: [PATCH] KBus fix after merget together

---
 Src/main.c |   94 ++++++++++++++++++++++++++++-------------------
 1 files changed, 56 insertions(+), 38 deletions(-)

diff --git a/Src/main.c b/Src/main.c
index fcbdaf3..36214fe 100644
--- a/Src/main.c
+++ b/Src/main.c
@@ -70,11 +70,11 @@
 /* USER CODE BEGIN PV */
 /* Private variables ---------------------------------------------------------*/
 
-#define RX2BUFSIZE 128
-#define TX2BUFSIZE 128
+#define RX2BUFSIZE 64
+#define TX2BUFSIZE 64
 
-unsigned char Uart1RxBuf[256];
-unsigned char Uart1TxBuf[280];
+unsigned char Uart1RxBuf[128];
+unsigned char Uart1TxBuf[260];
 
 unsigned char Uart2RxBuf[RX2BUFSIZE];
 unsigned char Uart2TxBuf[TX2BUFSIZE];
@@ -124,6 +124,8 @@
 		Count=0; 
 		KMem.CurTimeSec++;
 		KMem.ThisRunTime++; KMem.TotalRunTime++;
+		if (KMRunStat.bLEDFlick) KMRunStat.bLEDFlick--;
+		if (KMRunStat.bLEDFlick >120) KMRunStat.bLEDFlick=120;
 	}
 
 	return;
@@ -139,9 +141,10 @@
 int main(void)
 {
   /* USER CODE BEGIN 1 */
-
-	InitUartstat(&Uart1Stat,Uart1TxBuf,sizeof(Uart1RxBuf),Uart1TxBuf,sizeof(Uart1TxBuf));
-	InitUartstat(&Uart2Stat,Uart2TxBuf,sizeof(Uart2RxBuf),Uart2TxBuf,sizeof(Uart2TxBuf));
+	KMRunStat.bLEDFlick = 1;
+	
+	InitUartstat(&Uart1Stat,Uart1RxBuf,sizeof(Uart1RxBuf),Uart1TxBuf,sizeof(Uart1TxBuf));
+	InitUartstat(&Uart2Stat,Uart2RxBuf,sizeof(Uart2RxBuf),Uart2TxBuf,sizeof(Uart2TxBuf));
   /* USER CODE END 1 */
 
   /* MCU Configuration----------------------------------------------------------*/
@@ -153,18 +156,18 @@
 
 	for (int i=0;i<9;i++)
 	{
-//		memset(ChnStats[i],0,0);		
-		ChnStats[i].SendPackets=0;
-		ChnStats[i].RecvPackets=0;
-		ChnStats[i].LostPackets=0;
-		ChnStats[i].CtnLstPkts=0;
-		ChnStats[i].MaxCtnLstPkts=0;
-		ChnStats[i].NotPkgErr=0;
-		ChnStats[i].PkgLenErr=0;
-		ChnStats[i].TimeOutErr=0;
-		ChnStats[i].BCCErr=0;
-		ChnStats[i].Delay=0;
-		ChnStats[i].MaxDelay=0;
+//		memset(KBusChnStats[i],0,0);		
+		KBusChnStats[i].SendPackets=0;
+		KBusChnStats[i].RecvPackets=0;
+		KBusChnStats[i].LostPackets=0;
+		KBusChnStats[i].CtnLstPkts=0;
+		KBusChnStats[i].MaxCtnLstPkts=0;
+		KBusChnStats[i].NotPkgErr=0;
+		KBusChnStats[i].PkgLenErr=0;
+		KBusChnStats[i].TimeOutErr=0;
+		KBusChnStats[i].BCCErr=0;
+		KBusChnStats[i].Delay=0;
+		KBusChnStats[i].MaxDelay=0;
 	}
 	
 		KMem.LastScanTime=0;
@@ -190,7 +193,7 @@
   /* USER CODE BEGIN SysInit */
 	TickFreq=10000;		//Tick棰戠巼
 	InituS(TickFreq);	
- // HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/TickFreq);	//閲嶆柊瀹氫箟SysTick鐨勯鐜囷拷
+ // HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/TickFreq);	//閲嶆柊瀹氫箟SysTick鐨勯鐜�
 
   /* USER CODE END SysInit */
 
@@ -201,26 +204,29 @@
 	KMachineInit();
 	ReadSysCfgFromFlash(&storedKMSysCfg);
 	
+	KMRunStat.bLEDFlick = 1;
+	
 	KMem.EffJumperSW=ReadJumperSW();
 #if (BOARD_TYPE == 14)
 	KMem.EffJumperSW|=0x10;
-	nAddr=KMem.EffJumperSW&0x0f;
+	nStationID=KMem.EffJumperSW&0x0f;
   if ((KMem.EffJumperSW&0x10)!=0) {bKBusMaster=1;bKBusSlave=0;}
 	else{bKBusMaster=0;bKBusSlave=1;}
-	nChilds=nAddr;
+	nChilds=nStationID;
 	FP0_Init();
+
 #elif (BOARD_TYPE == 15 || BOARD_TYPE == 16)
-	nAddr=KMem.EffJumperSW&0x0f;
+	nStationID=KMem.EffJumperSW&0x0f;
 	if (KMem.EffJumperSW == 0x1f) {bKBusRepeater=1;bKBusMaster=1;bKBusSlave=0;}
   else if ((KMem.EffJumperSW&0x10)!=0) {bKBusMaster=1;bKBusSlave=0;}
 	else{bKBusMaster=0;bKBusSlave=1;}	
 #else
-	nAddr=KMem.EffJumperSW&0x7;
+	nStationID=KMem.EffJumperSW&0x7;
 	if (KMem.EffJumperSW == 0x0f) {bKBusRepeater=1;bKBusMaster=1;bKBusSlave=0;}
   else if ((KMem.EffJumperSW&0x08)!=0) {bKBusMaster=1;bKBusSlave=0;}
 	else{bKBusMaster=0;bKBusSlave=1;}
 #endif
-	nChilds=nAddr;
+	nChilds=nStationID;
 	nCurPollId=1;
 	//if (KMem.EffJumperSW == 0x00)
 		Uart1Baud = DefaultUart1Baud;
@@ -308,7 +314,6 @@
 	KWireLessInit(KMem.EffJumperSW&0x20,KMem.EffJumperSW&0x1f);
 	KWireLessStart();
 #endif
-
   while (1)
   {
 		//int MyKeyStat1,MyKeyStat2;
@@ -440,20 +445,33 @@
 //		KMem.WY[0]=nCount2>>5;
 		if (KMem.RunStat) {KMem.RunStat--;}
 		if (KMem.ErrStat) {KMem.ErrStat--;}
-
-		if (!KMem.RunStat) SetRunLed(SlowFlicker);
-		else SetRunLed(FastFlicker);
 		
-		if (!KMem.ErrStat) 
+		if (KMRunStat.bLEDFlick)
 		{
-			SetErrLed(0);
-			SetOutStat(1);
-		}
-		else 
-		{
+			SetRunLed(FastFlicker);
 			SetErrLed(FastFlicker);
-			SetOutStat(0);
+			SetErr2Led(FastFlicker);
+			SetOutStat(!FastFlicker);
+			//KMRunStat.bLEDFlick-- ;
+		}
+		else
+		{
+			if (!KMem.RunStat) SetRunLed(SlowFlicker);
+			else SetRunLed(FastFlicker);
 			
+			if (!KMem.ErrStat) 
+			{
+				SetErrLed(0);
+				SetErr2Led(0);
+				SetOutStat(1);
+			}
+			else 
+			{
+				SetErrLed(FastFlicker);
+				SetErr2Led(FastFlicker);
+				SetOutStat(0);
+				
+			}
 		}
 		
 //		SetRunLed(RunStat);
@@ -485,8 +503,8 @@
 		}
 		KMem.nRunCount++;
 //		int nSize=sizeof(stChnStat);
-//		memcpy(&KMem.SDT[64],&ChnStats[1],nSize);
-//		memcpy(&KMem.SDT[64+nSize/2],&ChnStats[2],nSize);
+//		memcpy(&KMem.SDT[64],&KBusChnStats[1],nSize);
+//		memcpy(&KMem.SDT[64+nSize/2],&KBusChnStats[2],nSize);
 //		for (int i=0;i<128;i++)	{		SDT[i]=i;	}
 //		SDT[48]=55;
 		if (Uart1RecvBuf1DataLen >0 && Uart1Stat.bPacketRecved)

--
Gitblit v1.9.1