AI录音上传修改 1690/target/2 1691/1 1691/head 1692/target/1
authorhcj <1224667075@qq.com>
Wed, 12 Mar 2025 01:27:37 +0000 (09:27 +0800)
committerhcj <1224667075@qq.com>
Wed, 12 Mar 2025 01:27:37 +0000 (09:27 +0800)
code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c
code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.h
code/sdk/application/wearable/service/ble_service/bleservice/bleService.c
code/sdk/application/wearable/service/ble_service/bleservice/bleService.h

index 9c92114..05974aa 100644 (file)
@@ -5656,18 +5656,8 @@ static void GetSynDataEndCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *to
         sendBleData(value,19);\r
     }\r
 }\r
-static uint8_t AI_interval=5;\r
 \r
-void set_AI_interval(uint8_t data)\r
-{\r
-    AI_interval=data;\r
-}\r
 \r
-void send_Ai_record(uint16_t len,uint8_t *data)\r
-{\r
-    svr_ble_bt_gatts_noyify_AI(data,len);\r
-    LOS_Msleep(AI_interval+get_ble_interval());\r
-}\r
 \r
 \r
 \r
index 2b9da97..e985db4 100644 (file)
@@ -848,9 +848,9 @@ void reply_APP_OpenSportModeCmd(bool falg);
 
 void watch_synchronization_time(void);
 
-void send_Ai_record(uint16_t len,uint8_t *data);
+// void send_Ai_record(uint16_t len,uint8_t *data,uint32_t count);
 
-void set_AI_interval(uint8_t data);
+// void set_AI_interval(uint8_t data);
 
 
 ///////////////////////////自定义文件传输协议/////////////////////////////
index 81709c5..38882d8 100644 (file)
@@ -2323,6 +2323,37 @@ void create_Ai_record_queue(void)
 \r
 \r
 #define Ai_TEST 0\r
+static uint32_t AI_data_count=0;\r
+\r
+\r
+static uint8_t AI_interval=5;\r
+\r
+void set_AI_interval(uint8_t data)\r
+{\r
+    AI_interval=data;\r
+}\r
+\r
+void send_Ai_record(uint16_t len,uint8_t *data,uint32_t count)\r
+{\r
+    uint8_t ai_buf[SDK_BLE_MTU_MAX]={0};\r
+    if(count)\r
+    {\r
+        \r
+        memcpy_s(ai_buf,SDK_BLE_MTU_MAX,&count,4);\r
+        memcpy_s(&ai_buf[4],SDK_BLE_MTU_MAX-4,data,len);\r
+        len+=4;\r
+    }\r
+    else\r
+    {\r
+        memcpy_s(ai_buf,SDK_BLE_MTU_MAX,data,len);\r
+    }\r
+   \r
+    svr_ble_bt_gatts_noyify_AI(ai_buf,len);\r
+\r
+    LOS_Msleep(AI_interval+get_ble_interval());\r
+}\r
+\r
+\r
 static void blesrvAi_send_service_task(void const *arg)\r
 {\r
     unused(arg);\r
@@ -2347,13 +2378,25 @@ static void blesrvAi_send_service_task(void const *arg)
         uint16_t server_handle = mail.service_handle;\r
         uint32_t msg_len = mail.msg_len;\r
 \r
+        if(server_handle==1 || server_handle==2)\r
+        {\r
+            AI_data_count=0;\r
+        }\r
+        else\r
+        {\r
+            AI_data_count++;\r
+        }\r
+\r
         #if Ai_TEST\r
             fwrite(fp,1,mail.msg_len,mail.msg_data);\r
         #endif\r
         // if(get_ble_connect())\r
-        if(mail.msg_data && mail.msg_len!=0)\r
-        send_Ai_record(mail.msg_len,mail.msg_data);\r
         \r
+\r
+        if(mail.msg_data && mail.msg_len!=0)\r
+        send_Ai_record(mail.msg_len,mail.msg_data,AI_data_count);\r
+       \r
+\r
         if(mail.msg_data)\r
         {\r
             free(mail.msg_data);\r
@@ -2375,7 +2418,7 @@ errcode_t uapi_Ai_send_service_init(void)
     taskcfg.attr.name = "Ai_record_queue_service";\r
     taskcfg.attr.priority = osPriorityNormal;\r
     // taskcfg.attr.stack_size = BLESRV_APP_BOARD_TASK_SIZE;\r
-    taskcfg.attr.stack_size = 0x1000;\r
+    taskcfg.attr.stack_size = 0x1500;\r
     taskcfg.func = blesrvAi_send_service_task;\r
     taskcfg.use_mem = USE_EXTEND_MEM;\r
 \r
@@ -2430,13 +2473,13 @@ int send_msg_data_into_Ai_msg_queue(void *buff,uint16_t len,uint8_t type)
 \r
     uint32_t sendlen = sizeof(blesrv_custom_cmd_t);\r
     uint32_t singlebuflen= ble_nus_max_data_len-20;\r
-\r
+    blesrv_mail.msg_data=0;\r
 \r
     if(len<=singlebuflen)\r
     {\r
         if(type==1)\r
         {\r
-            blesrv_mail.service_handle = 0;\r
+            blesrv_mail.service_handle = 1;\r
             blesrv_mail.msg_len = len;\r
             blesrv_mail.msg_data = (uint8_t*)malloc(len);\r
 \r
@@ -2451,6 +2494,13 @@ int send_msg_data_into_Ai_msg_queue(void *buff,uint16_t len,uint8_t type)
             {\r
                 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"len<=singlebuflen Error blesrv Check send failed! err=0x%X %d! \r\n", ret,send_msg_data_into_Ai_msg_queue_count);\r
             }\r
+\r
+            if(g_blesrv_mail.msg_data)\r
+            {\r
+                free(g_blesrv_mail.msg_data);\r
+                g_blesrv_mail.msg_data=NULL;\r
+                g_blesrv_mail.msg_len=0;\r
+            }\r
             return OSAL_SUCCESS;\r
 \r
         }\r
@@ -2481,7 +2531,7 @@ int send_msg_data_into_Ai_msg_queue(void *buff,uint16_t len,uint8_t type)
             }\r
            \r
 \r
-            blesrv_mail.service_handle = 0;\r
+            blesrv_mail.service_handle = 2;\r
             blesrv_mail.msg_len = len;\r
             blesrv_mail.msg_data = (uint8_t*)malloc(len);\r
 \r
@@ -2503,12 +2553,17 @@ int send_msg_data_into_Ai_msg_queue(void *buff,uint16_t len,uint8_t type)
         {\r
            if (g_blesrv_mail.msg_len!=0 || g_blesrv_mail.msg_data!=NULL)\r
            {\r
-                g_blesrv_mail.msg_data=realloc( g_blesrv_mail.msg_data,g_blesrv_mail.msg_len+len);\r
-                if(g_blesrv_mail.msg_data==NULL)\r
+                // g_blesrv_mail.msg_data=realloc( g_blesrv_mail.msg_data,g_blesrv_mail.msg_len+len);\r
+                uint8_t* temp_g_blesrv_mail_msg_data=malloc(g_blesrv_mail.msg_len+len);\r
+                if(temp_g_blesrv_mail_msg_data==NULL)\r
                 {\r
                     return  ERRCODE_FAIL;\r
                 }\r
-                memcpy_s(g_blesrv_mail.msg_data+ g_blesrv_mail.msg_len,singlebuflen,buff,len);\r
+                memcpy_s(temp_g_blesrv_mail_msg_data+ g_blesrv_mail.msg_len,singlebuflen,buff,len);\r
+                memcpy_s(temp_g_blesrv_mail_msg_data,singlebuflen,g_blesrv_mail.msg_data,g_blesrv_mail.msg_len);\r
+\r
+                free(g_blesrv_mail.msg_data);\r
+                g_blesrv_mail.msg_data=temp_g_blesrv_mail_msg_data;\r
                 g_blesrv_mail.msg_len+=len;\r
            }\r
            else\r
@@ -2520,7 +2575,7 @@ int send_msg_data_into_Ai_msg_queue(void *buff,uint16_t len,uint8_t type)
                 }\r
 \r
                 memcpy_s(g_blesrv_mail.msg_data+ g_blesrv_mail.msg_len,singlebuflen,buff,len);\r
-                g_blesrv_mail.msg_len+=len;\r
+                g_blesrv_mail.msg_len=len;\r
            }\r
            \r
             \r
@@ -2554,28 +2609,31 @@ int send_msg_data_into_Ai_msg_queue(void *buff,uint16_t len,uint8_t type)
         }\r
         else\r
         {\r
-            blesrv_mail.msg_len=g_blesrv_mail.msg_len;\r
-            blesrv_mail.msg_data=malloc(g_blesrv_mail.msg_len);\r
-            if(blesrv_mail.msg_data==NULL)\r
-            {\r
-                return  ERRCODE_FAIL;\r
-            }\r
             if(g_blesrv_mail.msg_len!=0 && g_blesrv_mail.msg_data!=NULL)\r
             {\r
+                blesrv_mail.msg_len=g_blesrv_mail.msg_len;\r
+                blesrv_mail.msg_data=malloc(g_blesrv_mail.msg_len);\r
+                if(blesrv_mail.msg_data==NULL)\r
+                {\r
+                    return  ERRCODE_FAIL;\r
+                }\r
+                \r
                 memcpy_s( blesrv_mail.msg_data,singlebuflen,g_blesrv_mail.msg_data,g_blesrv_mail.msg_len);\r
                 free(g_blesrv_mail.msg_data);\r
-            }\r
 \r
+                ret  = osal_msg_queue_write_copy(g_ble_Ai_record_queue, (void *)&blesrv_mail, sendlen , 0);\r
+                if (ret != OSAL_SUCCESS)\r
+                {\r
+                    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"len<=singlebuflen Error blesrv Check send failed! err=0x%X %d! \r\n", ret,send_msg_data_into_Ai_msg_queue_count);\r
+                }\r
+\r
+            }\r
         \r
             g_blesrv_mail.msg_len=len;\r
             g_blesrv_mail.msg_data=malloc(len);\r
-            memcpy_s( blesrv_mail.msg_data,singlebuflen,buff,len);\r
+            memcpy_s( g_blesrv_mail.msg_data,singlebuflen,buff,len);\r
      \r
-            ret  = osal_msg_queue_write_copy(g_ble_Ai_record_queue, (void *)&blesrv_mail, sendlen , 0);\r
-            if (ret != OSAL_SUCCESS)\r
-            {\r
-                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"len<=singlebuflen Error blesrv Check send failed! err=0x%X %d! \r\n", ret,send_msg_data_into_Ai_msg_queue_count);\r
-            }\r
+           \r
             return OSAL_SUCCESS; \r
         }\r
 \r
index 4837c67..3b0c4c0 100644 (file)
@@ -102,6 +102,9 @@ int send_msg_data_into_Ai_msg_queue(void *buff,uint16_t len,uint8_t type);
 
 void AI_data_assembly(uint8_t type,uint8_t *buf);
 
+
+void set_AI_interval(uint8_t data);
+
 #ifdef __cplusplus
 }
 #endif