From 341ec558fa7a30498be6da1df7aea145d04a4d20 Mon Sep 17 00:00:00 2001 From: xue <2144439972@qq.com> Date: Sat, 5 Jul 2025 16:53:24 +0800 Subject: [PATCH] =?utf8?q?=E4=BF=AE=E6=94=B9=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativeui/bloodpressure/include/BPModel.h | 21 ++- .../nativeui/bloodpressure/src/BPMainView.cpp | 7 + .../nativeui/bloodpressure/src/BPModel.cpp | 157 ++++++++++++++---- .../src/detection/BPDetectFirstView.cpp | 25 +-- .../src/detection/BPDetectionView.cpp | 8 +- .../peripheral/bp/service/bp_service.c | 2 +- .../peripheral/bp/service/bp_tcp_server.c | 12 +- 7 files changed, 175 insertions(+), 57 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 231221fe5..f7f880f09 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/include/BPModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/include/BPModel.h @@ -68,12 +68,13 @@ enum class BP_VALUE_TYPE { }; struct LAST_CHECK_DATA { - int16_t last_check_sbp_value; // 上次检测收缩压值 - int16_t last_check_dbp_value; // 上次检测舒张压值 - std::string timestamp; // 时间戳 单位s + uint64_t timestamp; // 时间戳 单位s + uint8_t last_check_sbp_value; // 上次检测收缩压值 + uint8_t last_check_dbp_value; // 上次检测舒张压值 + }; -#define BP_CHECK_TIME_MAX_TEST 120 //测量所需时间 +#define BP_CHECK_TIME_MAX_TEST 90 //测量所需时间 #define BP_CHECK_TIME_MAX 30 //测量所需时间 #define BP_ANLYSISI_TIME_MAX 5 //分析所需时间 #define BP_REMIND_TIME_MAX 5 //提醒所需时间 @@ -87,6 +88,10 @@ public: void SetCalibrationFlag(int value); // 获取当前时间年月日时分字符串 std::string GetCurrentTimeStr(); + std::string GetCurrentTimeStr(uint64_t timeStamp); + //获取当前时间戳 + uint32_t GetCurrentTime(); + std::string GetLastCalibrationTime(); // 当前状态管理 void BP_SetState(BPState state); BPState GetCurrentState(); @@ -110,15 +115,22 @@ public: int GetBPValueCnt(void); int mapValue(int value); void mapDataArray(int value); + bool IsSameDay(const std::string &timeStr1, const std::string &timeStr2); + /* --------------------------------- 最近检测数据 --------------------------------- */ #define BP_LAST_CHECK_FILE_PATH "/user/userdata/bp/bp_last_check.txt" + static constexpr const char *BP_JSON_PATH = "/user/userdata/bp/"; bool save_last_check_bp_data(LAST_CHECK_DATA data); bool load_last_check_bp_data(void); bool get_last_check_bp_data(LAST_CHECK_DATA &data); int get_last_check_data_num(void); const uint8_t max_checkout_num = 30; std::deque lastCheckData; // 存储最近检测数据 + bool CreateBPFolder(); + // 存储bin文件 + bool save_bin_BP(const LAST_CHECK_DATA &data); + bool UpdateHealthData(const LAST_CHECK_DATA &data); /* -------------------------------------------------------------------------- */ @@ -129,6 +141,7 @@ private: std::map> bp_check_value_map; //记录获取的sbp和dbp值 int bp_check_cnt = 0; //记录获取的次数 std::vector bp_check_value_vector; //测量值 + std::string LastCalibrationTime; }; } // namespace OHOS 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 36491068a..ca2c53ab2 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/BPMainView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/BPMainView.cpp @@ -23,6 +23,10 @@ #include "bloodpressure/include/BPMainView.h" #include "bloodpressure/include/BPModel.h" #include "wearable_log.h" +#ifdef ENABLE_BN02 +#include "bp_service.h" +#include "bp_tcp_server.h" +#endif namespace OHOS { static BPMainView *g_pBPMainView{nullptr}; @@ -36,6 +40,9 @@ namespace OHOS BPMainView::~BPMainView() { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BPMainView::~BPMainView"); + #ifdef ENABLE_BN02 + do_bp_tcp_server_send_data(BP_TCP_SERVICE_CMD_SERVER_DEINIT,NULL,0); + #endif DeInit(); g_pBPMainView = nullptr; } 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 79420461c..c5a5e317b 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/BPModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/BPModel.cpp @@ -23,6 +23,7 @@ #include "wearable_log.h" #include #include +#include #include #include "AppViewIDs.h" @@ -100,6 +101,51 @@ namespace OHOS return std::string(buffer); } + std::string BPModel::GetCurrentTimeStr(uint64_t timeStamp) + { + + if (timeStamp < 0) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to GetCurrentTimeStr"); + return "----/--/-- \n --/--"; + } + + // 将时间戳转换为 time_t 类型 + time_t rawtime = static_cast(timeStamp); + struct tm *timeinfo = localtime(&rawtime); + + if (timeinfo == NULL) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to convert time"); + return "----/--/-- \n --/--"; + } + + // 格式化时间为字符串 + char buffer[20]; // 格式: YYYY-MM-DD HH:MM + std::strftime(buffer, sizeof(buffer), "%Y-%m-%d \n %H:%M", timeinfo); + + return std::string(buffer); + } + // 获取当前时间戳 + uint32_t BPModel::GetCurrentTime() + { + uint32_t time; + if (uapi_get_timestampe_ss(&time) != ERRCODE_SUCC) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to get timestamp"); + return 0; + } + return time; + } + + std::string BPModel::GetLastCalibrationTime() + { + if (LastCalibrationTime.empty()) + { + return " "; + } + return LastCalibrationTime; + } /////////////////////////状态管理////////////////////////////////////////// int16_t BPModel::GetCalibrationFlag() { return CalibrationFlag; } void BPModel::SetCalibrationFlag(int value) { CalibrationFlag = value; } @@ -142,16 +188,19 @@ namespace OHOS */ bp_check_value_map.clear(); bp_check_value_vector.clear(); + if (bp_check_cnt != 0) + bp_check_cnt = 0; // 重置计数 + if (Time != BP_CHECK_TIME_MAX_TEST) + Time = BP_CHECK_TIME_MAX_TEST; // 重置时间120秒 + load_last_check_bp_data(); BP_StartTimer(); ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON); // 后期 周期被动状态 需要做区别 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "开启测量"); - // BP_START(); // 底层接口开启血压 + BP_START(); // 底层接口开启血压 + custom_dbp = 0; + custom_sbp = 0; - if (bp_check_cnt != 0) - bp_check_cnt = 0; // 重置计数 - if (Time != BP_CHECK_TIME_MAX_TEST) - Time = BP_CHECK_TIME_MAX_TEST; // 重置时间120秒 break; } @@ -274,7 +323,8 @@ namespace OHOS : BPSECUNDERCALIBRATIONVIEW, BPCALIBRATIONMINDVIEW); } - // BP_STOP();//停止测量---会关机 + LastCalibrationTime = BPModel::GetCurrentTimeStr(); // 获取校准完成时的时间 + BP_STOP(); BP_SetState(BPState::BP_NORMAL); CalibrationFlag++; return; @@ -445,17 +495,19 @@ namespace OHOS view->UpdateTimeText(data, bp_check_value_vector); } WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Time: %d", Time); - if (Time > 0 && Time < 60) // 一分钟后获取数据 + if (Time > 0 && Time < 30) // 一分钟后获取数据 { - LAST_CHECK_DATA newData; - // BP_GetData(&custom_sbp, &custom_dbp); - newData.last_check_sbp_value = rand() % (210 - 60) + 60; // 测试数据 - newData.last_check_dbp_value = rand() % (210 - 60) + 60; - newData.timestamp = BPModel::GetCurrentTimeStr(); - SetBPValueMap(newData.last_check_sbp_value, newData.last_check_dbp_value, bp_check_cnt); // 传入map - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bp_check_cnt: %d ,SBP: %d, DBP: %d", bp_check_cnt, custom_sbp, custom_dbp); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BPValueMap SBP: %d, DBP: %d", bp_check_value_map[bp_check_cnt].first, bp_check_value_map[bp_check_cnt].second); - bp_check_cnt++; + + BP_GetData(&custom_sbp, &custom_dbp); + if (custom_sbp > 0 && custom_dbp > 0) // 检测到数据 + { + LAST_CHECK_DATA newData; + newData.last_check_sbp_value = custom_sbp; // 测试数据 + newData.last_check_dbp_value = custom_dbp; + newData.timestamp = BPModel::GetCurrentTime(); + save_last_check_bp_data(newData); // 保存数据 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SBP: %d, DBP: %d", custom_sbp, custom_dbp); + } } break; } @@ -478,13 +530,19 @@ namespace OHOS view->UpdateTimeText(data, bp_check_value_vector); } WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Time: %d", Time); - if (Time > 0 && Time < 60) // 一分钟后获取数据 + if (Time > 0 && Time < 30) // 一分钟后获取数据 { - // BP_GetData(&custom_sbp, &custom_dbp); - // SetBPValueMap(custom_sbp, custom_dbp, bp_check_cnt); // 传入map - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bp_check_cnt: %d ,SBP: %d, DBP: %d", bp_check_cnt, custom_sbp, custom_dbp); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BPValueMap SBP: %d, DBP: %d", bp_check_value_map[bp_check_cnt].first, bp_check_value_map[bp_check_cnt].second); - bp_check_cnt++; + + BP_GetData(&custom_sbp, &custom_dbp); + if (custom_sbp > 0 && custom_dbp > 0) // 检测到数据 + { + LAST_CHECK_DATA newData; + newData.last_check_sbp_value = custom_sbp; // 测试数据 + newData.last_check_dbp_value = custom_dbp; + newData.timestamp = BPModel::GetCurrentTime(); + save_last_check_bp_data(newData); // 保存数据 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SBP: %d, DBP: %d", custom_sbp, custom_dbp); + } } break; @@ -508,15 +566,19 @@ namespace OHOS view->UpdateTimeText(data, bp_check_value_vector); } WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Time: %d", Time); - if (Time > 0 && Time < 60) // 一分钟后获取数据 + if (Time > 0 && Time < 30) // 一分钟后获取数据 { - // BP_GetData(&custom_sbp, &custom_dbp); - // SetBPValueMap(custom_sbp, custom_dbp, bp_check_cnt); // 传入map - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bp_check_cnt: %d ,SBP: %d, DBP: %d", bp_check_cnt, custom_sbp, custom_dbp); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BPValueMap SBP: %d, DBP: %d", bp_check_value_map[bp_check_cnt].first, bp_check_value_map[bp_check_cnt].second); - bp_check_cnt++; + BP_GetData(&custom_sbp, &custom_dbp); + if (custom_sbp > 0 && custom_dbp > 0) // 检测到数据 + { + LAST_CHECK_DATA newData; + newData.last_check_sbp_value = custom_sbp; // 测试数据 + newData.last_check_dbp_value = custom_dbp; + newData.timestamp = BPModel::GetCurrentTime(); + save_last_check_bp_data(newData); // 保存数据 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SBP: %d, DBP: %d", custom_sbp, custom_dbp); + } } - break; } case BPState::ECG_MEASURE: @@ -603,11 +665,9 @@ namespace OHOS /* ----------------------------- 3.将毫秒转换为系统时钟节拍数 * ---------------------------- */ - int tick = osMs2Tick(interval); - /* --------------------------------- 4.启动定时器 * -------------------------------- */ - osStatus_t ret = osTimerStart(g_timer, tick); + osStatus_t ret = osTimerStart(g_timer, 1000); /* -------------------- 5.检查定时器启动是否成功,如果启动失败,删除定时器并置为 * nullptr -------------------- */ if (ret != osOK) @@ -653,7 +713,7 @@ namespace OHOS void BPModel::BP_STOP(void) { #ifdef ENABLE_BN02 -// bp_stop(); + bp_stop(); #endif } void BPModel::BP_GetData(int *sbp, int *dbp) @@ -697,6 +757,15 @@ namespace OHOS bp_check_value_vector.push_back(mappedValue); } + + /* + 1.存储到BP.bin,存储前先判断文件夹是否存在 + 2.每次测量成功存储一次data,追加ab+ + 3.开机初始化读取文件,赋值到DBP,SBP + 4.每次更新,更新数组 + 5.更新完毕,存储到文件 + + */ // 保存上次检测数据 bool BPModel::save_last_check_bp_data(LAST_CHECK_DATA data) { @@ -713,6 +782,10 @@ namespace OHOS std::ofstream outFile(BP_LAST_CHECK_FILE_PATH, std::ios::trunc); if (!outFile) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "Open file failed! Path: %s, Error: %s", + BP_LAST_CHECK_FILE_PATH, + strerror(errno)); return false; // 文件打开失败 } @@ -764,4 +837,22 @@ namespace OHOS return lastCheckData.size(); } + bool BPModel::UpdateHealthData(const LAST_CHECK_DATA &data) + { + + return true; + } + // 存储bin文件 + bool BPModel::save_bin_BP(const LAST_CHECK_DATA &data) + { + return true; + } + /*创建文件夹*/ + bool BPModel::CreateBPFolder() + { + return true; + } + + + } // namespace OHOS diff --git a/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/detection/BPDetectFirstView.cpp b/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/detection/BPDetectFirstView.cpp index 27b7944de..8c0d82653 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/detection/BPDetectFirstView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/detection/BPDetectFirstView.cpp @@ -110,16 +110,15 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DBPText or SBPText or timeLabel is null"); return; } - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "11111"); // 获取上一次检测数据 ? 待定 LAST_CHECK_DATA data; if (BPModel::GetInstance()->get_last_check_bp_data(data)) { // 获取时间更新时间 - std::string timeStr = data.timestamp; + uint64_t timeStr = data.timestamp; std::string dbpValue = std::to_string(data.last_check_dbp_value); std::string sbpValue = std::to_string(data.last_check_sbp_value); - timeLabel->SetText(timeStr.c_str()); + timeLabel->SetText(BPModel::GetInstance()->GetCurrentTimeStr(data.timestamp).c_str()); DBPText->SetText(dbpValue.c_str()); SBPText->SetText(sbpValue.c_str()); } @@ -127,19 +126,19 @@ namespace OHOS void BPDetectFirstView::WriteMapToPointArrays(const std::map> &bpMap) { + for (int i = 0; i < 24; ++i) + { + sbpData[i].x = i; + sbpData[i].y = 120; + + dbpData[i].x = i; + dbpData[i].y = 80; + } + int dataCount = std::min(static_cast(bpMap.size()), 24); if (dataCount == 0) { - for (int i = 0; i < 24; ++i) - { - // x坐标使用数组索引,y坐标使用map中的值 - sbpData[i].x = i; - sbpData[i].y = 100; // SBP值 - - dbpData[i].x = i; - dbpData[i].y = 80; // DBP值 - } return; } auto it = bpMap.end(); @@ -151,9 +150,11 @@ namespace OHOS // x坐标使用数组索引,y坐标使用map中的值 sbpData[i].x = i; sbpData[i].y = it->second.first; // SBP值 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "sbpData[%d].y:%d", i, it->second.first); dbpData[i].x = i; dbpData[i].y = it->second.second; // DBP值 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "dbpDat[%d].y:%d", i, it->second.second); } } void BPDetectFirstView::InitChartView() diff --git a/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/detection/BPDetectionView.cpp b/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/detection/BPDetectionView.cpp index 44c15fce0..1ef124b68 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/detection/BPDetectionView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/detection/BPDetectionView.cpp @@ -15,7 +15,10 @@ #include "ui_resource_string.h" #include "power_display_service.h" #include "uicomponents/UIComponents.h" - +#ifdef ENABLE_BN02 +#include "bp_service.h" +#include "bp_tcp_server.h" +#endif namespace OHOS { @@ -29,6 +32,9 @@ namespace OHOS BPDetectionView::~BPDetectionView() { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BPDetectionView::~BPDetectionView"); + #ifdef ENABLE_BN02 + do_bp_tcp_server_send_data(BP_TCP_SERVICE_CMD_SERVER_DEINIT,NULL,0); + #endif if(container_) container_->RemoveAll(); diff --git a/code/sdk/drivers/peripheral/bp/service/bp_service.c b/code/sdk/drivers/peripheral/bp/service/bp_service.c index c2fbad5b5..a516ec1ce 100644 --- a/code/sdk/drivers/peripheral/bp/service/bp_service.c +++ b/code/sdk/drivers/peripheral/bp/service/bp_service.c @@ -167,7 +167,7 @@ void bp_stop(void) uapi_cat1_keep_wakeup(0); - // uapi_dev_runtime_set_bp_status(0); + uapi_dev_runtime_set_bp_status(0); do_bp_service_check_msg(BP_SERVICE_CMD_STOP_CHECK); uapi_get_timestampe_ss(&end_time); diff --git a/code/sdk/drivers/peripheral/bp/service/bp_tcp_server.c b/code/sdk/drivers/peripheral/bp/service/bp_tcp_server.c index 85bbd7f85..38d344276 100644 --- a/code/sdk/drivers/peripheral/bp/service/bp_tcp_server.c +++ b/code/sdk/drivers/peripheral/bp/service/bp_tcp_server.c @@ -2022,10 +2022,10 @@ static void tcp_data_handler(int *data,int len) } } - // if(LK_STATUS != 1 && g_listen_sock > 0) - // { - // bp_tcp_init(); - // } + if(LK_STATUS != 1 && g_listen_sock > 0) + { + bp_tcp_init(); + } if(tcp_data_cnt >= MAX_CNT) { @@ -2186,7 +2186,7 @@ errcode_t uapi_bp_tcp_server_init(void) app_task_definition_t taskcfg={0}; taskcfg.create_queue_handle = create_bp_tcp_queue; taskcfg.attr.name="bp_tcp_server_send_task"; - taskcfg.attr.priority = osPriorityBelowNormal3; + taskcfg.attr.priority = osPriorityNormal; taskcfg.attr.stack_size = BP_TCP_BOARD_TASK_SIZE; taskcfg.func = bp_tcp_server_send_task; taskcfg.use_mem = USE_EXTEND_MEM; @@ -2202,7 +2202,7 @@ errcode_t uapi_bp_tcp_server_init(void) taskcfg.create_queue_handle = NULL; taskcfg.attr.name="bp_tcp_server_recv_task"; - taskcfg.attr.priority = osPriorityBelowNormal4; + taskcfg.attr.priority = osPriorityNormal1; taskcfg.attr.stack_size = BP_TCP_BOARD_TASK_SIZE; taskcfg.func = bp_tcp_server_recv_task; taskcfg.use_mem = USE_EXTEND_MEM; -- 2.17.1