* @Author: luozheng 1732036298@qq.com
* @Date: 2024-04-08 18:40:09
* @LastEditors: penglei 1624952103@qq.com
- * @LastEditTime: 2025-08-12 10:29:17
+ * @LastEditTime: 2025-08-22 18:06:14
* @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/src/GoalModel.cpp
*/
#include "goal/include/goalmodel.h"
#include "activity/include/ActivityModel.h"
#include "ConfigModel.h"
-// #include "cywee_hal.h"
-// #include "goal_notification.h"
+
+#include "goal_notification.h"
#include "custom_utils.h"
// #include "cywee_ble_service.h"
// #include "goalmodel.h"
#ifdef SUPPORT_CYWEE_SERVICE
#include "cywee_data.h"
+#include "cywee_hal.h"
#endif
namespace OHOS
{
void GoalModel::GoalModelInitdata()
{
- // OHOS::set_Is_show_flag(ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_CALORIES_TIME),OHOS::GOAL_CALOREIE);
- // OHOS::set_Is_show_flag(ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_STANDUP_TIMES_TIME),OHOS::GOAL_STAND);
- // OHOS::set_Is_show_flag(ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_DURATION_TIME),OHOS::GOAL_FAT);
- // OHOS::set_Is_show_flag(ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_DISTANCE_TIME),OHOS::GOAL_DISTANCE);
- // OHOS::set_Is_show_flag(ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_STEPCOUNT_TIME),OHOS::GOAL_STEP);
+ OHOS::set_Is_show_flag(ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_CALORIES_TIME),OHOS::GOAL_CALOREIE);
+ OHOS::set_Is_show_flag(ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_STANDUP_TIMES_TIME),OHOS::GOAL_STAND);
+ OHOS::set_Is_show_flag(ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_DURATION_TIME),OHOS::GOAL_FAT);
+ OHOS::set_Is_show_flag(ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_DISTANCE_TIME),OHOS::GOAL_DISTANCE);
+ OHOS::set_Is_show_flag(ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_STEPCOUNT_TIME),OHOS::GOAL_STEP);
- // step_goal_show=ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_STEP);
- // other_goal_show=ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_OTHER);
+ step_goal_show=ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_STEP);
+ other_goal_show=ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_OTHER);
- // step_goal=ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_STEPCOUNT);
- // distanc_goal=ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_DISTANCE);
- // fat_goal=ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_DURATION);
- // calories_goal=ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_CALORIES);
- // stand_goal=ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_STANDUP_TIMES);
+ step_goal=ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_STEPCOUNT);
+ distanc_goal=ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_DISTANCE);
+ fat_goal=ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_DURATION);
+ calories_goal=ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_CALORIES);
+ stand_goal=ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_STANDUP_TIMES);
#ifdef SUPPORT_CYWEE_SERVICE
standdata_now = cywee_get_now_stand_count();
#endif
- // show_step=goal_parse_step_data();
- // show_calories=goal_parse_calories_data();
- // show_distance=goal_parse_distance_data();
- // show_fat=goal_parse_fat_data();
+ show_step=goal_parse_step_data();
+ show_calories=goal_parse_calories_data();
+ show_distance=goal_parse_distance_data();
+ show_fat=goal_parse_fat_data();
}
uint32_t GoalModel::goal_parse_step_data(void)
{
- // char path_[64]={0};
- // char timeday[12] = {0};
- // uapi_get_YYMMDD_Time_extend(timeday, '_',0);
- // sprintf_s(path_,64,"%s%s.bin",CWM_HISTORY_DATA_PATH,timeday);
- // FILE * fp = fopen(path_,"rb+");
- // uint32_t size=0;
- // uint32_t toal_data=0;
-
- // time_t currtime;
- // struct tm *timeinfo_now;
- // time(&currtime);
- // timeinfo_now = localtime(&currtime);
-
- // uint8_t mon_now=timeinfo_now->tm_mon;
- // uint8_t day_now=timeinfo_now->tm_mday;
-
- // if (fp != NULL)
- // {
- // fseek(fp, 0, SEEK_END); // 将文件指针移动到文件末尾
- // size = ftell(fp); // 获取当前文件指针位置,即文件大小
- // fseek(fp, 0, SEEK_SET); // 将文件指针移回文件开头
- // }
- // else
- // {
- // return 0;
- // }
- // uint8_t *date=(uint8_t *)malloc(size);
- // if(date==NULL) return 0;
+ char path_[64]={0};
+ char timeday[12] = {0};
+ uapi_get_YYMMDD_Time_extend(timeday, '_',0);
+#ifdef SUPPORT_CYWEE_SERVICE
+ sprintf_s(path_,64,"%s%s.bin",CWM_HISTORY_DATA_PATH,timeday);
+#endif
+ FILE * fp = fopen(path_,"rb+");
+ uint32_t size=0;
+ uint32_t toal_data=0;
+
+ time_t currtime;
+ struct tm *timeinfo_now;
+ time(&currtime);
+ timeinfo_now = localtime(&currtime);
+
+ uint8_t mon_now=timeinfo_now->tm_mon;
+ uint8_t day_now=timeinfo_now->tm_mday;
+
+ if (fp != NULL)
+ {
+ fseek(fp, 0, SEEK_END); // 将文件指针移动到文件末尾
+ size = ftell(fp); // 获取当前文件指针位置,即文件大小
+ fseek(fp, 0, SEEK_SET); // 将文件指针移回文件开头
+ }
+ else
+ {
+ return 0;
+ }
+ uint8_t *date=(uint8_t *)malloc(size);
+ if(date==NULL) return 0;
- // fread(date,sizeof(uint8_t),size,fp);
- // fclose(fp);
- // int32_t sing_date=0;
- // int32_t timetemp=0;
+ fread(date,sizeof(uint8_t),size,fp);
+ fclose(fp);
+ int32_t sing_date=0;
+ int32_t timetemp=0;
- // for(int i=0;i<size/8;i++ )
- // {
- // // uint8_t
- // memcpy(&timetemp,date+i*8,4);
- // memcpy(&sing_date,date+i*8+4,4);
- // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "time: %d", timetemp);
- // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "data: %d", sing_date);
+ for(int i=0;i<size/8;i++ )
+ {
+ // uint8_t
+ memcpy(&timetemp,date+i*8,4);
+ memcpy(&sing_date,date+i*8+4,4);
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "time: %d", timetemp);
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "data: %d", sing_date);
- // struct tm *timeinfo;
- // timeinfo = localtime((time_t *) &timetemp);
+ struct tm *timeinfo;
+ timeinfo = localtime((time_t *) &timetemp);
- // if(sing_date>0 && timeinfo->tm_mday==day_now && timeinfo->tm_mon==mon_now)
- // toal_data+=sing_date;
- // }
- // free(date);
- // return toal_data;
- return 0;
+ if(sing_date>0 && timeinfo->tm_mday==day_now && timeinfo->tm_mon==mon_now)
+ toal_data+=sing_date;
+ }
+ free(date);
+ return toal_data;
+ // return 0;
}
float GoalModel::goal_parse_calories_data(void)
{
- // char path_[64]={0};
- // char timeday[12] = {0};
- // uapi_get_YYMMDD_Time_extend(timeday, '_',0);
- // sprintf_s(path_,64,"%s%s.bin",CWM_HISTORY_DATA_CALORIES_PATH,timeday);
- // FILE * fp = fopen(path_,"rb+");
- // uint32_t size=0;
- // float toal_data=0;
-
- // time_t currtime;
- // struct tm *timeinfo_now;
- // time(&currtime);
- // timeinfo_now = localtime(&currtime);
-
- // uint8_t mon_now=timeinfo_now->tm_mon;
- // uint8_t day_now=timeinfo_now->tm_mday;
-
- // if (fp != NULL)
- // {
- // fseek(fp, 0, SEEK_END); // 将文件指针移动到文件末尾
- // size = ftell(fp); // 获取当前文件指针位置,即文件大小
- // fseek(fp, 0, SEEK_SET); // 将文件指针移回文件开头
- // }
- // else
- // {
- // return 0;
- // }
- // uint8_t *date=(uint8_t *)malloc(size);
- // if(date==NULL) return 0;
+ char path_[64]={0};
+ char timeday[12] = {0};
+ uapi_get_YYMMDD_Time_extend(timeday, '_',0);
+#ifdef SUPPORT_CYWEE_SERVICE
+ sprintf_s(path_,64,"%s%s.bin",CWM_HISTORY_DATA_CALORIES_PATH,timeday);
+#endif
+
+ FILE * fp = fopen(path_,"rb+");
+ uint32_t size=0;
+ float toal_data=0;
+
+ time_t currtime;
+ struct tm *timeinfo_now;
+ time(&currtime);
+ timeinfo_now = localtime(&currtime);
+
+ uint8_t mon_now=timeinfo_now->tm_mon;
+ uint8_t day_now=timeinfo_now->tm_mday;
+
+ if (fp != NULL)
+ {
+ fseek(fp, 0, SEEK_END); // 将文件指针移动到文件末尾
+ size = ftell(fp); // 获取当前文件指针位置,即文件大小
+ fseek(fp, 0, SEEK_SET); // 将文件指针移回文件开头
+ }
+ else
+ {
+ return 0;
+ }
+ uint8_t *date=(uint8_t *)malloc(size);
+ if(date==NULL) return 0;
- // fread(date,sizeof(uint8_t),size,fp);
- // fclose(fp);
- // float sing_date=0;
- // int32_t timetemp=0;
+ fread(date,sizeof(uint8_t),size,fp);
+ fclose(fp);
+ float sing_date=0;
+ int32_t timetemp=0;
- // for(int i=0;i<size/8;i++ )
- // {
- // // uint8_t
- // memcpy(&timetemp,date+i*8,4);
- // memcpy(&sing_date,date+i*8+4,4);
- // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "time: %d", timetemp);
- // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "data: %f", sing_date);
+ for(int i=0;i<size/8;i++ )
+ {
+ // uint8_t
+ memcpy(&timetemp,date+i*8,4);
+ memcpy(&sing_date,date+i*8+4,4);
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "time: %d", timetemp);
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "data: %f", sing_date);
- // struct tm *timeinfo;
- // timeinfo = localtime((time_t *) &timetemp);
+ struct tm *timeinfo;
+ timeinfo = localtime((time_t *) &timetemp);
- // if(sing_date>0 && timeinfo->tm_mday==day_now && timeinfo->tm_mon==mon_now)
- // toal_data+=sing_date;
- // }
- // free(date);
- // return toal_data;
- return 0;
+ if(sing_date>0 && timeinfo->tm_mday==day_now && timeinfo->tm_mon==mon_now)
+ toal_data+=sing_date;
+ }
+ free(date);
+ return toal_data;
+ // return 0;
}
float GoalModel::goal_parse_distance_data(void)
{
- // char path_[64]={0};
- // char timeday[12] = {0};
- // uapi_get_YYMMDD_Time_extend(timeday, '_',0);
- // sprintf_s(path_,64,"%s%s.bin",CWM_HISTORY_DATA_DISTANCE_PATH,timeday);
- // FILE * fp = fopen(path_,"rb+");
- // uint32_t size=0;
- // float toal_data=0;
-
- // time_t currtime;
- // struct tm *timeinfo_now;
- // time(&currtime);
- // timeinfo_now = localtime(&currtime);
-
- // uint8_t mon_now=timeinfo_now->tm_mon;
- // uint8_t day_now=timeinfo_now->tm_mday;
-
- // if (fp != NULL)
- // {
- // fseek(fp, 0, SEEK_END); // 将文件指针移动到文件末尾
- // size = ftell(fp); // 获取当前文件指针位置,即文件大小
- // fseek(fp, 0, SEEK_SET); // 将文件指针移回文件开头
- // }
- // else
- // {
- // return 0;
- // }
- // uint8_t *date=(uint8_t *)malloc(size);
- // if(date==NULL) return 0;
+ char path_[64]={0};
+ char timeday[12] = {0};
+ uapi_get_YYMMDD_Time_extend(timeday, '_',0);
+#ifdef SUPPORT_CYWEE_SERVICE
+ sprintf_s(path_,64,"%s%s.bin",CWM_HISTORY_DATA_DISTANCE_PATH,timeday);
+#endif
+ FILE * fp = fopen(path_,"rb+");
+ uint32_t size=0;
+ float toal_data=0;
+
+ time_t currtime;
+ struct tm *timeinfo_now;
+ time(&currtime);
+ timeinfo_now = localtime(&currtime);
+
+ uint8_t mon_now=timeinfo_now->tm_mon;
+ uint8_t day_now=timeinfo_now->tm_mday;
+
+ if (fp != NULL)
+ {
+ fseek(fp, 0, SEEK_END); // 将文件指针移动到文件末尾
+ size = ftell(fp); // 获取当前文件指针位置,即文件大小
+ fseek(fp, 0, SEEK_SET); // 将文件指针移回文件开头
+ }
+ else
+ {
+ return 0;
+ }
+ uint8_t *date=(uint8_t *)malloc(size);
+ if(date==NULL) return 0;
- // fread(date,sizeof(uint8_t),size,fp);
- // fclose(fp);
- // float sing_date=0;
- // int32_t timetemp=0;
+ fread(date,sizeof(uint8_t),size,fp);
+ fclose(fp);
+ float sing_date=0;
+ int32_t timetemp=0;
- // for(int i=0;i<size/8;i++ )
- // {
- // // uint8_t
- // memcpy(&timetemp,date+i*8,4);
- // memcpy(&sing_date,date+i*8+4,4);
- // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "time: %d", timetemp);
- // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "data: %f", sing_date);
+ for(int i=0;i<size/8;i++ )
+ {
+ // uint8_t
+ memcpy(&timetemp,date+i*8,4);
+ memcpy(&sing_date,date+i*8+4,4);
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "time: %d", timetemp);
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "data: %f", sing_date);
- // struct tm *timeinfo;
- // timeinfo = localtime((time_t *) &timetemp);
+ struct tm *timeinfo;
+ timeinfo = localtime((time_t *) &timetemp);
- // if(sing_date>0 && timeinfo->tm_mday==day_now && timeinfo->tm_mon==mon_now)
- // toal_data+=sing_date;
- // }
- // free(date);
- // return toal_data;
- return 0;
+ if(sing_date>0 && timeinfo->tm_mday==day_now && timeinfo->tm_mon==mon_now)
+ toal_data+=sing_date;
+ }
+ free(date);
+ return toal_data;
+ // return 0;
}
uint32_t GoalModel::goal_parse_fat_data(void)
{
- // char path_[64]={0};
- // char timeday[12] = {0};
- // uapi_get_YYMMDD_Time_extend(timeday, '_',0);
- // sprintf_s(path_,64,"%s%s.bin",CWM_HISTORY_DATA_FAT_PATH,timeday);
- // FILE * fp = fopen(path_,"rb+");
- // uint32_t size=0;
- // float toal_data=0;
-
- // time_t currtime;
- // struct tm *timeinfo_now;
- // time(&currtime);
- // timeinfo_now = localtime(&currtime);
-
- // uint8_t mon_now=timeinfo_now->tm_mon;
- // uint8_t day_now=timeinfo_now->tm_mday;
-
-
- // if (fp != NULL)
- // {
- // fseek(fp, 0, SEEK_END); // 将文件指针移动到文件末尾
- // size = ftell(fp); // 获取当前文件指针位置,即文件大小
- // fseek(fp, 0, SEEK_SET); // 将文件指针移回文件开头
- // }
- // else
- // {
- // return 0;
- // }
- // uint8_t *date=(uint8_t *)malloc(size);
- // if(date==NULL) return 0;
+ char path_[64]={0};
+ char timeday[12] = {0};
+ uapi_get_YYMMDD_Time_extend(timeday, '_',0);
+#ifdef SUPPORT_CYWEE_SERVICE
+ sprintf_s(path_,64,"%s%s.bin",CWM_HISTORY_DATA_FAT_PATH,timeday);
+#endif
+
+ FILE * fp = fopen(path_,"rb+");
+ uint32_t size=0;
+ float toal_data=0;
+
+ time_t currtime;
+ struct tm *timeinfo_now;
+ time(&currtime);
+ timeinfo_now = localtime(&currtime);
+
+ uint8_t mon_now=timeinfo_now->tm_mon;
+ uint8_t day_now=timeinfo_now->tm_mday;
+
+
+ if (fp != NULL)
+ {
+ fseek(fp, 0, SEEK_END); // 将文件指针移动到文件末尾
+ size = ftell(fp); // 获取当前文件指针位置,即文件大小
+ fseek(fp, 0, SEEK_SET); // 将文件指针移回文件开头
+ }
+ else
+ {
+ return 0;
+ }
+ uint8_t *date=(uint8_t *)malloc(size);
+ if(date==NULL) return 0;
- // fread(date,sizeof(uint8_t),size,fp);
- // fclose(fp);
- // uint16 sing_date=0;
- // int32_t timetemp=0;
+ fread(date,sizeof(uint8_t),size,fp);
+ fclose(fp);
+ uint16 sing_date=0;
+ int32_t timetemp=0;
- // for(int i=0;i<size/6;i++ )
- // {
- // // uint8_t
- // memcpy(&timetemp,date+i*6,4);
- // memcpy(&sing_date,date+i*6+4,2);
- // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "time: %d", timetemp);
- // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "data: %d", sing_date);
+ for(int i=0;i<size/6;i++ )
+ {
+ // uint8_t
+ memcpy(&timetemp,date+i*6,4);
+ memcpy(&sing_date,date+i*6+4,2);
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "time: %d", timetemp);
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "data: %d", sing_date);
- // struct tm *timeinfo;
- // timeinfo = localtime((time_t *) &timetemp);
+ struct tm *timeinfo;
+ timeinfo = localtime((time_t *) &timetemp);
- // if(sing_date>0 && timeinfo->tm_mday==day_now && timeinfo->tm_mon==mon_now)
- // toal_data+=sing_date;
- // }
- // free(date);
- // return toal_data;
- return 0;
+ if(sing_date>0 && timeinfo->tm_mday==day_now && timeinfo->tm_mon==mon_now)
+ toal_data+=sing_date;
+ }
+ free(date);
+ return toal_data;
+ // return 0;
}
uint32_t GoalModel::show_data_step_refresh(void)
{
- // int32_t value=0;
- // uint32_t toal_date;
+ int32_t value=0;
+ uint32_t toal_date;
- // toal_date=show_step;
- // cywee_get_now_hour_data(&value,STEP);
- // if(value>0)
- // toal_date+=value;
- // return toal_date;
+ toal_date=show_step;
+#ifdef SUPPORT_CYWEE_SERVICE
+ cywee_get_now_hour_data(&value,STEP);
+#endif
+ if(value>0)
+ toal_date+=value;
+ return toal_date;
return 0;
}
float GoalModel::show_data_calories_refresh(void)
{
- // float _f_value=0;
- // float toal_date;
- // toal_date=show_calories;
- // cywee_get_now_hour_data(&_f_value,CALORIES);
- // if(_f_value>0)
- // toal_date+=_f_value;
+ float _f_value=0;
+ float toal_date;
+ toal_date=show_calories;
+#ifdef SUPPORT_CYWEE_SERVICE
+ cywee_get_now_hour_data(&_f_value,CALORIES);
+#endif
+
+ if(_f_value>0)
+ toal_date+=_f_value;
- // return toal_date;
+ return toal_date;
return 0;
}
float GoalModel::show_data_distance_refresh(void)
{
- // float _f_value=0;
- // float toal_date;
- // toal_date=show_distance;
- // cywee_get_now_hour_data(&_f_value,DISTANCE);
- // if(_f_value>0)
- // toal_date+=_f_value;
+ float _f_value=0;
+ float toal_date;
+ toal_date=show_distance;
+#ifdef SUPPORT_CYWEE_SERVICE
+ cywee_get_now_hour_data(&_f_value,DISTANCE);
+#endif
+
+ if(_f_value>0)
+ toal_date+=_f_value;
- // return toal_date;
+ return toal_date;
- return 0;
+ // return 0;
}
uint32_t GoalModel::show_data_fat_refresh(void)
{
- // uint16_t _16_value=0;
- // uint32_t toal_date;
- // toal_date=show_fat;
- // cywee_get_now_hour_data(&_16_value,FAT);
- // if(_16_value>0)
- // toal_date+=_16_value;
+ uint16_t _16_value=0;
+ uint32_t toal_date;
+ toal_date=show_fat;
+
+#ifdef SUPPORT_CYWEE_SERVICE
+ cywee_get_now_hour_data(&_16_value,FAT);
+#endif
+ if(_16_value>0)
+ toal_date+=_16_value;
- // return toal_date;
+ return toal_date;
- return 0;
+ // return 0;
}