找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

帖子
查看: 2788|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

stm32 freeRTOS多串口通信 接收不定長(zhǎng)數(shù)據(jù)

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:1006976 發(fā)表于 2022-2-26 18:49 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
{
  /* Prevent unused argument(s) compilation warning */
  UNUSED(huart);
  /* NOTE: This function should not be modified, when the callback is needed,
   
           the HAL_UART_TxHalfCpltCallback could be implemented in the user file
   */
    if(huart->Instance==USART1){
        HAL_UART_Receive_DMA(&huart1,(uint8_t *)&aRxBuffer1,1);
    }
    if(huart->Instance==USART3){
        HAL_UART_Receive_DMA(&huart3,(uint8_t *)&aRxBuffer3,1);
    }
}
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
    char buf[255],enter[32];
    int i=1,temp=0;
    uint8_t data[30]={"\n I have received:OK"};
    char *map;
    char key[25];
    char value[4];
    int year,mon,day,hour,min,sec;
    char *ssid;
    char *passwd;
    UNUSED(huart);
    if(huart->Instance==USART1){
        Uart1_RxBuffer[Uart1_Rx_Cnt++]=aRxBuffer1;
        if((Uart1_RxBuffer[Uart1_Rx_Cnt-1]==0x0A)&&(Uart1_RxBuffer[Uart1_Rx_Cnt-2]==0x0D))
        {
            HAL_UART_Transmit_DMA(&huart1,(uint8_t *)Uart1_RxBuffer, strlen(Uart1_RxBuffer));

            if(strstr(Uart1_RxBuffer,"passwd")!=NULL)
            {
                        strtok(Uart1_RxBuffer,":");
                        ssid=strtok(NULL,"_");
                        strtok(NULL,":");
                        passwd=strtok(NULL,"_");

                        strcat(AT_CWJAP,ssid);      
                        strcat(AT_CWJAP,"\",\"");
                        strcat(AT_CWJAP,passwd);
                        strcat(AT_CWJAP,"\"\r\n");



                         my_printf("%s",AT_CWJAP);
                        strcpy(AT_CWJAP,"AT+CWJAP=\"");



                    }

            Uart1_Rx_Cnt=0;
//                  strcpy(Uart1_RxBuffer,"");
        }
        HAL_UART_Receive_DMA(&huart1,(uint8_t *)&aRxBuffer1,1);

    }


    if(huart->Instance==USART3){
        Uart3_RxBuffer[Uart3_Rx_Cnt++]=aRxBuffer3;

    if((Uart3_RxBuffer[Uart3_Rx_Cnt-1]==0x0A)&&(Uart3_RxBuffer[Uart3_Rx_Cnt-2]==0x0D))
    {   
          osMailPut(myQueue06Handle,Uart3_RxBuffer);
            //HAL_UART_Transmit_DMA(huart, data, strlen((char*)data));
            if(strstr(Uart3_RxBuffer, "led") != NULL)//在a中查找b,如果存在,
            {
                     osMessagePut(wifi_flagHandle,1,osWaitForever);

            }
            else
            {
                osMessagePut(wifi_flagHandle,0,osWaitForever);
            }
            if(strstr(Uart3_RxBuffer, "led_breath") != NULL)//在a中查找b,如果存在,
            {
                     led=1;

            }
                    if(strstr(Uart3_RxBuffer, "led_off") != NULL)//在a中查找b,如果存在,
            {
                     led=0;

            }
                    if(strstr(Uart3_RxBuffer, "led_on") != NULL)//在a中查找b,如果存在,
            {
                     led=2;

            }
            if(strstr(Uart3_RxBuffer, "date") != NULL)//在a中查找b,如果存在,
            {


                    strtok(Uart3_RxBuffer,"_");
                    year=atoi(strtok(NULL,"-"));

                    mon=atoi(strtok(NULL,"-"));

                    day=atoi(strtok(NULL,"_"));

                    hour=atoi(strtok(NULL,":"));

                    min=atoi(strtok(NULL,":"));

                    sec=atoi(strtok(NULL,":"));
                  strtok(NULL,"_");
                    ds1302_wirte_rig(0x8e,0x00);//關(guān)閉寫(xiě)保護(hù)
                    ds1302_wirte_rig(0x80,dtoh(sec));//seconds10秒
                    ds1302_wirte_rig(0x82,dtoh(min));//minutes10分
                    ds1302_wirte_rig(0x84,dtoh(hour));//hours10時(shí)
                    ds1302_wirte_rig(0x86,dtoh(day));//date12日
                    ds1302_wirte_rig(0x88,dtoh(mon));//months5月
//                  ds1302_wirte_rig(0x8a,dtoh(week));//days星期三
                    ds1302_wirte_rig(0x8c,dtoh(year));//year2021年
                    ds1302_wirte_rig(0x8e,0x80);//關(guān)閉寫(xiě)保護(hù)
//              HAL_UART_Transmit_DMA(huart, (uint8_t*)value, strlen((char*)value));
            }

            if(strstr(Uart3_RxBuffer, "valid") != NULL)//在a中查找b,如果存在,
            {

                HAL_UART_Transmit_DMA(&huart3, AT_CIPSTART, strlen((char*) AT_CIPSTART));

            }
        Uart3_Rx_Cnt=0;

//      memset(Uart3_RxBuffer,0,sizeof(Uart3_RxBuffer));


    }
    HAL_UART_Receive_DMA(&huart3,(uint8_t *)&aRxBuffer3,1);
}


}

評(píng)分

參與人數(shù) 1黑幣 +20 收起 理由
admin + 20 共享資料的黑幣獎(jiǎng)勵(lì)!

查看全部評(píng)分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表