From: luozheng <1732036298@qq.com> Date: Mon, 10 Mar 2025 03:29:21 +0000 (+0800) Subject: AI文件提交 X-Git-Url: http://git.snicker.com.cn/css/html/static/gitweb.css?a=commitdiff_plain;h=1ad85509eaab129d29b4fdb1c1eb5d8445b6a7aa;p=mirrors%2FFD230.git AI文件提交 --- 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 83881d330..64752cc9b 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c @@ -2211,6 +2211,341 @@ void Check_ble_adv_status(void) return; } +static unsigned long g_ble_Ai_record_queue = 0xFFFFFFFF; +static uint8_t g_ble_Ai_record_queue_created = 0; + +void create_Ai_record_queue(void) +{ + if (osal_msg_queue_create("Ai_record_queue", BLESRV_APP_BOARD_MSG_COUNT, &g_ble_Ai_record_queue, + 0, MAX_BUF_LEN) != ERRCODE_SUCC) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"[blesrv][service] app create mail fail g_blesrv_queue:%d\n",g_ble_Ai_record_queue); + g_ble_Ai_record_queue_created = 0; + }else{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"[blesrv][service] app create mail success g_blesrv_queue:%d\n",g_ble_Ai_record_queue); + g_ble_Ai_record_queue_created = 1; + } + +} + + +#define Ai_TEST 0 +static void blesrvAi_send_service_task(void const *arg) +{ + unused(arg); + int32_t ret; + blesrv_custom_cmd_t mail={0}; + uint32_t msgsize = MAX_BUF_LEN; + + #if Ai_TEST + FILE* fp= fopen("user/airecord.pcm","wb+"); + #endif + while (1) + { + ret = osal_msg_queue_read_copy(g_ble_Ai_record_queue, (void *)&mail, &msgsize, + OSAL_MSGQ_WAIT_FOREVER); + if (ret != OSAL_SUCCESS) + { + continue; + } + + + uint8_t *p_msgbuf = (mail.msg_data); + uint16_t server_handle = mail.service_handle; + uint32_t msg_len = mail.msg_len; + + #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) + { + free(mail.msg_data); + mail.msg_data = NULL; + } + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"ble_recv:end\r\n"); + } +} + + +static blesrv_custom_cmd_t g_blesrv_mail={0}; + +errcode_t uapi_Ai_send_service_init(void) +{ + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"uapi_blesrv_service_init !\r\n"); + app_task_definition_t taskcfg = {0}; + taskcfg.create_queue_handle = create_Ai_record_queue; + 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.func = blesrvAi_send_service_task; + taskcfg.use_mem = USE_EXTEND_MEM; + + g_blesrv_mail.msg_len=0; + g_blesrv_mail.msg_data=NULL; + + + errcode_t ret = uapi_create_osThread_custom(&taskcfg); + if (ret != ERRCODE_SUCC) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"create blesrv_service failed %d!\r\n", ret); + return ERRCODE_FAIL; + } + + return ERRCODE_SUCC; +} + + +uint32_t send_msg_data_into_Ai_msg_queue_count=0; + + +void AI_data_assembly(uint8_t type,uint8_t *buf) +{ + + memset_s(buf,ble_nus_max_data_len,0,19); + // 设置消息头部信息 + buf[0] = 0x72; // 消息头 + buf[1] = 0x08; // 类型 + if(type) + buf[2] = 0x01; // 类型ID + else + buf[2] = 0x02; // 类型ID + uint32_t temp_data=1; + memcpy(buf + 3, &temp_data, 4); // 总包数 + memcpy(buf + 7, &temp_data, 4); // 总数据长度 + memcpy(buf + 11, &temp_data, 4); // 数据包ID + memcpy(buf + 15, &temp_data, 2); // 包数据长度 + + buf[18] = 0; // 计算CRC +} + +static uint8_t g_blesrv_mail_flag=0; + + + +int send_msg_data_into_Ai_msg_queue(void *buff,uint16_t len,uint8_t type) +{ + blesrv_custom_cmd_t blesrv_mail={0}; + uint32_t ret ; + if( g_blesrv_queue_created == 0) return ERRCODE_FAIL; + if (buff == NULL) return ERRCODE_FAIL; + + uint32_t sendlen = sizeof(blesrv_custom_cmd_t); + uint32_t singlebuflen= ble_nus_max_data_len-20; + + + if(len<=singlebuflen) + { + if(type==1) + { + blesrv_mail.service_handle = 0; + blesrv_mail.msg_len = len; + blesrv_mail.msg_data = (uint8_t*)malloc(len); + + if(blesrv_mail.msg_data==NULL) + { + return ERRCODE_FAIL; + } + memcpy_s((void *)(blesrv_mail.msg_data),len,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; + + } + else if(type==2) + { + + blesrv_custom_cmd_t blesrv_mail_end={0}; + + if(g_blesrv_mail.msg_len!=0 && g_blesrv_mail.msg_data!=NULL) + { + blesrv_mail_end.msg_len=g_blesrv_mail.msg_len; + blesrv_mail_end.msg_data=malloc(g_blesrv_mail.msg_len); + if(blesrv_mail_end.msg_data==NULL) + { + return ERRCODE_FAIL; + } + + memcpy_s( blesrv_mail_end.msg_data,singlebuflen,g_blesrv_mail.msg_data,g_blesrv_mail.msg_len); + free(g_blesrv_mail.msg_data); + g_blesrv_mail.msg_data=NULL; + g_blesrv_mail.msg_len=0; + + ret = osal_msg_queue_write_copy(g_ble_Ai_record_queue, (void *)&blesrv_mail_end, 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); + } + } + + + blesrv_mail.service_handle = 0; + blesrv_mail.msg_len = len; + blesrv_mail.msg_data = (uint8_t*)malloc(len); + + if(blesrv_mail.msg_data==NULL) + { + return ERRCODE_FAIL; + } + memcpy_s((void *)(blesrv_mail.msg_data),len,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; + } + //以下为文件数据处理 + if(g_blesrv_mail.msg_len+len=singlebuflen) + { + blesrv_mail.msg_len = singlebuflen; + blesrv_mail.msg_data = (uint8_t*)malloc(singlebuflen); + + if(blesrv_mail.msg_data==NULL) + { + return ERRCODE_FAIL; + } + memcpy_s((void *)(blesrv_mail.msg_data),singlebuflen,buff+i*singlebuflen,singlebuflen); + residue_len-=singlebuflen; + } + else if(len%singlebuflen) + { + blesrv_mail.msg_len = len%singlebuflen; + blesrv_mail.msg_data = (uint8_t*)malloc( len%singlebuflen); + + if(blesrv_mail.msg_data==NULL) + { + return ERRCODE_FAIL; + } + memcpy_s((void *)(blesrv_mail.msg_data),len%singlebuflen,buff+i*singlebuflen,len%singlebuflen); + } + + + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"g_blesrv_queue:%d ble_recv:mail.msg_data %X %02X %02X %02X msg_data:%02X %02X %02X\r\n", + g_ble_Ai_record_queue, + blesrv_mail.msg_data, + blesrv_mail.msg_data[0], + blesrv_mail.msg_data[1], + blesrv_mail.msg_data[2], + msg_data[0], + msg_data[1], + msg_data[2] + ); + 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,"else Error blesrv Check send failed! err=0x%X %d %d! \r\n", ret,send_msg_data_into_Ai_msg_queue_count,len); + } + } + } + + + return ret; +} + + #ifdef __cplusplus } diff --git a/code/sdk/middleware/services/media/foundation/sample/wrapper/audio_capture_wrapper.cpp b/code/sdk/middleware/services/media/foundation/sample/wrapper/audio_capture_wrapper.cpp index f1aff0569..d04b55eba 100755 --- a/code/sdk/middleware/services/media/foundation/sample/wrapper/audio_capture_wrapper.cpp +++ b/code/sdk/middleware/services/media/foundation/sample/wrapper/audio_capture_wrapper.cpp @@ -466,7 +466,7 @@ static void* AudioCaptureProcess_AI(void* arg) int32_t streamingRecordAndSend_AI(void) { - const char *argv[] = {"01", "pcm", "16000", "1", "16", "/user/aiRecord.pcm"}; + const char *argv[] = {"01", "sbc", "16000", "1", "16", "/user/aiRecord.sbc"}; int32_t argc = 6; if (g_audioSourceProcessInput.bThreadRun) { return HandleAudioCaptureCmd(argc, argv);