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 |  110 ++++++++++++++++++++++++++++++++-----------------------
 1 files changed, 64 insertions(+), 46 deletions(-)

diff --git a/Src/main.c b/Src/main.c
index ae7bb97..36214fe 100644
--- a/Src/main.c
+++ b/Src/main.c
@@ -57,7 +57,7 @@
 #include "../src/Ethernet/loopback.h"
 #elif (BOARD_TYPE == 14)
 #include "FP0.h"
-#elif (BOARD_TYPE == 15)
+#elif (BOARD_TYPE == 15 || BOARD_TYPE == 16)
 #include "KWireless.h"
 //#include "user.h"
 //#include "../src/radio/inc/sx126x-board.h"
@@ -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)
-	nAddr=KMem.EffJumperSW&0x0f;
+
+#elif (BOARD_TYPE == 15 || BOARD_TYPE == 16)
+	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;
@@ -289,7 +295,7 @@
 #endif
 
 		if (GetBoardType() == 7 || GetBoardType() ==8 
-			|| GetBoardType() == 9 || GetBoardType() ==10 ||GetBoardType() ==13 ||GetBoardType() ==15 ) 
+			|| GetBoardType() == 9 || GetBoardType() ==10 ||GetBoardType() ==13 ||GetBoardType() ==15 || BOARD_TYPE == 16) 
 		{
 			displayInput(0xffff);		//
 			EnableDisIn(1);				//Input Diaplay Enable 595 
@@ -304,11 +310,10 @@
 		StartPLC();
 	}
 	KMem.WX[7]=0x5a;
-#if (BOARD_TYPE == 15)
+#if (BOARD_TYPE == 15 || BOARD_TYPE == 16)
 	KWireLessInit(KMem.EffJumperSW&0x20,KMem.EffJumperSW&0x1f);
 	KWireLessStart();
 #endif
-
   while (1)
   {
 		//int MyKeyStat1,MyKeyStat2;
@@ -339,7 +344,7 @@
 #endif
 		
 		if (GetBoardType() == 7 || GetBoardType() ==8 
-			|| GetBoardType() == 9 || GetBoardType() ==10 || GetBoardType() ==15) 
+			|| GetBoardType() == 9 || GetBoardType() ==10 || GetBoardType() ==15 || GetBoardType() ==16) 
 		{
 			displayInput(KMem.WX[0]);
 		}
@@ -368,7 +373,7 @@
 		}
 //*/
 
-#if (BOARD_TYPE == 15)
+#if (BOARD_TYPE == 15 || BOARD_TYPE == 16)
 		Radio.IrqProcess( ); // Process Radio IRQ
 #endif
 
@@ -421,7 +426,7 @@
 		if (bKBusSlave)		
 		{
 //			BufferOut[0]=KMem.WX[0];
-#if (BOARD_TYPE == 15)
+#if (BOARD_TYPE == 15 || BOARD_TYPE == 16)
 //			KBusSlaveFunc(2);	
 		//	if (! KMem.RunStat) {BufferIn[0]=0;}
 		//	KMem.WY[0]=BufferIn[0];
@@ -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);
@@ -469,7 +487,7 @@
 #endif
 		//PutOutput (KMem.nRunCount>>8);
 		//PutOutput(0x0f70);
-#if (BOARD_TYPE == 15)		
+#if (BOARD_TYPE == 15 || BOARD_TYPE == 16)		
 	//	KMem.WY[1]=KMem.nRunCount>>6;
 		KMem.WY[1]=KMem.WX[0];
 		KMem.WY[0]=KMem.WX[1];
@@ -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