From 9aed5d7e7b3c7bf09da712e9c272ece401a7acc9 Mon Sep 17 00:00:00 2001 From: QuakeGod <QuakeGod@sina.com> Date: 星期一, 25 十一月 2024 14:51:23 +0800 Subject: [PATCH] add UltraSonic and MultiWireLess --- Radio_LLCC68/Src/main.c | 92 +++++++++++++++++++++++++++++++++------------- 1 files changed, 66 insertions(+), 26 deletions(-) diff --git a/Radio_LLCC68/Src/main.c b/Radio_LLCC68/Src/main.c index 0c2f3de..76118a0 100644 --- a/Radio_LLCC68/Src/main.c +++ b/Radio_LLCC68/Src/main.c @@ -70,19 +70,37 @@ /* USER CODE BEGIN PV */ /* Private variables ---------------------------------------------------------*/ -#define RX2BUFSIZE 64 -#define TX2BUFSIZE 64 -unsigned char Uart1RxBuf[128]; -unsigned char Uart1TxBuf[260]; -unsigned char Uart2RxBuf[RX2BUFSIZE]; -unsigned char Uart2TxBuf[TX2BUFSIZE]; +unsigned char Uart1RxBuf1[Uart1RxBufSize]; +unsigned char Uart1TxBuf1[260]; + +unsigned char Uart2RxBuf1[RX2BUFSIZE]; +unsigned char Uart2TxBuf1[TX2BUFSIZE]; + +unsigned short Uart1RxBuf1DataLen = 0; +unsigned short Uart2RxBuf1DataLen = 0; unsigned char SlowFlicker=0; unsigned char FastFlicker=0; unsigned int Uart1IdelTimer = 0; +unsigned char Uart1Mode = 1; //Uart1宸ヤ綔妯″紡锛� 0 : 鏅�氾紝 1 : 閫忎紶妯″紡 + +unsigned int Uart1Baud = DefaultUart1Baud; +unsigned int Uart2Baud = DefaultUart2Baud; + +//unsigned char Uart1RecvBuf1[Uart1RecvBufSize]; +//unsigned short Uart1RecvBuf1DataLen=0; + +//unsigned char Uart2RecvBuf1[128]; +//unsigned short Uart2RecvBuf1DataLen=0; + +volatile char Uart1BaudGot=0; +volatile char Uart1BaudFirstGot=0; +volatile char Uart1DmaInts=0; + + #if (ENABLE_PLC) stBinProg1 * pProgs = (stBinProg1 *)STORE_PRG_BASE; #endif @@ -151,12 +169,46 @@ #endif if (Uart2Stat.bPacketRecved) { - KBusParsePacket(&KBus1, (pKBPacket)Uart2RecvBuf1, Uart2RecvBuf1DataLen); - Uart2RecvBuf1DataLen=0; + KBusParsePacket(&KBus1, (pKBPacket)Uart2RxBuf1, Uart2RxBuf1DataLen); + Uart2RxBuf1DataLen=0; Uart2Stat.bPacketRecved=0; - Uart2RecvDMA(Uart2RecvBuf1,sizeof(Uart2RecvBuf1)); + Uart2RecvDMA(Uart2RxBuf1,sizeof(Uart2RxBuf1)); KMem.WDT[2]++; } + if (Uart1RxBuf1DataLen >0 && Uart1Stat.bPacketRecved) + { + int res1 = -1; + if (Uart1RxBuf1DataLen == 3 && Uart1RxBuf1[0]=='+' && Uart1RxBuf1[0]=='+' && Uart1RxBuf1[0]=='+') + { + Uart1Mode = 0; // 鍒囨崲鍒板懡浠ゆā寮� + }else if (Uart1RxBuf1DataLen == 3 && Uart1RxBuf1[0]=='-' && Uart1RxBuf1[0]=='-' && Uart1RxBuf1[0]=='-') + { + Uart1Mode = 1; // 鍒囨崲鍒伴�忎紶妯″紡 + }else if (Uart1Mode == 0) { + + res1 = ModBusSlaveParsePkg(1, Uart1RxBuf1, Uart1RxBuf1DataLen); + if (res1 !=0) + { + KLParsePacket(1, Uart1RxBuf1, Uart1RxBuf1DataLen); + } + + }else if (Uart1Mode == 1) { + // 閫忎紶妯″紡 + if (KwRunStat.sizetosend == 0) { + memcpy( KwRunStat.ttTxBuf1,Uart1RxBuf1, Uart1RxBuf1DataLen); + KwRunStat.sentsize = 0; + KwRunStat.sizesending = 0; + KwRunStat.sizetosend = Uart1RxBuf1DataLen; + }else { + return; + } + + //SendPacket(1, Uart1RecvBuf1, Uart1RecvBuf1DataLen); + } + Uart1RxBuf1DataLen=0; + Uart1Stat.bPacketRecved=0; + Uart1IdelTimer = 0; + } } /* @@ -216,8 +268,8 @@ /* USER CODE BEGIN 1 */ KMRunStat.bLEDFlick = 1; - InitUartstat(&Uart1Stat,Uart1RxBuf,sizeof(Uart1RxBuf),Uart1TxBuf,sizeof(Uart1TxBuf)); - InitUartstat(&Uart2Stat,Uart2RxBuf,sizeof(Uart2RxBuf),Uart2TxBuf,sizeof(Uart2TxBuf)); + InitUartstat(&Uart1Stat,Uart1RxBuf1,sizeof(Uart1RxBuf1),Uart1TxBuf1,sizeof(Uart1TxBuf1)); +// InitUartstat(&Uart2Stat,Uart2RxBuf1,sizeof(Uart2RxBuf1),Uart2TxBuf1,sizeof(Uart2TxBuf1)); /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ @@ -326,7 +378,7 @@ LL_USART_EnableIT_TC(USART1); // LL_USART_EnableIT_RXNE(USART2); - Uart2RecvDMA(Uart2RecvBuf1,sizeof(Uart2RecvBuf1)); + Uart2RecvDMA(Uart2RxBuf1,sizeof(Uart2RxBuf1)); LL_USART_EnableIT_IDLE(USART2); LL_USART_EnableIT_TC(USART2); @@ -637,26 +689,14 @@ // 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) - { - int res1 = -1; - res1 = ModBusSlaveParsePkg(1, Uart1RecvBuf1, Uart1RecvBuf1DataLen); - if (res1 !=0) - { - KLParsePacket(1, Uart1RecvBuf1, Uart1RecvBuf1DataLen); - } - Uart1RecvBuf1DataLen=0; - Uart1Stat.bPacketRecved=0; - Uart1IdelTimer = 0; - }else { - +#if (USART1_AUTO_BAUDRATE == 1) if (Uart1IdelTimer>300000) { // 瓒呰繃60绉掓病鏈夋暟鎹紶杈擄紝閲嶆柊杩涘叆鑷�傚簲娉㈢壒鐜囩姸鎬� LL_USART_EnableAutoBaudRate(USART1); LL_USART_SetAutoBaudRateMode(USART1, LL_USART_AUTOBAUD_DETECT_ON_FALLINGEDGE); }else { Uart1IdelTimer++; } - } +#endif // if (bKBusSlave) HAL_Delay(0); /* if (!IsEmpty(&Uart1Stat.QRx)) -- Gitblit v1.9.1