弄了两天终于让我试出来了
参考了大佬的代码,大佬的代码只能存放64个数,但是我的需求要高一点,所以在大佬的基础上改了一下,先放上代码,后面再分析
void SampleApp_CallBack(uint8 port, uint8 event)
{uint8 UART0_RX_FINISH_FLAG = 0;#if 1 //uint8 Res;(void)event;// Intentionally unreferenced parameter while (Hal_UART_RxBufLen(port)) { uint8 Res;HalUARTRead (port, &Res, 1);//读取数据,存入字符RES中UART0_RX_BUFF[UART0_RX_STA&0x7F]=Res;//将数据存到BUFF中,表示总共能存127个数 UART0_RX_STA++; //数据+1if(UART0_RX_FINISH_FLAG == 0){//接收未完成if(UART0_RX_STA&0x80)//前一个接收到的数据结束符的“前一半”{if (Res==0x0A)UART0_RX_FINISH_FLAG = 1;//接收完成了else if(Res!=0x0D)UART0_RX_STA &= 0x7F;//不是结束符,则将前半个结束符标志置0 }else{if(Res==0x0D)UART0_RX_STA |= 0x80;}} if(UART0_RX_FINISH_FLAG == 1){UART0_RX_LEN = (UART0_RX_STA&0x7F)-2;memset(rxBuffer, 0, sizeof(rxBuffer));//将rxBuffer数字内容清空,重新写入数据memcpy(rxBuffer, UART0_RX_BUFF, sizeof(UART0_RX_BUFF));//将串口接收到的数据写入全局变量rxBuffer中memset(UART0_RX_BUFF,0,UART0_RX_BUFF_MAX);//将UART0_RX_BUFF数据清空-Reset//HalUARTWrite(HAL_UART_PORT_0,UART0_RX_BUFF, osal_strlen((char*)UART0_RX_BUFF));HalUARTWrite(HAL_UART_PORT_0,rxBuffer, osal_strlen((char*)rxBuffer));if(SampleApp_NwkState != DEV_ZB_COORD){osal_set_event(SampleApp_TaskID,SAMPLE_TestOfWhile);//SQ_P2P(RXBUFF);}UART0_RX_STA = 0;break;} }
#endif
}