| | |
| | | /* 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 |
| | |
| | | #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; |
| | | } |
| | | } |
| | | |
| | | /* |
| | |
| | | /* 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----------------------------------------------------------*/ |
| | |
| | | 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); |
| | | |
| | |
| | | // 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)) |