From: hcj <1224667075@qq.com> Date: Thu, 25 Apr 2024 02:41:49 +0000 (+0800) Subject: 修复使用cjson时的内存泄露,添加蓝牙训练协议对接 X-Git-Tag: release_V1.2.70_20241020_135402~1131^2 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=refs%2Fchanges%2F79%2Fhead;p=mirrors%2FFD230.git 修复使用cjson时的内存泄露,添加蓝牙训练协议对接 --- diff --git a/code/sdk/application/wearable/fd230app/nativeui/config/include/ConfigModel.h b/code/sdk/application/wearable/fd230app/nativeui/config/include/ConfigModel.h index 344f3ecbb..5bec295f3 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/config/include/ConfigModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/config/include/ConfigModel.h @@ -69,6 +69,7 @@ namespace OHOS CONFIGMODEL_ITEM_CALL_VOLUME,//通话音量 CONFIGMODEL_ITEM_VOLTE_CALL,//VoLTE通话 CONFIGMODEL_ITEM_MOTIONRECOGNITION,//运动识别 + CONFIGMODEL_ITEM_TRAINING_HEART_MAX,//训练最高心率 CONFIGMODEL_ITEM_MAX, } ; @@ -203,6 +204,7 @@ namespace OHOS {ConfigDataType::DATATYPE_INT, "CallVolume", "100" },// CONFIGMODEL_ITEM_CALL_VOLUME // {ConfigDataType::DATATYPE_BOOL, "VoLTECall", "false" },// CONFIGMODEL_ITEM_VOLTE_CALL {ConfigDataType::DATATYPE_BOOL, "MotionRecognition", "false" },// CONFIGMODEL_ITEM_MOTIONRECOGNITION + {ConfigDataType::DATATYPE_INT, "traningheart", "250"},//CONFIGMODEL_ITEM_TRAINING_HEART_MAX//训练最高心率 }; ConfigModel(); // 私有构造函数,确保无法在外部实例化 ConfigModel(const ConfigModel &) = delete; // 禁止拷贝构造 diff --git a/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemModel.cpp index 127f06ca1..d8a841f3d 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemModel.cpp @@ -37,10 +37,10 @@ namespace OHOS while (falg) { - for(int i=0;i<60;i++) - { - msleep(1000); - } + // for(int i=0;i<60;i++) + // { + // msleep(1000); + // } if(ConfigModel::GetInstance()->GetCat1_4Gability()) { upgrade_reported_data(); diff --git a/code/sdk/application/wearable/fd230app/nativeui/system/src/Systemupgrade.cpp b/code/sdk/application/wearable/fd230app/nativeui/system/src/Systemupgrade.cpp index 28accae7a..8145ef388 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/system/src/Systemupgrade.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/system/src/Systemupgrade.cpp @@ -160,6 +160,7 @@ namespace OHOS cJSON_AddStringToObject(dataJSON,"updateTime",""); buf = cJSON_PrintUnformatted(dataJSON); cJSON_Delete(dataJSON); + cJSON_free(buf); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "%s",buf); u16_t buf_len=strlen(buf); report_data_by_get_file(buf,buf_len); @@ -246,7 +247,7 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, ""); report_jsonString = cJSON_PrintUnformatted(data); - + cJSON_Delete(data); if(data!=NULL) { @@ -604,6 +605,8 @@ namespace OHOS fwrite(report_jsonString,1,data_len,FP_); fclose(FP_); printf("data%d %s\r\n",data_len,report_jsonString); + cJSON_free(report_jsonString); + report_jsonString=NULL; } } diff --git a/code/sdk/application/wearable/service/ble_service/blemoder/CMakeLists.txt b/code/sdk/application/wearable/service/ble_service/blemoder/CMakeLists.txt index afc10ddcb..8d6455e38 100644 --- a/code/sdk/application/wearable/service/ble_service/blemoder/CMakeLists.txt +++ b/code/sdk/application/wearable/service/ble_service/blemoder/CMakeLists.txt @@ -19,6 +19,7 @@ ${ROOT_DIR}/application/wearable/fd230app/nativeui/language/include ${ROOT_DIR}/application/wearable/fd230app/nativeui/language ${ROOT_DIR}/application/wearable/fd230app/nativeui/traing/training_card/include ${ROOT_DIR}/application/wearable/fd230app/nativeui/config/include +${ROOT_DIR}/application/wearable/fd230app/nativeui/traing/include ) 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 24777ccc8..9ea002e42 100644 --- a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp +++ b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp @@ -18,8 +18,9 @@ #include "health_service.h" #include "phoneaddressmodel.h" #include "LanguageInit.h" -#include "ConfigModel.h" +#include "ConfigModel.h" // #include "TraingCardPresenter.h" +//#include "TraingModel.h" #ifdef __cplusplus #if __cplusplus @@ -51,6 +52,9 @@ extern "C" { #include "bleService.h" #include "bletest.h" + + + void add_addressbookToRead(char *data)//转化用于·c文件 { char *name=NULL; @@ -125,7 +129,6 @@ void set_user_data(msg_user_info_t data) 时制 p_ConfigModel->set_condigData_Int(OHOS::ConfigModel::CONFIGMODEL_ITEM_CUSTOM_DATA_AGE,data.timeformat); */ - } int get_goal_stepcount(void) @@ -168,7 +171,20 @@ void set_SilentMode(uint8_t falg) return; } +void set_traning_updata_freq(uint8_t freq) +{ + OHOS::ConfigModel *p_ConfigModel = OHOS::ConfigModel::GetInstance(); + p_ConfigModel->set_condigData_Int(OHOS::ConfigModel::CONFIGMODEL_ITEM_TRANING_FREQ,freq); + return; +} + +void set_traning_heart_max(uint8_t data) +{ + OHOS::ConfigModel *p_ConfigModel = OHOS::ConfigModel::GetInstance(); + p_ConfigModel->set_condigData_Int(OHOS::ConfigModel::CONFIGMODEL_ITEM_TRAINING_HEART_MAX,data); + return; +} uint8_t ble_is_ready(void) { 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 fa3f6c74d..819ae4276 100644 --- a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.h +++ b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.h @@ -85,15 +85,22 @@ const char *get_health_data_path(void); void add_addressbookToRead(char *data); void set_user_data(msg_user_info_t data); + int get_goal_stepcount(void); + int get_vibrationremiander(void); + int get_SilentMode(void); + void set_goal_stepcount(uint32_t step); void set_vibrationremiander(uint8_t falg); void set_SilentMode(uint8_t falg); +void set_traning_updata_freq(uint8_t freq); + +void set_traning_heart_max(uint8_t data); #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 4397db94b..187d7efd4 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c @@ -273,11 +273,11 @@ void sendDataNow(uint8_t *buf,uint16_t len) } } -void send_big_data(uint8_t flag,char *data,int datalen,int total,uint32_t Packet_id,uint32_t packet_total,uint8_t type_id) +void send_big_data(uint8_t flag,char *data,int datalen,int total,uint32_t Packet_id,uint32_t packet_total,uint8_t type_id,uint8_t type) { uint8_t buf[512]={0}; buf[0]=0x72; - buf[1]=0x01; + buf[1]=type; buf[2]=type_id; memcpy(buf+3,&packet_total,4); memcpy(buf+7,&total,4); @@ -303,27 +303,38 @@ void send_big_data(uint8_t flag,char *data,int datalen,int total,uint32_t Packet sendBleData(buf,17+datalen+1); } - - // } - +} +//发送训练状态 +void sendtraningstatedata(uint8_t state ,uint16_t time) +{ + char data[3]={0}; + uint32_t data_len=3; + data[0]=state; + memcpy(&data[1],&time,2); + printf("发送训练状态数据%d %s\r\n",data_len,data); + send_big_data(0,data,data_len,data_len,1,1,0x50,5); + } void sendtraningdata(msg_get_train_data_info_t *data) { cJSON* dataJSON=cJSON_CreateObject(); + cJSON_AddNumberToObject(dataJSON,"st",data->st); cJSON_AddNumberToObject(dataJSON,"hr",data->hr); cJSON_AddNumberToObject(dataJSON,"ca",data->ca); cJSON_AddNumberToObject(dataJSON,"di",data->di); cJSON_AddNumberToObject(dataJSON,"stp",data->stp); cJSON_AddNumberToObject(dataJSON,"ti",data->ti); + char *jsonString = cJSON_PrintUnformatted(dataJSON); + uint32_t data_len=strlen(jsonString); printf("发送训练实时数据%d %s\r\n",data_len,jsonString); - send_big_data(0,jsonString,data_len,data_len,1,1,0x15); - - + send_big_data(0,jsonString,data_len,data_len,1,1,0x15,1); + cJSON_free(jsonString); + cJSON_Delete(dataJSON); } //发送ble数据 uint8_t phone_mac[6];//手机下发的mac地址 第一次连接为空 @@ -1076,7 +1087,7 @@ void sendParieSuccess(uint8_t flag,bd_addr_t *addr)//发送配对成功指令to fclose(file); } free(jsonString); - + cJSON_Delete(dataJSON); // 读取JSON文件 memcpy(value+18,addr->addr,6); @@ -2074,11 +2085,13 @@ static void SetAlarmDataCmd(uint16_t cmd,uint8_t *crcnum,uint16_t len,uint8_t *t }else{ if(data_len != 0){ memcpy(value+17,json_format,data_len); + free(json_format); } } value[data_len+17] = Calculate_CRC(value,data_len+17); sendBleData(value,data_len+17+1); + }else { uint8_t value[19]; @@ -2131,6 +2144,7 @@ static void aboutDeviceCmd(uint16_t cmd,uint8_t *crcnum,uint16_t len,uint8_t *to if(Check_CRC(crcnum,len,crcvalue)) { memcpy(value+17,(uint8_t *)json_format,data_len); + free(json_format); unsigned char lrc = Calculate_CRC(value,data_len+17); printf("lrc:%d",lrc); value[data_len+18] = lrc; @@ -2253,6 +2267,7 @@ static void GetCurDataCmd(uint16_t cmd,uint8_t *crcnum,uint16_t len,uint8_t *tot if(Check_CRC(crcnum,len,crcvalue)) { memcpy(value+17,(uint8_t *)json_format,data_len); + free(json_format); uint8_t lrc = Calculate_CRC(value,data_len+17); printf("lrc:%d",lrc); value[data_len+18] = lrc; @@ -2541,7 +2556,7 @@ static void SetRTDataFreCmd(uint16_t cmd,uint8_t *crcnum,uint16_t len,uint8_t *t if(Check_CRC(crcnum,len,crcvalue)) { uint8_t Frequence = crcnum[0];//频率单位是s - + set_traning_updata_freq(Frequence); value[17] = 1; //1 操作成功 2 操作失败 value[18] = Calculate_CRC(value,18); sendBleData(value,19); @@ -2632,9 +2647,11 @@ static void SetMaxHrRemindCmd(uint16_t cmd,uint8_t *crcnum,uint16_t len,uint8_t if(Check_CRC(crcnum,len,crcvalue))// { uint8_t maxHr = crcnum[0]; + if(maxHr > 250)maxHr = 250; else if(maxHr <= 0) maxHr = 0; + set_traning_heart_max(maxHr); //255 关闭 value[17] = 1; value[18] = Calculate_CRC(value,18); @@ -3983,7 +4000,7 @@ void Read_file_buf_send_bin_Data(uint8_t num,uint16_t id,uint8_t single_data_len } if(path==NULL) { - send_big_data(1,NULL,1,1,1,1,id); + send_big_data(1,NULL,1,1,1,1,id,1); sendbigDataBufState = false;//分包同步数据不允许打断 return; } @@ -3991,7 +4008,7 @@ void Read_file_buf_send_bin_Data(uint8_t num,uint16_t id,uint8_t single_data_len FILE *fp= fopen(path,"r+"); if(fp==NULL) { - send_big_data(1,NULL,1,1,1,1,id); + send_big_data(1,NULL,1,1,1,1,id,1); printf("打开文件失败%s\r\n",path); sendbigDataBufState = false;//分包同步数据不允许打断 return; @@ -4043,13 +4060,13 @@ void Read_file_buf_send_bin_Data(uint8_t num,uint16_t id,uint8_t single_data_len if(item_num-1==i) { printf("sendbuf :%s sendbuf_len%d\r\n",send_buf,send_len); - send_big_data(1,send_buf,send_len,item_num*5,Packet_id,packet_total,id); + send_big_data(1,send_buf,send_len,item_num*5,Packet_id,packet_total,id,1); free(send_buf); sendbigDataBufState=false; }else { - send_big_data(1,send_buf,send_len,item_num*5,Packet_id,packet_total,id); + send_big_data(1,send_buf,send_len,item_num*5,Packet_id,packet_total,id,1); free(send_buf); send_buf=(char *)malloc(sizeof(char)*HEART_DATA_LEN); send_len=0; 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 7bbb6270e..6c90bac78 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.h +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.h @@ -603,14 +603,22 @@ void getPhoneInfo_test(void); void setFindWatchFlag(uint8_t flag);//查找手表标识 errcode_t UnbindSucessCmd(uint8_t flag);// 1确认解绑 0取消解绑 发送解绑指令,解绑界面调用这个函数 如果点了✓调用这个函数 返回成功后延迟10s再重启设备 void getDeviceState(void); + void cleanUnbindInfor(uint8_t flag);//和旧手机解绑清除配对信息 0不清除配对信息 1清除配对信息重启 + void comfirmPaire(uint8_t flag);//发送确认配对指令 1确认配对 0取消配对 + void cameraSend(void); + void senfindphoneSend(uint8_t flag); + void readDevDataBle(uint8_t *crcnum,uint16_t len,uint8_t crcvalue); + void free_ble_data(void); void sendtraningdata(msg_get_train_data_info_t *data); + +void sendtraningstatedata(uint8_t state ,uint16_t time); #ifdef __cplusplus } #endif