From 21f27aacf20748b69f627c21b982e36b14417b30 Mon Sep 17 00:00:00 2001 From: hcj <1224667075@qq.com> Date: Fri, 12 Jul 2024 18:43:13 +0800 Subject: [PATCH] =?utf8?q?=E5=A2=9E=E5=8A=A0ai=E6=95=B0=E6=8D=AE=E5=AD=97?= =?utf8?q?=E7=AC=A6=E9=95=BF=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../service/ble_service/bleservice/bleEvent.c | 64 ++++++++++++++----- 1 file changed, 47 insertions(+), 17 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 879b667db..94cb1612b 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c @@ -2014,9 +2014,9 @@ uint8_t binCheck_AI(uint8_t *buf,uint8_t *check,uint16_t len)//json 格式解析 memcpy_s(&txt_len,2,&buf[offset],2); offset+=2; - char txt_buf[128]={0}; - memcpy_s(txt_buf,128,&buf[offset],txt_len); - printf("binCheck_AI txtbuf:%s %d\r\n",txt_buf,txt_len); + char txt_buf[256]={0}; + memcpy_s(txt_buf,256,&buf[offset],txt_len); + printf("binCheck_AI Question txtbuf:%s %d\r\n",txt_buf,txt_len); ble_set_ai_Question_str(txt_buf); offset+=txt_len; //offset+=1; @@ -2029,24 +2029,38 @@ uint8_t binCheck_AI(uint8_t *buf,uint8_t *check,uint16_t len)//json 格式解析 offset+=2; - char txt_buf[128]={0}; - memcpy_s(txt_buf,128,&buf[offset],txt_len); - printf("binCheck_AI txtbuf %s %d\r\n",txt_buf,txt_len); + if(txt_len>=1024*3) + txt_len=1024*3; + + char *txt_buf=(char*)malloc(txt_len+1); + if(txt_buf==NULL) + { + printf("binCheck_AI txtbuf malloc fail\r\n"); + ble_set_ai_Answer_str("手表缓存不足"); + return 0; + } + + txt_buf[txt_len]=0; + memcpy_s((char *)txt_buf,1024*3,&buf[offset],txt_len); + + printf("binCheck_AI txtbuf Answer %s %d\r\n",txt_buf,txt_len); ble_set_ai_Answer_str(txt_buf); + free(txt_buf); + offset+=txt_len; //offset+=1; - } - if(offset>=len) - { - break; } if(buf[offset]==0) { printf("AI 解析失败\r\n"); - offset++; - break; } - offset++; + + if(offset>=len) + { + break; + } + offset++; + } *check = 1; @@ -6045,6 +6059,7 @@ errcode_t cancel_recv_file(ble_read_data *buffer_handle) static uint8_t timer_flie_type=0; static uint32_t timer_flie_flag=0; +ble_read_data* ble_read_timer_p=NULL; static void ble_transfer_Timer_CallBack(int data) { timer_flie_flag--; @@ -6063,6 +6078,23 @@ static void ble_transfer_Timer_CallBack(int data) { TRANSMIT_DATA=TRANS_FREE; } + // if (ble_read_timer_p->file_recv_stat.recv_file_stat != 2) //已经下载完毕的文件,没有必要cancel了。 + // { + + // if (ble_read_timer_p->file_recv_stat.file!=NULL) + // { + // fclose(ble_read_timer_p->file_recv_stat.file); + // ble_read_timer_p->file_recv_stat.file = NULL; + // } + // if (ble_read_timer_p->file_recv_stat.file_name != NULL) + // { + // free(ble_read_timer_p->file_recv_stat.file_name); + // ble_read_timer_p->file_recv_stat.file_name=NULL; + // } + // ble_read_timer_p->file_recv_stat.recv_file_stat = -1; + + // ble_reply_cmd(FILE_RECV_REPLY_STAT_CMD,0);//接收失败 + // } CustomEventPublish(TOPIC_EVENT_BLE_TRANSMIT,&TRANSMIT_DATA,1); if(BR_TRANSFER_timer) { @@ -6183,7 +6215,8 @@ errcode_t handle_recv_file(ble_read_data *buffer_handle,uint8_t *data, uint16_t BR_TRANSFER_timer = NULL; } timer_flie_type=buffer_handle->file_recv_stat.file_type; - timer_flie_flag=3; + ble_read_timer_p=buffer_handle; + timer_flie_flag=10; BR_TRANSFER_timer = osTimerNew((osTimerFunc_t)ble_transfer_Timer_CallBack, osTimerPeriodic, NULL, NULL); tick =1000;// osMs2Tick(1000); @@ -6195,10 +6228,7 @@ errcode_t handle_recv_file(ble_read_data *buffer_handle,uint8_t *data, uint16_t return ERRCODE_FAIL; } /////////////////////////////////////////////////////////// - - } - if (buffer_handle->file_recv_stat.file == NULL) { printf("6194 buffer_handle->file_recv_stat.file \n"); -- 2.17.1