From: Caisking Date: Mon, 16 Jun 2025 04:33:46 +0000 (+0800) Subject: Merge branch 'sdk602patch0911' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0... X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=dd30a88ac08915c468cf33c5be3bb155eec0d967;p=mirrors%2FFD230.git Merge branch 'sdk602patch0911' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0911 --- dd30a88ac08915c468cf33c5be3bb155eec0d967 diff --cc code/sdk/application/wearable/fd230app/nativeui/bloodpressure/include/BPModel.h index 9625a770b,0e10aab50..6fcdad54d --- a/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/include/BPModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/include/BPModel.h @@@ -5,33 -17,70 +5,36 @@@ #include #include -namespace OHOS -{ - // 血氧检测状态 - enum class BPState - { - End = 0, - Start, - }; - enum class BPMain - { - NOT_TESTED = 0, // 未检测 - SUCCESS, // 检测成功 - NOT_WORN, // 未佩戴检测 - TIMEOUT, // 检测超时 - HIGH_RESULT, // 检测结果过高 - LOW_RESULT, // 检测结果过低 - INVALID_DATA // 无效数据 - }; - class BPModel - { - public: - BPModel(); - ~BPModel(); - static BPModel *GetInstance(); - - void UpSPO2data(uint8_t spo2); - uint16_t GetSPO2data(); - uint16_t GetShowSPO2data(); - - uint32_t GetCheckTime(); - void SetCheckTime(uint32_t time); - void SetWearStatus(int32_t wear); - void SetMain(BPMain result); - BPMain GetMain(); - - void BP_Stop(void); - void BP_Start(void); - void BP_Save(void); - void BP_Main(void); - - void BP_Control(BPState state); - void ClearDisplayData(); - void CleanAllData(); - - // 定时器管理 - void BP_StartTimer(uint32_t interval = 1000); - void BP_StopTimer(void); - - - private: - uint16_t displayspo2; - uint16_t currentspo2; - uint32_t timestamp_ms; - int32_t wear_; - - bool sensorstate{false}; - bool startspo2{false}; - - uint16_t unwear_counter_; // 无效佩戴计数器 - uint16_t valid_counter_; // 有效数计数器 - uint16_t disvalid_counter_; // 无效数计数器 - BPMain bloodresult_ = BPMain::NOT_TESTED; // 检测结果 - bool initstatus; - }; -} +namespace OHOS { +// 血压检测状态 +enum class BPState { + End = 0, + Start, +}; +// 血压检测结果 +enum class BPRESULT { + NOT_TESTED = 0, // 未检测 + SUCCESS, // 检测成功 + NOT_WORN, // 未佩戴检测 + TIMEOUT, // 检测超时 + HIGH_RESULT, // 检测结果过高 + LOW_RESULT, // 检测结果过低 + INVALID_DATA // 无效数据 +}; +class BPModel { +public: + BPModel(); + ~BPModel(); + static BPModel *GetInstance(); + + //获取当前时间年月日时分字符串 + std::string GetCurrentTimeStr(); ++ // 定时器管理 ++ void BP_StartTimer(uint32_t interval = 1000); ++ void BP_StopTimer(void); + +private: +}; +} // namespace OHOS #endif diff --cc code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/BPModel.cpp index d32491f23,9381dbc45..523ee684b --- a/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/BPModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/BPModel.cpp @@@ -1,71 -1,395 +1,161 @@@ #include "bloodpressure/include/BPModel.h" #include "bloodpressure/include/BPMainPresenter.h" -#include "DialModelSPO2.h" -#include "wearable_log.h" #include "heart_blood/health_service/health_service.h" -#include "custom_utils.h" +#include "wearable_log.h" -#include + #include ++#include + #include + extern "C" errcode_t uapi_get_timestamp_ms(uint32_t *tm); -#include "custom_utils.h" -#include "ppg_service.h" -#include "ConfigModel.h" #include "AppViewIDs.h" +#include "ConfigModel.h" #include "NativeAbility.h" -#include "battery_hal.h" -// #include "heart_blood/BloodCardView.h" -#include "MainViewSample.h" -#include +#include "battery_hal.h" +#include "custom_utils.h" +#include "ppg_service.h" - #define MAX_UNWARE_COUNT 10 #define MAX_VALID_SPO2_COUNT 30 #define MAX_DISVALID_SPO2_COUNT 100 -namespace OHOS -{ - static osTimerId_t g_timer = nullptr; - static int Time = 30; - - /** - * @brief Constructor for the BPModel class. - */ - BPModel::BPModel() - { - // BPData *data = HealthService::GetInstance()->ReadBPData(); - // if (data) - // { - // currentspo2 = data->SPO2; - // timestamp_ms = data->timestamp; - // // 更新表盘血氧数据 - // DialModelSPO2::GetInstance()->UpdateSPO2(currentspo2); - // delete data; - // } - // else - // { - currentspo2 = 0; - timestamp_ms = 0; - // } - } - BPModel::~BPModel() {} - BPModel *BPModel::GetInstance(void) - { - static BPModel instance; - return &instance; - } - /* ---------------------------------- 状态检测 ---------------------------------- */ - - void BPModel::ClearDisplayData() - { - // currentspo2 = 0; - // timestamp_ms = 0; - // 不需要清空 - } - - // 血氧监控 - void BPModel::BP_Control(BPState state) - { - // if (state == BPState::End && startspo2 == true) - // { - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "startspo2 End"); - // uint16_t md = PPG_SERVICE_CMD_TYPE_STOP_SPO2_TEST; - // send_ppg_cmd_msg(md); - // startspo2 = false; - - // uapi_save_runtime_log(RUNTIME_LOG_OXYGEN_MEASURE_END); - // } - // else if (state == BPState::Start && startspo2 == false) - // { - // /*充电状态下不进行检测*/ - // bool isCharging = get_charge_stat(); // 获取充电状态 - // if (isCharging) - // { - // WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "充电不能检测"); - // return; - // } - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "startspo2 Start"); - // uint16_t md = PPG_SERVICE_CMD_TYPE_DO_SPO2_TEST; - // send_ppg_cmd_msg(md); - // startspo2 = true; - - // uapi_save_runtime_log(RUNTIME_LOG_OXYGEN_MEASURE); - // } - } - - uint16_t BPModel::GetSPO2data() - { - return currentspo2; - } - - uint16_t BPModel::GetShowSPO2data() - { - return displayspo2; - } - - uint32_t BPModel::GetCheckTime() - { - return timestamp_ms; - } - void BPModel::SetCheckTime(uint32_t time) - { - timestamp_ms = time; - } - void BPModel::SetMain(BPMain result) - { - bloodresult_ = result; - } - BPMain BPModel::GetMain() - { - return bloodresult_; - } - - // 开始检测 - void BPModel::BP_Start() - { - // displayspo2 = 0; - // SetMain(BPMain::NOT_TESTED); // 成功检测 - // // 进行初始化操作 - // if (!sensorstate) - // { - // BP_Control(BPState::Start); - // sensorstate = true; - // } - } - - // 结束检测 - void BPModel::BP_Stop() - { - // valid_counter_ = 0; - // disvalid_counter_ = 0; - // unwear_counter_ = 0; - - // if (sensorstate) - // { - // BP_Control(BPState::End); - // sensorstate = false; - // BP_Main(); // 处理结果 - // } - } - - // 保存检测数据 - void BPModel::BP_Save() - { -// uint32_t timestamp = BPMainPresenter::GetInstance()->GetCurrentTime(); -// SetCheckTime(timestamp); -// #if MSG_SAVE_TEST -// BPData data; -// data.SPO2 = currentspo2; -// data.timestamp = timestamp_ms; -// HealthService::GetInstance()->UpdateHealthData(data); -// #else -// HealthService::GetInstance()->send_blood_save(); -// #endif - } - - // 显示检测结果// 显示检测结果 - void BPModel::BP_Main() - { - // uint16_t MiniBP = ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_OXYGEN_THRESHOLD_VALUE); - - // // 检查当前血氧值并设置结果 需要检测成功 - // if(bloodresult_ == BPMain::SUCCESS){ - // if (currentspo2 < MiniBP && currentspo2 != 0) - // { - // // 测量结果小于最小血氧值 - // bloodresult_ = BPMain::LOW_RESULT; - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "检测结果: 低结果情况, currentspo2 = %d, MiniBP = %d", currentspo2, MiniBP); - // } - // } - - // // 根据结果进行处理 - // switch (bloodresult_) - // { - // case BPMain::SUCCESS: - // { - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "检测结果: 成功"); - // BP_Save(); - // NativeAbility::GetInstance().Back(); // 成功 - // break; - // } - // case BPMain::NOT_WORN: // 未佩戴状态 - // { - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "检测结果: 未佩戴状态"); - // NativeAbility::GetInstance().ChangeSlice(VIEW_CHECK_ABNORMAL); - // break; - // } - // case BPMain::TIMEOUT: // 超时情况 - // { - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "检测结果: 超时情况"); - // NativeAbility::GetInstance().ChangeSlice(VIEW_CHECK_ABNORMAL); - // break; - // } - // case BPMain::LOW_RESULT: // 低结果情况 - // { - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "检测结果: 低结果情况"); - // HealthState healthState; - // healthState.checkType = BP_CHECK; - // healthState.resultStatus = LOW; - // healthState.checkMain = MiniBP; - // HealthService::GetInstance()->SetHealthCurrent(healthState); - // //保存异常数据 - // BP_Save(); - // NativeAbility::GetInstance().ChangeSlice(VIEW_CHECK_INVALID); - // break; - // } - // case BPMain::INVALID_DATA: // 无效数据情况 - // { - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "检测结果: 无效数据情况"); - // NativeAbility::GetInstance().ChangeSlice(VIEW_CHECK_ABNORMAL); - // break; - // } - // default: - // { - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "检测结果: 未知状态"); - // break; - // } - // } - } - // 更新佩戴状态 - void BPModel::SetWearStatus(int32_t wear) - { - // // 设置佩戴状态 - // WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BPModel Weartest::%d", wear); - // //开启检测才对佩戴进行监听 - // if (sensorstate) - // { - // // 计数更新 - // if (wear_ != 1 && wear != 1) - // { - // unwear_counter_++; // 佩戴错误计时器计数 - // } - // else - // { - // unwear_counter_ = 0; // 佩戴正常情况下清零计数器 - // } - // wear_ = wear; - // // 检查是否达到了最大未佩戴计数限制 - // if (unwear_counter_ >= MAX_UNWARE_COUNT) - // { - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "检测结果: 未佩戴计数最大 unwear_counter: %d", unwear_counter_); - // SetMain(BPMain::NOT_WORN); - // BP_Stop(); - // } - // } - } +/* +---------------------------- +收缩压:DBP +舒张压:SBP +血压:Blood Pressure(BP) +高血压:Hypertension +低血压:Hypotension +---------------------------- +血压测量标准: +1、正常血压:收缩压(高压)<120 mmHg 且 舒张压(低压)<80 mmHg。 +2、高血压:收缩压≥140 mmHg 或 舒张压≥90 mmHg。 +3、低血压:收缩压<90 mmHg 且 舒张压<60 mmHg。 +---------------------------- +*/ +namespace OHOS { +/** + * @brief Constructor for the BPModel class. + */ +BPModel::BPModel() {} +BPModel::~BPModel() {} +BPModel *BPModel::GetInstance(void) { + static BPModel instance; + return &instance; +} - // 更新SPO2数据 - void BPModel::UpSPO2data(uint8_t spo2) - { - // displayspo2 = spo2; +//获取当前时间戳字符串 +std::string BPModel::GetCurrentTimeStr() { + uint32_t timeStamp = 0; - // // 处理有效与无效计数 - // if (displayspo2 != 0) - // { - // currentspo2 = displayspo2; // 更新 currentspo2 - // valid_counter_++; // 增加有效计数器 - // disvalid_counter_ = 0; // 清空无效计数器 - // } - // else - // { - // disvalid_counter_++; // 增加无效计数器 - // valid_counter_ = 0; // 清零有效计数器 - // } + if (uapi_get_timestamp_ms(&timeStamp) != ERRCODE_SUCC) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to get timestamp"); + return "----/--/-- /n --/--"; + } - // // 检查无效计数器是否达标 - // if (disvalid_counter_ >= MAX_DISVALID_SPO2_COUNT) - // { - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "检测结果: 无效数达标 disvalid_counter: %d", disvalid_counter_); - // SetMain(BPMain::INVALID_DATA); // 无效数达标 - // BP_Stop(); - // } + // 将时间戳转换为 time_t 类型 + time_t rawtime = static_cast(timeStamp); + struct tm *timeinfo = localtime(&rawtime); - // // 检查有效计数器是否达标 - // if (valid_counter_ >= MAX_VALID_SPO2_COUNT) - // { - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "检测结果: 成功 valid_counter: %d currentspo2: %d", valid_counter_, currentspo2); - // SetMain(BPMain::SUCCESS); // 成功检测 - // BP_Stop(); - // } - } + if (timeinfo == NULL) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to convert time"); + return "----/--/-- /n --/--"; + } - // 更新血氧数据 - void BPModel::CleanAllData(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Nextday!"); - // if (MainViewSample::GetInstance() != nullptr && BPCardView::GetInstance() != nullptr) - // { - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "更新主界面血氧卡片"); - // BPCardView::GetInstance()->UpSPO2Text(); - // } - if (BPMainView::GetInstance() != nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "更新测量血氧卡片"); - // BPMainView::GetInstance()->UpSPO2Text(); - } - } - /* -------------------------------------------------------------------------- */ - /*定时器到期时的处理*/ - static void BP_TimerCallbackProc(int data) - { - // 等待完成的定时器 - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BP_TimerCallbackProc,Time = %d", Time); - if (Time < 0) // 如果校准超时30s,进入完成界面 - { - BPModel::GetInstance()->BP_StopTimer(); - BPMainView::GetInstance()->ChangeView(BPUNDERCALIBRATIONVIEW,BPVALUEVIEW); - } - return; - } + // 格式化时间为字符串 + char buffer[20]; // 格式: YYYY-MM-DD HH:MM + std::strftime(buffer, sizeof(buffer), "%Y-%m-%d /n %H:%M", timeinfo); - /* - * @brief 回调函数 - */ - static void BP_TimerCallback(int data) - { - Time -= 1; - GraphicService::GetInstance()->PostGraphicEvent(std::bind(BP_TimerCallbackProc, data)); - } + return std::string(buffer); +} + - /* - * @brief 开启定时器函数 - * @param interval 时间间隔,单位ms - */ - void BPModel::BP_StartTimer(uint32_t interval) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BPModel::BP_StartTimer"); - /* -------------------------- 1.检查定时器是否已经存在,如果存在则返回 ------------------------- */ - if (g_timer != nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Timer already exists!!"); - return; - } + - /* --------------------------------- 2.创建定时器 -------------------------------- */ - g_timer = osTimerNew((osTimerFunc_t)BP_TimerCallback, osTimerPeriodic, nullptr, nullptr); - // 检查定时器创建是否成功 - if (g_timer == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Timer create failed!!"); - return; - } ++/////////////////////////////////////////////////////////////////////////////////////// + - /* ----------------------------- 3.将毫秒转换为系统时钟节拍数 ---------------------------- */ - int tick = osMs2Tick(interval); ++/*定时器到期时的处理*/ ++static void BP_TimerCallbackProc(int data) { ++ // 等待完成的定时器 ++ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BP_TimerCallbackProc,Time = %d", ++ Time); ++ if (Time < 0) // 如果校准超时30s,进入完成界面 ++ { ++ BPModel::GetInstance()->BP_StopTimer(); ++ BPMainView::GetInstance()->ChangeView(BPUNDERCALIBRATIONVIEW, BPVALUEVIEW); ++ } ++ return; ++} + - /* --------------------------------- 4.启动定时器 -------------------------------- */ - osStatus_t ret = osTimerStart(g_timer, tick); - /* -------------------- 5.检查定时器启动是否成功,如果启动失败,删除定时器并置为 nullptr -------------------- */ - if (ret != osOK) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret); - if (g_timer != nullptr) - { - ret = osTimerDelete(g_timer); - } - g_timer = nullptr; - return; - } - } ++/* ++ * @brief 回调函数 ++ */ ++static void BP_TimerCallback(int data) { ++ Time -= 1; ++ GraphicService::GetInstance()->PostGraphicEvent( ++ std::bind(BP_TimerCallbackProc, data)); ++} + - /* - * @brief 停止定时器 - */ - void BPModel::BP_StopTimer(void) - { - // 检查定时器是否存在 - if (g_timer != nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BPModel::BP_StopTimer"); - osTimerStop(g_timer); - // 删除定时器并置为 nullptr - osStatus_t ret = osTimerDelete(g_timer); - if (ret != osOK) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret); - } - g_timer = nullptr; - Time = 30; - } - } ++/* ++ * @brief 开启定时器函数 ++ * @param interval 时间间隔,单位ms ++ */ ++void BPModel::BP_StartTimer(uint32_t interval) { ++ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BPModel::BP_StartTimer"); ++ /* -------------------------- 1.检查定时器是否已经存在,如果存在则返回 ++ * ------------------------- */ ++ if (g_timer != nullptr) { ++ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Timer already exists!!"); ++ return; ++ } ++ ++ /* --------------------------------- 2.创建定时器 ++ * -------------------------------- */ ++ g_timer = osTimerNew((osTimerFunc_t)BP_TimerCallback, osTimerPeriodic, ++ nullptr, nullptr); ++ // 检查定时器创建是否成功 ++ if (g_timer == nullptr) { ++ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Timer create failed!!"); ++ return; ++ } ++ ++ /* ----------------------------- 3.将毫秒转换为系统时钟节拍数 ++ * ---------------------------- */ ++ int tick = osMs2Tick(interval); ++ ++ /* --------------------------------- 4.启动定时器 ++ * -------------------------------- */ ++ osStatus_t ret = osTimerStart(g_timer, tick); ++ /* -------------------- 5.检查定时器启动是否成功,如果启动失败,删除定时器并置为 ++ * nullptr -------------------- */ ++ if (ret != osOK) { ++ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ++ ret); ++ if (g_timer != nullptr) { ++ ret = osTimerDelete(g_timer); ++ } ++ g_timer = nullptr; ++ return; ++ } ++} ++/* ++ * @brief 停止定时器 ++ */ ++void BPModel::BP_StopTimer(void) { ++ // 检查定时器是否存在 ++ if (g_timer != nullptr) { ++ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BPModel::BP_StopTimer"); ++ osTimerStop(g_timer); ++ // 删除定时器并置为 nullptr ++ osStatus_t ret = osTimerDelete(g_timer); ++ if (ret != osOK) { ++ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, ++ "osTimerDelete failed, ret = %lx!!", ret); ++ } ++ g_timer = nullptr; ++ Time = 30; ++ } + } ++ +} // namespace OHOS