From 4aa742d00442cb2cdd0bf39879abc5db9f39c44a Mon Sep 17 00:00:00 2001 From: hcj <1224667075@qq.com> Date: Wed, 12 Mar 2025 09:27:37 +0800 Subject: [PATCH] =?utf8?q?AI=E5=BD=95=E9=9F=B3=E4=B8=8A=E4=BC=A0=E4=BF=AE?= =?utf8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../service/ble_service/bleservice/bleEvent.c | 10 -- .../service/ble_service/bleservice/bleEvent.h | 4 +- .../ble_service/bleservice/bleService.c | 104 ++++++++++++++---- .../ble_service/bleservice/bleService.h | 3 + 4 files changed, 86 insertions(+), 35 deletions(-) diff --git a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c index 9c9211459..05974aad5 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c @@ -5656,18 +5656,8 @@ static void GetSynDataEndCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *to sendBleData(value,19); } } -static uint8_t AI_interval=5; -void set_AI_interval(uint8_t data) -{ - AI_interval=data; -} -void send_Ai_record(uint16_t len,uint8_t *data) -{ - svr_ble_bt_gatts_noyify_AI(data,len); - LOS_Msleep(AI_interval+get_ble_interval()); -} diff --git a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.h b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.h index 2b9da97b5..e985db45c 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.h +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.h @@ -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); ///////////////////////////自定义文件传输协议///////////////////////////// diff --git a/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c b/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c index 81709c525..38882d80f 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c @@ -2323,6 +2323,37 @@ void create_Ai_record_queue(void) #define Ai_TEST 0 +static uint32_t AI_data_count=0; + + +static uint8_t AI_interval=5; + +void set_AI_interval(uint8_t data) +{ + AI_interval=data; +} + +void send_Ai_record(uint16_t len,uint8_t *data,uint32_t count) +{ + uint8_t ai_buf[SDK_BLE_MTU_MAX]={0}; + if(count) + { + + memcpy_s(ai_buf,SDK_BLE_MTU_MAX,&count,4); + memcpy_s(&ai_buf[4],SDK_BLE_MTU_MAX-4,data,len); + len+=4; + } + else + { + memcpy_s(ai_buf,SDK_BLE_MTU_MAX,data,len); + } + + svr_ble_bt_gatts_noyify_AI(ai_buf,len); + + LOS_Msleep(AI_interval+get_ble_interval()); +} + + static void blesrvAi_send_service_task(void const *arg) { unused(arg); @@ -2347,13 +2378,25 @@ static void blesrvAi_send_service_task(void const *arg) uint16_t server_handle = mail.service_handle; uint32_t msg_len = mail.msg_len; + if(server_handle==1 || server_handle==2) + { + AI_data_count=0; + } + else + { + AI_data_count++; + } + #if Ai_TEST fwrite(fp,1,mail.msg_len,mail.msg_data); #endif // if(get_ble_connect()) - if(mail.msg_data && mail.msg_len!=0) - send_Ai_record(mail.msg_len,mail.msg_data); + + if(mail.msg_data && mail.msg_len!=0) + send_Ai_record(mail.msg_len,mail.msg_data,AI_data_count); + + if(mail.msg_data) { free(mail.msg_data); @@ -2375,7 +2418,7 @@ errcode_t uapi_Ai_send_service_init(void) taskcfg.attr.name = "Ai_record_queue_service"; taskcfg.attr.priority = osPriorityNormal; // taskcfg.attr.stack_size = BLESRV_APP_BOARD_TASK_SIZE; - taskcfg.attr.stack_size = 0x1000; + taskcfg.attr.stack_size = 0x1500; taskcfg.func = blesrvAi_send_service_task; taskcfg.use_mem = USE_EXTEND_MEM; @@ -2430,13 +2473,13 @@ int send_msg_data_into_Ai_msg_queue(void *buff,uint16_t len,uint8_t type) uint32_t sendlen = sizeof(blesrv_custom_cmd_t); uint32_t singlebuflen= ble_nus_max_data_len-20; - + blesrv_mail.msg_data=0; if(len<=singlebuflen) { if(type==1) { - blesrv_mail.service_handle = 0; + blesrv_mail.service_handle = 1; blesrv_mail.msg_len = len; blesrv_mail.msg_data = (uint8_t*)malloc(len); @@ -2451,6 +2494,13 @@ int send_msg_data_into_Ai_msg_queue(void *buff,uint16_t len,uint8_t type) { 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); } + + if(g_blesrv_mail.msg_data) + { + free(g_blesrv_mail.msg_data); + g_blesrv_mail.msg_data=NULL; + g_blesrv_mail.msg_len=0; + } return OSAL_SUCCESS; } @@ -2481,7 +2531,7 @@ int send_msg_data_into_Ai_msg_queue(void *buff,uint16_t len,uint8_t type) } - blesrv_mail.service_handle = 0; + blesrv_mail.service_handle = 2; blesrv_mail.msg_len = len; blesrv_mail.msg_data = (uint8_t*)malloc(len); @@ -2503,12 +2553,17 @@ int send_msg_data_into_Ai_msg_queue(void *buff,uint16_t len,uint8_t type) { if (g_blesrv_mail.msg_len!=0 || g_blesrv_mail.msg_data!=NULL) { - g_blesrv_mail.msg_data=realloc( g_blesrv_mail.msg_data,g_blesrv_mail.msg_len+len); - if(g_blesrv_mail.msg_data==NULL) + // g_blesrv_mail.msg_data=realloc( g_blesrv_mail.msg_data,g_blesrv_mail.msg_len+len); + uint8_t* temp_g_blesrv_mail_msg_data=malloc(g_blesrv_mail.msg_len+len); + if(temp_g_blesrv_mail_msg_data==NULL) { return ERRCODE_FAIL; } - memcpy_s(g_blesrv_mail.msg_data+ g_blesrv_mail.msg_len,singlebuflen,buff,len); + memcpy_s(temp_g_blesrv_mail_msg_data+ g_blesrv_mail.msg_len,singlebuflen,buff,len); + memcpy_s(temp_g_blesrv_mail_msg_data,singlebuflen,g_blesrv_mail.msg_data,g_blesrv_mail.msg_len); + + free(g_blesrv_mail.msg_data); + g_blesrv_mail.msg_data=temp_g_blesrv_mail_msg_data; g_blesrv_mail.msg_len+=len; } else @@ -2520,7 +2575,7 @@ int send_msg_data_into_Ai_msg_queue(void *buff,uint16_t len,uint8_t type) } memcpy_s(g_blesrv_mail.msg_data+ g_blesrv_mail.msg_len,singlebuflen,buff,len); - g_blesrv_mail.msg_len+=len; + g_blesrv_mail.msg_len=len; } @@ -2554,28 +2609,31 @@ int send_msg_data_into_Ai_msg_queue(void *buff,uint16_t len,uint8_t type) } else { - blesrv_mail.msg_len=g_blesrv_mail.msg_len; - blesrv_mail.msg_data=malloc(g_blesrv_mail.msg_len); - if(blesrv_mail.msg_data==NULL) - { - return ERRCODE_FAIL; - } if(g_blesrv_mail.msg_len!=0 && g_blesrv_mail.msg_data!=NULL) { + blesrv_mail.msg_len=g_blesrv_mail.msg_len; + blesrv_mail.msg_data=malloc(g_blesrv_mail.msg_len); + if(blesrv_mail.msg_data==NULL) + { + return ERRCODE_FAIL; + } + memcpy_s( blesrv_mail.msg_data,singlebuflen,g_blesrv_mail.msg_data,g_blesrv_mail.msg_len); free(g_blesrv_mail.msg_data); - } + ret = osal_msg_queue_write_copy(g_ble_Ai_record_queue, (void *)&blesrv_mail, sendlen , 0); + if (ret != OSAL_SUCCESS) + { + 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); + } + + } g_blesrv_mail.msg_len=len; g_blesrv_mail.msg_data=malloc(len); - memcpy_s( blesrv_mail.msg_data,singlebuflen,buff,len); + memcpy_s( g_blesrv_mail.msg_data,singlebuflen,buff,len); - ret = osal_msg_queue_write_copy(g_ble_Ai_record_queue, (void *)&blesrv_mail, sendlen , 0); - if (ret != OSAL_SUCCESS) - { - 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); - } + return OSAL_SUCCESS; } diff --git a/code/sdk/application/wearable/service/ble_service/bleservice/bleService.h b/code/sdk/application/wearable/service/ble_service/bleservice/bleService.h index 4837c6745..3b0c4c09b 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleService.h +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleService.h @@ -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 -- 2.17.1