4G AI 修改,asr不再维持长链接 1899/1 1899/head 1900/target/1
authorhcj <1224667075@qq.com>
Sat, 28 Jun 2025 08:48:33 +0000 (16:48 +0800)
committerhcj <1224667075@qq.com>
Sat, 28 Jun 2025 08:48:33 +0000 (16:48 +0800)
17 files changed:
code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModel.h
code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp
code/sdk/application/wearable/service/ble_service/bleservice/bleService.c
code/sdk/drivers/peripheral/slip/asio.c
code/sdk/drivers/peripheral/slip/cat1Service/cat1_at_cmd.cpp
code/sdk/drivers/peripheral/slip/cat1Service/cat1_server.cpp
code/sdk/drivers/peripheral/slip/cat1Service/cat1_ws.cpp
code/sdk/drivers/peripheral/slip/cat1Service/cat1_ws.h
code/sdk/drivers/peripheral/slip/slipif.c
code/sdk/drivers/peripheral/slip/uart_slip.c
code/sdk/middleware/services/media/foundation/sample/wrapper/voice_call_volte_sample_wrapper.cpp
code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/include/lwip/lwipopts.h
code/sdk/open_source/openharmony/third_party/lwip/src/api/api_msg.c
code/sdk/open_source/openharmony/third_party/lwip/src/api/tcpip.c
code/sdk/open_source/openharmony/third_party/lwip/src/core/init.c
code/sdk/open_source/openharmony/third_party/lwip/src/core/tcp.c
code/sdk/open_source/openharmony/third_party/lwip/src/core/tcp_out.c

index 9240d80..931d8c7 100644 (file)
@@ -112,7 +112,7 @@ namespace OHOS
         void start_ai4g_connect_timer(uint32_t interval = 1000);
         void stop_ai4g_connect_timer(void);
 
-        void start_ai4g_tts_play_timer(uint32_t interval = 1000);
+        void start_ai4g_tts_play_timer(uint32_t interval = 500);
         void stop_ai4g_tts_play_timer(void);
 
         void SetSelectAiModel(int index);
index 15c5307..bd2b03d 100644 (file)
@@ -407,7 +407,8 @@ namespace OHOS
                 PlayersModel::GetInstance()->PlayerPause();         // 暂停手机音乐
                 if (model->GetSelect4gorbt() == AI_SELECT_4G)
                 {
-                    uapi_start_asr();
+                    uapi_UI_start_asr();
+usleep(50000);
                     ChangeViewAndLogicOperator(AIVOICE_RETURN_RESULT_TEXT_VIEWID, AIVOICE_AIMODE_CONNECTING);
                     return true;
                 }
index 1eab3d5..25ce3dc 100644 (file)
@@ -2552,7 +2552,7 @@ int send_msg_data_into_Ai_msg_queue(void *buff,uint16_t len,uint8_t type)
     // uint32_t singlebuflen= ble_nus_max_data_len-20;\r
     uint32_t singlebuflen = 0;\r
     if(getselect4gorbtai() == 1) {\r
-        singlebuflen = 288*5;//4G\r
+        singlebuflen = 288*4;//4G\r
     } else {\r
         singlebuflen = ble_nus_max_data_len-20;//BT\r
     }\r
index 4912c80..7665472 100644 (file)
@@ -182,13 +182,14 @@ sio_fd_t sio_open(u8_t devnum)
  *
  * @note This function will block until the character can be sent.
  */
+#define SLIP_END     0xC0 /* 0300: start and end of every packet */
 void sio_send(u8_t c, sio_fd_t fd)
 {
        // slip_uart_write( (const char *)&c, 1);
        //uart_write_bytes(UART_NUM_0, (const char *)&c, 1);
        slip_send_buffer.buffer[slip_send_buffer.len] = c;
        slip_send_buffer.len += 1;
-       if( slip_send_buffer.len >= (SLIP_UART_SEND_BUFFER_MAX) ) {
+       if( slip_send_buffer.len >= (SLIP_UART_SEND_BUFFER_MAX) || c == SLIP_END) {
                //printf("send2 data len = %d\n", slip_send_buffer.len);
                // uart_write_bytes(UART_NUM_0, (const char *)slip_send_buffer.buffer, slip_send_buffer.len);
                slip_uart_write((const char *)slip_send_buffer.buffer, slip_send_buffer.len);
index 13f68c0..47d28f7 100644 (file)
@@ -91,6 +91,36 @@ static uint32_t cat1_power(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
 
     return ERRCODE_SUCC;
 }
+static uint32_t cat1_pwr(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
+{
+    UNUSED(strCommonCmd);
+    uint8_t argv[PPG_MAX_ARGC][PPG_MAX_ARGV_LEN] = { 0 };
+    uint32_t argc = 0;
+
+    int ret = ConvertCmdToParam(para, paraLen, argv, &argc);
+    if (ret != PPG_SUCCESS) {
+        wstp_print("CAT1TEST ATCMD Convert Command Failed\n");
+        return ERRCODE_FAIL;
+    }
+
+    if (argc != 1) {
+        wstp_print("CAT1TEST ATCMD Set Parameter Failed\n");
+        return ERRCODE_FAIL;
+    }
+    // char *mode = (char*)argv[0];
+    int enabled = atoi((char*)argv[0]);
+    
+    wstp_print("CAT1TEST ATCMD  power  enable %d \n",enabled);
+
+    if(enabled == 1)
+    {
+        power_on_cat1();
+    }else{
+        power_off_cat1();
+    }
+
+    return ERRCODE_SUCC;
+}
 static uint32_t at_cat1_dial(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
 {
     UNUSED(strCommonCmd);
@@ -205,6 +235,32 @@ static uint32_t cat1_wakeup(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
 
     return ERRCODE_SUCC;
 }
+static uint32_t cat1_keep_wakeup(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
+{
+    UNUSED(strCommonCmd);
+    uint8_t argv[PPG_MAX_ARGC][PPG_MAX_ARGV_LEN] = { 0 };
+    uint32_t argc = 0;
+
+    int ret = ConvertCmdToParam(para, paraLen, argv, &argc);
+    if (ret != PPG_SUCCESS) {
+        printf("CAT1TEST ATCMD Convert Command Failed\n");
+        return ERRCODE_FAIL;
+    }
+    if (argc != 1) {
+        printf("CAT1TEST ATCMD Set Parameter Failed\n");
+        return ERRCODE_FAIL;
+    }
+    // char *mode = (char*)argv[0];
+    int enabled = atoi((char*)argv[0]);
+    if(enabled == 0)
+        uapi_cat1_keep_wakeup(0);
+    else 
+        uapi_cat1_keep_wakeup(1);
+    printf("CAT1TEST ATCMD keep wakeup cat1   enabled = %d\n",enabled);
+
+    return ERRCODE_SUCC;
+}
+
 #include "lwip/api_shell.h"
 static uint32_t cat1_ping(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
 {
@@ -473,6 +529,7 @@ static uint32_t sendttstxt(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
     return 0;
 }
 
+extern void uapi_UI_start_asr(void);
 
 static uint32_t start_asr(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
 {
@@ -485,12 +542,27 @@ static uint32_t start_asr(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
         printf("CAT1TEST ATCMD Convert Command Failed\n");
         return ERRCODE_FAIL;
     }
-    uapi_start_asr();
+    uapi_UI_start_asr();
 
     return 0;
 }
-extern void uapi_start_asr_task(void);
+extern void record_test_tcp(void);
 
+static uint32_t sendfilebindata(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
+{
+    UNUSED(strCommonCmd);
+    uint8_t argv[PPG_MAX_ARGC][PPG_MAX_ARGV_LEN] = { 0 };
+    uint32_t argc = 0;
+    printf("ai_msg\n");
+    int ret = ConvertCmdToParam(para, paraLen, argv, &argc);
+    if (ret != PPG_SUCCESS) {
+        printf("CAT1TEST ATCMD Convert Command Failed\n");
+        return ERRCODE_FAIL;
+    }
+    uapi_cat1_keep_wakeup(1);
+    record_test_tcp();
+    return 0;
+}
 static uint32_t sendbindata(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
 {
     UNUSED(strCommonCmd);
@@ -502,7 +574,8 @@ static uint32_t sendbindata(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
         printf("CAT1TEST ATCMD Convert Command Failed\n");
         return ERRCODE_FAIL;
     }
-    uapi_start_asr_task();
+    uapi_cat1_keep_wakeup(1);
+    uapi_UI_start_asr();
     return 0;
 }
 #include "dev_authentication.h"
@@ -576,6 +649,7 @@ static uint32_t stopwstest(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
 
 
 static const at_cmd_table_t g_cat1_cmd[] = {
+    { (char *)"AT^CAT1PWR",      cat1_pwr, (char *)"1" },
     { (char *)"AT^CAT1POWER",      cat1_power, (char *)"1" },
     { (char *)"AT^CAT1DIAL",      at_cat1_dial, (char *)"1" },
     { (char *)"AT^CAT1ANSWER",      at_cat1_answer, (char *)"1" },
@@ -585,6 +659,7 @@ static const at_cmd_table_t g_cat1_cmd[] = {
     { (char *)"AT^CAT1NETTEST",      cat1_nettest, (char *)"1" },
     { (char *)"AT^PING",      cat1_ping, (char *)"1" },
     { (char *)"AT^CAT1WAKECAT1",      cat1_wakeup, (char *)"1" },
+    { (char *)"AT^CAT1KEEPWAKECAT1",      cat1_keep_wakeup, (char *)"1" },
     { (char *)"AT^IFCONFIG",      cat1_ifconfig, (char *)"1" },
     { (char *)"AT^CAT1GETVER",      at_cat1_getver, (char *)"1" },
     { (char *)"AT^CAT1AT",      at_cat1_atcmd, (char *)"1" },
@@ -600,6 +675,7 @@ static const at_cmd_table_t g_cat1_cmd[] = {
     { (char *)"AT^AI_ASR",      start_record, (char *)"1" },
     { (char *)"AT^STARTASR",      start_asr, (char *)"1" },
     { (char *)"AT^SENDBINDATA",      sendbindata, (char *)"1" },
+    { (char *)"AT^SENDFILEDATA",      sendfilebindata, (char *)"1" },
     { (char *)"AT^ACTIVE",      active, (char *)"1" },
     { (char *)"AT^READPUT",      readfileput, (char *)"1" },
     { (char *)"AT^LOGIN",      autlogin, (char *)"1" },
index 03e85ba..ea949f9 100644 (file)
@@ -1651,7 +1651,7 @@ void cat1_server_task(void *pvParameters)
     int index;
     socklen_t addrLen = sizeof(sourceAddr);
     while (1) {
-        if( g_listen_sock > 0 ) close(g_listen_sock);
+        if( g_listen_sock > 0 ) lwip_close(g_listen_sock);
         g_listen_sock = udp_socket_init();
         if( g_listen_sock < 0 ) {
             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"socket init fail and retry\n");
index 5afbc9a..25f242e 100644 (file)
@@ -125,6 +125,8 @@ extern "C" {
 
 #include <stdint.h>
 #include <stdint.h>
+#include <asm/delay.h>
+
 
 extern osStatus_t osDelay(uint32_t ticks);
 #define cat1_msleep(ms) LOS_Msleep(ms) /* osDelay(1) : 1ms */
@@ -133,7 +135,7 @@ static osTimerId_t g_timer_time_sync = NULL;
 
 void bk_sleep(uint32_t time)
 {
-    cat1_msleep(time);
+    msleep(time);
 }
 #include <stdio.h>
 #include <stdlib.h>
@@ -151,6 +153,10 @@ void uapi_start_tts_single_txt(char *buf);
 
 void uapi_start_tts_single(void);
 
+
+errcode_t asr_server_init(void);
+
+
 static uint8_t server_state=0;
 
 static uint8_t disconnect_server=0;
@@ -456,8 +462,8 @@ int send_handshake(WebSocketClient *client,const char *headers) {
     }
     
     printf("send_handshake request:\r\n%s",request);
-    if (send(client->sockfd, request, strlen(request), 0) < 0) {
-        printf("send handshake failed");
+    if (lwip_send(client->sockfd, request, strlen(request), 0) < 0) {
+        printf("lwip_send handshake failed");
         
         ret = -1;
     }
@@ -518,8 +524,8 @@ int send_websocket_message(WebSocketClient *client, const unsigned char *message
     // 发送帧
     WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"offset %d\r\n",offset);
 
-    if (send(client->sockfd, frame, offset, 0) < 0) {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"send message failed\r\n");
+    if (lwip_send(client->sockfd, frame, offset, 0) < 0) {
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"lwip_send message failed\r\n");
         ret =  -1;
         goto send_websocket_message_ERROR;
     }
@@ -537,19 +543,22 @@ int  receive_websocket_message(WebSocketClient *client, unsigned char *buf,int l
     //printf("receive_websocket_message 1 timer_ms=%d\n",timer_ms);
     unsigned char frame[20]={0};
     unsigned char masking_key[4];
-    unsigned int bytes_received = 0;
+    int bytes_received = 0;
     int recv_len = 0 ;
     static uint8_t last_byte = 0;
     // while(1)
     // {
-    //     recv_len = recv(client->sockfd, frame+bytes_received, 2-bytes_received, 0);
+    //     recv_len = lwip_send(client->sockfd, frame+bytes_received, 2-bytes_received, 0);
     //     bytes_received +=recv_len;
     //     if(bytes_received>=2)
     //         break;
     // }
-    while(1)
+    int max_count=len;
+
+    while(max_count)
     {
-        bytes_received = recv(client->sockfd, frame, 1, 0);
+        bytes_received = lwip_recv(client->sockfd, frame, 1, 0);
+
         if (bytes_received <= 0) 
         {
             if (bytes_received == 0) {
@@ -559,6 +568,8 @@ int  receive_websocket_message(WebSocketClient *client, unsigned char *buf,int l
             }
             return -1;
         }
+max_count--;
+
         if(frame[0]!= 0x80 && frame[0]!= 0x81 && frame[0]!= 0x82 && frame[0]!= 0x88 && frame[0]!= 0x89 && frame[0]!= 0x8A)
         {
             printf("receive_websocket_message:hend =0x%X,0x%X ,last_byte =0x%x ERROR!!!!!!!!!",frame[0],frame[1],last_byte);
@@ -579,9 +590,13 @@ int  receive_websocket_message(WebSocketClient *client, unsigned char *buf,int l
             break;
         }
     }
+if(max_count==0)
+    {
+        return -1;
+    }
     timer_ms = (uint32_t)osKernelGetTickCount();
     //printf("receive_websocket_message 2 timer_ms=%d\n",timer_ms);
-    bytes_received = recv(client->sockfd, frame+1, 1, 0);
+    bytes_received = lwip_recv(client->sockfd, frame+1, 1, 0);
     if (bytes_received <= 0) {
         if (bytes_received == 0) {
             printf("Connection lwip_closed by server.\n");
@@ -599,14 +614,14 @@ int  receive_websocket_message(WebSocketClient *client, unsigned char *buf,int l
     size_t offset = 2;
     if (payload_len == 126) {
         unsigned short extended_payload_len;
-        bytes_received += recv(client->sockfd, frame+offset, 2, 0);
+        bytes_received += lwip_recv(client->sockfd, frame+offset, 2, 0);
         memcpy(&extended_payload_len, frame + 2, 2);
         payload_len = ntohs(extended_payload_len);
         //printf("receive_websocket_message:payload_len=0x%X",extended_payload_len);
         offset += 2;
     } else if (payload_len == 127) {
         uint64_t extended_payload_len;
-        bytes_received += recv(client->sockfd, frame+offset, 8, 0);
+        bytes_received += lwip_recv(client->sockfd, frame+offset, 8, 0);
         memcpy(&extended_payload_len, frame + 2, 8);
         payload_len = ntohll(extended_payload_len);
         offset += 8;
@@ -620,7 +635,7 @@ int  receive_websocket_message(WebSocketClient *client, unsigned char *buf,int l
 
         // }
         // fopen
-        recv(client->sockfd, buf, len, 0);
+        lwip_recv(client->sockfd, buf, len, 0);
         return -1;
     }
     timer_ms = (uint32_t)osKernelGetTickCount();
@@ -633,7 +648,7 @@ int  receive_websocket_message(WebSocketClient *client, unsigned char *buf,int l
     // printf("receive_websocket_message:payload_len=%d frame[0]&0x8E=%d",payload_len,frame[0]&0x8E);
     if (mask) {
         
-        bytes_received = recv(client->sockfd, frame+offset, 4, 0);
+        bytes_received = lwip_recv(client->sockfd, frame+offset, 4, 0);
         memcpy(masking_key, frame + offset, 4);
         offset += 4;    
     } 
@@ -642,12 +657,12 @@ int  receive_websocket_message(WebSocketClient *client, unsigned char *buf,int l
     while(1)//读主体内容
     {
         //bk_sleep(recv_len/1000+1);
-        recv_len = recv(client->sockfd, buf+bytes_received, payload_len-bytes_received, 0);
+        recv_len = lwip_recv(client->sockfd, buf+bytes_received, payload_len-bytes_received, 0);
         if(recv_len>0)
             bytes_received += recv_len;
         else if(recv_len<0)
         {
-            printf("receive_websocket_message: recv_len =%d  recv ERROR!!!!!!",recv_len);
+            printf("receive_websocket_message: recv_len =%d  lwip_recv ERROR!!!!!!",recv_len);
             return -1;
         }
         //printf("receive_websocket_message:bytes_received=%d recv_len =%d",bytes_received,recv_len);
@@ -685,7 +700,7 @@ int  receive_websocket_message(WebSocketClient *client, unsigned char *buf,int l
         payload_len = 0;
     }else if(*code == WS_PING)
     {
-        printf("send_websocket_message  WS_PING \n");
+        printf("send_websocket_message  WS_PONG \n");
         send_websocket_message(client,buf,payload_len,WS_PONG);
         payload_len = 0;
     }else if(*code == WS_CONT)
@@ -727,6 +742,7 @@ WebSocketClient *init_websocket_client(const char *url, const char *headers,uint
     struct in_addr in_addr_t={0};
     ip_addr_t  ip;
     struct cat1_ws_init_t ip_sem={0};
+int opt = 1;
 
     err_t ret=0;
 
@@ -752,12 +768,14 @@ WebSocketClient *init_websocket_client(const char *url, const char *headers,uint
         goto client_ERROR;
     }
 
-    client->sockfd = socket(AF_INET, SOCK_STREAM, 0);
+    
+
+    client->sockfd = lwip_socket(AF_INET, SOCK_STREAM, 0);
     if (client->sockfd < 0) {
-        printf("socket creation failed %d \r\n",client->sockfd);
+        printf("socket creation failed %d errno: %d\r\n",client->sockfd,errno);
         goto client_ERROR;
     }
-
+lwip_setsockopt(client->sockfd, SOL_SOCKET, SO_KEEPALIVE, (const void*)&opt, sizeof(opt));
    // printf("init_websocket_client 3\n");
     if(use_dns)
     {
@@ -812,7 +830,7 @@ WebSocketClient *init_websocket_client(const char *url, const char *headers,uint
     }
     printf("recv: ???  ");
 
-    bytes_received = recv(client->sockfd, buffer, BUFFER_SIZE - 1, 0);
+    bytes_received = lwip_recv(client->sockfd, buffer, BUFFER_SIZE - 1, 0);
 
     printf("recv; ");
 
@@ -975,7 +993,7 @@ static uint8_t ai_tts_server_init_flag   = 0;   //tts初始化标志
 // 获取ASR服务初始化标志
 uint8_t get_ai_asr_service_init_flag(void)
 {
-    return ai_asr_service_init_flag;
+    return true;
 }
 
 // 设置ASR服务初始化标志
@@ -1033,6 +1051,7 @@ void bk_websocket_demo(void *data) {
 
             if (chat_client== NULL) {
             client_count--;
+bk_sleep(1000);
             continue ;
             }
             else
@@ -1130,6 +1149,19 @@ int32_t uapi_tts_paly_init(void);
 int32_t uapi_tts_paly_stop(void);
 
 
+
+void uapi_UI_start_asr(void)
+{
+    asr_server_init();
+}
+
+void uapi_UI_stop_asr(void)
+{
+    stop_AudioCaptureProcess_AI();
+}
+
+
+
 //查询是否可以对话
 void uapi_start_asr(void)
 {
@@ -1232,7 +1264,8 @@ void record_test(void)
 
         if(read_size!=0)
         {
-            send_ai_bin(buf,read_size);
+            send_msg_data_into_Ai_msg_queue((void *)buf,(uint16_t)read_size,0);
+            // send_ai_bin(buf,read_size);
             // bk_sleep(100);
             read_size_num+=read_size;
 
@@ -1313,6 +1346,7 @@ bool aer_result_analysis(char *buf)
         memcpy_s(result_str_asr,256,result_str,strlen(result_str));
         SendMsgToUIService(UI_AI_JUMP_TO_RESULT_VIEW, 0, nullptr, 0);//先跳转到结果界面
         ble_set_ai_Question_str(result_str_asr);
+
         stop_AudioCaptureProcess_AI();
         // uapi_stop_asr();
         send_ai_txt(0,result_str_asr);
@@ -1324,7 +1358,9 @@ bool aer_result_analysis(char *buf)
     {
         //查询结果
         // streamingRecordAndSend_AI(0);
-        // startAudioCaptureTask();
+        startAudioCaptureTask();
+//  do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_AI_SEND_TEST, nullptr, 0);
+
         if(asr_is_start==0)
         {
             asr_is_start=1;
@@ -1349,6 +1385,7 @@ bool aer_result_analysis(char *buf)
         {
             asr_is_start=0;
         }
+return false;
     
     }
     if(strcmp(event_str,"Failed")==0)
@@ -1385,6 +1422,7 @@ bool asr_ws_url_init(char * put_buf)
 }
 
 
+static int asr_client_ping=0;
 
 
 void bk_websocket_asr(void *data) {
@@ -1395,7 +1433,7 @@ void bk_websocket_asr(void *data) {
     bool state = true;
     
     is_bk_websocket_asr=1;
-
+// while (disconnect_server==0)
     {
         //ws://amp.raisound.com/asr/ws
         // char url_buf[124]={0};
@@ -1417,6 +1455,7 @@ void bk_websocket_asr(void *data) {
             if (asr_client== NULL) {
                  printf("init_websocket_client fail %d\r\n",client_count);
                 client_count--;
+bk_sleep(1000);
             continue ;
             }
              else
@@ -1441,34 +1480,55 @@ void bk_websocket_asr(void *data) {
        
         asr_recv_buf=(char *)malloc(0x400);
         set_ai_asr_service_init_flag(1);
+
+        if(osTimerIsRunning(g_timer_time_sync)==0  )
+        {
+            osStatus_t ret = osTimerStart(g_timer_time_sync,5000*3); 
+            WEARABLE_LOGI(WEARABLE_LOG_MODULE_MAIN_SERVICE,"cat1 restart_time_sync timer ret %d\n",ret);
+        }
+
         // uapi_start_asr();
         // SendMsgToUIService(UI_4G_AI_INIT_STAUS, 0,&state, sizeof(bool));
+uapi_start_asr();
         
         while (disconnect_server==0)
         {
             memset_s(asr_recv_buf,1024,0,1024);
             int len=  receive_websocket_message(asr_client,(unsigned char *)asr_recv_buf,1024,&type);
             // if(type==WS_CONT || 
-            printf(" bk_websocket_asr %d\r\n",type);
-            printf("bk_websocket_demo %s %d",asr_recv_buf,type);
+            printf(" bk_websocket_asr type %d len %d\r\n",type,len);
+            printf("bk_websocket_demo %s %d\n",asr_recv_buf,type);
 
             if( type==WS_CLOSE || len==-1)
             {
                 printf("WS_lwip_close bk_websocket_asr\r\n");
+
+                if (len>2&& type==WS_CLOSE)
+                {
+                    printf("WS_CLOSE reason %s\n",asr_recv_buf+2);
+                }
                 break;
             }
-          printf(" bk_websocket_asr %d\r\n",type);
-            printf("bk_websocket_demo %s %d",asr_recv_buf,type);
+          if(type==WS_TEXT)
+            {
             if(false== aer_result_analysis(asr_recv_buf))
             {
+printf("WS_lwip_close false== aer_result_analysis(asr_recv_buf)\r\n");
                 break;
             }
-            //
+            }
+            if(type==WS_PONG)
+            {
+                asr_client_ping=0;
+            }
         }
+
         set_ai_asr_service_init_flag(0);
         free(asr_recv_buf);
         lwip_close_websocket_client(asr_client);
         asr_client=NULL;
+asr_client_ping=0;
+        bk_sleep(1000);
         // return;
     }
     is_bk_websocket_asr=0;
@@ -1684,16 +1744,16 @@ void bk_websocket_tts(void *data) {
 
     {
         //ws://amp.raisound.com/asr/ws
-        char url_buf[124]={0};
-        if(tts_ws_url_init(url_buf))
-        {
-            printf("%s\r\n",url_buf);
-        }
-        else 
-        {
-            is_bk_websocket_tts=0;
-            return;
-        }
+        // char url_buf[124]={0};
+        // if(tts_ws_url_init(url_buf))
+        // {
+        //     printf("%s\r\n",url_buf);
+        // }
+        // else 
+        // {
+        //     is_bk_websocket_tts=0;
+            //     return;
+        // }
 
         uint8_t client_count=3;
 
@@ -1707,6 +1767,7 @@ void bk_websocket_tts(void *data) {
             {
                  printf("init_websocket_client fail %d\r\n",client_count);
                 client_count--;
+                bk_sleep(1000);
                 continue ;
             }
             else
@@ -1789,11 +1850,11 @@ errcode_t tts_server_init(void)
     {
         return ERRCODE_FAIL;
     }
-    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"asr_server_init !\r\n");
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"tts_server_init !\r\n");
     app_task_definition_t taskcfg={0};
     taskcfg.create_queue_handle = NULL;
     taskcfg.attr.name="tts_server_init";
-    taskcfg.attr.priority = (osPriority_t)35;
+    taskcfg.attr.priority = TASK_PRIORITY_APP;
     taskcfg.attr.stack_size = 0x1000;
     taskcfg.func = bk_websocket_tts;
     taskcfg.use_mem = USE_EXTEND_MEM;
@@ -1848,9 +1909,46 @@ int32_t uapi_tts_paly_stop(void)
     return ret;   
 }
 
+void asr_server_deinit(void)
+{
+     WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"WS_CLOSE");
+    send_websocket_message(asr_client,(const unsigned char *)"WS_CLOSE",strlen("WS_CLOSE"),WS_CLOSE);
+}
+
+
+void chat_server_deinit(void)
+{
+    send_websocket_message(chat_client,(const unsigned char *)"WS_CLOSE",strlen("WS_CLOSE"),WS_CLOSE);
+}
+
+
+void tts_server_deinit(void)
+{
+    send_websocket_message(tts_client,(const unsigned char *)"WS_CLOSE",strlen("WS_CLOSE"),WS_CLOSE);
+}
+
+
 
 static void time_sync_func(void)
 {
+if(asr_client)
+    {
+         if(asr_client_ping)
+        {
+            asr_server_deinit();
+            lwip_close_websocket_client(asr_client);
+            asr_client=NULL;
+        }
+        else
+        {
+            if(0==send_websocket_message(asr_client,( const unsigned char *)"ping",strlen("ping"),WS_PING))
+            {
+                asr_client_ping=1;
+            }
+
+        }
+        
+    }
 
 }
 
@@ -1863,13 +1961,18 @@ bool init_ai_task(void)
     {
         disconnect_server=0;
 
-        //  g_timer_time_sync = osTimerNew((osTimerFunc_t)time_sync_func, osTimerPeriodic, NULL, NULL);
-        // if (g_timer_time_sync == NULL)
-        // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"g_timer_time_sync create failed\n");
+        g_timer_time_sync = osTimerNew((osTimerFunc_t)time_sync_func, osTimerPeriodic, NULL, NULL);
+        if (g_timer_time_sync == NULL)
+        {
+              WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"g_timer_time_sync create failed\n");
+}
+      
+
+    
 
 
         uapi_tts_paly_init();
-        asr_server_init();
+        
         chat_server_init();
         tts_server_init();
         // is_init_ai=0;
@@ -1879,21 +1982,6 @@ bool init_ai_task(void)
 }
 
 
-void asr_server_deinit(void)
-{
-    send_websocket_message(asr_client,(const unsigned char *)"WS_CLOSE",strlen("WS_CLOSE"),WS_CLOSE);
-}
-
-void chat_server_deinit(void)
-{
-    send_websocket_message( chat_client,(const unsigned char *)"WS_CLOSE",strlen("WS_CLOSE"),WS_CLOSE);
-}
-
-
-void tts_server_deinit(void)
-{
-    send_websocket_message( tts_client,(const unsigned char *)"WS_CLOSE",strlen("WS_CLOSE"),WS_CLOSE);
-}
 
 
 
@@ -1903,12 +1991,11 @@ bool dinit_ai_task(void)
     {
         disconnect_server=1;
 
-        // if(g_timer_time_sync==NULL)
-        // {
-        //     g_timer_time_sync = osTimerNew((osTimerFunc_t)time_sync_func, osTimerPeriodic, NULL, NULL);
-        // }
-        // if (g_timer_time_sync == NULL)
-        // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"g_timer_time_sync create failed\n");
+        if(g_timer_time_sync)
+        {
+            osTimerDelete(g_timer_time_sync);
+            g_timer_time_sync =NULL;
+        }
 
         uapi_tts_paly_stop();
 
index c08dcce..4c2dcd9 100644 (file)
@@ -5,25 +5,38 @@
 extern "C" {
 #endif /* __cplusplus */
 #endif /* __cplusplus */
+////////////////////////// UI 使用接口///////////////////////////////////
+bool init_ai_task(void);
 
-void uapi_start_asr(void);
+bool dinit_ai_task(void);
 
-void uapi_stop_asr(void);
+void uapi_UI_start_asr(void);
 
-bool init_ai_task(void);
-bool dinit_ai_task(void);
+void uapi_UI_stop_asr(void);
 
 void uapi_start_tts_single_txt(char *buf);
 
+////////////////////////////////////////////////////////////////////////
+
+
+
+
+
+
 uint8_t get_ai_asr_service_init_flag(void);
 void set_ai_asr_service_init_flag(uint8_t flag);
 uint8_t get_ai_chat_service_init_flag(void);
 void set_ai_chat_service_init_flag(uint8_t flag);
 uint8_t get_ai_tts_server_init_flag(void);
 void set_ai_tts_server_init_flag(uint8_t flag);
+
 void uapi_start_asr_task(void);
 
 void asr_record_test(void);
+
+
+
+
 #ifdef __cplusplus
 #if __cplusplus
 }
index f91f234..3e38733 100644 (file)
@@ -155,8 +155,8 @@ slipif_output(struct netif *netif, struct pbuf *p)
   }
   /* End with packet delimiter. */
   sio_send(SLIP_END, priv->sd);
-  extern void sio_send_all(sio_fd_t fd);
-  sio_send_all(priv->sd);
+  // extern void sio_send_all(sio_fd_t fd);
+  // sio_send_all(priv->sd);
   return ERR_OK;
 }
 
index 803ae8d..8de82a0 100644 (file)
@@ -128,7 +128,7 @@ int user_netif_init(void)
         return -1;
        }
     netif_set_up(&sl_netif);
-       sl_netif.mtu = 1500;
+       sl_netif.mtu = IP_FRAG_MAX_MTU;
        netif_set_link_up(&sl_netif);
 
     // if( mode == 1 ) {
index f512b60..6ce130d 100755 (executable)
@@ -1291,6 +1291,9 @@ static void* AudioCaptureProcess_AI(void* arg)
 
     FILE *fp= fopen("/user/aiRecord.bin","wb+");
 
+    uint32_t record_size=0;
+
+
     while (!g_sample_needStop) {
         LOS_Msleep(10);
         CapturerBuffer capBuf = {};
@@ -1302,7 +1305,14 @@ static void* AudioCaptureProcess_AI(void* arg)
         {
              MEDIA_ERR_LOG("readlen %d",readlen);
             send_msg_data_into_Ai_msg_queue((void *)data_buf,(uint16_t)readlen,0);
-            // fwrite(data_buf,1,readlen,fp);
+
+            record_size+=readlen;
+
+            fwrite(data_buf,1,readlen,fp);
+            if(record_size>=1024*20)
+            {
+                g_sample_needStop=1;
+            }
             memset_s(data_buf,1024,0,1024);
         }
         
index 07e77c1..6b09419 100644 (file)
@@ -65,8 +65,8 @@
 #define TCP_SACK_DEBUG                  LWIP_DBG_OFF
 #define TCP_TLP_DEBUG                   LWIP_DBG_OFF
 #define UDP_DEBUG                       LWIP_DBG_OFF
-#define TCPIP_DEBUG                     LWIP_DBG_OFF
-#define SLIP_DEBUG                      LWIP_DBG_OFF
+#define TCPIP_DEBUG                     LWIP_DBG_ON
+#define SLIP_DEBUG                      LWIP_DBG_ON
 #define DHCP_DEBUG                      LWIP_DBG_OFF
 #define AUTOIP_DEBUG                    LWIP_DBG_OFF
 #define DNS_DEBUG                       LWIP_DBG_OFF
 #define MEMP_NUM_NETDB                  8
 #define IP_REASS_MAXAGE                 3
 #define IP_SOF_BROADCAST                1
+#if 0  
+//BSD socket bind connect 冲突
 #define IP_SOF_BROADCAST_RECV           1
+#define LWIP_COMPAT_SOCKETS             1 
+#else
+#define IP_SOF_BROADCAST_RECV           0
+#define LWIP_COMPAT_SOCKETS             0 
+#endif
 #define LWIP_MULTICAST_PING             1
 #define LWIP_RAW                        1
 #define LWIP_DHCP_AUTOIP_COOP_TRIES     64
 #define LWIP_NETIF_HOSTNAME             1
 #define LWIP_NETIF_TX_SINGLE_PBUF       1
 #define LWIP_NETCONN_FULLDUPLEX         1 // Caution
-#define LWIP_COMPAT_SOCKETS             1 //2
 #define LWIP_POSIX_SOCKETS_IO_NAMES     0
 #define LWIP_TCP_KEEPALIVE              1
 #define RECV_BUFSIZE_DEFAULT            65535
 
 // Options in old lwipopts.h
 #define ARP_QUEUEING                    1
-#define DEFAULT_ACCEPTMBOX_SIZE         32
+#define DEFAULT_ACCEPTMBOX_SIZE         LWIP_CONFIG_NUM_SOCKETS
 #define DEFAULT_RAW_RECVMBOX_SIZE       128
 #define DEFAULT_TCP_RECVMBOX_SIZE       128
 #define DEFAULT_UDP_RECVMBOX_SIZE       128
 #define PBUF_POOL_SIZE                  64
 #define SO_REUSE                        1
 #define TCPIP_MBOX_SIZE                 512
-#define TCPIP_THREAD_PRIO               16  //osPriorityBelowNormal 16
+#define TCPIP_THREAD_PRIO               25  //osPriorityBelowNormal 16
 #define TCPIP_THREAD_STACKSIZE          0x2000
-#define TCP_MAXRTX                      64
-// #define TCP_MSS                         1400
+#define TCP_MAXRTX                      12 //max 12
+#define LWIP_TCP_RTO_TIME               1500
 #define TCP_MSS                         (IP_FRAG_MAX_MTU - 20 - 20)
-#define TCP_SND_BUF                     65535
-#define TCP_SND_QUEUELEN                (8 * TCP_SND_BUF) / TCP_MSS
+#define TCP_SND_BUF                     (10* TCP_MSS)
+#define TCP_SND_QUEUELEN                (2*(TCP_SND_BUF/TCP_MSS))
+#define TCP_SNDLOWAT                    LWIP_MIN(LWIP_MAX(((TCP_SND_BUF)/2), (2 * TCP_MSS) + 1), (TCP_SND_BUF) - 1)
+#define TCP_SNDQUEUELOWAT               LWIP_MAX(((TCP_SND_QUEUELEN)/2), 5)
 #define TCP_TTL                         255
-#define TCP_WND                         32768
+#define TCP_WND                         (TCP_SND_BUF/2)
 #define UDP_TTL                         255
 #define MEMP_NUM_TCP_SEG                (((TCP_SND_BUF * 3 / 2) + TCP_WND) * LWIP_CONFIG_NUM_SOCKETS / TCP_MSS)
 
 #endif
 
 // Change some options for lwIP 2.1.2
-#undef TCP_MAXRTX
-#define TCP_MAXRTX                      12
 
-#undef LWIP_COMPAT_SOCKETS
-#define LWIP_COMPAT_SOCKETS             0
 
 #define MEMP_NUM_SYS_TIMEOUT            (LWIP_NUM_SYS_TIMEOUT_INTERNAL + (LWIP_IPV6 * LWIP_IPV6_DHCP6))
 
-#undef DEFAULT_ACCEPTMBOX_SIZE
-#define DEFAULT_ACCEPTMBOX_SIZE         LWIP_CONFIG_NUM_SOCKETS
 
-// #undef TCP_MSS
-// #define TCP_MSS                         (IP_FRAG_MAX_MTU - 20 - 20)
 
-#undef IP_SOF_BROADCAST_RECV
-#define IP_SOF_BROADCAST_RECV           0
 
 /**
  * Defines whether to enable debugging for driver module.
 
 
 // Options for enhancement code, same for old lwipopts.h
-#define LWIP_NETIF_PROMISC              1
+#define LWIP_NETIF_PROMISC              0
 #define LWIP_TFTP                       LOSCFG_NET_LWIP_SACK_TFTP
 #define LWIP_DHCPS                      1
 #define LWIP_ENABLE_NET_CAPABILITY      1
 #define LWIP_ENABLE_CAP_NET_BROADCAST   0
 
 // Options for liteos_m
-#undef LWIP_NETIF_PROMISC
-#define LWIP_NETIF_PROMISC              0
 
 #define MEMP_MEM_MALLOC                 1
 
-// #undef LWIP_IPV6
-// #define LWIP_IPV6                       0
 
 // #undef LWIP_SOCKET_SELECT
 // #define LWIP_SOCKET_SELECT              1
index 3f08e03..bbe970c 100644 (file)
@@ -221,6 +221,7 @@ recv_udp(void *arg, struct udp_pcb *pcb, struct pbuf *p,
   struct netbuf *buf;
   struct netconn *conn;
   u16_t len;
+  err_t err;
 #if LWIP_SO_RCVBUF
   int recv_avail;
 #endif /* LWIP_SO_RCVBUF */
@@ -269,8 +270,10 @@ recv_udp(void *arg, struct udp_pcb *pcb, struct pbuf *p,
   }
 
   len = p->tot_len;
-  if (sys_mbox_trypost(&conn->recvmbox, buf) != ERR_OK) {
+  err = sys_mbox_trypost(&conn->recvmbox, buf);
+  if (err != ERR_OK) {
     netbuf_delete(buf);
+    LWIP_DEBUGF(API_MSG_DEBUG, ("recv_udp: sys_mbox_trypost failed, err=%d\n", err));
     return;
   } else {
 #if LWIP_SO_RCVBUF
@@ -492,7 +495,7 @@ err_tcp(void *arg, err_t err)
         conn->current_msg->err = err;
       }
       op_completed_sem = LWIP_API_MSG_SEM(conn->current_msg);
-      LWIP_ASSERT("inavlid op_completed_sem", sys_sem_valid(op_completed_sem));
+      LWIP_ASSERT("invalid op_completed_sem", sys_sem_valid(op_completed_sem));
       conn->current_msg = NULL;
       /* wake up the waiting task */
       sys_sem_signal(op_completed_sem);
index 9a5a538..bd0d384 100644 (file)
@@ -72,8 +72,18 @@ static app_task_definition_t taskcfg={0};
 static void tcpip_thread_handle_msg(struct tcpip_msg *msg);
 
 #if !LWIP_TIMERS
-/* wait for a message with timers disabled (e.g. pass a timer-check trigger into tcpip_thread) */
-#define TCPIP_MBOX_FETCH(mbox, msg) sys_mbox_fetch(mbox, msg)
+
+/** Wait for a message with timers disabled (e.g. pass a timer-check trigger into tcpip_thread) */
+static void
+tcpip_mbox_fetch(sys_mbox_t* mbox, void** msg)
+{
+  LWIP_ASSERT_CORE_LOCKED();
+
+  UNLOCK_TCPIP_CORE();
+  sys_mbox_fetch(mbox, msg);
+  LOCK_TCPIP_CORE();
+}
+
 #else /* !LWIP_TIMERS */
 /* wait for a message, timeouts are processed while waiting */
 #define TCPIP_MBOX_FETCH(mbox, msg) tcpip_timeouts_mbox_fetch(mbox, msg)
index f417589..a81ce80 100644 (file)
@@ -306,6 +306,9 @@ PACK_STRUCT_END
 #if TCP_SNDLOWAT >= TCP_SND_BUF
 #error "lwip_sanity_check: WARNING: TCP_SNDLOWAT must be less than TCP_SND_BUF. If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error."
 #endif
+#if TCP_MSS >= ((16 * 1024) - 1)
+#error "lwip_sanity_check: WARNING: TCP_MSS must be <= 16382 to prevent u16_t underflow in TCP_SNDLOWAT calculation!"
+#endif
 #if TCP_SNDLOWAT >= (0xFFFF - (4 * TCP_MSS))
 #error "lwip_sanity_check: WARNING: TCP_SNDLOWAT must at least be 4*MSS below u16_t overflow!"
 #endif
index d907235..94856d3 100644 (file)
@@ -1153,6 +1153,9 @@ tcp_connect(struct tcp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port,
   pcb->rcv_wnd = pcb->rcv_ann_wnd = TCPWND_MIN16(TCP_WND);
   pcb->rcv_ann_right_edge = pcb->rcv_nxt;
   pcb->snd_wnd = TCP_WND;
+  LWIP_DEBUGF(TCP_DEBUG, ("tcp_connect: snd_wnd TCP_WND %"U16_F"\n", TCP_WND));
+
+  
   /* As initial send MSS, we use TCP_MSS but limit it to 536.
      The send MSS is updated when an MSS option is received. */
   pcb->mss = INITIAL_MSS;
@@ -1898,8 +1901,10 @@ tcp_alloc(u8_t prio)
     /* As initial send MSS, we use TCP_MSS but limit it to 536.
        The send MSS is updated when an MSS option is received. */
     pcb->mss = INITIAL_MSS;
-    pcb->rto = 3000 / TCP_SLOW_INTERVAL;
-    pcb->sv = 3000 / TCP_SLOW_INTERVAL;
+    /* Set initial TCP's retransmission timeout to 3000 ms by default.
+       This value could be configured in lwipopts */
+    pcb->rto = LWIP_TCP_RTO_TIME / TCP_SLOW_INTERVAL;
+    pcb->sv = LWIP_TCP_RTO_TIME / TCP_SLOW_INTERVAL;
     pcb->rtime = -1;
     pcb->cwnd = 1;
     pcb->tmr = tcp_ticks;
index 8149d39..b9077a0 100644 (file)
@@ -1290,6 +1290,7 @@ tcp_output(struct tcp_pcb *pcb)
 
   netif = tcp_route(pcb, &pcb->local_ip, &pcb->remote_ip);
   if (netif == NULL) {
+      LWIP_DEBUGF(TCP_CWND_DEBUG, ("tcp_output: netif==NULL"));
     return ERR_RTE;
   }
 
@@ -1297,6 +1298,7 @@ tcp_output(struct tcp_pcb *pcb)
   if (ip_addr_isany(&pcb->local_ip)) {
     const ip_addr_t *local_ip = ip_netif_get_local_ip(netif, &pcb->remote_ip);
     if (local_ip == NULL) {
+        LWIP_DEBUGF(TCP_CWND_DEBUG, ("tcp_output: local_ip==NULL"));
       return ERR_RTE;
     }
     ip_addr_copy(pcb->local_ip, *local_ip);
@@ -1319,6 +1321,7 @@ tcp_output(struct tcp_pcb *pcb)
     if (pcb->flags & TF_ACK_NOW) {
       return tcp_send_empty_ack(pcb);
     }
+    LWIP_DEBUGF(TCP_CWND_DEBUG, ("tcp_output: lwip_ntohl(seg->tcphdr->seqno) - pcb->lastack + seg->len > wnd"));
     goto output_done;
   }
   /* Stop persist timer, above conditions are not active */
@@ -1341,8 +1344,11 @@ tcp_output(struct tcp_pcb *pcb)
      *   either seg->next != NULL or pcb->unacked == NULL;
      *   RST is no sent using tcp_write/tcp_output.
      */
+   LWIP_DEBUGF(TCP_CWND_DEBUG, ("tcp_do_output_nagle"));
+
     if ((tcp_do_output_nagle(pcb) == 0) &&
         ((pcb->flags & (TF_NAGLEMEMERR | TF_FIN)) == 0)) {
+          LWIP_DEBUGF(TCP_CWND_DEBUG, ("tcp_do_output_nagle==0"));
       break;
     }
 #if TCP_CWND_DEBUG
@@ -1455,6 +1461,7 @@ tcp_output_segment_busy(const struct tcp_seg *seg)
 static err_t
 tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb, struct netif *netif)
 {
+  LWIP_DEBUGF(TCP_RTO_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("tcp_output_segment: start\n"));
   err_t err;
   u16_t len;
   u32_t *opts;
@@ -1507,7 +1514,7 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb, struct netif *netif
   }
 #if LWIP_TCP_TIMESTAMPS
   pcb->ts_lastacksent = pcb->rcv_nxt;
-
+0
   if (seg->flags & TF_SEG_OPTS_TS) {
     tcp_build_timestamp_option(pcb, opts);
     opts += 3;
@@ -1605,6 +1612,7 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb, struct netif *netif
   TCP_STATS_INC(tcp.xmit);
 
   NETIF_SET_HINTS(netif, &(pcb->netif_hints));
+
   err = ip_output_if(seg->p, &pcb->local_ip, &pcb->remote_ip, pcb->ttl,
                      pcb->tos, IP_PROTO_TCP, netif);
   NETIF_RESET_HINTS(netif);