From 6595d602841900623c14f969a0e05b5f306ae343 Mon Sep 17 00:00:00 2001 From: hcj <1224667075@qq.com> Date: Mon, 1 Jul 2024 17:31:05 +0800 Subject: [PATCH] =?utf8?q?AI=E8=AF=AD=E9=9F=B3ble=E5=8D=8F=E8=AE=AE?= =?utf8?q?=E6=9B=B4=E6=96=B0=EF=BC=8C=E5=8D=8F=E8=AE=AE=E5=B7=B2=E6=B5=8B?= =?utf8?q?=E8=AF=95=EF=BC=8CUI=E8=BF=98=E9=9C=80=E8=A6=81=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/blemoder/bletest.cpp | 110 ++++++++++++++++++ .../service/ble_service/blemoder/bletest.h | 5 + .../service/ble_service/bleservice/bleEvent.c | 49 ++++---- 3 files changed, 142 insertions(+), 22 deletions(-) diff --git a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp index 930eef597..dc1dc03de 100644 --- a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp +++ b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp @@ -35,6 +35,7 @@ #include "SetDialModel.h" +#include "AiVoiceModel.h" #include "SleepModel.h" //#include "AlarmClockModel.h" #ifdef __cplusplus @@ -70,6 +71,108 @@ extern "C" { #include +void ble_set_ai_Question_str(char *buf) +{ + OHOS::AiVoiceModel::GetInstance().SetUserQuestionStr(std::string(buf)); +} + +void ble_set_ai_Answer_str(char *buf) +{ + OHOS::AiVoiceModel::GetInstance().SetaiAnswerStrStr(std::string(buf)); +} + + +char * dir_to_json_buf_malloc_(uint8_t type) +{ + char dir_path[128]={0}; + switch (type) + { + case 0x43: //同步步数历史数据 + sprintf_s(dir_path,64,"%s","user/userdata/music"); + break; + default: + break; + } + cJSON *dataJSON = cJSON_CreateObject(); + cJSON* data_arryJSON = cJSON_CreateArray(); + + struct DIR *dir; + struct dirent *ent; + uint32_t file_size=0; + if ((dir = opendir(dir_path)) != NULL) + { + while ((ent = readdir(dir)) != NULL) + { + std::string fileName = ent->d_name; + + if (fileName != "." && fileName != "..") + { + //std::string filePath = directory + fileName; + + + if (ent->d_type == DT_REG || ent->d_type == DT_UNKNOWN ) // 普通文件 + { + + //*file_size=ent->d_reclen; + // char file_path[128]={0}; + // sprintf_s(file_path,128,"%s/%s",TAR_PATH,ent->d_name); + + // FILE * fp = fopen(file_path,"rb+"); + // if(fp==NULL) + // { + // printf(" fopen fail %s\r\n",file_path); + // return NULL; + // } + // if (fp != NULL) + // { + // fseek(fp, 0, SEEK_END); // 将文件指针移动到文件末尾 + // file_size = ftell(fp); // 获取当前文件指针位置,即文件大小 + // fseek(fp, 0, SEEK_SET); // 将文件指针移回文件开头 + // } + // fclose(fp); + + // cJSON* itemJSON = cJSON_CreateObject(); + + // cJSON_AddNumberToObject(itemJSON,"index",file_index); + // cJSON_AddNumberToObject(itemJSON,"count",file_count); + + // cJSON_AddNumberToObject(itemJSON,"crc",crc); + + // cJSON_AddStringToObject(itemJSON,"name",fileName.c_str()); + // cJSON_AddNumberToObject(itemJSON,"size",file_size); + + // char *json_format = cJSON_PrintUnformatted(itemJSON); + + // int pSize = cJSON_GetArraySize(dataJSON); + // printf("文件数据:%s\r\n",json_format); + // cJSON_Delete(dataJSON); + // file_index++; + + // return json_format; + + //cJSON_AddItemReferenceToArray(data_arryJSON,itemJSON); + + } + else if (ent->d_type == DT_DIR) // 目录 + { + continue; + } + + } + + } + closedir(dir); + } + else + { + printf("opendir fail\r\n"); + } + return NULL; +} + + + + uint8_t ble_AT_add_nap_data(uint16_t time) { OHOS::NAP_T data; @@ -630,6 +733,13 @@ char * struct_to_json_buf_malloc_(uint8_t day) cJSON_AddNumberToObject(itemJSON,"di",data->di); cJSON_AddNumberToObject(itemJSON,"hr",data->hr); cJSON_AddNumberToObject(itemJSON,"stp",data->stp); + cJSON_AddNumberToObject(itemJSON,"ti",data->ti); + cJSON_AddNumberToObject(itemJSON,"cir",data->cir); + cJSON_AddNumberToObject(itemJSON,"alt",data->alt); + cJSON_AddNumberToObject(itemJSON,"fpc",data->fpc); + cJSON_AddNumberToObject(itemJSON,"spc",data->spc); + cJSON_AddNumberToObject(itemJSON,"std",data->std); + cJSON_AddNumberToObject(itemJSON,"cdc",data->cdc); cJSON_AddItemReferenceToArray(data_arryJSON,itemJSON); free(data); diff --git a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.h b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.h index b87b1dedc..af82ebc6d 100644 --- a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.h +++ b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.h @@ -256,6 +256,11 @@ uint8_t ble_get_sleep_data(uint32_t file_size,uint8_t day_,uint8_t *data); uint8_t ble_AT_add_nap_data(uint16_t time); +/////////////////////////////AI相关///////////////////////// +void ble_set_ai_Question_str(char *buf); + +void ble_set_ai_Answer_str(char *buf); + #ifdef __cplusplus #if __cplusplus } 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 ff7c50de0..f91965c58 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c @@ -2078,13 +2078,13 @@ uint8_t binCheck_AI(uint8_t *buf,uint8_t *check,uint16_t len)//json 格式解析 uint8_t flag = 0; // printf("jsonCheck_weather:len: json:%f jsonlen:%d\r\n",0.011,strlen((char *)json)); #if 0 - FILE *fp=fopen("user/weather.json","wb+"); - printf("jsonCheck_weather len %d",strlen((char *)buf)+1); - //fwrite((void*)buf,1,strlen((char *)buf)+1,fp); - fputs((char *)buf,fp); + FILE *fp=fopen("user/AI.txt","wb+"); + printf("binCheck_AI len %d\r\n",len); + fwrite((void*)buf,1,len,fp); + //fputs((char *)buf,fp); fclose(fp); - 1+1+2 #endif + uint16_t offset=0; while (len>offset) @@ -2092,22 +2092,27 @@ uint8_t binCheck_AI(uint8_t *buf,uint8_t *check,uint16_t len)//json 格式解析 if(buf[offset]==1) { offset++; - uint16_t txt_len=buf[offset]; - offset++; - char buf[128]={0}; - memcpy_s(buf,128,buf[offset],txt_len); - printf("%s\r\n",buf); + uint16_t txt_len; + 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); + ble_set_ai_Question_str(txt_buf); offset+=txt_len; offset+=1; } else if(buf[offset]==2) { offset++; - uint16_t txt_len=buf[offset]; - offset++; - char buf[128]={0}; - memcpy_s(buf,128,buf[offset],txt_len); - printf("%s\r\n",buf); + uint16_t txt_len=buf[offset]+buf[offset+1]*256; + offset+=2; + + char txt_buf[128]={0}; + memcpy_s(txt_buf,128,&buf[offset],txt_len); + printf("%s %d\r\n",txt_buf,txt_len); + ble_set_ai_Answer_str(txt_buf); offset+=txt_len; offset+=1; } @@ -2153,7 +2158,7 @@ void GetWeatherCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *totalData,ui } -void GetAiResultCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *totalData,uint8_t crcvalue)//获取天气数据 +void GetAiResultCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *totalData,uint8_t crcvalue) { uint32_t tmp = 1; uint16_t tmp_data = 1; @@ -2161,7 +2166,7 @@ void GetAiResultCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *totalData,u memset(sendBuf,0,19); sendBuf[0] = 0x72; sendBuf[1] = 0x02; - sendBuf[2] = 0x20; + sendBuf[2] = 0x1f; memcpy(sendBuf+3,&tmp,4); memcpy(sendBuf+7,&tmp,4); memcpy(sendBuf+11,&tmp,4); @@ -2390,9 +2395,8 @@ void getAPPaddressbook(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *totalDat void type2AE4Data(ble_read_data *buffer_handle,uint8_t *buf_cmd,uint8_t *data,uint16_t datalen,uint8_t *totalData,uint8_t crcvalue) { uint16_t typeID = buf_cmd[1]*256+buf_cmd[2]; - #ifdef BLE_LOG + printf("type2AE4Data typeID:0x%04X\r\n",typeID); - #endif switch (typeID) //ID { case USER_INFOR_CMD://app下发的获取用户信息 @@ -4000,6 +4004,7 @@ static void GetAiRecordCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *tota printf("fopen fail %s\r\n",file_name); goto GetAiRecordFail; } + do { memset_s(data,num+1,0,num+1); @@ -4007,7 +4012,7 @@ static void GetAiRecordCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *tota send_big_data(1,data,read_size,file_size,pack_id,pack,0x34,1); pack_id++; - msleep(50); + msleep(20); } while (read_size==num); free(data); @@ -4658,10 +4663,10 @@ void type2AE3Data(ble_read_data *buffer_handle,uint8_t *cmd_buf ,uint8_t *data,u case GET_PASSWORD_CMD: //获取手表密码 GetPasswordCmd(cmd,data,datalen,totaldata,crcvalue); break; - case AI_IS_READ_DATA_CMD: + case APP_GET_AI_PCM_DATA_CMD: GetAiRecordCmd(cmd,data,datalen,totaldata,crcvalue); break; - case APP_GET_AI_PCM_DATA_CMD://获取手表闹钟//同步闹钟 + case AI_IS_READ_DATA_CMD: case SYN_HEART_HISTORY_DATA_CMD://同步心率历史数据 //heartDataCmd(cmd,data,datalen,totaldata,crcvalue); case SYN_SPO2_HISTORY_DATA_CMD://同步血氧历史数据 -- 2.17.1