From cc8e9f45464bb5c93e115987ca838a25a6bb7f0e Mon Sep 17 00:00:00 2001 From: hcj <1224667075@qq.com> Date: Fri, 21 Jun 2024 11:22:05 +0800 Subject: [PATCH] =?utf8?q?=E7=9B=AE=E6=A0=87=E5=8E=86=E5=8F=B2=E6=95=B0?= =?utf8?q?=E6=8D=AE=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../service/ble_service/blemoder/bletest.cpp | 5 +- .../service/ble_service/bleservice/bleEvent.c | 13 ++- .../msg_center/src/msg_center_customer.cpp | 7 ++ .../drivers/peripheral/cywee/Inc/cywee_hal.h | 11 ++- .../peripheral/cywee/service/cywee_service.c | 2 +- .../peripheral/cywee/src/board_yh601s.c | 82 +++++++++++++++--- .../drivers/peripheral/cywee/src/main_dml.c | 84 +++++++++++++++---- 7 files changed, 167 insertions(+), 37 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 cdeb65a6d..c554baecf 100644 --- a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp +++ b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp @@ -174,6 +174,8 @@ void install_Register_dial( char * name,uint16_t id) #define CWM_HISTORY_STAND_DATA_PATH "/user/userdata/goal/stand_" +#define CWM_HISTORY_DATA_FAT_PATH "/user/userdata/goal/fat_" + char * ble_sywee_history(uint8_t day,uint16_t *len ,uint8_t type) { char path_[64]={0}; @@ -186,7 +188,7 @@ char * ble_sywee_history(uint8_t day,uint16_t *len ,uint8_t type) sprintf_s(path_,64,"%s%s.bin",CWM_HISTORY_DATA_PATH,timeday); break; case 0x44://同步燃脂时间数据 - sprintf_s(path_,64,"%s%s.bin",CWM_HISTORY_DATA_PATH,timeday); + sprintf_s(path_,64,"%s%s.bin",CWM_HISTORY_DATA_FAT_PATH,timeday); break; case 0x45://同步站立历史数据 sprintf_s(path_,64,"%s%s.bin",CWM_HISTORY_STAND_DATA_PATH,timeday); @@ -588,7 +590,6 @@ char * tar_dir_to_json_buf_malloc_(char* file_name,uint32_t *file_size) if ((dir = opendir(dir_path)) != NULL) { - while ((ent = readdir(dir)) != NULL) { std::string fileName = ent->d_name; 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 aa62ccf35..57f92474b 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c @@ -90,6 +90,7 @@ static const char* getHandlname(uint16_t handle) if (data2ae3Cmd == handle) return "data2ae3Cmd"; if (data2ae4Cmd == handle) return "data2ae4Cmd"; if (data2ae5Cmd == handle) return "data2ae5Cmd"; + //if (data2ae2Cmd == handle) return "data2ae2Cmd"; return "unknown handle"; @@ -2690,6 +2691,7 @@ static void GetBatteryLevelCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t * power = battery_get_voltage(&voltage); value[17] = power; value[18] = Calculate_CRC(value,18); + printf("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"); sendBleData(value,19); }else { @@ -4725,9 +4727,12 @@ void readDevDataBle(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *totalData,u break; case 0x44://同步燃脂时间数据 - EACH_DATA_LEN = FATTIME_DATA_LEN; - num=(ble_nus_max_data_len-18)/EACH_DATA_LEN; - Read_JSON_file_buf_send_bin_Data(data[0],num,0x44,"heart_data_list"); + num=(ble_nus_max_data_len-18); + if(num>482) + { + num=482; + } + Read_BIN_file_buf_send_bin_Data(data[0],num,0x44); break; case 0x45://同步站立历史数据 @@ -5771,7 +5776,7 @@ void type2AE0Data(ble_read_data *buffer_handle) decode_file_checksum(buffer_handle); break; case SINGLE_DIAL_FILE_RECV_CMD: - if (decode_single_dial_info( buffer_handle) == ERRCODE_SUCC) + if (decode_single_dial_info(buffer_handle) == ERRCODE_SUCC) { ble_reply_cmd(SINGLE_DIAL_FILE_RECV_CMD,1); 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 10d7600ac..6e0935721 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 @@ -290,6 +290,8 @@ void MsgCenterNotifyONtimeProc(const Topic topic, Request* req) calories_history_save(); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "保存每小时距离数据"); distances_history_save(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "保存每小时燃脂数据"); + fat_history_save(); } void MsgCenterNotifystepProc(const Topic topic, Request* req) @@ -950,6 +952,11 @@ void MsgCenterNotifyActivityProc(const Topic topic, Request* req) if(c_activity_result_t->distance!=0) set_distance_data(c_activity_result_t->distance); + if(c_activity_result_t->MHR>=2) + set_fat_time_data(); + + + } void MsgCenterNotifyInactivityProc(const Topic topic, Request *req) { diff --git a/code/sdk/drivers/peripheral/cywee/Inc/cywee_hal.h b/code/sdk/drivers/peripheral/cywee/Inc/cywee_hal.h index 89e489ef5..f79393237 100644 --- a/code/sdk/drivers/peripheral/cywee/Inc/cywee_hal.h +++ b/code/sdk/drivers/peripheral/cywee/Inc/cywee_hal.h @@ -22,6 +22,7 @@ typedef enum { CYWEE_SAVE_DATA_STEP, CYWEE_SAVE_DATA_DISTANCE, CYWEE_SAVE_DATA_CALORIES, + CYWEE_SAVE_DATA_FAT, } CYWEE_SAVE_DATA_TYPE; @@ -36,10 +37,10 @@ extern int CWM_OS_i2cWrite(uint16_t slaveAddr, uint16_t reg, int regLength, uint extern int CWM_OS_i2cTransfer(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *writeData, int writeDataSize, uint8_t *readData, int readDataSize, int busIndex); 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(int* data, uint32_t len,uint8_t type); 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); +extern void CWM_OS_restoreData(int* data, uint32_t len,uint8_t type); /********************CYWEE LIB*************************/ @@ -519,6 +520,10 @@ void step_history_save(void); void stand_history_save(void); void calories_history_save(void); void distances_history_save(void); +void fat_history_save(void); + +void cywee_goal_history_save(void); + void set_stand_falg(void); void set_calories_data(uint32_t data); @@ -527,6 +532,8 @@ int get_calories_data(void); void set_distance_data(uint32_t data); int get_distance_data(void ); +void set_fat_time_data(void); + void cywee_get_chipinfo(char *databuf,uint8_t len); void cywee_get_acc_switch(uint8_t cmd); void cywee_set_sedentary_interval(int time); diff --git a/code/sdk/drivers/peripheral/cywee/service/cywee_service.c b/code/sdk/drivers/peripheral/cywee/service/cywee_service.c index 32af17bfb..a91890b21 100644 --- a/code/sdk/drivers/peripheral/cywee/service/cywee_service.c +++ b/code/sdk/drivers/peripheral/cywee/service/cywee_service.c @@ -377,7 +377,7 @@ static void cywee_service_check_task(void const *arg) break; case CYWEE_SERVICE_CMD_SAVE_DATA: - cywee_save_data(); + cywee_save_data(NULL, 0); break; case CYWEE_SERVICE_CMD_START_GET_ACC: diff --git a/code/sdk/drivers/peripheral/cywee/src/board_yh601s.c b/code/sdk/drivers/peripheral/cywee/src/board_yh601s.c index fd33fb2a3..36df2028e 100644 --- a/code/sdk/drivers/peripheral/cywee/src/board_yh601s.c +++ b/code/sdk/drivers/peripheral/cywee/src/board_yh601s.c @@ -262,13 +262,45 @@ int CWM_OS_dbgPrintf(const char * format,...) CWM_OS_dbgOutput(InputBuff); return 0; } -#define CWM_DATA_PATH "/user/userdata/sport/stepcount.bin" -void CWM_OS_saveData(int* data, uint32_t len){ +typedef enum { + CYWEE_SAVE_DATA_STEP, + CYWEE_SAVE_DATA_DISTANCE, + CYWEE_SAVE_DATA_CALORIES, + CYWEE_SAVE_DATA_FAT, +} CYWEE_SAVE_DATA_TYPE; + +#define CWM_STEP_DATA_PATH "/user/userdata/sport/stepcount.bin" +#define CWM_CALORIES_DATA_PATH "/user/userdata/sport/caloriescount.bin" +#define CWM_DISTANCE_DATA_PATH "/user/userdata/sport/distancecount.bin" +#define CWM_FAT_DATA_PATH "/user/userdata/sport/fatcount.bin" + +void CWM_OS_saveData(int* data, uint32_t len,uint8_t type){ - FILE * fp = fopen(CWM_DATA_PATH,"wb"); + FILE * fp=NULL; + switch (type) + { + case CYWEE_SAVE_DATA_CALORIES: + fp = fopen(CWM_CALORIES_DATA_PATH,"wb"); + break; + case CYWEE_SAVE_DATA_STEP: + fp = fopen(CWM_STEP_DATA_PATH,"wb"); + break; + case CYWEE_SAVE_DATA_DISTANCE: + fp = fopen(CWM_DISTANCE_DATA_PATH,"wb"); + break; + case CYWEE_SAVE_DATA_FAT: + fp = fopen(CWM_FAT_DATA_PATH,"wb"); + break; + + default: + break; + } + + + if(fp==NULL) { - CWM_OS_dbgPrintf("%s open fail\n",CWM_DATA_PATH); + CWM_OS_dbgPrintf("%s open fail\n",CWM_STEP_DATA_PATH); return; } int ret =fwrite(data,1,len,fp); @@ -280,18 +312,18 @@ void CWM_OS_saveData(int* data, uint32_t len){ } + + #define CWM_HISTORY_DATA_PATH "/user/userdata/goal/step_" #define CWM_HISTORY_DATA_CALORIES_PATH "/user/userdata/goal/calories_" #define CWM_HISTORY_DATA_DISTANCE_PATH "/user/userdata/goal/distance_" +#define CWM_HISTORY_DATA_FAT_PATH "/user/userdata/goal/fat_" + #define GOAL_DATA_CONFIG_DIR "/user/userdata/goal" -typedef enum { - CYWEE_SAVE_DATA_STEP, - CYWEE_SAVE_DATA_DISTANCE, - CYWEE_SAVE_DATA_CALORIES, -} CYWEE_SAVE_DATA_TYPE; + #include @@ -318,9 +350,13 @@ void CWM_OS_saveData_history(int* new_data,int *history ,uint32_t len,uint8_t ty case CYWEE_SAVE_DATA_STEP: sprintf_s(path_,64,"%s%s.bin",CWM_HISTORY_DATA_PATH,timeday); break; - case CYWEE_SAVE_DATA_DISTANCE: + case CYWEE_SAVE_DATA_DISTANCE: sprintf_s(path_,64,"%s%s.bin",CWM_HISTORY_DATA_DISTANCE_PATH,timeday); break; + case CYWEE_SAVE_DATA_FAT: + sprintf_s(path_,64,"%s%s.bin",CWM_HISTORY_DATA_FAT_PATH,timeday); + break; + default: break; } @@ -424,11 +460,31 @@ void CWM_OS_saveData_STAND_history(uint8_t *falg,uint32_t len){ -void CWM_OS_restoreData(int* data, uint32_t len){ - FILE * fp = fopen(CWM_DATA_PATH,"rb"); +void CWM_OS_restoreData(int* data, uint32_t len,uint8_t type){ + + FILE * fp=NULL; + switch (type) + { + case CYWEE_SAVE_DATA_CALORIES: + fp = fopen(CWM_CALORIES_DATA_PATH,"wb"); + break; + case CYWEE_SAVE_DATA_STEP: + fp = fopen(CWM_STEP_DATA_PATH,"wb"); + break; + case CYWEE_SAVE_DATA_DISTANCE: + fp = fopen(CWM_DISTANCE_DATA_PATH,"wb"); + break; + case CYWEE_SAVE_DATA_FAT: + fp = fopen(CWM_FAT_DATA_PATH,"wb"); + break; + default: + break; + } + + if(fp==NULL) { - CWM_OS_dbgPrintf("%s open fail\n",CWM_DATA_PATH);; + CWM_OS_dbgPrintf("%s open fail\n",CWM_HISTORY_DATA_PATH);; return; } int ret =fread(data,1,len,fp); diff --git a/code/sdk/drivers/peripheral/cywee/src/main_dml.c b/code/sdk/drivers/peripheral/cywee/src/main_dml.c index 5ae371e05..c43b5068b 100644 --- a/code/sdk/drivers/peripheral/cywee/src/main_dml.c +++ b/code/sdk/drivers/peripheral/cywee/src/main_dml.c @@ -43,19 +43,22 @@ uint8_t hrs_mode_state = 0; static int history_step = 0; static int stepcount = 0; - -int history_step_=0;//存一个小时前的步数数据,每次保存步数时会更新改数据 +static int history_step_=0;//存一个小时前的步数数据,每次保存步数时会更新改数据 uint8_t stand_falg=0;//站立falg,如果发生站立,一个小时内会被置1; int new_calories=0; //存卡路里数据 - int history_calories=0; //一小时前卡路里数据 +int history_calories_=0; int new_distance=0; //存距离数据 +int history_distances=0; //历史数据 +int history_distances_=0; //一小时前距离数据 -int history_distances=0; //一小时前距离数据 +int new_fat=0; //存燃脂数据 +int history_fat=0; //历史数据 +int history_fat_=0; //一小时前燃脂数据 static char chipInfo[64] = {0}; @@ -84,9 +87,36 @@ void cywee_get_chipinfo(char *databuf,uint8_t len) memcpy_s(databuf,len,chipInfo,strlen(chipInfo)); } -void cywee_save_data(void) +void cywee_save_data(int* data, uint32_t len) +{ + CWM_OS_saveData(&stepcount,sizeof(int),CYWEE_SAVE_DATA_STEP); + new_calories+=history_calories; + CWM_OS_saveData(&(new_calories),sizeof(int),CYWEE_SAVE_DATA_CALORIES); + new_distance+=history_distances; + CWM_OS_saveData(&(new_distance),sizeof(int),CYWEE_SAVE_DATA_DISTANCE); + CWM_OS_saveData(&new_fat,sizeof(int),CYWEE_SAVE_DATA_FAT); + +} + +void cywee_OS_data_save_(int* data, uint32_t len) +{ + cywee_save_data(data,len); +} + + + +void CWM_OS_restoreData_(int* data, uint32_t len) { - CWM_OS_saveData(&stepcount,sizeof(int)); + CWM_OS_restoreData(&history_step,sizeof(int),CYWEE_SAVE_DATA_STEP); + history_step_=history_step; + CWM_OS_restoreData(&history_calories,sizeof(int),CYWEE_SAVE_DATA_CALORIES); + history_calories_=history_calories; + CWM_OS_restoreData(&history_distances,sizeof(int),CYWEE_SAVE_DATA_DISTANCE); + history_distances_=history_distances; + CWM_OS_restoreData(&history_fat,sizeof(int),CYWEE_SAVE_DATA_FAT); + history_fat_=history_fat; + + //WM_OS_restoreData(int* data, uint32_t len,uint8_t type)(int* data, uint32_t len,uint8_t type); } void step_history_save(void) @@ -96,7 +126,7 @@ void step_history_save(void) int get_calories_data(void) { - return new_calories; + return new_calories+history_calories; } void set_calories_data(uint32_t data) { @@ -106,14 +136,21 @@ void set_calories_data(uint32_t data) void set_distance_data(uint32_t data) { - new_distance=data; + new_fat++; } int get_distance_data(void ) { - return new_distance; + return new_distance+history_distances; +} + +void set_fat_time_data(void) +{ + new_calories++; } + + void set_stand_falg(void) { stand_falg=1; @@ -125,14 +162,30 @@ void stand_history_save(void) void calories_history_save(void) { - CWM_OS_saveData_history(&new_calories,&history_calories,sizeof(int),CYWEE_SAVE_DATA_CALORIES); + 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); + CWM_OS_saveData_history(&new_distance,&history_calories_,sizeof(int),CYWEE_SAVE_DATA_DISTANCE); +} + +void fat_history_save(void) +{ + CWM_OS_saveData_history(&new_fat,&history_fat_,sizeof(int),CYWEE_SAVE_DATA_FAT); +} + +void cywee_goal_history_save(void) +{ + stand_history_save(); + calories_history_save(); + fat_history_save(); + distances_history_save(); + step_history_save(); } + + void cywee_ar_alert_switch(int cmd) { memset(&scl, 0, sizeof(scl)); @@ -808,8 +861,8 @@ int cywee_main_dml(void) .free = CWM_OS_free, .malloc = CWM_OS_malloc, .i2cTransfer = custom_i2c_transfer, - .restoreData = CWM_OS_restoreData, - .saveData = CWM_OS_saveData, + .restoreData = CWM_OS_restoreData_, + .saveData = cywee_OS_data_save_, .spiRead = NULL, .spiWrite = NULL, .securityCodeWrite = NULL, @@ -1008,8 +1061,9 @@ int cywee_main_dml(void) // CWM_Sensor_Enable(IDX_ALGO_ANY_MOTIOIN); //CWM_Sensor_Enable(IDX_ALGO_ABSOLUTE_STATIC); //CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__); - CWM_OS_restoreData(&history_step,sizeof(int)); - history_step_=history_step; + CWM_OS_restoreData_(&history_step,sizeof(int)); + + cywee_activity_mode_change(SPORT_ACTIVE_MODE_NORMAL); -- 2.17.1