增加血压测量过程中的曲线更新
authorCaisking <Casiking@zhihuishixun.com>
Mon, 7 Jul 2025 08:46:29 +0000 (16:46 +0800)
committerCaisking <Casiking@zhihuishixun.com>
Mon, 7 Jul 2025 08:46:29 +0000 (16:46 +0800)
13 files changed:
code/sdk/application/wearable/fd230app/nativeui/bloodpressure/include/BPModel.h
code/sdk/application/wearable/fd230app/nativeui/bloodpressure/include/BPSecUnderCalibrationView.h
code/sdk/application/wearable/fd230app/nativeui/bloodpressure/include/BPUnderCalibrationView.h
code/sdk/application/wearable/fd230app/nativeui/bloodpressure/include/detection/BPDetectBeginView.h
code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/BPModel.cpp
code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/BPSecUnderCalibrationView.cpp
code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/BPUnderCalibrationView.cpp
code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/detection/BPDetectBeginView.cpp
code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/detection/BPDetectFirstView.cpp
code/sdk/drivers/peripheral/bp/bn02/bn02.c
code/sdk/drivers/peripheral/bp/bn02/bn02.h
code/sdk/drivers/peripheral/bp/service/bp_service.c
code/sdk/drivers/peripheral/bp/service/bp_service.h

index f7f880f..91b49b4 100644 (file)
@@ -2,6 +2,7 @@
 #ifndef BP_MODEL_H
 #define BP_MODEL_H
 
+#include <cstdint>
 #include <stdint.h>
 #include <string>
 #include <deque> 
@@ -74,8 +75,7 @@ struct LAST_CHECK_DATA {
 
 };
 
-#define BP_CHECK_TIME_MAX_TEST 90   //测量所需时间
-#define BP_CHECK_TIME_MAX 30   //测量所需时间
+#define BP_CHECK_TIME_MAX 90   //测量所需时间
 #define BP_ANLYSISI_TIME_MAX 5 //分析所需时间
 #define BP_REMIND_TIME_MAX 5   //提醒所需时间
 class BPModel {
@@ -85,7 +85,7 @@ public:
   static BPModel *GetInstance();
   // 获取第几次校准
   int16_t GetCalibrationFlag();
-  void SetCalibrationFlag(int value);
+  void SetCalibrationFlag(uint8_t value);
   // 获取当前时间年月日时分字符串
   std::string GetCurrentTimeStr();
   std::string GetCurrentTimeStr(uint64_t timeStamp);
@@ -98,33 +98,36 @@ public:
   // 控制血压检测
   void BP_Control(BPState state);
   void BP_SetValue(BP_VALUE_TYPE type, bool set_value);
-  int GetValue(BP_VALUE_TYPE type);
+  uint8_t GetValue(BP_VALUE_TYPE type);
   void BP_timer_callback_out();
-  void BP_timer_callback_proc(int data);
+  void BP_timer_callback_proc(uint8_t data);
 
   ///////////////////////////////////////////////
   void BP_StartTimer(uint32_t interval = 1 * 1000); // 1s定时器
   void BP_StopTimer(void);
+  void BP_Start_GetData_Timer(uint32_t interval = 1 * 300); // 300ms定时器
+  void BP_Stop_GetData_Timer(void);
 
   void BP_START(void);
   void BP_STOP(void);
-  void BP_GetData(int *sbp,int *dbp);
+  void BP_GetData(uint8_t *sbp,uint8_t *dbp);
 
-  std::map<int, std::pair<int, int>> GetBPValueMap(void);
-  void SetBPValueMap(int sbp,int dbp,int index);
-  int GetBPValueCnt(void);
-  int mapValue(int value);
-  void mapDataArray(int value);
-  bool IsSameDay(const std::string &timeStr1, const std::string &timeStr2);
+  std::map<uint8_t, std::pair<uint8_t, uint8_t>> GetBPValueMap(void);
+  void SetBPValueMap(uint8_t sbp,uint8_t dbp,uint8_t index);
+  uint8_t GetBPValueCnt(void);
+  uint8_t mapValue(uint8_t value);
+  void mapDataArray(uint8_t value);
+  //获取过程值数据
+  std::vector<uint8_t> GetBPCheckDataArray(void);
 
 
   /* --------------------------------- 最近检测数据 --------------------------------- */
   #define BP_LAST_CHECK_FILE_PATH "/user/userdata/bp/bp_last_check.txt"
-  static constexpr const char *BP_JSON_PATH = "/user/userdata/bp/";
+  static constexpr const char *BP_DATA_PATH = "/user/userdata/health/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);
+  uint8_t get_last_check_data_num(void);
   const uint8_t max_checkout_num = 30;
   std::deque<LAST_CHECK_DATA> lastCheckData;          // 存储最近检测数据
   bool CreateBPFolder();
@@ -136,12 +139,13 @@ public:
 
 private:
   BPState current_state = BPState::BP_NORMAL;
-  int custom_sbp = SBP_VALUE;
-  int custom_dbp = DBP_VALUE;
-  std::map<int, std::pair<int, int>> bp_check_value_map;  //记录获取的sbp和dbp值
-  int bp_check_cnt = 0;                                   //记录获取的次数
-  std::vector<int> bp_check_value_vector;                 //测量值
+  uint8_t custom_sbp = SBP_VALUE;
+  uint8_t custom_dbp = DBP_VALUE;
+  std::map<uint8_t, std::pair<uint8_t, uint8_t>> bp_check_value_map;  //记录获取的sbp和dbp值
+  uint8_t bp_check_cnt = 0;                                   //记录获取的次数
+  std::vector<uint8_t> bp_check_value_vector;                 //测量值
   std::string LastCalibrationTime;
+  uint8_t CalibrationFlag = 0;
 };
 } // namespace OHOS
 
index 784651c..c4ee025 100644 (file)
@@ -26,7 +26,7 @@ namespace OHOS
         bool Initbackground();
         void InitChartView();
 
-        void UpdateTimeText(int data, std::vector<int> &input);
+        void UpdateTimeText(int data);
 
     private:
         UIImageView *background = nullptr;
index 9adb9bf..6a887d4 100644 (file)
@@ -26,7 +26,7 @@ namespace OHOS
         bool Initbackground();
         void InitChartView();
 
-        void UpdateTimeText(int data, std::vector<int> &input);
+        void UpdateTimeText(int data);
 
     private:
         UIImageView *background = nullptr;
index 9bf35d7..28ce544 100644 (file)
@@ -26,7 +26,8 @@ namespace OHOS
         bool Initbackground();
         void InitChartView();
     
-          void UpdateTimeText(int data, std::vector<int> &input);
+        void UpdateTimeText(int data);
+        void UpdateChartData();
 
     private:
         UIImageView *background = nullptr;
index c5a5e31..6335c32 100644 (file)
@@ -59,13 +59,12 @@ namespace OHOS
  * @brief Constructor for the BPModel class.
  */
 #define MAX_UNWARE_COUNT 10
-#define MAX_VALID_SPO2_COUNT 30
-#define MAX_DISVALID_SPO2_COUNT 100
-  static uint16 CalibrationFlag = 0;
+#define MAX_SHOW_CHECK_NUM 100
+#define DECLARE_BP_TIMER 1
+#define DECLARE_BP_GETDATA 1
+
+static uint8_t Time = 30;
 
-  // 声明定时器变量
-  static osTimerId_t g_timer = nullptr;
-  static int Time = 30;
 
   BPModel::BPModel() {}
   BPModel::~BPModel() {}
@@ -148,7 +147,7 @@ namespace OHOS
   }
   /////////////////////////状态管理//////////////////////////////////////////
   int16_t BPModel::GetCalibrationFlag() { return CalibrationFlag; }
-  void BPModel::SetCalibrationFlag(int value) { CalibrationFlag = value; }
+  void BPModel::SetCalibrationFlag(uint8_t value) { CalibrationFlag = value; }
 
   // 管理当前状态
   void BPModel::BP_SetState(BPState state) { current_state = state; }
@@ -173,8 +172,10 @@ namespace OHOS
        关闭常亮
      */
       BP_StopTimer();
+      BP_Stop_GetData_Timer();
       ScreenAlwaysOnCtr(CANCEL_SCREEN_ALWAYS_ON);
       Time = BP_CHECK_TIME_MAX;
+      BP_STOP(); // 底层接口关闭血压
       break;
     }
     case BPState::BP_CALIBRATING_SECONDTIME: // 测量与校准数据
@@ -190,13 +191,15 @@ namespace OHOS
       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();
+
+      if (Time != BP_CHECK_TIME_MAX)
+        Time = BP_CHECK_TIME_MAX; // 重置时间120秒
+
+      // load_last_check_bp_data();
       BP_StartTimer();
+      BP_Start_GetData_Timer();
       ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON); // 后期 周期被动状态 需要做区别
-      WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,
-                    "开启测量");
+      WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"开启测量");
       BP_START(); // 底层接口开启血压
       custom_dbp = 0;
       custom_sbp = 0;
@@ -288,13 +291,159 @@ namespace OHOS
       }
     }
   }
-  int BPModel::GetValue(BP_VALUE_TYPE type)
+  uint8_t BPModel::GetValue(BP_VALUE_TYPE type)
   {
     if (type == BP_VALUE_TYPE::SBP)
       return custom_sbp;
     else
       return custom_dbp;
   }
+  void BPModel::BP_START(void)
+  {
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BP_START");
+#ifdef ENABLE_BN02
+    bp_start(BP);
+#endif
+  }
+  void BPModel::BP_STOP(void)
+  {
+#ifdef ENABLE_BN02
+    bp_stop();
+#endif
+  }
+void BPModel::BP_GetData(uint8_t *sbp, uint8_t *dbp)
+  {
+  #ifdef ENABLE_BN02
+      if (sbp && dbp) {
+          int temp_sbp = 0, temp_dbp = 0;
+          bp_get_data(&temp_sbp, &temp_dbp);
+          
+          // 添加范围检查,避免数据截断
+          if (temp_sbp >= 0 && temp_sbp <= UINT8_MAX) {
+              *sbp = static_cast<uint8_t>(temp_sbp);
+          } else {
+              *sbp = 0; // 默认值
+          }
+          
+          if (temp_dbp >= 0 && temp_dbp <= UINT8_MAX) {
+              *dbp = static_cast<uint8_t>(temp_dbp);
+          } else {
+              *dbp = 0;
+          }
+      }
+  #endif
+  }
+
+  std::map<uint8_t, std::pair<uint8_t, uint8_t>> BPModel::GetBPValueMap()
+  {
+    return bp_check_value_map;
+  }
+
+  /*
+    显示内容映射 (60~210)这个数据只是显示一个趋势 不代表什么,为了显示效果
+  */
+  uint8_t BPModel::mapValue(uint8_t value)
+  {
+    // 确保输入值在0-255范围内
+    if (value < 0)
+      value = 0;
+    if (value > 255)
+      value = 255;
+
+    // 线性映射公式:output = (input - input_min) * (output_max - output_min) / (input_max - input_min) + output_min
+    return (value - 0) * (210 - 60) / (255 - 0) + 60;
+  }
+
+void BPModel::mapDataArray(uint8_t value)
+{
+    value = mapValue(value);
+
+    // 使用固定大小的vector,通过索引循环覆盖旧数据
+    static size_t index = 0;
+    if (bp_check_value_vector.size() < MAX_SHOW_CHECK_NUM) 
+    {
+        bp_check_value_vector.push_back(value);
+    } 
+    else 
+    {
+        bp_check_value_vector[index] = value;
+        index = (index + 1) % MAX_SHOW_CHECK_NUM;
+    }
+}
+
+  //获取过程值数据
+  std::vector<uint8_t> BPModel::GetBPCheckDataArray()
+  {
+    return bp_check_value_vector;
+  }
+
+
+  /*
+  1.存储到BP.bin,存储前先判断文件夹是否存在
+  2.每次测量成功存储一次data,追加ab+
+  3.开机初始化读取文件,赋值到DBP,SBP
+  4.每次更新,更新数组
+  5.更新完毕,存储到文件
+  
+  */
+  // 保存上次检测数据
+  bool BPModel::save_last_check_bp_data(LAST_CHECK_DATA data)
+  {
+    return true;
+  }
+
+  // 加载上次检测数据
+  bool BPModel::load_last_check_bp_data(void)
+  {
+    std::ifstream inFile(BP_LAST_CHECK_FILE_PATH);
+    if (!inFile)
+    {
+      WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BPModel::load_last_check_bp_data");
+      return false; // 文件打开失败
+    }
+    // 读取文件内容,解析检测数据
+    LAST_CHECK_DATA data;
+    while (inFile >> data.last_check_sbp_value >> data.last_check_dbp_value >> data.timestamp)
+    {
+      lastCheckData.push_back(data);
+    }
+    return true;
+  }
+
+  bool BPModel::get_last_check_bp_data(LAST_CHECK_DATA &data)
+  {
+    // 获取队列中最后一次检测数据
+    if (lastCheckData.size() > 0)
+    {
+      data = lastCheckData.back();
+      return true;
+    }
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BPModel::get_last_check_bp_data is empty");
+    return false;
+  }
+
+  // 获取最近检测数据数量
+  uint8_t BPModel::get_last_check_data_num(void)
+  {
+    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;
+  }
+
   //////////////////////////////////time处理////////////////////////////////////
   // time到时的处理
   void BPModel::BP_timer_callback_out()
@@ -466,7 +615,7 @@ namespace OHOS
     }
   }
   // 每秒的处理
-  void BPModel::BP_timer_callback_proc(int data)
+  void BPModel::BP_timer_callback_proc(uint8_t data)
   {
 
     // 根据状态处理
@@ -482,17 +631,7 @@ namespace OHOS
       BPDetectBeginView *view = BPDetectBeginView::GetInstance();
       if (view)
       {
-        int BPv = rand() % (210 - 60) + 60;
-        mapDataArray(BPv);
-        BPv = rand() % (210 - 60) + 60;
-        mapDataArray(BPv);
-        BPv = rand() % (210 - 60) + 60;
-        mapDataArray(BPv);
-        BPv = rand() % (210 - 60) + 60;
-        mapDataArray(BPv);
-        BPv = rand() % (210 - 60) + 60;
-        mapDataArray(BPv);
-        view->UpdateTimeText(data, bp_check_value_vector);
+        view->UpdateTimeText(data);
       }
       WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Time: %d", Time);
       if (Time > 0 && Time < 30) // 一分钟后获取数据
@@ -501,12 +640,12 @@ namespace OHOS
         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);
+          // 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;
@@ -517,17 +656,7 @@ namespace OHOS
       BPUnderCalibrationView *view = BPUnderCalibrationView::GetInstance();
       if (view)
       {
-        int BPv = rand() % (210 - 60) + 60;
-        mapDataArray(BPv);
-        BPv = rand() % (210 - 60) + 60;
-        mapDataArray(BPv);
-        BPv = rand() % (210 - 60) + 60;
-        mapDataArray(BPv);
-        BPv = rand() % (210 - 60) + 60;
-        mapDataArray(BPv);
-        BPv = rand() % (210 - 60) + 60;
-        mapDataArray(BPv);
-        view->UpdateTimeText(data, bp_check_value_vector);
+         view->UpdateTimeText(data);
       }
       WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Time: %d", Time);
       if (Time > 0 && Time < 30) // 一分钟后获取数据
@@ -553,17 +682,7 @@ namespace OHOS
           BPSecUnderCalibrationView::GetInstance();
       if (view)
       {
-        int BPv = rand() % (210 - 60) + 60;
-        mapDataArray(BPv);
-        BPv = rand() % (210 - 60) + 60;
-        mapDataArray(BPv);
-        BPv = rand() % (210 - 60) + 60;
-        mapDataArray(BPv);
-        BPv = rand() % (210 - 60) + 60;
-        mapDataArray(BPv);
-        BPv = rand() % (210 - 60) + 60;
-        mapDataArray(BPv);
-        view->UpdateTimeText(data, bp_check_value_vector);
+        view->UpdateTimeText(data);
       }
       WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Time: %d", Time);
       if (Time > 0 && Time < 30) // 一分钟后获取数据
@@ -612,11 +731,14 @@ namespace OHOS
       return;
     }
   }
-  /////////////////////////////////////定时器处理 不要修改//////////////////////////////////////////////////
-
+  /////////////////////////////////////测量时间 定时器处理 不要修改//////////////////////////////////////////////////
+#if DECLARE_BP_TIMER
+  // 声明定时器变量
+  static osTimerId_t g_timer = nullptr;
   /*定时器到期时的处理*/
-  static void BP_TimerCallbackProc(int data)
+  static void BP_TimerCallbackProc(uint8_t data)
   {
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BP_TimerCallbackProc %d", Time);
     // 倒计时
     Time--;
     // 到时的处理
@@ -630,7 +752,7 @@ namespace OHOS
   /*
    * @brief 回调函数
    */
-  static void BP_TimerCallback(int data)
+  static void BP_TimerCallback(uint8_t data)
   {
     WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BP_TimerCallback %d", data);
     GraphicService::GetInstance()->PostGraphicEvent(
@@ -703,156 +825,96 @@ namespace OHOS
     }
   }
 
-  void BPModel::BP_START(void)
-  {
-    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BP_START");
-#ifdef ENABLE_BN02
-    bp_start(BP);
-#endif
-  }
-  void BPModel::BP_STOP(void)
-  {
-#ifdef ENABLE_BN02
-    bp_stop();
-#endif
-  }
-  void BPModel::BP_GetData(int *sbp, int *dbp)
-  {
-#ifdef ENABLE_BN02
-    bp_get_data(sbp, dbp);
-#endif
-  }
-
-  std::map<int, std::pair<int, int>> BPModel::GetBPValueMap()
-  {
-    return bp_check_value_map;
-  }
-
-  void BPModel::SetBPValueMap(int sbp, int dbp, int index)
-  {
-    bp_check_value_map[index] = {sbp, dbp};
-  }
-
-  int BPModel::GetBPValueCnt(void)
+  #endif
+  
+  /////////////////////////////////////获取数据 定时器处理 不要修改//////////////////////////////////////////////////
+#if DECLARE_BP_GETDATA
+  // 声明定时器变量
+  static osTimerId_t g_timer_get_data = nullptr;
+  /*定时器到期时的处理*/
+  static void BP_Timer_GetData_CallbackProc(uint8_t data)
   {
-    return bp_check_cnt;
-  }
+    //取出48个数 添加到 显示数组
+    uint8_t sensorData[48] = {0};
+    #ifdef ENABLE_BN02
+      get_bp_ui_data(sensorData, 48); // 提取前48个字节
+    #endif
 
-  int BPModel::mapValue(int value)
-  {
-    // 确保输入值在0-255范围内
-    if (value < 0)
-      value = 0;
-    if (value > 255)
-      value = 255;
+    for(uint8_t i = 0; i < 48; i++) {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"Data[%d] = %d\n", i, sensorData[i]);
+        //更新显示数组
+        BPModel::GetInstance()->mapDataArray(sensorData[i]);
+    }
 
-    // 线性映射公式:output = (input - input_min) * (output_max - output_min) / (input_max - input_min) + output_min
-    return (value - 0) * (210 - 60) / (255 - 0) + 60;
+    //更新UI 测试更新
+    BPDetectBeginView *view = BPDetectBeginView::GetInstance();
+    if (view)
+    {
+      view->UpdateChartData();
+    }
   }
-
-  void BPModel::mapDataArray(int value)
+  /*
+   * @brief 回调函数
+   */
+  static void BP_Timer_GetData_Callback(uint8_t data)
   {
-    int mappedValue = mapValue(value);
-
-    bp_check_value_vector.push_back(mappedValue);
+    WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BP_Timer_GetData_Callback %d", data);
+    GraphicService::GetInstance()->PostGraphicEvent(
+        std::bind(BP_Timer_GetData_CallbackProc, data));
   }
 
-
   /*
-  1.存储到BP.bin,存储前先判断文件夹是否存在
-  2.每次测量成功存储一次data,追加ab+
-  3.开机初始化读取文件,赋值到DBP,SBP
-  4.每次更新,更新数组
-  5.更新完毕,存储到文件
-  
-  */
-  // 保存上次检测数据
-  bool BPModel::save_last_check_bp_data(LAST_CHECK_DATA data)
+   *  @brief 开启定时器函数
+   *  @param interval 时间间隔,单位ms
+   */
+  void BPModel::BP_Start_GetData_Timer(uint32_t interval)
   {
-    // 检查容量,最多存储30条日志
-    if (lastCheckData.size() >= max_checkout_num)
-    {
-      lastCheckData.pop_front(); // 超出限制,删除最旧的日志
-    }
-
-    // 保存新日志,将传入的完整检测数据添加到队列
-    lastCheckData.push_back(data);
-
-    // 将lastCheckData写入文件,覆盖写
-    std::ofstream outFile(BP_LAST_CHECK_FILE_PATH, std::ios::trunc);
-    if (!outFile)
+    WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BPModel::BP_StartTimer");
+    if (g_timer_get_data != nullptr)
     {
-      WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,
-                    "Open file failed! Path: %s, Error: %s",
-                    BP_LAST_CHECK_FILE_PATH,
-                    strerror(errno));
-      return false; // 文件打开失败
+      WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Timer already exists!!");
+      return;
     }
-
-    // 遍历队列,将每条检测数据(包括收缩压、舒张压和时间戳)写入文件
-    for (const auto &Data : lastCheckData)
+    g_timer_get_data = osTimerNew((osTimerFunc_t)BP_Timer_GetData_Callback, osTimerPeriodic,
+                         nullptr, nullptr);
+    if (g_timer_get_data == nullptr)
     {
-      outFile << Data.last_check_sbp_value << " ";
-      outFile << Data.last_check_dbp_value << " ";
-      outFile << Data.timestamp << std::endl;
+      WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Timer create failed!!");
+      return;
     }
-    outFile.close();
-
-    return true;
-  }
 
-  // 加载上次检测数据
-  bool BPModel::load_last_check_bp_data(void)
-  {
-    std::ifstream inFile(BP_LAST_CHECK_FILE_PATH);
-    if (!inFile)
-    {
-      WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BPModel::load_last_check_bp_data");
-      return false; // 文件打开失败
-    }
-    // 读取文件内容,解析检测数据
-    LAST_CHECK_DATA data;
-    while (inFile >> data.last_check_sbp_value >> data.last_check_dbp_value >> data.timestamp)
+    osStatus_t ret = osTimerStart(g_timer_get_data, interval);
+    if (ret != osOK)
     {
-      lastCheckData.push_back(data);
+      WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,
+                    "osTimerDelete failed, ret = %lx!!", ret);
+      if (g_timer_get_data != nullptr)
+      {
+        ret = osTimerDelete(g_timer_get_data);
+      }
+      g_timer_get_data = nullptr;
+      return;
     }
-    return true;
   }
-
-  bool BPModel::get_last_check_bp_data(LAST_CHECK_DATA &data)
+  /*
+   * @brief 停止定时器
+   */
+  void BPModel::BP_Stop_GetData_Timer(void)
   {
-    // 获取队列中最后一次检测数据
-    if (lastCheckData.size() > 0)
+    // 检查定时器是否存在
+    if (g_timer_get_data != nullptr)
     {
-      data = lastCheckData.back();
-      return true;
+      WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BPModel::BP_StopTimer");
+      osTimerStop(g_timer_get_data);
+      // 删除定时器并置为 nullptr
+      osStatus_t ret = osTimerDelete(g_timer_get_data);
+      if (ret != osOK)
+      {
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,
+                      "osTimerDelete failed, ret = %lx!!", ret);
+      }
+      g_timer_get_data = nullptr;
     }
-    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BPModel::get_last_check_bp_data is empty");
-    return false;
   }
-
-  // 获取最近检测数据数量
-  int BPModel::get_last_check_data_num(void)
-  {
-    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;
-  }
-
-
-  
+#endif
 } // namespace OHOS
index ac82981..e7beb0d 100644 (file)
@@ -84,36 +84,36 @@ namespace OHOS
             }
     }
     /* -------------------------------------------------------------------------- */
-  void BPSecUnderCalibrationView::UpdateTimeText(int data, std::vector<int> &input)
+  void BPSecUnderCalibrationView::UpdateTimeText(int data)
     {
         if (timenumLabel != nullptr && data >= 0 && data <= BP_CHECK_TIME_MAX)
         {
             timenumLabel->SetText(std::to_string(data).c_str());
         }
-        int takeCount = 60;
-        int inputSize = input.size();
-        int actualCount = std::min({takeCount, inputSize});
-
-        if (actualCount <= 0)
-            return; // 无有效数据可赋值
-
-        // 计算input中起始索引
-        int startIndex = inputSize - actualCount;
-
-        // 赋值:将input最后actualCount个元素赋值给testData的前actualCount个位置
-        for (int i = 0; i < actualCount; ++i)
-        {
-            testData[i].y = input[startIndex + i];
-        }
-
-        // 更新图表数据
-        if (datachart && dataSerial)
-        {
-            dataSerial->ClearData();
-            dataSerial->AddPoints(testData, 60);
-            datachart->AddDataSerial(dataSerial);
-            RootView::GetInstance()->Invalidate();
-        }
+        // int takeCount = 60;
+        // int inputSize = input.size();
+        // int actualCount = std::min({takeCount, inputSize});
+
+        // if (actualCount <= 0)
+        //     return; // 无有效数据可赋值
+
+        // // 计算input中起始索引
+        // int startIndex = inputSize - actualCount;
+
+        // // 赋值:将input最后actualCount个元素赋值给testData的前actualCount个位置
+        // for (int i = 0; i < actualCount; ++i)
+        // {
+        //     testData[i].y = input[startIndex + i];
+        // }
+
+        // // 更新图表数据
+        // if (datachart && dataSerial)
+        // {
+        //     dataSerial->ClearData();
+        //     dataSerial->AddPoints(testData, 60);
+        //     datachart->AddDataSerial(dataSerial);
+        //     RootView::GetInstance()->Invalidate();
+        // }
     }
 
     void BPSecUnderCalibrationView::InitChartView()
index 06c8e58..ec2cba5 100644 (file)
@@ -84,36 +84,36 @@ namespace OHOS
             }
     }
     /* -------------------------------------------------------------------------- */
-    void BPUnderCalibrationView::UpdateTimeText(int data, std::vector<int> &input)
+    void BPUnderCalibrationView::UpdateTimeText(int data)
     {
         if (timenumLabel != nullptr && data >= 0 && data <= BP_CHECK_TIME_MAX)
         {
             timenumLabel->SetText(std::to_string(data).c_str());
         }
-        int takeCount = 60;
-        int inputSize = input.size();
-        int actualCount = std::min({takeCount, inputSize});
-
-        if (actualCount <= 0)
-            return; // 无有效数据可赋值
-
-        // 计算input中起始索引
-        int startIndex = inputSize - actualCount;
-
-        // 赋值:将input最后actualCount个元素赋值给testData的前actualCount个位置
-        for (int i = 0; i < actualCount; ++i)
-        {
-            testData[i].y = input[startIndex + i];
-        }
-
-        // 更新图表数据
-        if (datachart && dataSerial)
-        {
-            dataSerial->ClearData();
-            dataSerial->AddPoints(testData, 60);
-            datachart->AddDataSerial(dataSerial);
-            RootView::GetInstance()->Invalidate();
-        }
+        // int takeCount = 60;
+        // int inputSize = input.size();
+        // int actualCount = std::min({takeCount, inputSize});
+
+        // if (actualCount <= 0)
+        //     return; // 无有效数据可赋值
+
+        // // 计算input中起始索引
+        // int startIndex = inputSize - actualCount;
+
+        // // 赋值:将input最后actualCount个元素赋值给testData的前actualCount个位置
+        // for (int i = 0; i < actualCount; ++i)
+        // {
+        //     testData[i].y = input[startIndex + i];
+        // }
+
+        // // 更新图表数据
+        // if (datachart && dataSerial)
+        // {
+        //     dataSerial->ClearData();
+        //     dataSerial->AddPoints(testData, 60);
+        //     datachart->AddDataSerial(dataSerial);
+        //     RootView::GetInstance()->Invalidate();
+        // }
     }
 
     void BPUnderCalibrationView::InitChartView()
index f05d26c..a299128 100644 (file)
@@ -87,36 +87,35 @@ namespace OHOS
     }
     /* -------------------------------------------------------------------------- */
     // 倒计时更新时间文本
-     void BPDetectBeginView::UpdateTimeText(int data, std::vector<int> &input)
+     void BPDetectBeginView::UpdateTimeText(int data)
     {
         if (timenumLabel != nullptr && data >= 0 && data <= BP_CHECK_TIME_MAX)
         {
             timenumLabel->SetText(std::to_string(data).c_str());
         }
-        int takeCount = 60;
-        int inputSize = input.size();
-        int actualCount = std::min({takeCount, inputSize});
-
-        if (actualCount <= 0)
-            return; // 无有效数据可赋值
-
-        // 计算input中起始索引
-        int startIndex = inputSize - actualCount;
+    }
+    //更新曲线图
+    void BPDetectBeginView::UpdateChartData()
+    {
+        if (dataSerial == nullptr || datachart == nullptr)
+            return;
+        
+        std ::vector<uint8> bp_check_value_vector = BPModel::GetInstance()->GetBPCheckDataArray();
+        size_t bp_check_value_vectorSize = bp_check_value_vector.size();
+        if (bp_check_value_vectorSize == 0)
+            return;
 
-        // 赋值:将input最后actualCount个元素赋值给testData的前actualCount个位置
-        for (int i = 0; i < actualCount; ++i)
+        for (int i = 0; i < bp_check_value_vectorSize; ++i)
         {
-            testData[i].y = input[startIndex + i];
+            // 获取数据
+            testData[i].y = bp_check_value_vector[i];
         }
 
         // 更新图表数据
-        if (datachart && dataSerial)
-        {
-            dataSerial->ClearData();
-            dataSerial->AddPoints(testData, 60);
-            datachart->AddDataSerial(dataSerial);
-            RootView::GetInstance()->Invalidate();
-        }
+        dataSerial->ClearData();
+        dataSerial->AddPoints(testData, 100);
+        datachart->AddDataSerial(dataSerial);
+        RootView::GetInstance()->Invalidate();
     }
 
     void BPDetectBeginView::InitChartView()
index 8c0d826..d748a5d 100644 (file)
@@ -159,7 +159,7 @@ namespace OHOS
     }
     void BPDetectFirstView::InitChartView()
     {
-        WriteMapToPointArrays(BPModel::GetInstance()->GetBPValueMap());
+        // WriteMapToPointArrays(BPModel::GetInstance()->GetBPValueMap());
         // 初始化图表控件
         if (bpchart == nullptr)
         {
index a510f32..bebd4fc 100644 (file)
@@ -38,8 +38,20 @@ static int data_cnt = 0;
 \r
 static uint8_t *bn02_data = NULL;\r
 \r
-bool Bn02_write_reg(uint8_t data)\r
+static uint8_t bn02_ui_data[48] = {0};\r
+\r
+void bn02_get_ui_data(uint8_t *data,uint8_t len)\r
 {\r
+       if(data == NULL || len == 0 || len > 48)\r
+       {\r
+               printf("bn02_get_ui_data valid param \n");\r
+               return;\r
+       }\r
+       memcpy_s(data,len,bn02_ui_data,len);\r
+}\r
+\r
+bool Bn02_write_reg(uint8_t data)\r
+{      \r
        // uint8_t cnt = pm_veto_get_id_cnt(PM_ID_BP);\r
     // if (cnt == 0) \r
     // {\r
@@ -176,7 +188,8 @@ void bn02_int_handle(void)
                {\r
                        printf("data_cnt:%d\n",data_cnt);\r
                        memcpy_s(bn02_data + data_cnt,MAX_CNT - data_cnt,bn02_buf,48);\r
-\r
+                       // memset(bn02_ui_data,0,48);\r
+                       memcpy_s(bn02_ui_data,48,bn02_buf,48);\r
                        // for(int i = tcp_data_cnt; i < tcp_data_cnt+len; i ++)\r
                        // {\r
                        //     printf("222data[%d]:%d\n",i,tcp_data[i]);\r
@@ -195,7 +208,7 @@ void bn02_start(void)
        Bn02_Power_Ctrl(1);\r
        bn02_int_init();\r
        Bn02_write_reg(BN02_START_CMD);\r
-#if 0\r
+#if 1\r
        if(bn02_data == NULL)\r
        {\r
                bn02_data = malloc(MAX_CNT);\r
@@ -227,7 +240,7 @@ void bn02_stop(void)
 \r
        // do_bp_tcp_server_send_data(BP_TCP_SERVICE_CMD_SERVER_DEINIT,NULL,0);\r
 \r
-#if 0\r
+#if 1\r
        if(fp != NULL)\r
        {\r
                fclose(fp);\r
index 497af30..f7ca3e6 100644 (file)
@@ -15,6 +15,7 @@
 void bn02_int_handle(void);\r
 void bn02_start(void);\r
 void bn02_stop(void);\r
+void bn02_get_ui_data(uint8_t *data,uint8_t len);\r
 \r
 #endif // _HRS3300_H_\r
 \r
index a516ec1..54f3055 100644 (file)
@@ -178,6 +178,12 @@ void bp_stop(void)
     }
 
 }
+
+void get_bp_ui_data(uint8_t *data, uint8_t len)
+{
+    bn02_get_ui_data(data,len);
+}
+
 // void bp_service_service_resume(void)
 // {
 //     MMC_LOG("bp_service_service resume!\r\n");
index 8f660ca..af27c50 100644 (file)
@@ -41,6 +41,7 @@ void bp_int_callback(pin_t pin, uintptr_t param);
 void bp_start(uint8_t type);
 void bp_stop(void);
 void bp_get_measure_time(uint32_t *b_time,uint32_t *e_time);
+void get_bp_ui_data(uint8_t *data, uint8_t len);
 
 #ifdef __cplusplus
 #if __cplusplus