From 2eed67dc7a07ac5ce9fb3fa3b9e15985bb0fce4e Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E8=83=A1=E4=BC=A0=E5=86=9B?= <1224667075@qq.com> Date: Thu, 3 Oct 2024 11:33:31 +0000 Subject: [PATCH] Merge #1085 into sdk602patch0626 from refs/changes/1085/head MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 对接文件读写锁 * refs/changes/1085/head: (4 commits squashed) - 对接文件读写锁 - 对接文件读写锁(补 - 每日目标数据上传增加安全保护 - Merge branch 'sdk602patch0626' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into 0626 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/1085 --- .../service/ble_service/blemoder/bletest.cpp | 66 ++++++++------ .../service/ble_service/bleservice/bleEvent.c | 87 +++++++++++++++++-- .../service/ble_service/bleservice/bleEvent.h | 2 + .../msg_center/src/msg_center_customer.cpp | 1 + .../drivers/peripheral/cywee/src/main_dml.c | 23 ++++- .../drivers/peripheral/utils/custom_runtime.c | 12 +++ .../drivers/peripheral/utils/custom_runtime.h | 9 ++ 7 files changed, 162 insertions(+), 38 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 06245c015..e2ecded8c 100644 --- a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp +++ b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp @@ -1250,27 +1250,35 @@ char * ble_sywee_history(uint8_t day,uint16_t *len ,uint8_t type) switch (type) { case 0x43: //同步步数历史数据 - get_now_hour_data(&value,CYWEE_SAVE_DATA_STEP); - if(value>0) + + if( get_now_hour_data(&value,CYWEE_SAVE_DATA_STEP)) { - memcpy(buf+size,&creationTime,4); - size+=4; - memcpy(buf+size,&value,4); - size+=4; + if(value>0) + { + memcpy(buf+size,&creationTime,4); + size+=4; + memcpy(buf+size,&value,4); + size+=4; + } } + break; case 0x44://同步燃脂时间数据 - get_now_hour_data(&value,CYWEE_SAVE_DATA_FAT); - if(value>0) + if(get_now_hour_data(&value,CYWEE_SAVE_DATA_FAT)) { - memcpy(buf+size,&creationTime,4); - size+=4; - uint16 temp_value= (value); - memcpy(buf+size,&(temp_value),2); - size+=2; + if(value>0) + { + memcpy(buf+size,&creationTime,4); + size+=4; + int16 temp_value= (value); + memcpy(buf+size,&(temp_value),2); + size+=2; + } } + break; case 0x45://同步站立历史数据 + if(get_stand_falg()) { memcpy(buf+size,&creationTime,4); @@ -1279,24 +1287,30 @@ char * ble_sywee_history(uint8_t day,uint16_t *len ,uint8_t type) break; case 0x46://同步卡路里历史数据 - get_now_hour_data(&f_value,CYWEE_SAVE_DATA_CALORIES); - if(f_value>0) - { - memcpy(buf+size,&creationTime,4); - size+=4; - memcpy(buf+size,&f_value,4); - size+=4; + if(get_now_hour_data(&f_value,CYWEE_SAVE_DATA_CALORIES)) + { + if(f_value>0) + { + memcpy(buf+size,&creationTime,4); + size+=4; + memcpy(buf+size,&f_value,4); + size+=4; + } } + break; case 0x47://同步距离历史数据 - get_now_hour_data(&f_value,CYWEE_SAVE_DATA_DISTANCE); - if(f_value>0) + if(get_now_hour_data(&f_value,CYWEE_SAVE_DATA_DISTANCE)) { - memcpy(buf+size,&creationTime,4); - size+=4; - memcpy(buf+size,&f_value,4); - size+=4; + if(f_value>0) + { + memcpy(buf+size,&creationTime,4); + size+=4; + memcpy(buf+size,&f_value,4); + size+=4; + } } + break; default: break; 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 c6b1df065..a0b4730e1 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c @@ -341,7 +341,6 @@ errcode_t sendBleData(uint8_t *buf,uint16_t len) #ifdef BLE_LOG printf("bigDataBufState:%d and sendbigDataBufState %d\r\n",bigDataBufState,sendbigDataBufState); #endif - if(bigDataBufState == true || sendbigDataBufState == true)return ERRCODE_FAIL; //在手表发送分包数据时 手表不允许发指令给app if(Bleconnect == true ) { ret = svr_ble_bt_gatts_noyify(buf,len); @@ -2273,7 +2272,7 @@ void SYN_train_heart_datatCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *t int num=(ble_nus_max_data_len-18); if(num>482)num=482; - int num_check=file_size%6; + int num_check=file_size%5; if(num_check!=0) { printf("数据有误 %d \r\n",cmd); @@ -3303,7 +3302,7 @@ bool bin_Check_sos(uint8_t *data,uint16_t len) { free(name); } - + ble_sos_data_save(); return true; @@ -6344,10 +6343,7 @@ void Read_BIN_file_buf_send_bin_Data(uint8_t day,uint32_t pack_size,uint16_t id) //手机app下发读设备数据指令 void readDevDataBle(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *totalData,uint8_t crcvalue) { - // if() - // { - - // } + uint8_t sendBuf[19]; memset(sendBuf,0,19); uint8_t type = cmd/256; @@ -6375,80 +6371,144 @@ void readDevDataBle(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *totalData,u switch (bleSendTypeID) { case 0x40://同步心率历史数据 - + if(uapi_dev_runtime_get_heartrate_storage_status()) + { + ble_reply_cmdarr(SYN_HEART_HISTORY_DATA_CMD,NULL,0); + return; + } num=(ble_nus_max_data_len-18); if(num>482)num=482; #ifdef BLE_LOG printf("同步心率数据,每包最多:%d 数据 data:%d %d\r\n",num,data[0],len); #endif + uapi_dev_runtime_set_heartrate_storage_status(1); if(!Read_Health_BIN_file_buf_send_bin_Data(data[0],num,0x40)) { ble_data_type type_={0x01,0x40,0,1,1}; send_big_data(type_,NULL,0); } + uapi_dev_runtime_set_heartrate_storage_status(0); //send_big_data(1,NULL,0,0,1,1,0x40,1); break; case 0x41://同步血氧历史数据 + if(uapi_dev_runtime_get_bloodoxygen_storage_status()) + { + ble_reply_cmdarr(SYN_SPO2_HISTORY_DATA_CMD,NULL,0); + return; + } num=(ble_nus_max_data_len-18); if(num>482)num=482; + uapi_dev_runtime_set_bloodoxygen_storage_status(1); if(!Read_Health_BIN_file_buf_send_bin_Data(data[0],num,0x41)) { ble_data_type type_={0x01,0x41,0,1,1}; send_big_data(type_,NULL,0); } + uapi_dev_runtime_set_bloodoxygen_storage_status(0); break; case 0x43: //同步步数历史数据 + + if(uapi_dev_runtime_get_goal_storage_status()) + { + ble_reply_cmdarr(SYN_STEP_HISTORY_DATA_CMD,NULL,0); + return; + } num=(ble_nus_max_data_len-18); if(num>482)num=482; - + uapi_dev_runtime_set_goal_storage_status(1); Read_BIN_file_buf_send_bin_Data(data[0],num,0x43); + uapi_dev_runtime_set_goal_storage_status(0); break; case 0x44://同步燃脂时间数据 + + if(uapi_dev_runtime_get_goal_storage_status()) + { + ble_reply_cmdarr(SYN_FAT_BURN_HISTORY_DATA_CMD,NULL,0); + return; + } + num=(ble_nus_max_data_len-18); if(num>482)num=482; + uapi_dev_runtime_set_goal_storage_status(1); Read_BIN_file_buf_send_bin_Data(data[0],num,0x44); + uapi_dev_runtime_set_goal_storage_status(0); break; case 0x45://同步站立历史数据 + if(uapi_dev_runtime_get_goal_storage_status()) + { + ble_reply_cmdarr(SYN_STAND_HISTORY_DATA_CMD,NULL,0); + return; + } + + num=(ble_nus_max_data_len-18); if(num>482) { num=482; } + uapi_dev_runtime_set_goal_storage_status(1); Read_BIN_file_buf_send_bin_Data(data[0],num,0x45); + uapi_dev_runtime_set_goal_storage_status(0); break; case 0x46://同步卡路里历史数据 + if(uapi_dev_runtime_get_goal_storage_status()) + { + ble_reply_cmdarr(SYN_KCAL_HISTORY_DATA_CMD,NULL,0); + return; + } + num=(ble_nus_max_data_len-18); if(num>482) { num=482; } + uapi_dev_runtime_set_goal_storage_status(1); Read_BIN_file_buf_send_bin_Data(data[0],num,0x46); + uapi_dev_runtime_set_goal_storage_status(0); break; case 0x47://同步距离历史数据 + + if(uapi_dev_runtime_get_goal_storage_status()) + { + ble_reply_cmdarr(SYN_DIS_HISTORY_DATA_CMD,NULL,0); + return; + } + num=(ble_nus_max_data_len-18); if(num>482) { num=482; } + uapi_dev_runtime_set_goal_storage_status(1); Read_BIN_file_buf_send_bin_Data(data[0],num,0x47); + uapi_dev_runtime_set_goal_storage_status(0); break; case 0x49://同步基础训练历史数据 + + if(uapi_dev_runtime_get_train_storage_status()) + { + ble_reply_cmdarr(SYN_BASIC_TRANIN_HISTORY_DATA_CMD,NULL,0); + return; + } + EACH_DATA_LEN = DIS_DATA_LEN; num=(ble_nus_max_data_len-18); if(num>482) { num=482; } + uapi_dev_runtime_set_train_storage_status(1); Send_json_Data_Cmd(data[0],num,0x49); + uapi_dev_runtime_set_train_storage_status(0); break; case 0x01://同步闹钟 EACH_DATA_LEN = DIS_DATA_LEN; @@ -6460,10 +6520,19 @@ void readDevDataBle(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *totalData,u Send_json_Data_Cmd(data[0],num,0x01); break; case 0x4b://睡眠历史数据 + + if(uapi_dev_runtime_get_sleep_storage_status()) + { + ble_reply_cmdarr(SYN_SLEEP_HISTORY_DATA_CMD,NULL,0); + return; + } + EACH_DATA_LEN = DIS_DATA_LEN; num=(ble_nus_max_data_len-18); if(num>482)num=482; + uapi_dev_runtime_set_sleep_storage_status(1); Send_Sleep_Bin_Data(data[0],num); + uapi_dev_runtime_set_sleep_storage_status(0); break; case 0x21://文件目录 EACH_DATA_LEN = DIS_DATA_LEN; 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 e46f1927d..204c99410 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.h +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.h @@ -84,6 +84,7 @@ void cameram_send_data(void); #define GET_PASSWORD_CMD 0x012F //app获取手机密码 #define ENTER_FACTORY_TEST_CMD 0x0130 //进入工厂测试模式 #define GET_SEDENT_CMD 0x0131 //获取久坐提醒设置 +//需要加锁数据 #define SYN_HEART_HISTORY_DATA_CMD 0x0140 //同步心率历史数据 #define SYN_SPO2_HISTORY_DATA_CMD 0x0141 //同步血氧历史数据 #define SYN_STRESS_HISTORY_DATA_CMD 0x0142 //同步压力历史数据 @@ -94,6 +95,7 @@ void cameram_send_data(void); #define SYN_DIS_HISTORY_DATA_CMD 0x0147 //同步距离历史数据 #define SYN_BASIC_TRANIN_HISTORY_DATA_CMD 0x0149 //同步基础训练历史数据basic training #define SYN_SLEEP_HISTORY_DATA_CMD 0x014B //同步睡眠历史数据 + #define SYN_GET_MSG_CONFIG_CMD 0x0133 //获取消息开关 #define APP_GET_AI_PCM_DATA_CMD 0x0134 //APP获取录音文件 #define APP_GET_SOS_DATA_CMD 0x0136 //APP获取SOS信息 diff --git a/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp b/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp index e5868cbb2..574f08922 100644 --- a/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp @@ -339,6 +339,7 @@ void MsgCenterNotifyONtimeProc(const Topic topic, Request* req) unused(req); // The alarm notification is not displayed if the incoming call notification is already being processed // cywee_save_data(); + do_cywee_service_check_msg(CYWEE_SERVICE_CMD_SAVE_DATA,NULL); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "保存每小时步数"); diff --git a/code/sdk/drivers/peripheral/cywee/src/main_dml.c b/code/sdk/drivers/peripheral/cywee/src/main_dml.c index 01dca4fa1..a8d1783d9 100644 --- a/code/sdk/drivers/peripheral/cywee/src/main_dml.c +++ b/code/sdk/drivers/peripheral/cywee/src/main_dml.c @@ -192,6 +192,12 @@ void cywee_get_version(char *databuf,uint8_t len) void cywee_save_data(void) { + if(uapi_dev_runtime_get_goal_storage_status()) + { + return; + } + uapi_dev_runtime_set_goal_storage_status(1); + int step=history_step+stepcount; CWM_OS_saveData(&step,sizeof(int),CYWEE_SAVE_DATA_STEP); CWM_OS_OneHourAgo_saveData(&history_step_,sizeof(int),CYWEE_SAVE_DATA_STEP); @@ -208,6 +214,8 @@ void cywee_save_data(void) int fat=history_fat+new_fat; CWM_OS_saveData(&fat,sizeof(int),CYWEE_SAVE_DATA_FAT); CWM_OS_OneHourAgo_saveData(&history_fat_,sizeof(uint16_t),CYWEE_SAVE_DATA_FAT); + + uapi_dev_runtime_set_goal_storage_status(0); } void cywee_restoreData(void) @@ -332,24 +340,33 @@ int32_t get_now_hour_data(void*value, uint8_t type) case CYWEE_SAVE_DATA_STEP: data= get_step_data()-history_step_; + if(data<0) + return 0; memcpy_s(value,4,&data,4); return 1; case CYWEE_SAVE_DATA_CALORIES: data =get_calories_data(); f_data=(float)data-history_calories_; + if(f_data<0) + return 0; memcpy_s(value,4,&f_data,4); return 1; case CYWEE_SAVE_DATA_DISTANCE: data= get_distance_data(); f_data=(float)data/1000.0-history_distances_; + if(f_data<0) + return 0; memcpy_s(value,4,&f_data,4); - break; + return 1; + case CYWEE_SAVE_DATA_FAT: data= get_fat_time_data(); - uint32_t data_=data/60-history_fat_; + int32_t data_=data/60-history_fat_; + if(data_<0) + return 0; memcpy_s(value,4,&data,4); - break; + return 1; default: break; } diff --git a/code/sdk/drivers/peripheral/utils/custom_runtime.c b/code/sdk/drivers/peripheral/utils/custom_runtime.c index 35e0d6a79..253e3417e 100644 --- a/code/sdk/drivers/peripheral/utils/custom_runtime.c +++ b/code/sdk/drivers/peripheral/utils/custom_runtime.c @@ -94,6 +94,8 @@ typedef struct uint8_t lock_flag_blood;//血氧 uint8_t lock_flag_sleep;//睡眠 + uint8_t lock_flag_goal;//每日目标数据 5个数据一起锁 + } runtime_status_t; @@ -516,6 +518,16 @@ uint8_t uapi_dev_runtime_get_sleep_storage_status(void) { return g_runtime.lock_flag_sleep; } + +//设置目标数据存储 +void uapi_dev_runtime_set_goal_storage_status(uint8_t status) +{ + g_runtime.lock_flag_goal = status; +} +uint8_t uapi_dev_runtime_get_goal_storage_status(void) +{ + return g_runtime.lock_flag_goal; +} //后续还需要补充。。。 // 设置被动心率检测状态 diff --git a/code/sdk/drivers/peripheral/utils/custom_runtime.h b/code/sdk/drivers/peripheral/utils/custom_runtime.h index 6e71c8ffd..0360c8e62 100644 --- a/code/sdk/drivers/peripheral/utils/custom_runtime.h +++ b/code/sdk/drivers/peripheral/utils/custom_runtime.h @@ -149,6 +149,15 @@ uint8_t uapi_dev_runtime_get_bloodoxygen_storage_status(void); void uapi_dev_runtime_set_sleep_storage_status(uint8_t status); uint8_t uapi_dev_runtime_get_sleep_storage_status(void); +/* + 每日目标数据存储 + 0 未存储 + 1 正在存储 +*/ +void uapi_dev_runtime_set_goal_storage_status(uint8_t status); + +uint8_t uapi_dev_runtime_get_goal_storage_status(void); + /*运动识别*/ void uapi_dev_runtime_set_motion_recognition_status(uint8_t status); uint8_t uapi_dev_runtime_get_motion_recognition_status(void); -- 2.17.1