From: xue <2144439972@qq.com> Date: Tue, 8 Jul 2025 07:45:28 +0000 (+0800) Subject: 增加上次校准时间逻辑处理 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=d25610d9899bf531a82d8b903689a2c3eee5c168;p=mirrors%2FFD230.git 增加上次校准时间逻辑处理 --- diff --git a/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/include/BPLastCalibrationTimeView.h b/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/include/BPLastCalibrationTimeView.h index a66f22cd3..c1d97840a 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/include/BPLastCalibrationTimeView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/include/BPLastCalibrationTimeView.h @@ -18,7 +18,7 @@ namespace OHOS ~BPLastCalibrationTimeView(); static BPLastCalibrationTimeView *GetInstance(); UIViewGroup *InitBPLastCalibrationTimeView(); - void UpdateCalibrationTime(std::string time); + void UpdateCalibrationTime(); private: void DeInit(); diff --git a/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/include/BPModel.h b/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/include/BPModel.h index 6d5ca2efe..0e14b19ce 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/include/BPModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/include/BPModel.h @@ -15,7 +15,7 @@ namespace OHOS { // 检测状态 - static constexpr size_t StateMapperSize = BP_STATE_NUM; // 根据实际条目数修改 + static constexpr size_t StateMapperSize = BP_STATE_NUM; // 根据实际条目数修改 // 血压测量状态枚举 enum class BPState { @@ -67,7 +67,7 @@ namespace OHOS struct LAST_CHECK_DATA { - uint64_t timestamp; // 时间戳 单位s + uint32_t timestamp; // 时间戳 单位s uint8_t last_check_sbp_value; // 上次检测收缩压值 uint8_t last_check_dbp_value; // 上次检测舒张压值 }; @@ -84,12 +84,16 @@ namespace OHOS // 获取第几次校准 int16_t GetCalibrationFlag(); void SetCalibrationFlag(uint8_t value); - // 获取当前时间年月日时分字符串 - std::string GetCurrentTimeStr(); - std::string GetCurrentTimeStr(uint64_t timeStamp); - // 获取当前时间戳 - uint32_t GetCurrentTime(); + + /* ---------------------------------时间处理 --------------------------------- */ + std::string GetCurrentTimeStr(); // 获取当前时间年月日时分字符串 + std::string GetCurrentTimeStr(uint32_t timeStamp); + uint32_t GetCurrentTime(); // 获取当前时间戳 std::string GetLastCalibrationTime(); + bool IsCalibrationOver(); + bool needMeasure(int validityDays = 30); + + /* -------------------------------------------------------------------------- */ /* ---------------------------------状态处理 --------------------------------- */ void BP_SetState(BPState state); BPState GetCurrentState(); @@ -109,13 +113,13 @@ namespace OHOS void BPControlECGMeasureEnd(); void BPControlEMOMeasure(); void BPControlEMOMeasureEnd(); - void BPControlCalibratingAnalysis(); - void BPControlStressAnalysis(); - void BPControlFatigueAnalysis(); - void BPControlECGRemind(); - void BPControlECGAnalysis(); - void BPControlECGResult(); - void BPControlEMOAnalysis(); + void BPControlCalibratingAnalysis(); + void BPControlStressAnalysis(); + void BPControlFatigueAnalysis(); + void BPControlECGRemind(); + void BPControlECGAnalysis(); + void BPControlECGResult(); + void BPControlEMOAnalysis(); /* -------------------------------------------------------------------------- */ // 控制血压检测 @@ -142,7 +146,6 @@ namespace OHOS uint8_t mapValue(uint8_t value); void mapDataArray(uint8_t value); bool CleanBPData(void); - bool needMeasure(int validityDays = 30); // 获取过程值数据 std::vector GetBPCheckDataArray(void); @@ -166,9 +169,10 @@ namespace OHOS std::map> bp_check_value_map; // 记录获取的sbp和dbp值 std::vector bp_check_value_vector; // 测量值-----没用了 std::string LastCalibrationTime; - uint8_t CalibrationFlag = 0; - LAST_CHECK_DATA lastData; // 上一次测量的数据 - BPRESULT bp_resullt = BPRESULT::NOT_TESTED; // 测量状态 + uint8_t CalibrationFlag = 0; + LAST_CHECK_DATA lastData; // 上一次测量的数据 + BPRESULT bp_resullt = BPRESULT::NOT_TESTED; // 测量状态 + bool NeedCalibrationFlag = ture; // 是否需要校准标志位 }; } // namespace OHOS diff --git a/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/BPLastCalibrationTimeView.cpp b/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/BPLastCalibrationTimeView.cpp index 51cb657c4..3aedde31d 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/BPLastCalibrationTimeView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/BPLastCalibrationTimeView.cpp @@ -45,11 +45,11 @@ namespace OHOS } // 更新校准时间 - void BPLastCalibrationTimeView::UpdateCalibrationTime(std::string time) + void BPLastCalibrationTimeView::UpdateCalibrationTime() { if (timeLabel != nullptr) { - std::string str = time; + std::string str = BPModel::GetInstance()->GetLastCalibrationTime();//获取上次校准时间 WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "UpdateCalibrationTime: %s", str.c_str()); timeLabel->SetText(str.c_str()); timeLabel->Invalidate(); @@ -194,6 +194,7 @@ namespace OHOS CalibrationButton->SetStyleForState(STYLE_BACKGROUND_OPA, 0x00, UIButton::PRESSED); CalibrationButton->SetOnClickListener((UIView::OnClickListener *)OHOS::BPMainPresenter::GetInstance()); group->Add(CalibrationButton); + UpdateCalibrationTime(); return group; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/BPMainView.cpp b/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/BPMainView.cpp index ca2c53ab2..e3f4d3c38 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/BPMainView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/BPMainView.cpp @@ -115,18 +115,15 @@ namespace OHOS container_->SetDraggable(true); container_->SetTouchable(true); container_->SetOnDragListener(presenter_); - - if (BPModel::GetInstance()->GetCalibrationFlag() == 0) + if (BPModel::GetInstance()->GetCalibrationFlag() == 0 || BPModel::GetInstance()->IsCalibrationOver())//超过了一天需要重新校准 { + BPModel::GetInstance()->SetCalibrationFlag(0); //超过一天自动重置 ChangeView(MAX_BPVIEW, BPCALPOSREQVIEW); // 切换到第一个界面 - BPMainPresenter::GetInstance()->SetPassflag(0); // 重置校准成功按钮标志位 } - else { BPModel::GetInstance()->SetCalibrationFlag(2); ChangeView(MAX_BPVIEW, BPLASTCALIBRATIONTIME); - BPMainPresenter::GetInstance()->SetPassflag(1); // 校准成功按钮标志位 } // 增加按键监听 diff --git a/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/BPModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/BPModel.cpp index 4df6d556b..47c939d7a 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/BPModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/BPModel.cpp @@ -134,7 +134,7 @@ namespace OHOS return binFilePath; } - std::string BPModel::GetCurrentTimeStr(uint64_t timeStamp) + std::string BPModel::GetCurrentTimeStr(uint32_t timeStamp) { if (timeStamp < 0) @@ -173,12 +173,135 @@ namespace OHOS // 获取上次校准时间 std::string BPModel::GetLastCalibrationTime() { + int FirstCalibrationTime = 0; +#if defined(BOARD_W9) + FirstCalibrationTime = ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_BP_CALIBRATION_FIRST_TIME); +#endif + // 检查存储的时间戳是否有效(非负) + if (FirstCalibrationTime < 0) + { + // 处理无效时间(例如:返回 true 表示需要重新校准) + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed that FirstCalibrationTime is negative number"); + return std::string(); + } + + // 将 int 转换为 uint32_t(确保非负) + uint32_t FirstTime = static_cast(FirstCalibrationTime); + LastCalibrationTime = GetCurrentTimeStr(FirstTime); if (LastCalibrationTime.empty()) { - return " "; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to format timestamp %u", FirstTime); + return std::string(); } return LastCalibrationTime; } + // 判断校准时间是否超过一天 + bool BPModel::IsCalibrationOver() + { + int FirstCalibrationTime = 0; +#if defined(BOARD_W9) + FirstCalibrationTime = ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_BP_CALIBRATION_FIRST_TIME); +#endif + uint32_t CurrentTime = GetCurrentTime(); + // 检查存储的时间戳是否有效(非负) + if (FirstCalibrationTime < 0) + { + // 处理无效时间(例如:返回 true 表示需要重新校准) + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed that FirstCalibrationTime is negative number"); + return true; + } + + // 将 int 转换为 uint32_t(确保非负) + uint32_t FirstTime = static_cast(FirstCalibrationTime); + + // 计算时间差(避免负值) + if (CurrentTime < FirstTime) + { + // 当前时间早于存储时间,未超过一天 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed that FirstTime more than CurrentTime"); + return false; + } + + uint32_t elapsedTime = CurrentTime - FirstTime; + + // 判断是否超过一天(以秒为单位) + const uint32_t SECONDS_IN_A_DAY = 86400; // 24 * 60 * 60 + return elapsedTime > SECONDS_IN_A_DAY; + } + /** + * @brief 判断是否需要进行新的测量 + * @param validityDays 校准有效期(天),默认30天 + * @return true 需要测量(校准无效),false 无需测量(校准有效) + */ + bool BPModel::needMeasure(int validityDays) + { + // 校验输入参数有效性 + if (validityDays <= 0) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "有效期参数无效(必须为正数): %d", validityDays); + return true; // 参数错误时需要测量 + } + + // 获取两次校准时间 + int firstCalibTime = 0; + int secondCalibTime = 0; +#if defined(BOARD_W9) + firstCalibTime = ConfigModel::GetInstance()->get_configData_int(OHOS::ConfigModel::CONFIGMODEL_ITEM_BP_CALIBRATION_FIRST_TIME); + secondCalibTime = ConfigModel::GetInstance()->get_configData_int(OHOS::ConfigModel::CONFIGMODEL_ITEM_BP_CALIBRATION_SECOND_TIME); +#endif + + // 获取当前时间(秒级时间戳) + uint32_t now = 0; + uapi_get_timestampe_ss(&now); + + // 定义时间常量 + const int64_t SECONDS_PER_DAY = 24 * 3600; + const int64_t validitySeconds = validityDays * SECONDS_PER_DAY; + + // 检查校准时间是否未设置(无效值) + if (firstCalibTime <= 0 || secondCalibTime <= 0) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "校准时间未设置(首次:%d,二次:%d),需要测量", + firstCalibTime, secondCalibTime); + return true; + } + + // 检查校准时间是否晚于当前时间(时间异常) + if (static_cast(firstCalibTime) > now || static_cast(secondCalibTime) > now) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "校准时间异常(当前:%u,首次:%d,二次:%d),需要测量", + now, firstCalibTime, secondCalibTime); + return true; + } + + // 计算时间差 + int64_t firstDiff = now - static_cast(firstCalibTime); + int64_t secondDiff = now - static_cast(secondCalibTime); + + bool firstValid = firstDiff <= validitySeconds; + bool secondValid = secondDiff <= validitySeconds; + + // 输出调试日志 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "时间差检查:当前=%u, 首次校准=%d(%llds前), 二次校准=%d(%llds前), 有效期=%llds", + now, firstCalibTime, firstDiff, secondCalibTime, secondDiff, validitySeconds); + + // 检查校准是否过期 + if (!firstValid) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "第一次校准已过期,需要测量"); + return true; + } + if (!secondValid) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "第二次校准已过期,需要测量"); + return true; + } + + // 两次校准均有效 + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "两次校准均在有效期内,无需测量"); + return false; + } /////////////////////////状态管理////////////////////////////////////////// int16_t BPModel::GetCalibrationFlag() { return CalibrationFlag; } void BPModel::SetCalibrationFlag(uint8_t value) { CalibrationFlag = value; } @@ -537,45 +660,6 @@ namespace OHOS return true; } - /** - * @brief 判断是否需要进行新的测量 - * @param validityDays 校准有效期(天),默认30天 - * @return true 需要测量(校准无效),false 无需测量(校准有效) - */ - bool BPModel::needMeasure(int validityDays) - { - int firstCalibTime = 0; - int secondCalibTime = 0; -#if defined(BOARD_W9) - firstCalibTime = ConfigModel::GetInstance()->get_configData_int(OHOS::ConfigModel::CONFIGMODEL_ITEM_BP_CALIBRATION_FIRST_TIME); - secondCalibTime = ConfigModel::GetInstance()->get_configData_int(OHOS::ConfigModel::CONFIGMODEL_ITEM_BP_CALIBRATION_SECOND_TIME); -#endif - // 2. 获取当前时间(秒级时间戳) - uint32_t now = 0; - uapi_get_timestampe_ss(&now); - // 3. 计算有效期(秒) - const int64_t validitySeconds = validityDays * 24 * 3600; - - // 4. 检查两次校准是否均在有效期内 - bool firstValid = (now - firstCalibTime) <= validitySeconds; - bool secondValid = (now - secondCalibTime) <= validitySeconds; - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "now:%d,firstCalibTime:%d,secondCalibTime:%d", now, firstCalibTime, secondCalibTime); - - if (!firstValid) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "第一次校准已过期,需要测量"); - return true; - } - if (!secondValid) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "第二次校准已过期,需要测量"); - return true; - } - - // 5. 两次校准均有效,无需测量 - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "两次校准均在有效期内,无需测量"); - return false; - } //////////////////////////////////time处理//////////////////////////////////// // time到时的处理 void BPModel::BP_timer_callback_out() @@ -808,6 +892,9 @@ namespace OHOS newData.last_check_sbp_value = custom_sbp; // 测试数据 newData.last_check_dbp_value = custom_dbp; newData.timestamp = BPModel::GetCurrentTime(); + lastData = newData; + // 测量完成 + bp_resullt == BPRESULT::SUCCESS; WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SBP: %d, DBP: %d", custom_sbp, custom_dbp); } } @@ -832,6 +919,9 @@ namespace OHOS newData.last_check_sbp_value = custom_sbp; // 测试数据 newData.last_check_dbp_value = custom_dbp; newData.timestamp = BPModel::GetCurrentTime(); + lastData = newData; + // 测量完成 + bp_resullt == BPRESULT::SUCCESS; WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SBP: %d, DBP: %d", custom_sbp, custom_dbp); } }