debug界面添加佩戴信息,优化心率采样处理,加快进入产测指令返回数据速度
authorpenglei <1624952103@qq.com>
Mon, 11 Nov 2024 09:13:57 +0000 (17:13 +0800)
committerpenglei <1624952103@qq.com>
Mon, 11 Nov 2024 09:13:57 +0000 (17:13 +0800)
code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepModel.h
code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepModelC.h
code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepModel.cpp
code/sdk/application/wearable/service/factorytest_service/factorytest_protocol.c
code/sdk/application/wearable/service/msg_center/include/notify/debug_output_notification/debug_output_notification.h
code/sdk/application/wearable/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp
code/sdk/drivers/peripheral/cywee/Inc/cywee_hal.h
code/sdk/drivers/peripheral/cywee/src/main_dml.c
code/sdk/drivers/peripheral/ppg/hx3695/hx3695_hrs_agc.c
code/sdk/drivers/peripheral/utils/custom_fileoperate_service.c

index 0b70065..49ab135 100644 (file)
@@ -38,6 +38,12 @@ namespace OHOS
         uint16_t total_time;            // 总时长
     } SLEEP_T;
 
+    typedef struct
+    {
+        uint32_t timestamp; //时间戳
+        uint8_t stat;       // 状态
+    } SLEEP_STAT_T;
+
 #pragma pack (pop)
 
     // bool save_nap_data(NAP_T *data);
@@ -48,11 +54,13 @@ namespace OHOS
     void set_sleep_data(SLEEP_T *data);
     // bool save_sleep_data(SLEEP_T *data);
     bool read_sleep_data(SLEEP_T *data);
+    void read_wear_data(void);
     bool read_nap_data(NAP_T *data);
     // void clean_sleep_data(void);
     // bool create_sleep_folder(void);
     std::string get_sleep_asleep_time_str(void);
     std::string get_sleep_wake_time_str(void);
+    std::string get_wear_status_str(void);
     //void clean_sleep_file(void);
     // 睡眠状态
     enum class SLEEPSTATE
index 78dd4da..9a28746 100644 (file)
@@ -22,6 +22,7 @@ extern "C"
     void custom_sleep_model_updata(void);
     void update_sleep_data(uint32_t sleep_timestamp,uint32_t wake_timestamp,uint32_t totaltime);
     void update_nap_data(uint32_t sleep_timestamp,uint32_t wake_timestamp,uint32_t totaltime);
+    void custom_read_wear_data(void);
 #ifdef __cplusplus
 #if __cplusplus
 }
index bb52bff..0e58805 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: penglei 1624952103@qq.com
  * @Date: SLEPPNOTIFY24-06-26 19:36:48
  * @LastEditors: penglei 1624952103@qq.com
- * @LastEditTime: 2024-11-08 20:05:21
+ * @LastEditTime: 2024-11-11 16:59:29
  * @FilePath:
  * /FD230/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepModel.cpp
  * @Description:
@@ -53,6 +53,9 @@ extern "C" errcode_t uapi_get_TIME_STR(uint32_t time, char *p_time,
 extern "C" int get_sleep_time_from_config_model(void);
 extern "C" int get_wake_up_time_from_config_model();
 
+
+static uint32_t len = 0;
+static OHOS::SLEEP_STAT_T *wear_stat;
 namespace OHOS
 {
 #define SLEPPNOTIFY 20
@@ -94,6 +97,46 @@ namespace OHOS
     return S_ISREG(file_stat.st_mode); // 检查文件是否为普通文件
   }
 
+  std::string get_wear_status_str(void) 
+  {
+      std::string result;
+      std::string wear_status;
+        // 进行文件读取
+        do_custom_fileoperate_service_check_msg(  
+            CUSTOM_FILEOPERATE_MSG_TYPE_WEAR_DATA_READ, nullptr, 0);  
+        LOS_Msleep(100); // 等待文件系统准备  
+
+        if(len == 0)
+            return result;
+
+        for(int i = 0; i < len/5; i++)
+        {
+            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"data.timestamp : %d , data.stat : %d", wear_stat[i].timestamp,wear_stat[i].stat);
+            if(wear_stat[i].stat)
+                wear_status = "已配戴";
+            else
+                wear_status = "未配戴";
+
+            std::string timestr;
+            char labelTime[20] = {0};
+
+            if (uapi_get_TIME_STR(wear_stat[i].timestamp, labelTime, '.', ':', DATE_Y_M_D_H_M) != ERRCODE_SUCC)  
+            {  
+                timestr = "--";  
+            }  
+            else  
+            {  
+                timestr = labelTime;  
+            } 
+
+            result += wear_status + ":"+ timestr + "\n";
+        }
+        free(wear_stat);
+        return result; // 返回结果字符串  
+    } 
+
+
+
   std::string get_sleep_asleep_time_str(void)
   {
       std::string timestr;
@@ -126,6 +169,33 @@ namespace OHOS
       return timestr;
   }
 
+  void read_wear_data(void)   
+  {
+      uint32_t size = 0;
+      len = uapi_get_file_size("user/userdata/wear.bin");
+      if(!len)
+        return;
+
+      wear_stat = (SLEEP_STAT_T *)malloc(len);
+      FILE *fp;
+
+      fp = fopen("user/userdata/wear.bin", "rb"); 
+      if (fp == NULL) 
+      {
+          WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "wear file open failed");
+          free(wear_stat);
+          return;
+      }
+
+      size = fread(wear_stat, 1, len, fp);
+      if(size != len)
+      {
+          free(wear_stat);
+          WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "wear file read failed");
+      }
+      fclose(fp);
+  }
+  
   bool read_sleep_data(SLEEP_T *data)
   {
     char day[12] = {0};
@@ -767,8 +837,6 @@ namespace OHOS
 #endif /* __cplusplus */
 #endif /* __cplusplus */
 
-
-
     void custom_read_sleep_data(void)
     {
       memset(&sleep_data, 0, sizeof(SLEEP_T));
@@ -781,6 +849,11 @@ namespace OHOS
       read_nap_data(&nap_data);
     }
 
+    void custom_read_wear_data(void)
+    {
+        read_wear_data();
+    }
+
     void custom_sleep_model_updata(void)
     {
       OHOS::SleepModel::GetInstance().ReInitData();
@@ -802,6 +875,7 @@ namespace OHOS
       nap_update_timestamp = nap_data.wake_up_timestamp;
     }
 
+  
 #ifdef __cplusplus
 #if __cplusplus
   }
index f7fcaa7..d250bfb 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: penglei 1624952103@qq.com\r
  * @Date: 2024-06-17 14:31:08\r
  * @LastEditors: penglei 1624952103@qq.com\r
- * @LastEditTime: 2024-11-05 17:18:36\r
+ * @LastEditTime: 2024-11-11 17:08:33\r
  * @FilePath: /FD230/code/sdk/application/wearable/service/factorytest_service/factorytest_protocol.c\r
  * @Description: \r
  * \r
@@ -485,17 +485,19 @@ void factorytest_protocol_common_decode(uint8_t submode,uint8_t testitem,uint8_t
                 uint8_t send_data=0;\r
 \r
                 factorytest_mode_flag = 1;\r
+\r
                 ChargerEventPublish(TOPIC_EVENT_CHARGE_UNPLUG,0); //进入产测模式 关闭充电弹窗\r
                 uapi_dev_runtime_set_factory_test_status(1); //设置产测模式runtime\r
                 svr_ble_adv_factory_test_start_param(); //设置蓝牙广播 避免出现连接问题\r
+\r
+                factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_COMMON,\r
+                BLE_TEST_CMD_COMMON_SUB_MODE_SWITCH_MODE,\r
+                0x01,\r
+                send_data,\r
+                1);\r
                 uapi_hfp_connect_();\r
                 LOS_Msleep(500);\r
                 uapi_a2dp_snk_connect_();\r
-                factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_COMMON,\r
-                        BLE_TEST_CMD_COMMON_SUB_MODE_SWITCH_MODE,\r
-                        0x01,\r
-                        send_data,\r
-                        1);\r
             } else if (testitem == 0x02)\r
             {\r
     \r
index 8720702..a48baba 100644 (file)
@@ -1,8 +1,8 @@
 /*
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-10-02 14:12:12
- * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-11-04 17:36:14
+ * @LastEditors: penglei 1624952103@qq.com
+ * @LastEditTime: 2024-11-11 15:03:39
  * @FilePath: /FD230/code/sdk/application/wearable/service/msg_center/include/notify/debug_output_notification.h
  */
 #ifndef DEBUG_OUTPUT_NOTIFICATION_H
@@ -40,6 +40,7 @@ namespace OHOS
         std::string get_battery_info(void);
         std::string get_shutdown_info(void);
         std::string get_sleep_time(void);
+        std::string get_wear_status(void);
         std::string get_free_memory(void);
         std::string get_nextday_log(void);
         std::string get_heart_rate(void);
index a02b1c0..0946b3b 100644 (file)
@@ -151,6 +151,8 @@ namespace OHOS
         debugOutputItemInfo[index++] = {index, "uart_service_status"};
         //Vote状态服务
         debugOutputItemInfo[index++] = {index, "vote_service_status"};
+        // 佩戴状态
+        debugOutputItemInfo[index++] = {index, "wear_status"};
         usedLen = index;
         /* -------------------------------- Add data -------------------------------- */
         for (uint8_t i = 0; i < usedLen; i++)
@@ -448,6 +450,12 @@ namespace OHOS
 
         return result; // 返回结果字符串  
     } 
+
+    // 获取佩戴状态  
+    std::string DebugOutputViewEventListener::get_wear_status(void) {
+        return get_wear_status_str(); // 返回结果字符串  
+    } 
+
     // 获取系统free内存
     std::string DebugOutputViewEventListener::get_free_memory()
     {
@@ -714,6 +722,9 @@ namespace OHOS
         case 14:
             str = get_current_vote_status();
             break;
+        case 15:
+            str = get_wear_status();
+            break;
         default:
             str = "--";
             break;
index 38c05a0..4f66b64 100644 (file)
@@ -579,6 +579,8 @@ void cywee_custom_save_sleep_data(void);
 void cywee_custom_save_nap_data(void);
 void cywee_reset_history_daily_data(void);
 void cywee_check_acc(void);
+
+void cywee_custom_save_wear_data(void);
 #pragma pack()
 
 
index 33499da..9c25a57 100644 (file)
@@ -833,8 +833,12 @@ void cywee_wearstatus_update(int wearstatus)
     memset(&csd, 0, sizeof(CUSTOM_OFFBODY_DETECT));
     csd.sensorType = CUSTOM_OFFBODY_DETECT;
     csd.fData[0] = wearstatus;
+    wear_status = wearstatus;
     CWM_CustomSensorInput(&csd);
     // CWM_OS_dbgPrintf("111wearstatus : %d\r\n",wearstatus);
+
+    do_custom_fileoperate_service_check_msg(  
+            CUSTOM_FILEOPERATE_MSG_TYPE_WEAR_DATA_SAVE, NULL, 0);  
 #endif
 }
 
@@ -1878,4 +1882,14 @@ void cywee_custom_save_nap_data(void)
     cywee_save_nap_data(sleep_time);
     uapi_dev_runtime_set_sleep_storage_status(0);
 }
-   
\ No newline at end of file
+
+void cywee_custom_save_wear_data(void)
+{
+    SLEEP_STAT_T data;
+    uint32_t tm = 0;
+    uapi_get_timestampe_ss(&tm);
+    data.timestamp = tm;
+    data.stat = wear_status;
+    // CWM_OS_dbgPrintf("data.timestamp : %d , data.stat : %d\n", data.timestamp,data.stat);
+    uapi_save_file_data("user/userdata/wear.bin",&data,sizeof(SLEEP_STAT_T),"ab");
+}
index ad21679..fe82912 100644 (file)
@@ -469,7 +469,7 @@ void hx3695_hrs_cal_init(void)
 void hx3695_hrs_cal_off(void)\r
 {\r
     uint16_t sample_rate = 25;                       /*config the data rate of chip alps2_fm ,uint is Hz*/\r
-    uint32_t prf_clk_num = 32000/sample_rate*24/25;       /*period in clk num, num = Fclk/fs */\r
+    uint32_t prf_clk_num = 32000/sample_rate;       /*period in clk num, num = Fclk/fs */\r
                uint8_t  data_avg_num = 0;\r
     hx3695_write_reg(0X2a, (uint8_t)prf_clk_num);    // prf bit<7:0>\r
     hx3695_write_reg(0X2b, (uint8_t)(prf_clk_num>>8)); // prf bit<15:8>\r
index 5dc455d..32a02c4 100644 (file)
@@ -174,6 +174,15 @@ static void custom_fileoperate_service_check_task(void const *arg)
             // printf("[%d] %d\r\n",__LINE__,mail.data[0]);
             save_popup_windows_log_c(mail.data[0]);
             break;
+
+        case CUSTOM_FILEOPERATE_MSG_TYPE_WEAR_DATA_READ:
+            custom_read_wear_data();
+            break;
+
+        case CUSTOM_FILEOPERATE_MSG_TYPE_WEAR_DATA_SAVE:
+            cywee_custom_save_wear_data();
+            break;
+
         default:
             PRINT("Unknown CUSTOM_FILE_OPERATE_MSG cmd 0x%02X \r\n", mail.cmd);
             break;