From 4c665b41ea5197d6dac168de6060f89927e8ecfa Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E8=83=A1=E4=BC=A0=E5=86=9B?= <1224667075@qq.com> Date: Tue, 2 Jul 2024 01:21:48 +0000 Subject: [PATCH] Merge #423 into sdk602patch0521 from refs/changes/423/head MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Code review from 胡传军 * refs/changes/423/head: (17 commits squashed) - 修复表盘协议BUG - Merge branch 'sdk602patch0521' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0521 - 低电量修改 - Merge branch 'sdk602patch0521' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0521 - 优化低电量关机 - Merge branch 'sdk602patch0521' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0521 - 更改低电量报警 - ble扫描过滤去除,ble read属性更新 - Merge branch 'sdk602patch0521' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0521 - 修改步数等数据存储,从记录一小时内的增值,改为记录当前时间点总值 - 补交 - LCD - LCD补交 - Merge branch 'sdk602patch0521' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0521 - 表盘BUG修复 - AI语音ble协议更新,协议已测试,UI还需要修改 - 表盘map增加误判断,避免错误id因为不当操作注册进来 Signed-off-by: aliyun8003852482 <1224667075@qq.com> Reviewed-by: snickersun@163.com Merged-by: snickersun@163.com CR-link: https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230/change/423 --- .../nativeui/set_dial/src/SetDialModel.cpp | 46 +++++--- .../service/ble_service/blemoder/bletest.cpp | 110 ++++++++++++++++++ .../service/ble_service/blemoder/bletest.h | 5 + .../service/ble_service/bleservice/bleEvent.c | 49 ++++---- 4 files changed, 170 insertions(+), 40 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/set_dial/src/SetDialModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/set_dial/src/SetDialModel.cpp index b9d56647b..f2e4e1af0 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/set_dial/src/SetDialModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/set_dial/src/SetDialModel.cpp @@ -136,11 +136,13 @@ namespace OHOS /* 注册表盘map */ void SetDialModel::RegisterDial(uint16_t ID, const char *dialname) { + if(ID==0 || strlen(dialname)==0) + return; registeredDials[ID] = std::string(dialname); // 唯一性 - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RegisterDial %s is ok!", dialname); - + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RegisterDial %d %s is ok!",ID, dialname); + LoadAllDial(); saveDialfile(); @@ -170,7 +172,10 @@ namespace OHOS /* 获取当前表盘Id */ uint16_t SetDialModel::GetCurrentDialID() { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "currentDialID is %d,name is %s", currentDialID, registeredDials[currentDialID].c_str()); + if (registeredDials.find(currentDialID) != registeredDials.end()) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "currentDialID is %d,name is %s", currentDialID, registeredDials[currentDialID].c_str()); + } return currentDialID; } /* 获取所有表盘Id 每个表盘Id 2个字节 拼接为字符串 */ @@ -224,6 +229,8 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UninstallDial the dial %d is ok", ID); registeredDials.erase(ID); + LoadAllDial(); + return true; } @@ -236,25 +243,28 @@ namespace OHOS /*更新表盘*/ void SetDialModel::UpdateDialSetting(uint16_t ID) { - std::string dialname = registeredDials[ID]; // 根据ID找到对应的表盘名称 - // 在dialInfoList中查找同名表盘 - for (size_t i = 0; i < dialInfoList.size(); i++) + if (registeredDials.find(ID) != registeredDials.end()) { - if (dialInfoList[i].dialName == dialname) + std::string dialname = registeredDials[ID]; // 根据ID找到对应的表盘名称 + // 在dialInfoList中查找同名表盘 + for (size_t i = 0; i < dialInfoList.size(); i++) { - DialSetting diagSetting; - SetDialInfo &info = dialInfoList[i]; - diagSetting.dialFlag = info.dialFlag; - diagSetting.dialId = info.id; - diagSetting.dialFullName = info.dialFullName; - MainModel::GetInstance().AddDialSetting(diagSetting); // 更新表盘设置 - currentDialID = ID; // 更新当前表盘Id - NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN); - return; // 更新成功后直接返回 + if (dialInfoList[i].dialName == dialname) + { + DialSetting diagSetting; + SetDialInfo &info = dialInfoList[i]; + diagSetting.dialFlag = info.dialFlag; + diagSetting.dialId = info.id; + diagSetting.dialFullName = info.dialFullName; + MainModel::GetInstance().AddDialSetting(diagSetting); // 更新表盘设置 + currentDialID = ID; // 更新当前表盘Id + NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN); + return; // 更新成功后直接返回 + } } + NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDialModel UpdateDialSetting: Cannot find dial with name %s", dialname.c_str()); } - NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDialModel UpdateDialSetting: Cannot find dial with name %s", dialname.c_str()); } /*加载所有表盘*/ 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