From c734c7ff70d35063f09971a19e5a8c6c49c52327 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E8=83=A1=E4=BC=A0=E5=86=9B?= <1224667075@qq.com> Date: Mon, 1 Sep 2025 03:27:17 +0000 Subject: [PATCH] Merge #2189 into sdk650pathc0423 from refs/changes/2189/head MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Code review from 胡传军 * refs/changes/2189/head: (4 commits squashed) - ble处理函数安全性修改 - Merge branch 'sdk650pathc0423' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk650pathc0423 - ancs修改 - Merge branch 'sdk650pathc0423' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk650pathc0423 Signed-off-by: aliyun8003852482 <1224667075@qq.com> Merged-by: Caisking <3449750381@qq.com> CR-link: https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230/change/2189 --- .../ble_service/blemoder/bleInstruct.cpp | 259 ++++++++++-------- .../services/ble_service/bleservice/bleANCS.c | 46 ++-- 2 files changed, 166 insertions(+), 139 deletions(-) diff --git a/code/sdk/zhihui/services/ble_service/blemoder/bleInstruct.cpp b/code/sdk/zhihui/services/ble_service/blemoder/bleInstruct.cpp index 8751029b7..a3e9a090d 100644 --- a/code/sdk/zhihui/services/ble_service/blemoder/bleInstruct.cpp +++ b/code/sdk/zhihui/services/ble_service/blemoder/bleInstruct.cpp @@ -29,7 +29,34 @@ #include "cywee_data.h" #endif - +// 安全调用函数指针的宏定义 +#define SAFE_CALL(func_ptr, ...) \ + do { \ + if ((func_ptr) != NULL) { \ + (func_ptr)(__VA_ARGS__); \ + } else { \ + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Function pointer is NULL: %s", #func_ptr); \ + } \ + } while(0) + +#define SAFE_CALL_RETURN(func_ptr, ret_val, ...) \ + do { \ + if ((func_ptr) != NULL) { \ + ret_val = (func_ptr)(__VA_ARGS__); \ + } else { \ + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Function pointer is NULL: %s", #func_ptr); \ + ret_val = 0; \ + } \ + } while(0) + +#define SAFE_CALL_BOOL(func_ptr, ...) \ + ((func_ptr) != NULL ? (func_ptr)(__VA_ARGS__) : false) + +#define SAFE_CALL_PTR(func_ptr, ...) \ + ((func_ptr) != NULL ? (func_ptr)(__VA_ARGS__) : NULL) + +#define SAFE_CALL_PTR_NO_ARGS(func_ptr) \ + ((func_ptr) != NULL ? (func_ptr)() : NULL) // #include "font/base_font.h" // #include "uicomponents/UIComponents.h" @@ -81,7 +108,7 @@ errcode_t get_dial_file_path(char* input_dialname ,uint32_t input_size, char* ou uint8_t get_dial_num() { - return bleInstruct_t.get_dial_num_cb(); + return SAFE_CALL_PTR_NO_ARGS(bleInstruct_t.get_dial_num_cb); } bool ble_is_Alipay_bind(void) @@ -92,7 +119,7 @@ bool ble_is_Alipay_bind(void) void set_ota_upgrade(void) { - bleInstruct_t.set_ota_upgrade_cb(); + SAFE_CALL(bleInstruct_t.set_ota_upgrade_cb); } void test_paly(uint8_t falg) @@ -102,47 +129,47 @@ void test_paly(uint8_t falg) bool get_training_spead_path(char *path ,uint32_t time,uint32_t max_len) { - return bleInstruct_t.get_training_spead_path_cb(path,time,max_len); + return SAFE_CALL_BOOL(bleInstruct_t.get_training_spead_path_cb, path, time, max_len); } bool get_training_heart_path(char *path ,uint32_t time,uint32_t max_len) { - return bleInstruct_t.get_training_heart_path_cb(path,time,max_len); + return SAFE_CALL_BOOL(bleInstruct_t.get_training_heart_path_cb, path, time, max_len); } void ble_sos_data_save(void) { - bleInstruct_t.ble_sos_data_save_cb(); + SAFE_CALL(bleInstruct_t.ble_sos_data_save_cb); } void ble_SOS_data_init(void) { - bleInstruct_t.ble_SOS_data_init_cb(); + SAFE_CALL(bleInstruct_t.ble_SOS_data_init_cb); } void ota_updata_init(void) { - bleInstruct_t.ota_updata_init_cb(); + SAFE_CALL(bleInstruct_t.ota_updata_init_cb); } uint8_t * ble_get_sos_all_data_malloc(uint32_t *len) { - return bleInstruct_t.ble_get_sos_all_data_malloc_cb(len); + return SAFE_CALL_PTR(bleInstruct_t.ble_get_sos_all_data_malloc_cb, len); } #define before_file_day 30 //sos void ble_sos_number_clean(void) { - return bleInstruct_t.ble_sos_number_clean_cb(); + SAFE_CALL(bleInstruct_t.ble_sos_number_clean_cb); } bool ble_add_sos_number(uint8_t sex,char *name,char *number) { - return bleInstruct_t.ble_add_sos_number_cb(sex,name,number); + return SAFE_CALL_BOOL(bleInstruct_t.ble_add_sos_number_cb, sex, name, number); } void ble_Alipayunbind(void) @@ -154,18 +181,18 @@ void ble_Alipayunbind(void) void get_music_path(char *buf,uint8_t max_len) { - return bleInstruct_t.get_music_path_cb(buf,max_len); + SAFE_CALL(bleInstruct_t.get_music_path_cb, buf, max_len); } bool is_first_pair(void) { - return bleInstruct_t.is_first_pair_cb(); + return SAFE_CALL_BOOL(bleInstruct_t.is_first_pair_cb); } bool Ble_Set_ScheduleInfo(uint8_t id,uint32_t timetamp_begin,uint32_t timetamp_end,char *title,char *data,bool is_end) { - return bleInstruct_t.Ble_Set_ScheduleInfo_cb( id, timetamp_begin, timetamp_end,title,data, is_end); + return SAFE_CALL_BOOL(bleInstruct_t.Ble_Set_ScheduleInfo_cb, id, timetamp_begin, timetamp_end, title, data, is_end); } @@ -173,100 +200,96 @@ bool Ble_Set_ScheduleInfo(uint8_t id,uint32_t timetamp_begin,uint32_t timetamp_e //在此处实现,给UI回复消息。 void ble_app_reply(bool data) { - return bleInstruct_t.ble_app_reply(data); + SAFE_CALL(bleInstruct_t.ble_app_reply, data); } void ble_connect_ok(void) { - return bleInstruct_t.ble_connect_ok(); + SAFE_CALL(bleInstruct_t.ble_connect_ok); } void ble_disconnect_ok(void) { - if( bleInstruct_t.ble_disconnect_ok==NULL) - { - return; - } - return bleInstruct_t.ble_disconnect_ok(); + SAFE_CALL(bleInstruct_t.ble_disconnect_ok); } void hand_watch_first_time_Paired(void) { - return bleInstruct_t.hand_watch_first_time_Paired(); + SAFE_CALL(bleInstruct_t.hand_watch_first_time_Paired); } void ble_set_ai_Question_str(char *buf) { - return bleInstruct_t.ble_set_ai_Question_str(buf); + SAFE_CALL(bleInstruct_t.ble_set_ai_Question_str, buf); } void ble_set_ai_Answer_str(char *buf,uint8_t type) { - return bleInstruct_t.ble_set_ai_Answer_str(buf,type); + SAFE_CALL(bleInstruct_t.ble_set_ai_Answer_str, buf, type); } char* ble_get_ai_audio_path_str(void) { - return bleInstruct_t.ble_get_ai_audio_path_str(); + return SAFE_CALL_PTR(bleInstruct_t.ble_get_ai_audio_path_str); } void ble_set_pair(uint8_t falg) { - return bleInstruct_t.ble_set_pair(falg); + SAFE_CALL(bleInstruct_t.ble_set_pair, falg); } uint8_t get_ble_pair(void) { - return bleInstruct_t.get_ble_pair(); + return SAFE_CALL_PTR_NO_ARGS(bleInstruct_t.get_ble_pair); } uint8_t get_br_is_pair(void) { - return bleInstruct_t.get_br_is_pair(); + return SAFE_CALL_PTR_NO_ARGS(bleInstruct_t.get_br_is_pair); } void set_br_pair(uint8_t data) { - return bleInstruct_t.set_br_pair(data); + SAFE_CALL(bleInstruct_t.set_br_pair, data); } bool get_lcd_state(void) { - return bleInstruct_t.get_lcd_state(); + return SAFE_CALL_BOOL(bleInstruct_t.get_lcd_state); } uint8_t ble_get_heart_data() { - return bleInstruct_t.ble_get_heart_data(); + return SAFE_CALL_PTR_NO_ARGS(bleInstruct_t.ble_get_heart_data); } uint8_t ble_get_oxygen_data() { - return bleInstruct_t.ble_get_oxygen_data(); + return SAFE_CALL_PTR_NO_ARGS(bleInstruct_t.ble_get_oxygen_data); } cJSON* ble_get_recs_data() { - return bleInstruct_t.ble_get_recs_data(); + return SAFE_CALL_PTR(bleInstruct_t.ble_get_recs_data); } //通过时间戳获取训练数据 cJSON* ble_get_Trainingdata_by_timetamp(uint32_t timetamp) { - return bleInstruct_t .ble_get_Trainingdata_by_timetamp(timetamp); + return SAFE_CALL_PTR(bleInstruct_t.ble_get_Trainingdata_by_timetamp, timetamp); } bool delete_MP3_file_By_ID(uint16_t id) { - return bleInstruct_t .delete_MP3_file_By_ID(id); + return SAFE_CALL_BOOL(bleInstruct_t.delete_MP3_file_By_ID, id); } char * dir_to_json_buf_malloc(uint8_t type) { - return bleInstruct_t .dir_to_json_buf_malloc(type); + return SAFE_CALL_PTR(bleInstruct_t.dir_to_json_buf_malloc, type); } @@ -274,12 +297,12 @@ char * dir_to_json_buf_malloc(uint8_t type) uint8_t ble_AT_add_nap_data(uint16_t time) { - return bleInstruct_t .ble_AT_add_nap_data(time); + return SAFE_CALL_PTR(bleInstruct_t.ble_AT_add_nap_data, time); } uint8_t ble_get_sleep_data(uint32_t file_size,uint8_t day_,uint8_t *data) { - return bleInstruct_t .ble_get_sleep_data(file_size,day_,data); + return SAFE_CALL_PTR(bleInstruct_t.ble_get_sleep_data, file_size, day_, data); } @@ -287,17 +310,17 @@ uint8_t ble_get_sleep_data(uint32_t file_size,uint8_t day_,uint8_t *data) uint8_t ble_get_sleep_data_dir(uint32_t *file_size,uint8_t day_) { - return bleInstruct_t .ble_get_sleep_data_dir(file_size,day_); + return SAFE_CALL_PTR(bleInstruct_t.ble_get_sleep_data_dir, file_size, day_); } void ble_set_password(uint8_t falg, char * data) { - return bleInstruct_t .ble_set_password(falg,data); + SAFE_CALL(bleInstruct_t.ble_set_password, falg, data); } uint8_t ble_get_password(void) { - return bleInstruct_t .ble_get_password(); + return SAFE_CALL_PTR_NO_ARGS(bleInstruct_t.ble_get_password); } // void set_sedent_param(msg_sedent_set_param_info_t * data) @@ -309,21 +332,21 @@ uint8_t ble_get_password(void) void get_sedent_param( msg_sedent_set_param_info_t * data) { - return bleInstruct_t.get_sedent_param(data); + SAFE_CALL(bleInstruct_t.get_sedent_param, data); } bool check_dial_freespace(uint16_t id,uint32_t dial_size) { - return bleInstruct_t.check_dial_freespace(id,dial_size); + return SAFE_CALL_BOOL(bleInstruct_t.check_dial_freespace, id, dial_size); } void ble_get_dial_path(char * buf,uint16_t id) { - return bleInstruct_t.ble_get_dial_path(buf,id); + SAFE_CALL(bleInstruct_t.ble_get_dial_path, buf, id); } void ble_save_dial_custom(msg_recv_custom_dial_info_t *data) { - return bleInstruct_t.ble_save_dial_custom(data); + SAFE_CALL(bleInstruct_t.ble_save_dial_custom, data); } // void ble_set_dial_by_id_(uint16_t id) @@ -334,29 +357,29 @@ void ble_save_dial_custom(msg_recv_custom_dial_info_t *data) void ble_set_dial_by_id(uint16_t id) { // printf("ble_set_dial_by_id %d\n",id); - return bleInstruct_t.ble_set_dial_by_id(id); + SAFE_CALL(bleInstruct_t.ble_set_dial_by_id, id); } void ble_get_custom_dial(uint16_t id,char *buf) { - return bleInstruct_t.ble_get_custom_dial(id,buf); + SAFE_CALL(bleInstruct_t.ble_get_custom_dial, id, buf); } uint16_t ble_get_dial_id(void) { - return bleInstruct_t.ble_get_dial_id(); + return SAFE_CALL_PTR_NO_ARGS(bleInstruct_t.ble_get_dial_id); } bool ble_is_dial_install_by_id(uint16_t id) { - return bleInstruct_t.ble_is_dial_install_by_id(id); + return SAFE_CALL_BOOL(bleInstruct_t.ble_is_dial_install_by_id, id); } int ble_get_dial_num(void) { - return bleInstruct_t.ble_get_dial_num(); + return SAFE_CALL_PTR_NO_ARGS(bleInstruct_t.ble_get_dial_num); } // void ble_delete_dial_(uint16_t id) @@ -367,18 +390,18 @@ int ble_get_dial_num(void) bool ble_delete_dial(uint16_t id) { - return bleInstruct_t.ble_delete_dial(id); + return SAFE_CALL_BOOL(bleInstruct_t.ble_delete_dial, id); } int get_all_dial_id( char * buf,uint16_t MAX_LEN) { - return bleInstruct_t.get_all_dial_id(buf,MAX_LEN); + return SAFE_CALL_PTR(bleInstruct_t.get_all_dial_id, buf, MAX_LEN); } bool dial_file_save(void ) { - return bleInstruct_t.dial_file_save(); + return SAFE_CALL_BOOL(bleInstruct_t.dial_file_save); } // void install_Register_dial_( char * name,uint16_t id) @@ -388,7 +411,7 @@ bool dial_file_save(void ) // } void install_Register_dial( char * name,uint16_t id) { - return bleInstruct_t.install_Register_dial(name,id); + SAFE_CALL(bleInstruct_t.install_Register_dial, name, id); } @@ -698,13 +721,13 @@ char * ble_sywee_history(uint8_t day,uint16_t *len ,uint8_t type) void ble_set_sleep_remind(msg_get_sleep_param_info_t data) { - return bleInstruct_t.ble_set_sleep_remind(data); + SAFE_CALL(bleInstruct_t.ble_set_sleep_remind, data); } void ble_get_sleep_remind(msg_get_sleep_param_info_t *data) { - return bleInstruct_t.ble_get_sleep_remind(data); + SAFE_CALL(bleInstruct_t.ble_get_sleep_remind, data); } @@ -714,13 +737,13 @@ void ble_get_sleep_remind(msg_get_sleep_param_info_t *data) void ble_set_drink_remind(msg_drink_info_t data) { - return bleInstruct_t.ble_set_drink_remind(data); + SAFE_CALL(bleInstruct_t.ble_set_drink_remind, data); } void ble_get_drink_remind(msg_drink_info_t *data) { - return bleInstruct_t.ble_get_drink_remind(data); + SAFE_CALL(bleInstruct_t.ble_get_drink_remind, data); } // 闹钟数据: @@ -738,13 +761,13 @@ static const char *alarmName[6] = {"clock1", "clock2", "clock3", "clock4", "cloc void ble_delet_all_AlarmInfo(void) { - return bleInstruct_t.ble_delet_all_AlarmInfo(); + SAFE_CALL(bleInstruct_t.ble_delet_all_AlarmInfo); } void ble_SetAlarmInfo(uint32_t time_hour, uint32_t time_min, uint8_t week,uint8_t id,uint8_t enable) { // OHOS::uapi_connect_pbap_pce(); - return bleInstruct_t.ble_SetAlarmInfo(time_hour,time_min,week,id,enable); + SAFE_CALL(bleInstruct_t.ble_SetAlarmInfo, time_hour, time_min, week, id, enable); } @@ -756,12 +779,12 @@ void ble_AlarmClock_refresh(void) char * struct_to_json_buf_malloc_Alarm(void) { - return bleInstruct_t.struct_to_json_buf_malloc_Alarm(); + return SAFE_CALL_PTR(bleInstruct_t.struct_to_json_buf_malloc_Alarm); } char * struct_to_json_buf_malloc(uint8_t day) { - return bleInstruct_t.struct_to_json_buf_malloc(day); + return SAFE_CALL_PTR(bleInstruct_t.struct_to_json_buf_malloc, day); } #define TAR_PATH EXC_TAR_PATH @@ -928,7 +951,7 @@ char * tar_dir_to_json_buf_malloc_(char* file_name,uint32_t *file_size) void add_addressbookToRead(char *data) { - return bleInstruct_t.add_addressbookToRead(data); + SAFE_CALL(bleInstruct_t.add_addressbookToRead, data); } static uint32_t languaage_id=0; @@ -945,125 +968,125 @@ char *addressbook(void)//获取通讯录保存文件地址路径 void addressbookToRead(char *buf)//转化用于·c文件 { - return bleInstruct_t.addressbookToRead(buf); + SAFE_CALL(bleInstruct_t.addressbookToRead, buf); } void addressbookTowrite(void)//转化用于·c文件 { - return bleInstruct_t.addressbookTowrite(); + SAFE_CALL(bleInstruct_t.addressbookTowrite); } uint8_t ble_falg=0; void set_user_data(msg_user_info_t *data) { - return bleInstruct_t.set_user_data(data); + SAFE_CALL(bleInstruct_t.set_user_data, data); } int get_goal_stepcount(void) { - return bleInstruct_t.get_goal_stepcount(); + return SAFE_CALL_PTR_NO_ARGS(bleInstruct_t.get_goal_stepcount); } int get_goal_caloriescount(void)//获取运动目标卡路里 { - return bleInstruct_t.get_goal_caloriescount(); + return SAFE_CALL_PTR_NO_ARGS(bleInstruct_t.get_goal_caloriescount); } int get_goal_discount(void)//获取运动目标卡路里 { - return bleInstruct_t.get_goal_discount(); + return SAFE_CALL_PTR_NO_ARGS(bleInstruct_t.get_goal_discount); } int get_vibrationremiander(void) { - return bleInstruct_t.get_vibrationremiander(); + return SAFE_CALL_PTR_NO_ARGS(bleInstruct_t.get_vibrationremiander); } int get_SilentMode(void) { - return bleInstruct_t.get_SilentMode(); + return SAFE_CALL_PTR_NO_ARGS(bleInstruct_t.get_SilentMode); } void set_quick_auxiliary_paramters(uint8_t id)//设置快捷辅助功能参数id { - return bleInstruct_t.set_quick_auxiliary_paramters(id); + SAFE_CALL(bleInstruct_t.set_quick_auxiliary_paramters, id); } int get_quick_auxiliary_paramters(void)//获取快捷辅助功能参数id { - return bleInstruct_t.get_quick_auxiliary_paramters(); + return SAFE_CALL_PTR_NO_ARGS(bleInstruct_t.get_quick_auxiliary_paramters); } void set_goal_stepcount(uint32_t step) { - return bleInstruct_t.set_goal_stepcount(step); + SAFE_CALL(bleInstruct_t.set_goal_stepcount, step); } void set_goal_caloriescount(uint32_t kcal) { - return bleInstruct_t.set_goal_caloriescount(kcal); + SAFE_CALL(bleInstruct_t.set_goal_caloriescount, kcal); } void set_notify_switch(bool on) { - return bleInstruct_t.set_notify_switch(on); + SAFE_CALL(bleInstruct_t.set_notify_switch, on); } bool get_notify_switch(void) { - return bleInstruct_t.get_notify_switch(); + return SAFE_CALL_BOOL(bleInstruct_t.get_notify_switch); } uint8_t get_other_goal_notify_switch(void) { - return bleInstruct_t.get_other_goal_notify_switch(); + return SAFE_CALL_PTR_NO_ARGS(bleInstruct_t.get_other_goal_notify_switch); } uint8_t get_step_goal_notify_switch(void) { - return bleInstruct_t.get_step_goal_notify_switch(); + return SAFE_CALL_PTR_NO_ARGS(bleInstruct_t.get_step_goal_notify_switch); } void set_goal_discount(uint32_t dis) { - return bleInstruct_t.set_goal_discount(dis); + SAFE_CALL(bleInstruct_t.set_goal_discount, dis); } void set_goal_durationcount(uint32_t time) { - return bleInstruct_t.set_goal_durationcount(time); + SAFE_CALL(bleInstruct_t.set_goal_durationcount, time); } int get_goal_durationcount(void) { - return bleInstruct_t.get_goal_durationcount(); + return SAFE_CALL_PTR_NO_ARGS(bleInstruct_t.get_goal_durationcount); } void set_goal_standupcount(uint32_t time) { - return bleInstruct_t.set_goal_standupcount(time); + SAFE_CALL(bleInstruct_t.set_goal_standupcount, time); } int get_goal_standupcount(void) { - return bleInstruct_t.get_goal_standupcount(); + return SAFE_CALL_PTR_NO_ARGS(bleInstruct_t.get_goal_standupcount); } void set_vibrationremiander(uint8_t falg)//设置震动模式 { - return bleInstruct_t.set_vibrationremiander(falg); + SAFE_CALL(bleInstruct_t.set_vibrationremiander, falg); } void set_SilentMode(uint8_t falg)//设置静音模式 { - return bleInstruct_t.set_SilentMode(falg); + SAFE_CALL(bleInstruct_t.set_SilentMode, falg); } /*设置自动获取实时数据开关*/ void set_traning_updata_auto(uint8_t traingauto) { - return bleInstruct_t.set_traning_updata_auto(traingauto); + SAFE_CALL(bleInstruct_t.set_traning_updata_auto, traingauto); } void set_goal_other_notification(uint8_t data) { - return bleInstruct_t.set_goal_other_notification(data); + SAFE_CALL(bleInstruct_t.set_goal_other_notification, data); } void set_goal_step_notification(uint8_t data) { - return bleInstruct_t.set_goal_step_notification(data); + SAFE_CALL(bleInstruct_t.set_goal_step_notification, data); } @@ -1073,89 +1096,89 @@ void set_goal_step_notification(uint8_t data) /*设置获取实时数据频率*/ void set_traning_updata_freq(uint8_t freq) { - return bleInstruct_t.set_traning_updata_freq(freq); + SAFE_CALL(bleInstruct_t.set_traning_updata_freq, freq); } /*设置最大心率提醒*/ void set_traning_heart_max(uint8_t data) { - return bleInstruct_t.set_traning_heart_max(data); + SAFE_CALL(bleInstruct_t.set_traning_heart_max, data); } void set_brigthness(uint8_t data) //设置屏幕亮度 { - return bleInstruct_t.set_brigthness(data); + SAFE_CALL(bleInstruct_t.set_brigthness, data); } void Set_DmpChangeMode(int state) { - return bleInstruct_t.Set_DmpChangeMode(state); + SAFE_CALL(bleInstruct_t.Set_DmpChangeMode, state); } void Set_heart_cmd(msg_get_heart_set_param_info_t *data) { - return bleInstruct_t.Set_heart_cmd(data); + SAFE_CALL(bleInstruct_t.Set_heart_cmd, data); } void Get_heart_cmd(msg_get_heart_set_param_info_t *data) { - return bleInstruct_t.Get_heart_cmd(data); + SAFE_CALL(bleInstruct_t.Get_heart_cmd, data); } void Set_oxygen_cmd(msg_get_spo2_set_param_info_t *data) { - return bleInstruct_t.Set_oxygen_cmd(data); + SAFE_CALL(bleInstruct_t.Set_oxygen_cmd, data); } void Get_oxygen_cmd(msg_get_spo2_set_param_info_t *data) { - return bleInstruct_t.Get_oxygen_cmd(data); + SAFE_CALL(bleInstruct_t.Get_oxygen_cmd, data); } int Get_DmpChangeMode(void) { - return bleInstruct_t.Get_DmpChangeMode(); + return SAFE_CALL_PTR_NO_ARGS(bleInstruct_t.Get_DmpChangeMode); } int get_brigthness(void) //获取屏幕亮度 { - return bleInstruct_t.get_brigthness(); + return SAFE_CALL_PTR_NO_ARGS(bleInstruct_t.get_brigthness); } void set_ScreenDuration(int data) //设置亮屏时长 { - return bleInstruct_t.set_ScreenDuration(data); + SAFE_CALL(bleInstruct_t.set_ScreenDuration, data); } int get_ScreenDuration(void) //获取亮屏时长 { - return bleInstruct_t.get_ScreenDuration(); + return SAFE_CALL_PTR_NO_ARGS(bleInstruct_t.get_ScreenDuration); } void Set_RaiseToWake(bool value) //抬婉亮屏开关 { - return bleInstruct_t.Set_RaiseToWake(value); + SAFE_CALL(bleInstruct_t.Set_RaiseToWake, value); } int Get_RaiseToWake(void) //获取抬婉亮屏开关 { - return bleInstruct_t.Get_RaiseToWake(); + return SAFE_CALL_PTR_NO_ARGS(bleInstruct_t.Get_RaiseToWake); } void Set_SystemVolume(int value) //设置系统音量 { - return bleInstruct_t.Set_SystemVolume(value); + SAFE_CALL(bleInstruct_t.Set_SystemVolume, value); } int Get_SystemVolume(void) //获取系统音量 { - return bleInstruct_t.Get_SystemVolume(); + return SAFE_CALL_PTR_NO_ARGS(bleInstruct_t.Get_SystemVolume); } void Set_CallVolume(int value) //设置通话音量 { - return bleInstruct_t.Set_CallVolume(value); + SAFE_CALL(bleInstruct_t.Set_CallVolume, value); } int Get_CallVolume(void) //获取通话音量 { - return bleInstruct_t.Get_CallVolume(); + return SAFE_CALL_PTR_NO_ARGS(bleInstruct_t.Get_CallVolume); } uint8_t ble_is_ready(void) @@ -1171,25 +1194,25 @@ void set_ble_falg(bool falg) void get_health_HEART_data_path(char *path, uint8_t day,uint16_t max_size) { - return bleInstruct_t.get_health_HEART_data_path(path,day,max_size); + SAFE_CALL(bleInstruct_t.get_health_HEART_data_path, path, day, max_size); } void get_health_OXYGEN_data_path(char *path, uint8_t day,uint16_t max_size) { - return bleInstruct_t.get_health_OXYGEN_data_path(path,day,max_size); + SAFE_CALL(bleInstruct_t.get_health_OXYGEN_data_path, path, day, max_size); } void set_weather_now_data(int humidity, char* windScale, char* textNight,int uvIndex,int temp,int iconNight) { //UpdateWeatherViewData(); - return bleInstruct_t.set_weather_now_data(humidity,windScale,textNight,uvIndex,temp,iconNight); + SAFE_CALL(bleInstruct_t.set_weather_now_data, humidity, windScale, textNight, uvIndex, temp, iconNight); } void set_weather_address_data(int lat, char* atm, char* city,char* subLocality,int lon) { - return bleInstruct_t.set_weather_address_data(lat,atm,city,subLocality,lon); + SAFE_CALL(bleInstruct_t.set_weather_address_data, lat, atm, city, subLocality, lon); } // struct ONE_DAY_DATA // { @@ -1202,7 +1225,7 @@ void set_weather_address_data(int lat, char* atm, char* city,char* subLocality,i void set_weather_one_data(int tempMin, int iconDay,int fxDate, int tempMax, char *textDay,int count) { - return bleInstruct_t.set_weather_one_data(tempMin,iconDay,fxDate,tempMax,textDay,count); + SAFE_CALL(bleInstruct_t.set_weather_one_data, tempMin, iconDay, fxDate, tempMax, textDay, count); } @@ -1213,7 +1236,7 @@ void ble_UpdateMainWeatherData(void) void ble_add_message_index(uint32_t old_index) { - return bleInstruct_t.ble_add_message_index(old_index); + SAFE_CALL(bleInstruct_t.ble_add_message_index, old_index); } void SendDtfmStrNumberToCat1(char ch) // ble发送单个字符到CAT1 DTMF功能 @@ -1230,31 +1253,31 @@ void ble_mp3_list_update(void) bool IS_free_save_Mp3(uint32_t size) { - return bleInstruct_t.IS_free_save_Mp3(size); + return SAFE_CALL_BOOL(bleInstruct_t.IS_free_save_Mp3, size); } bool ble_bin_install(const char * data) { - return bleInstruct_t.ble_bin_install(data); + return SAFE_CALL_BOOL(bleInstruct_t.ble_bin_install, data); } bool ble_app_delete(const char *data) { - return bleInstruct_t.ble_app_delete(data); + return SAFE_CALL_BOOL(bleInstruct_t.ble_app_delete, data); } cJSON* ble_app_list(void) { - return bleInstruct_t.ble_app_list(); + return SAFE_CALL_PTR(bleInstruct_t.ble_app_list); } cJSON* ble_get_watch_msg(void) { - return bleInstruct_t.ble_get_watch_msg(); + return SAFE_CALL_PTR(bleInstruct_t.ble_get_watch_msg); } diff --git a/code/sdk/zhihui/services/ble_service/bleservice/bleANCS.c b/code/sdk/zhihui/services/ble_service/bleservice/bleANCS.c index 830ccfece..9e8d0d40a 100644 --- a/code/sdk/zhihui/services/ble_service/bleservice/bleANCS.c +++ b/code/sdk/zhihui/services/ble_service/bleservice/bleANCS.c @@ -235,7 +235,7 @@ static uint8_t ble_ancs_client_at_cmd_get_notify_att(uint16_t conn_id,uint32_t n { /* 获取来电通知属性 */ - ble_ancs_notification_attr_req_t *notify_attr_req = bt_os_new( + ble_ancs_notification_attr_req_t *notify_attr_req = bts_sample_mem_new( sizeof(ble_ancs_notification_attr_req_t) + (5 * sizeof(ble_ancs_attr_req_t))); notify_attr_req->att_num = 5; notify_attr_req->notification_uid = notify_uid; @@ -257,7 +257,7 @@ static uint8_t ble_ancs_client_at_cmd_get_notify_att(uint16_t conn_id,uint32_t n //decode_att_req_from_str(argv[BT_INDEX_4], notify_attr_req->attr); errcode_t ret = ble_ancs_client_send_get_notify_att_cmd(g_client_id, conn_id, notify_attr_req); - bt_os_free(notify_attr_req); + bts_sample_mem_free(notify_attr_req); printf("ble ancs client notify att get ret:0x%x\r\n", ret); return 0; } @@ -356,49 +356,53 @@ static void ble_ancs_client_notification_attr_rsp_cbk(uint8_t client_id, uint16_ } printf("[ANCSClientNotifyATTRSPCBK]conn_id:%d status:0x%x notify_uid:%lu\r\n", - conn_id, status, notify_attr_rsp->notification_uid); + conn_id, status, notify_attr_rsp->notification_uid); - ble_ancs_attr_rsp_t *node = NULL ;//(ble_ancs_attr_rsp_t *)notify_attr_rsp->attr_rsp_lst.head; + struct osal_list_head *list_head = &(notify_attr_rsp->attr_rsp_lst); + struct osal_list_head *node = list_head->next; + + // ble_ancs_attr_rsp_t *node = (ble_ancs_attr_rsp_t *)notify_attr_rsp->attr_rsp_lst.head; uint16_t att_num = 0; time_t timestamp = 0; - while (node != NULL) { - if (node->att != NULL) { + while (node != NULL && node != list_head) { + ble_ancs_attr_rsp_t *attr_node = (ble_ancs_attr_rsp_t *)node; + if (attr_node->att != NULL) { printf("[ANCSClientNotifyATTRSPCBK]att id:%d length:%lu att_value:%s\r\n", - node->att_id, node->att_length, node->att); + attr_node->att_id, attr_node->att_length, attr_node->att); - size_t att_length = strlen((char*)node->att); - if (node->att_id == 1) { + size_t att_length = strlen((char*)attr_node->att); + if (attr_node->att_id == 1) { memset_s(title_buf, 300, 0, 300); if (att_length < 300) { - memcpy_s(title_buf, 300, node->att, att_length); + memcpy_s(title_buf, 300, attr_node->att, att_length); } else { - printf("标题缓冲区溢出: %s\r\n", node->att); + printf("标题缓冲区溢出: %s\r\n", attr_node->att); } - } else if (node->att_id == 3) { + } else if (attr_node->att_id == 3) { memset_s(msg_buf, 300, 0,300); if (att_length < 300) { - memcpy_s(msg_buf, 300, node->att, att_length); + memcpy_s(msg_buf, 300, attr_node->att, att_length); } else { - printf("消息缓冲区溢出: %s\r\n", node->att); + printf("消息缓冲区溢出: %s\r\n", attr_node->att); } - } else if (node->att_id == 0) { + } else if (attr_node->att_id == 0) { memset_s(app_buf, 70, 0, 70); if (att_length < 70) { - memcpy_s(app_buf,70, node->att, att_length); + memcpy_s(app_buf,70, attr_node->att, att_length); } else { - printf("应用缓冲区溢出: %s\r\n", node->att); + printf("应用缓冲区溢出: %s\r\n", attr_node->att); } - } else if (node->att_id == 5) { + } else if (attr_node->att_id == 5) { struct tm tm = {0}; - if (strptime((const char *)node->att, "%Y%m%dT%H%M%S", &tm) != NULL) { + if (strptime((const char *)attr_node->att, "%Y%m%dT%H%M%S", &tm) != NULL) { timestamp = mktime(&tm); } else { - printf("时间字符串解析失败: %s\r\n", node->att); + printf("时间字符串解析失败: %s\r\n", attr_node->att); } } } - node = lnext(node); + node = node->next; att_num++; if (att_num >= notify_attr_rsp->att_num) { break; -- 2.17.1