From: Caisking <3449750381@qq.com> Date: Thu, 31 Oct 2024 13:39:36 +0000 (+0800) Subject: 优化nextday X-Git-Tag: fd230_release_V1.3.102~29^2~95^2~1 X-Git-Url: http://git.snicker.com.cn/css/html/static/gitweb.css?a=commitdiff_plain;h=deaf42704ed36c73ff585fac39329e1abf58b144;p=mirrors%2FFD230.git 优化nextday --- diff --git a/code/sdk/application/wearable/fd230app/nativeui/alarmclocktimerconfig/src/AlarmClockTimerConfig.cpp b/code/sdk/application/wearable/fd230app/nativeui/alarmclocktimerconfig/src/AlarmClockTimerConfig.cpp index 491dfa292..3703e8ace 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/alarmclocktimerconfig/src/AlarmClockTimerConfig.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/alarmclocktimerconfig/src/AlarmClockTimerConfig.cpp @@ -332,7 +332,7 @@ extern "C" #endif AlarmTimerEventPublish(TOPIC_EVENT_NEXTDAY_UPDATE, unuse); - SetZeroAlarm(); // 重置闹钟 + SetZeroAlarm(); // 重置nextday闹钟 } static void on_time_CallBackProc(void) diff --git a/code/sdk/application/wearable/fd230app/nativeui/heart_blood/health_service/health_service.cpp b/code/sdk/application/wearable/fd230app/nativeui/heart_blood/health_service/health_service.cpp index a19afb13c..d20f91d44 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/heart_blood/health_service/health_service.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/heart_blood/health_service/health_service.cpp @@ -81,6 +81,8 @@ void save_heart_rate_data() { printf("save_heart_rate_data success\n"); return; } +//进行心率列表保存 +void save_heart_list() { HealthService::GetInstance()->SaveDailyHeartRate(); } } static HealthService *g_pHealthService = nullptr; /*获取日期*/ @@ -489,7 +491,9 @@ bool HealthService::CleanHealthData() { //清空心率数组 ClearHourlyHeartRates(); //进行数据存储 - SaveDailyHeartRate(); + do_custom_fileoperate_service_check_msg( + CUSTOM_FILEOPERATE_MSG_TYPE_HEART_DATA_LIST, nullptr, 0); + // SaveDailyHeartRate(); HeartModel::GetInstance()->ClearDisplayData(); // BloodOxygenModel::GetInstance()->ClearDisplayData(); @@ -590,8 +594,20 @@ void HealthService::UpdateHourlyHeartRate(time_t timestamp, uint16_t hour = static_cast(timeInfo->tm_hour); if (hour < MAX_HOURS && heartRate > 0) { - dailyHeartRates[hour] = {heartRate, timestamp}; // 更新心率和时间戳 - currenthour = hour; // 记录当前小时 + + // 更新当前小时的心率和时间戳 + dailyHeartRates[hour].Heart = heartRate; + dailyHeartRates[hour].timestamp = timestamp; + + currenthour = hour; + + // 从当前小时的下一个小时开始,清除后续所有已记录的值 + if (hour != 23) { + for (int i = hour + 1; i < MAX_HOURS; ++i) { + dailyHeartRates[i].Heart = 0; + dailyHeartRates[i].timestamp = 0; + } + } WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UpdateHourlyHeartRate is ok"); } else { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, @@ -672,11 +688,11 @@ void HealthService::LoadHeartMaxMin(uint16_t &max, uint16_t &min) { //进行消息发送 void HealthService::send_heart_save() { - do_custom_fileoperate_service_check_msg( - CUSTOM_FILEOPERATE_MSG_TYPE_HEARTRATE_SAVE, nullptr, 0); + do_custom_fileoperate_service_check_msg( + CUSTOM_FILEOPERATE_MSG_TYPE_HEARTRATE_SAVE, nullptr, 0); } void HealthService::send_blood_save() { - do_custom_fileoperate_service_check_msg( - CUSTOM_FILEOPERATE_MSG_TYPE_BLOODXYGEN_SAVE, nullptr, 0); + do_custom_fileoperate_service_check_msg( + CUSTOM_FILEOPERATE_MSG_TYPE_BLOODXYGEN_SAVE, nullptr, 0); } } // namespace OHOS diff --git a/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/include/SafeModeManagerModelC.h b/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/include/SafeModeManagerModelC.h index 3e539e444..6717e0d32 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/include/SafeModeManagerModelC.h +++ b/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/include/SafeModeManagerModelC.h @@ -14,6 +14,8 @@ void store_sport_data(void); void save_heart_rate_data(void); //进行血氧存储 void save_blood_oxygen_data(void); +//进行心率列表存储 +void save_heart_rate_data(void); #ifdef __cplusplus } diff --git a/code/sdk/application/wearable/fd230app/nativeui/system/include/SystemLogModel.h b/code/sdk/application/wearable/fd230app/nativeui/system/include/SystemLogModel.h index 59f74b12e..1f8637861 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/system/include/SystemLogModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/system/include/SystemLogModel.h @@ -54,7 +54,17 @@ enum class SystemLogType { struct SystemLogData { SystemLogType type; // 日志类型 uint32_t timestamp; // 时间戳 -}; +}; + +enum class nextday_type { + NEXTDAY_BEGAN = 0, + NEXTDAY_END, +}; + +struct nextday_log_data { + nextday_type type; + uint32_t timestamp; +}; enum class popup_windows_type // 弹窗类型 { @@ -87,9 +97,9 @@ public: return getFolderSize(TOTAL_RES_SPACE_PATH); } /* ------------------------------- nextday日志记录 ------------------------------ */ - bool save_nextday_log(uint32_t timestamp); // 保存nextday日志 + bool save_nextday_log(nextday_log_data data); // 保存nextday日志 bool load_nextday_log(); // 加载nextday日志 - const std::deque &get_nextday_log() const; // 获取nextday日志记录(常量引用) + const std::deque &get_nextday_log() const; // 获取nextday日志记录(常量引用) size_t get_nextday_log_size() const;//获取日志大小 /* ------------------------------ popup_windows 日志记录----------------------------- */ bool save_popup_windows_log(popup_windows_log_data data); // 保存popup_windows日志 @@ -108,7 +118,7 @@ private: SystemLogModel &operator=(const SystemLogModel &) = delete; std::deque logData; // 存储日志数据 - std::deque nextday_log; // 存储nextday时间戳 + std::deque nextday_log; // 存储nextday时间戳 std::deque popup_windows_log; // 存储popup_windows时间戳 }; } // namespace OHOS diff --git a/code/sdk/application/wearable/fd230app/nativeui/system/include/SystemLogModelC.h b/code/sdk/application/wearable/fd230app/nativeui/system/include/SystemLogModelC.h index ef40e5481..e4fd948af 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/system/include/SystemLogModelC.h +++ b/code/sdk/application/wearable/fd230app/nativeui/system/include/SystemLogModelC.h @@ -12,7 +12,8 @@ void start_report_log(void); void stop_report_log(void); void resume_report_log(void); void update_version_report_log(void); -void start_report_nextday_log(void); +void start_report_nextday_log_start(void); +void start_report_nextday_log_end(void); void nextday_clear_popup_windows_log(void); diff --git a/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemLogModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemLogModel.cpp index a0a50b208..11321a4fc 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemLogModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemLogModel.cpp @@ -5,6 +5,7 @@ #include "iostream" #include "securec.h" #include "system/include/SystemLogModelC.h" +#include "uicomponents/UIComponents.h" #include "wearable_log.h" #include #include @@ -25,7 +26,6 @@ #include #include #include -#include "uicomponents/UIComponents.h" #define SYSTEM_LOG_PATH "/user/system/" #define SYSTEM_LOG_FILE_PATH "/user/system/system_log.txt" @@ -58,9 +58,19 @@ void update_version_report_log(void) { } //保存nextday日志 -void start_report_nextday_log(void) { +void start_report_nextday_log_start(void) { + OHOS::nextday_log_data data; + uint32_t timestamp = OHOS::SystemLogModel::GetInstance()->GetCurrentTime(); + data.type = OHOS::nextday_type::NEXTDAY_BEGAN; + data.timestamp = timestamp; + OHOS::SystemLogModel::GetInstance()->save_nextday_log(data); +} +void start_report_nextday_log_end(void) { + OHOS::nextday_log_data data; uint32_t timestamp = OHOS::SystemLogModel::GetInstance()->GetCurrentTime(); - OHOS::SystemLogModel::GetInstance()->save_nextday_log(timestamp); + data.type = OHOS::nextday_type::NEXTDAY_END; + data.timestamp = timestamp; + OHOS::SystemLogModel::GetInstance()->save_nextday_log(data); } // 清空popup_windows日志 void nextday_clear_popup_windows_log(void) { @@ -250,29 +260,38 @@ bool SystemLogModel::canSyncFile(std::string path, uint32_t path_max_size, return (usedSpace + download_size) <= path_max_size; } // nextday相关 -bool SystemLogModel::save_nextday_log(uint32_t timestamp) { + +bool SystemLogModel::save_nextday_log(nextday_log_data data) { // 检查容量,最多存储7条日志 if (nextday_log.size() >= 7) { nextday_log.pop_front(); // 超出限制,删除最旧的日志 } - // 保存新日志 - nextday_log.push_back(timestamp); + // 保存新日志,将传入的完整日志数据添加到队列 + nextday_log.push_back(data); - // 将日志写入文件 + // 将nextday_log写入文件,覆盖写 std::ofstream outFile(SYSTEM_LOG_FILE_PATH_NEXTDAY, std::ios::trunc); if (!outFile) { return false; // 文件打开失败 } - outFile << timestamp << std::endl; // 写入时间戳 + // 遍历队列,将每条日志数据(包括类型和时间戳)写入文件 + for (const auto &logData : nextday_log) { + // 将日志类型转换为整数写入 + outFile << static_cast(logData.type) << " "; + outFile << logData.timestamp << std::endl; + } + outFile.close(); return true; } +// 加载下一日日志 bool SystemLogModel::load_nextday_log() { nextday_log.clear(); // 清空当前的日志 + std::ifstream inFile(SYSTEM_LOG_FILE_PATH_NEXTDAY); if (!inFile) { return false; // 无法打开文件 @@ -281,20 +300,27 @@ bool SystemLogModel::load_nextday_log() { std::string line; while (std::getline(inFile, line)) { std::istringstream ss(line); - uint32_t timestamp; - if (ss >> timestamp) { - nextday_log.push_back(timestamp); // 读取时间戳并存储 + nextday_log_data data; + + // 先读取日志类型(转换为整数读取),再读取时间戳 + int typeValue; + if (ss >> typeValue >> data.timestamp) { + data.type = static_cast(typeValue); + nextday_log.push_back(data); // 读取时间戳并存储完整日志数据 } } inFile.close(); + return true; } -const std::deque &SystemLogModel::get_nextday_log() const { +// 获取下一日日志 +const std::deque &SystemLogModel::get_nextday_log() const { return nextday_log; // 返回日志记录的常量引用 } -//获取日志大小 + +// 获取日志大小 size_t SystemLogModel::get_nextday_log_size() const { return nextday_log.size(); } 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 1f1772616..8ccff4567 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 @@ -579,6 +579,8 @@ void MsgCenterNotifyNextDayProc(const Topic topic, Request *req) // current_year = 0; #ifdef FD230 printf("******nextday is begin******\r\n"); + // 存储nextday执行日志 + start_report_nextday_log_start(); /* ----------------------------------- 睡眠相关 ----------------------------------- */ if (!ConfigModel::GetInstance()->get_configData_int(OHOS::ConfigModel::CONFIGMODEL_ITEM_SLEEP)) { @@ -588,6 +590,7 @@ void MsgCenterNotifyNextDayProc(const Topic topic, Request *req) GraphicService::GetInstance()->PostGraphicEvent( std::bind(&OHOS::SleepModel::UpdateSleepView, &OHOS::SleepModel::GetInstance())); } + printf("sleep end\n"); /* ---------------------------------- 健康数据相关 ---------------------------------- */ // 清空当日的心率血氧数据 HealthService::GetInstance()->CleanHealthData(); @@ -595,7 +598,9 @@ void MsgCenterNotifyNextDayProc(const Topic topic, Request *req) GraphicService::GetInstance()->PostGraphicEvent( std::bind(&OHOS::HeartModel::CleanAllData, OHOS::HeartModel::GetInstance())); GraphicService::GetInstance()->PostGraphicEvent( - std::bind(&OHOS::BloodOxygenModel::CleanAllData, OHOS::BloodOxygenModel::GetInstance())); + std::bind(&OHOS::BloodOxygenModel::CleanAllData, + OHOS::BloodOxygenModel::GetInstance())); + printf("health end\n"); /* --------------------------------- 每日目标相关 --------------------------------- */ // 午夜清除运动数据 for(int i=1;i<6;i++) @@ -604,11 +609,12 @@ void MsgCenterNotifyNextDayProc(const Topic topic, Request *req) } cywee_reset_history_daily_data(); //清除运动相关数据 do_cywee_service_check_msg(CYWEE_SERVICE_CMD_RESET_DAILY_DATA, NULL); + printf("sport end\n"); /* ---------------------------------- 呼吸训练相关 ---------------------------------- */ RespiratoryTrainingModel::GetInstance().ClearTotalRespiratoryTrainingTime(); // 存储nextday执行日志 - start_report_nextday_log(); + start_report_nextday_log_end(); // 清除popup_windows日志 nextday_clear_popup_windows_log(); diff --git a/code/sdk/application/wearable/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp b/code/sdk/application/wearable/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp index 88812c13f..0da23904b 100644 --- a/code/sdk/application/wearable/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp @@ -411,7 +411,6 @@ namespace OHOS std::string result = logModel->get_system_mem_info(); return result; } - std::string DebugOutputViewEventListener::get_nextday_log() { std::ostringstream result; @@ -420,21 +419,26 @@ namespace OHOS auto logModel = SystemLogModel::GetInstance(); const auto &nextday_logs = logModel->get_nextday_log(); - // 遍历日志并拼接到结果字符串 + // 遍历日志并拼接到结果字符串 for (const auto &log : nextday_logs) { - std::string timestr; - if (log == 0) { - timestr = "--"; // 默认值 - } else { - timestr = formatTime(log); - } - result << "[" << timestr << "] "; // 使用格式化后的时间拼接日志记录 - } + std::string timestr; + if (log.timestamp == 0) { + timestr = "--"; // 默认值 + } else { + timestr = formatTime(log.timestamp); + if (log.type == nextday_type::NEXTDAY_BEGAN) { + timestr += " 开始"; + } else if(log.type == nextday_type::NEXTDAY_END){ + timestr += " 结束:"; + } + } + result << "[" << timestr << "] "; // 使用格式化后的时间拼接日志记录 + } return result.str(); - return result.str(); } + // 定义心率数据文件夹的路径 static const char *HEART_DATA_PATH = "/user/userdata/health/heart"; diff --git a/code/sdk/drivers/peripheral/utils/custom_fileoperate_service.c b/code/sdk/drivers/peripheral/utils/custom_fileoperate_service.c index 8ba44f019..def59e40d 100644 --- a/code/sdk/drivers/peripheral/utils/custom_fileoperate_service.c +++ b/code/sdk/drivers/peripheral/utils/custom_fileoperate_service.c @@ -154,6 +154,9 @@ static void custom_fileoperate_service_check_task(void const *arg) case CUSTOM_FILEOPERATE_MSG_TYPE_RECORDING_SPACE_READ: CheckRecordingSpaceOutC(); break; + case CUSTOM_FILEOPERATE_MSG_TYPE_HEART_DATA_LIST: + save_heart_rate_data(); + break; default: PRINT("Unknown CUSTOM_FILE_OPERATE_MSG cmd 0x%02X \r\n", mail.cmd); break; diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.h b/code/sdk/drivers/peripheral/utils/custom_utils.h index 3fb2bdd72..4d9bb552b 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.h +++ b/code/sdk/drivers/peripheral/utils/custom_utils.h @@ -262,7 +262,8 @@ errcode_t do_custom_cmd_service_check_msg_head(int cmd, void *params, int paraml #define CUSTOM_FILEOPERATE_MSG_TYPE_MUSICNAME_READ 0x0C //读取音乐文件名 -#define CUSTOM_FILEOPERATE_MSG_TYPE_RECORDING_SPACE_READ 0x0D //读取录音空间 +#define CUSTOM_FILEOPERATE_MSG_TYPE_RECORDING_SPACE_READ 0x0D //读取录音空间 +#define CUSTOM_FILEOPERATE_MSG_TYPE_HEART_DATA_LIST 0x0E //存储心率数据列表 errcode_t uapi_custom_fileoperate_service_init(void); errcode_t do_custom_fileoperate_service_check_msg(int cmd, void *params, int paramlen);