From da85a7c40c9467c50ec349a0bd74f548f054e1ed Mon Sep 17 00:00:00 2001 From: Caisking Date: Mon, 16 Jun 2025 12:26:55 +0800 Subject: [PATCH] =?utf8?q?=E8=A1=80=E5=8E=8Bmodel=E5=A2=9E=E5=8A=A0?= =?utf8?q?=E8=8E=B7=E5=8F=96=E6=97=B6=E9=97=B4str=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativeui/bloodpressure/include/BPModel.h | 100 ++---- .../nativeui/bloodpressure/src/BPModel.cpp | 329 +++--------------- 2 files changed, 76 insertions(+), 353 deletions(-) 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 5f0f91033..9625a770b 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/include/BPModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/include/BPModel.h @@ -1,15 +1,3 @@ -/*** - * @Date: 2024-04-15 10:55:58 - * @LastEditors: Caisking 3449750381@qq.com - * @LastEditTime: 2024-09-05 14:58:21 - * @FilePath: /FD230/code/sdk/application/wearable/fd230/nativeapp/nativeui/bloodpressure/include/BPModel.h - */ -/*** - * @Date: 2024-04-15 10:55:58 - * @LastEditors: Caisking 3449750381@qq.com - * @LastEditTime: 2024-07-31 10:38:26 - * @FilePath: /FD230/code/sdk/application/wearable/fd230/nativeapp/nativeui/bloodpressure/include/BPModel.h - */ #ifndef BP_MODEL_H #define BP_MODEL_H @@ -17,65 +5,33 @@ #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(); - - 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(); + +private: +}; +} // namespace OHOS #endif 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 421c956e7..d32491f23 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/BPModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/BPModel.cpp @@ -1,304 +1,71 @@ #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" 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 "custom_utils.h" +#include "ppg_service.h" -#include #define MAX_UNWARE_COUNT 10 #define MAX_VALID_SPO2_COUNT 30 #define MAX_DISVALID_SPO2_COUNT 100 -namespace OHOS -{ - /** - * @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); - // } - // } +/* +---------------------------- +收缩压: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; +} - // // 根据结果进行处理 - // 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(); - // } - // } - } +//获取当前时间戳字符串 +std::string BPModel::GetCurrentTimeStr() { + uint32_t timeStamp = 0; - // 更新SPO2数据 - void BPModel::UpSPO2data(uint8_t spo2) - { - // displayspo2 = spo2; + if (uapi_get_timestamp_ms(&timeStamp) != ERRCODE_SUCC) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to get timestamp"); + return "----/--/-- /n --/--"; + } - // // 处理有效与无效计数 - // if (displayspo2 != 0) - // { - // currentspo2 = displayspo2; // 更新 currentspo2 - // valid_counter_++; // 增加有效计数器 - // disvalid_counter_ = 0; // 清空无效计数器 - // } - // else - // { - // disvalid_counter_++; // 增加无效计数器 - // valid_counter_ = 0; // 清零有效计数器 - // } + // 将时间戳转换为 time_t 类型 + time_t rawtime = static_cast(timeStamp); + struct tm *timeinfo = localtime(&rawtime); - // // 检查无效计数器是否达标 - // if (disvalid_counter_ >= MAX_DISVALID_SPO2_COUNT) - // { - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "检测结果: 无效数达标 disvalid_counter: %d", disvalid_counter_); - // SetMain(BPMain::INVALID_DATA); // 无效数达标 - // BP_Stop(); - // } + if (timeinfo == NULL) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to convert time"); + return "----/--/-- /n --/--"; + } - // // 检查有效计数器是否达标 - // 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(); - // } - } + // 格式化时间为字符串 + char buffer[20]; // 格式: YYYY-MM-DD HH:MM + std::strftime(buffer, sizeof(buffer), "%Y-%m-%d /n %H:%M", timeinfo); - // 更新血氧数据 - 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(); - } - } + return std::string(buffer); } +} // namespace OHOS -- 2.17.1