From f4bcb5aa0c155b986e1b59c3540ffa231feb1bc1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E8=83=A1=E4=BC=A0=E5=86=9B?= <1224667075@qq.com> Date: Wed, 12 Jun 2024 03:39:06 +0000 Subject: [PATCH] Merge #261 into sdk602patch0521 from refs/changes/261/head MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Code review from 胡传军 * refs/changes/261/head: (3 commits squashed) - 卡路里距离历史数据同步 - 增加传输过程UI长亮 - Merge branch 'sdk602patch0521' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0521 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/261 --- .../service/ble_service/blemoder/bletest.cpp | 65 +++++++------------ .../service/ble_service/blemoder/bletest.h | 3 +- .../service/ble_service/bleservice/bleEvent.c | 41 ++++-------- .../msg_center/src/msg_center_customer.cpp | 32 ++++++++- .../msg_center/src/notify/transmitting.cpp | 17 ++++- .../drivers/peripheral/cywee/Inc/cywee_hal.h | 15 ++++- .../peripheral/cywee/src/board_yh601s.c | 55 +++++++++++----- .../drivers/peripheral/cywee/src/main_dml.c | 32 ++++++++- 8 files changed, 170 insertions(+), 90 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 2512104fc..e8bffe48d 100644 --- a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp +++ b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp @@ -59,58 +59,43 @@ extern "C" { #include "string.h" #include "bleService.h" #include "bletest.h" +#include #define CWM_HISTORY_DATA_PATH "/user/userdata/step_" -char * ble_step_history(uint8_t day,uint16_t *len) -{ - char path_[64]={0}; - char timeday[12] = {0}; - uapi_get_YYMMDD_Time(timeday, '_'); - sprintf_s(path_,64,"%s%s.bin",CWM_HISTORY_DATA_PATH,timeday); - - FILE * fp = fopen(path_,"rb+"); - if(fp==NULL) - { - printf("fopen fail\r\n"); - return NULL; - } - uint32_t size; - if (fp != NULL) - { - fseek(fp, 0, SEEK_END); // 将文件指针移动到文件末尾 - size = ftell(fp); // 获取当前文件指针位置,即文件大小 - fseek(fp, 0, SEEK_SET); // 将文件指针移回文件开头 - } - printf("size %d \r\n",size); +#define CWM_HISTORY_DATA_CALORIES_PATH "/user/userdata/calories_" - char * buf=(char *)malloc(size); - if(buf==NULL) - { - printf("malloc fail\r\n"); - return buf; - } - uint32_t ret= fread(buf,1,size,fp); - - printf("fread %d \r\n",ret); - for(int i=0;i482) + { + num=482; + } + Read_BIN_file_buf_send_bin_Data(num,0x46); break; case 0x47://同步距离历史数据 - EACH_DATA_LEN = DIS_DATA_LEN; - num=(ble_nus_max_data_len-18)/EACH_DATA_LEN; - Read_JSON_file_buf_send_bin_Data(num,0x47,"heart_data_list"); + num=(ble_nus_max_data_len-18); + if(num>482) + { + num=482; + } + Read_BIN_file_buf_send_bin_Data(num,0x47); break; case 0x49://同步基础训练历史数据 EACH_DATA_LEN = DIS_DATA_LEN; 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 3c4d271de..68252f18e 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 @@ -270,10 +270,17 @@ 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(); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "保存每小时步数"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "保存每小时步数"); step_history_save(); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "保存每小时站立数据"); stand_history_save(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "保存每小时卡路里数据"); + calories_history_save(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "保存每小时距离数据"); + distances_history_save(); + + + } @@ -891,7 +898,28 @@ void MsgCenterNotifyDrinkReminderProc(const Topic topic, Request* req) void MsgCenterNotifyActivityProc(const Topic topic, Request* req) { unused(topic); - unused(req); + cywee_activity_result_t* c_activity_result_t = (cywee_activity_result_t *) malloc(req->len); + if(c_activity_result_t==NULL) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Memory allocation failure"); + return; + } + + int rets = memcpy_s(c_activity_result_t, req->len, (cywee_activity_result_t*)req->data, req->len); + if (rets != EOK) + { + free(c_activity_result_t); + c_activity_result_t = NULL; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "memcpy_s c_activity_result_t failed, ret = %d", rets); + return; + } + if(c_activity_result_t->calories!=0) + set_calories_data(c_activity_result_t->calories); + + + if(c_activity_result_t->distance!=0) + set_distance_data(c_activity_result_t->distance); + } void MsgCenterNotifyInactivityProc(const Topic topic, Request *req) { diff --git a/code/sdk/application/wearable/service/msg_center/src/notify/transmitting.cpp b/code/sdk/application/wearable/service/msg_center/src/notify/transmitting.cpp index b76cb6d03..ef774916f 100644 --- a/code/sdk/application/wearable/service/msg_center/src/notify/transmitting.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/notify/transmitting.cpp @@ -12,7 +12,7 @@ #include "components/ui_slider.h" // #include "UiConfig.h" #include "bleEvent.h" - +#include "power_display_service.h" namespace OHOS { static UIImageView *imageCharge = nullptr; @@ -147,6 +147,14 @@ namespace OHOS } transmitting_timer = nullptr; } + + const power_display_svr_api_t *display_api = power_display_svr_get_api(); + if (display_api->get_screen_state() != SCREEN_ON) + { + display_api->turn_on_screen(); + } + display_api->set_auto_timeout_function(true); + RootView::GetInstance()->Remove(UIViewGroup_transmitting); @@ -548,6 +556,13 @@ namespace OHOS UIViewGroup_transmitting->SetOnClickListener(button1Click); UIViewGroup_transmitting->SetTouchable(true); + const power_display_svr_api_t *display_api = power_display_svr_get_api(); + if (display_api->get_screen_state() != SCREEN_ON) + { + display_api->turn_on_screen(); + } + display_api->set_auto_timeout_function(false); + diff --git a/code/sdk/drivers/peripheral/cywee/Inc/cywee_hal.h b/code/sdk/drivers/peripheral/cywee/Inc/cywee_hal.h index 2eaf1ddef..ee472fe3d 100644 --- a/code/sdk/drivers/peripheral/cywee/Inc/cywee_hal.h +++ b/code/sdk/drivers/peripheral/cywee/Inc/cywee_hal.h @@ -18,6 +18,11 @@ extern "C" { #include "stdint.h" #include "errcode.h" +typedef enum { + CYWEE_SAVE_DATA_STEP, + CYWEE_SAVE_DATA_DISTANCE, + CYWEE_SAVE_DATA_CALORIES, +} CYWEE_SAVE_DATA_TYPE; extern uint64_t CWM_OS_GetTimeNs(void); @@ -32,7 +37,7 @@ extern int CWM_OS_i2cTransfer(uint16_t slaveAddr, uint16_t reg, int regLength, u extern void* CWM_OS_malloc(int size); extern void CWM_OS_free(void *ptr); extern void CWM_OS_saveData(int* data, uint32_t len); -extern void CWM_OS_saveData_history(int* new_data,int *history ,uint32_t len); +extern void CWM_OS_saveData_history(int* new_data,int *history ,uint32_t len,uint8_t type); extern void CWM_OS_saveData_STAND_history(uint8_t *falg,uint32_t len); extern void CWM_OS_restoreData(int* data, uint32_t len); @@ -507,9 +512,16 @@ void cywee_activity_mode_change(int mode); void cywee_time_sync(void); void cywee_hand_updown_switch(int cmd); void cywee_ar_alert_switch(int cmd); + void step_history_save(void); void stand_history_save(void); +void calories_history_save(void); +void distances_history_save(void); + void set_stand_falg(void); +void set_calories_data(uint32_t data); +void set_distance_data(uint32_t data); + void cywee_get_chipinfo(char *databuf,uint8_t len); void cywee_get_acc_switch(uint8_t cmd); void cywee_set_sedentary_interval(int time); @@ -522,6 +534,7 @@ extern uint8_t hrs_mode_state; + /********************CYWEE DML*********************/ diff --git a/code/sdk/drivers/peripheral/cywee/src/board_yh601s.c b/code/sdk/drivers/peripheral/cywee/src/board_yh601s.c index 28bab83cf..fdee522b7 100644 --- a/code/sdk/drivers/peripheral/cywee/src/board_yh601s.c +++ b/code/sdk/drivers/peripheral/cywee/src/board_yh601s.c @@ -282,14 +282,49 @@ void CWM_OS_saveData(int* data, uint32_t len){ #define CWM_HISTORY_DATA_PATH "/user/userdata/step_" -void CWM_OS_saveData_history(int* new_data,int *history ,uint32_t len){ +#define CWM_HISTORY_DATA_CALORIES_PATH "/user/userdata/calories_" + +#define CWM_HISTORY_DATA_DISTANCE_PATH "/user/userdata/distance_" + +typedef enum { + CYWEE_SAVE_DATA_STEP, + CYWEE_SAVE_DATA_DISTANCE, + CYWEE_SAVE_DATA_CALORIES, +} CYWEE_SAVE_DATA_TYPE; + + +void CWM_OS_saveData_history(int* new_data,int *history ,uint32_t len,uint8_t type){ char path_[64]={0}; char timeday[12] = {0}; uapi_get_YYMMDD_Time(timeday, '_'); - sprintf_s(path_,64,"%s%s.bin",CWM_HISTORY_DATA_PATH,timeday); + switch (type) + { + case CYWEE_SAVE_DATA_CALORIES: + sprintf_s(path_,64,"%s%s.bin",CWM_HISTORY_DATA_CALORIES_PATH,timeday); + break; + case CYWEE_SAVE_DATA_STEP: + sprintf_s(path_,64,"%s%s.bin",CWM_HISTORY_DATA_PATH,timeday); + break; + case CYWEE_SAVE_DATA_DISTANCE: + sprintf_s(path_,64,"%s%s.bin",CWM_HISTORY_DATA_DISTANCE_PATH,timeday); + break; + default: + break; + } + CWM_OS_dbgPrintf(" save path %s \n",path_); + int data= *new_data-*history;//新数据减去旧数据,作为这一个小时的步数值 + if(data<=0) + { + data=0; + *history=0; + CWM_OS_dbgPrintf("异常 清除步数数据\n"); + return; + + } + FILE * fp = fopen(path_,"ab+"); if(fp==NULL) { @@ -307,17 +342,6 @@ void CWM_OS_saveData_history(int* new_data,int *history ,uint32_t len){ CWM_OS_dbgPrintf("fwrite failed %d\n",ret); } - - - //新数据减去旧数据,作为这一个小时的步数值 - - int data= *new_data-*history; - if(data<0) - { - data=0; - *history=0; - CWM_OS_dbgPrintf("异常 清除步数数据\n"); - } ret =fwrite(&data,1,len,fp); if(ret==0) @@ -370,10 +394,9 @@ void CWM_OS_saveData_STAND_history(uint8_t *falg,uint32_t len){ } } - - //CWM_OS_dbgPrintf("fwrite data %d\n",data); + // calories 数据存储 + - diff --git a/code/sdk/drivers/peripheral/cywee/src/main_dml.c b/code/sdk/drivers/peripheral/cywee/src/main_dml.c index 17ac1f209..5009ec1ff 100644 --- a/code/sdk/drivers/peripheral/cywee/src/main_dml.c +++ b/code/sdk/drivers/peripheral/cywee/src/main_dml.c @@ -48,6 +48,15 @@ int history_step_=0;//存一个小时前的步数数据,每次保存步数时 uint8_t stand_falg=0;//站立falg,如果发生站立,一个小时内会被置1; +int new_calories=0; //存卡路里数据 + +int history_calories=0; //一小时前卡路里数据 + +int new_distance=0; //存距离数据 + +int history_distances=0; //一小时前距离数据 + + static char chipInfo[64] = {0}; static int get_acc_swtich = 0; @@ -56,6 +65,7 @@ static int sedentary_interval = 1; static int sedentary_interval_count = 0; + int cm__hs1__init(void); int cm__hs1__deinit(void); @@ -81,7 +91,17 @@ void cywee_save_data(void) void step_history_save(void) { - CWM_OS_saveData_history(&stepcount,&history_step_,sizeof(int)); + CWM_OS_saveData_history(&stepcount,&history_step_,sizeof(int),CYWEE_SAVE_DATA_STEP); +} + +void set_calories_data(uint32_t data) +{ + new_calories=data; +} + +void set_distance_data(uint32_t data) +{ + new_distance=data; } void set_stand_falg(void) @@ -93,6 +113,16 @@ void stand_history_save(void) CWM_OS_saveData_STAND_history(&stand_falg,sizeof(int)); } +void calories_history_save(void) +{ + CWM_OS_saveData_history(&new_calories,&history_calories,sizeof(int),CYWEE_SAVE_DATA_CALORIES); +} + +void distances_history_save(void) +{ + CWM_OS_saveData_history(&new_calories,&history_calories,sizeof(int),CYWEE_SAVE_DATA_DISTANCE); +} + void cywee_ar_alert_switch(int cmd) { -- 2.17.1