优化睡眠模式初始化流程与时间戳计算
authorpenglei <1624952103@qq.com>
Fri, 13 Sep 2024 09:51:18 +0000 (17:51 +0800)
committerpenglei <1624952103@qq.com>
Fri, 13 Sep 2024 09:51:18 +0000 (17:51 +0800)
睡眠UI增加查看当前睡眠数据功能
增加蓝牙通话与4G通话音量映射
增加PING网站的蓝牙指令
优化运动配速数据计算

code/sdk/application/wearable/fd230app/nativeui/alarmclocktimerconfig/src/AlarmClockTimerConfig.cpp
code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepModel.h
code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepModel.cpp
code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepView.cpp
code/sdk/application/wearable/service/factorytest_service/factorytest_protocol.c
code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp
code/sdk/drivers/peripheral/cywee/src/main_dml.c
code/sdk/drivers/peripheral/utils/custom_utils.c
code/sdk/drivers/peripheral/utils/custom_utils.h
code/sdk/middleware/services/media/foundation/audiomanager/frameworks/audiomanager/cpp/audio_manager.cpp

index bc6416a..087c205 100644 (file)
@@ -457,7 +457,8 @@ extern "C"
                 // uapi_dev_runtime_set_nap_monitoring_status(0);\r
                 if(uapi_dev_runtime_get_nap_monitoring_status() == 1)\r
                     uapi_clean_sleep_flag();                        // 清除睡眠标志文件\r
-                set_keep_in_wear_det_mode(0);                                       // 关闭小睡佩戴监测\r
+                OHOS::create_sleep_folder();                     // 创建睡眠文件夹              \r
+                set_keep_in_wear_det_mode(0);                       \r
                 do_cywee_service_check_msg(CYWEE_SERVICE_CMD_GET_SLEEP_DATA, &cmd); // 强制获取小睡数据,结束小睡\r
                 // 睡眠弹窗\r
                 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "要睡觉啦!");\r
index 999d9c4..482cb10 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: penglei 1624952103@qq.com
  * @Date: 2024-06-26 19:36:48
  * @LastEditors: penglei 1624952103@qq.com
- * @LastEditTime: 2024-09-04 19:02:28
+ * @LastEditTime: 2024-09-13 12:03:38
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepModel.h
  * @Description:
  *
@@ -35,7 +35,7 @@
 
 #define SLEEP_DATA_DIR "user/userdata/sleep/"
 
-#define SLEEP_STATUS_LENGTH 50
+#define SLEEP_STATUS_LENGTH 80
 
 namespace OHOS
 {
@@ -76,6 +76,7 @@ namespace OHOS
     bool save_sleep_data(SLEEP_T *data);
     bool read_sleep_data(SLEEP_T *data);
     void clean_sleep_data(void);
+    bool create_sleep_folder(void);
     // 睡眠状态
     enum class SLEEPSTATE
     {
index c481d6d..6afb0f3 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-09-09 18:25:14
+ * @LastEditTime: 2024-09-13 17:00:34
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepModel.cpp
  * @Description:
  *
@@ -43,6 +43,7 @@
 #include "ConfigModelC.h"
 #include "power_display_service.h"
 #include "MainModel.h"
+#include "cywee_service.h"
 
 extern "C" errcode_t uapi_get_TIME_STR(uint32_t time, char *p_time, char date_separator, char time_separator, date_format_t format);
 extern "C" int get_sleep_time_from_config_model(void);
@@ -139,6 +140,7 @@ namespace OHOS
 
     static uint32_t fall_asleep_timestamp = 0;
     static uint32_t history_wake_up_timestamp = 0;
+    static char day[12] = {0};
 
     void clean_sleep_data(void)
     {
@@ -149,17 +151,22 @@ namespace OHOS
         total_wake_time = 0;
         memset(time_file_path,0,sizeof(time_file_path));
         memset(status_file_path,0,sizeof(status_file_path));
+        memset(day,0,sizeof(day));
         fall_asleep_timestamp = 0;
     }
 
-    
-    bool save_sleep_data(SLEEP_T *data)
+    bool create_sleep_folder(void)
     {
-
         struct stat info;
         char dir_path[64] = {0};
-        char day[12] = {0};
-        uapi_get_YYMMDD_Time(day, '\0');
+
+        uint32_t sleep_time = get_sleep_time_from_config_model();
+        uint32_t wake_up_time = get_wake_up_time_from_config_model();
+        
+        if(sleep_time > wake_up_time)
+            uapi_get_YYMMDD_Time_extend(day, '\0' , -1);
+        else
+            uapi_get_YYMMDD_Time_extend(day, '\0' , 0);
 
         sprintf_s(dir_path, 64, SLEEP_DIR_PATH, day);
         if (stat("user/userdata/sleep", &info) != 0)
@@ -178,9 +185,11 @@ namespace OHOS
                 return false; // Failed to create folder
             }
         }
-        
-
+        return true; 
+    }
 
+    bool save_sleep_data(SLEEP_T *data)
+    {
         if(access(time_file_path, F_OK) == -1)
         {
             memset(time_file_path,0,sizeof(time_file_path));
@@ -204,10 +213,14 @@ namespace OHOS
         }
         fwrite(&fall_asleep_timestamp, 1, 4, fp);
 
+
         uint32_t wake_up_timestamp = data->wake_up_timestamp;
         fwrite(&wake_up_timestamp, 1, 4, fp);
 
-        total_time = (wake_up_timestamp - fall_asleep_timestamp) / 60;
+        if(data->wake_up_timestamp == 0)
+            total_time = data->total_time;
+        else
+            total_time = (wake_up_timestamp - fall_asleep_timestamp) / 60;
 
         uint8_t total_time_hour = (total_time / 60);
         fwrite(&total_time_hour, 1, 1, fp);
@@ -237,7 +250,10 @@ namespace OHOS
         total_time_minute = (total_rem_sleep_time % 60);
         fwrite(&total_time_minute, 1, 1, fp);
 
-        total_wake_time = total_time - total_rem_sleep_time - total_mild_sleep_time - total_deep_sleep_time;
+        if(data->wake_up_timestamp == 0)
+            total_wake_time = data->total_wake_time;
+        else
+            total_wake_time = total_time - total_rem_sleep_time - total_mild_sleep_time - total_deep_sleep_time;
         total_time_hour = (total_wake_time / 60);
         fwrite(&total_time_hour, 1, 1, fp);
 
@@ -246,6 +262,13 @@ namespace OHOS
 
         fclose(fp);
 
+        if(data->wake_up_timestamp == 0) // 临时数据清掉
+        {
+            total_deep_sleep_time -= data->total_deep_sleep_time;
+            total_mild_sleep_time -= data->total_mild_sleep_time;
+            total_rem_sleep_time -= data->total_rem_sleep_time;
+        }
+
         if(access(status_file_path, F_OK) == -1)
         {
             memset(status_file_path,0,sizeof(status_file_path));
@@ -268,7 +291,7 @@ namespace OHOS
                 return false;
             }
 
-            if(history_wake_up_timestamp != data->wake_up_timestamp)
+            if(history_wake_up_timestamp != data->wake_up_timestamp && ((data->fall_asleep_timestamp - history_wake_up_timestamp) < 2 * 60 * 60))
             {
                 fseek(fp, -sizeof(SLEEP_STATE_T), SEEK_END);
                 SLEEP_STATE_T sleep_status = {0,0};
@@ -278,6 +301,8 @@ namespace OHOS
                 fwrite(&sleep_status, sizeof(SLEEP_STATE_T), 1, fp); //替换历史出睡数据 改为清醒状态
                 fwrite(&data->sleep_status[1], sizeof(SLEEP_STATE_T), data->status_num - 1, fp); //跳过入睡状态写入文件
             }
+            else
+                fwrite(data->sleep_status, sizeof(SLEEP_STATE_T), data->status_num, fp);
         }
         fclose(fp);
         return true;
@@ -369,6 +394,9 @@ namespace OHOS
     void SleepModel::ReInitData()
     {
         // 配置睡眠数据
+        int cmd = 0;
+        do_cywee_service_check_msg(CYWEE_SERVICE_CMD_GET_SLEEP_DATA, &cmd); //获取睡眠数据 但不中止睡眠
+        LOS_Msleep(500);
         SLEEP_T *data = new SLEEP_T();
         if (read_sleep_data(data))
         {
index 1c8499c..de2224a 100644 (file)
@@ -31,6 +31,9 @@ namespace OHOS
     {
         // 获取睡眠数据
         SleepModel &sleepModel = SleepModel::GetInstance();
+        // 读取一次文件
+        sleepModel.ReInitData();
+
         int sleep_hour = sleepModel.get_sleep_hour();
         int sleep_min = sleepModel.get_sleep_min();
         int total_sleep = sleepModel.get_sleep_total();
index 6f9c8f1..b8ec7c0 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-09-07 19:55:48\r
+ * @LastEditTime: 2024-09-12 20:31:12\r
  * @FilePath: /FD230/code/sdk/application/wearable/service/factorytest_service/factorytest_protocol.c\r
  * @Description: \r
  * \r
 #include "battery_service.h"\r
 #include "cywee_service.h"\r
 \r
+#ifdef SUPPORT_TCPIP\r
+#include "lwip/api_shell.h"\r
+#endif\r
+\r
 #pragma pack(1)\r
 typedef struct factorytest_cmd_header_t\r
 {\r
@@ -468,7 +472,7 @@ void factorytest_protocol_common_decode(uint8_t submode,uint8_t testitem,uint8_t
             {\r
                 uint8_t send_data = 0x00;\r
 \r
-                power_on_cat1();\r
+                uapi_set4GCapability(true);\r
                 \r
                 factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_COMMON,\r
                         BLE_TEST_CMD_COMMON_SUB_MODE_POWERCONSUMPTION,\r
@@ -482,7 +486,7 @@ void factorytest_protocol_common_decode(uint8_t submode,uint8_t testitem,uint8_t
                 send_ppg_cmd_msg(PPG_SERVICE_CMD_TYPE_STOP_WEAR_MODE_TEST); \r
                 send_ppg_cmd_msg(PPG_SERVICE_CMD_TYPE_STOP_SPO2_TEST); \r
 \r
-                power_off_cat1();\r
+                uapi_set4GCapability(false);\r
 \r
                 factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_COMMON,\r
                         BLE_TEST_CMD_COMMON_SUB_MODE_POWERCONSUMPTION,\r
@@ -1609,6 +1613,41 @@ void factorytest_protocol_soft_test_decode(uint8_t submode,uint8_t testitem,uint
                         0x13,\r
                         &send_data,\r
                         1);\r
+            } else if(testitem == 0x14)\r
+            {\r
+                //PING \r
+                uint8_t send_data = 0;\r
+#ifdef SUPPORT_TCPIP\r
+                char *str = (char *)malloc(len + 1);\r
+\r
+                if (str == NULL) \r
+                {\r
+                    PRINT("malloc failed\n");\r
+                    return;\r
+                }\r
+\r
+                char *hostname = (char *)malloc(len + 1 + 8);\r
+                if (hostname == NULL) \r
+                {\r
+                    PRINT("malloc failed\n");\r
+                    free(str);\r
+                    return;\r
+                }\r
+\r
+                for (int i = 0; i < len; i++) \r
+                    str[i] = (char)data[i];\r
+                str[len] = '\0';\r
+\r
+                sprintf(hostname,"www.%s.com",str);\r
+                PRINT("hostname : %s\n",hostname);\r
+                send_data = OsShellPing(1,hostname);\r
+                free(str);\r
+#endif\r
+                factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST,\r
+                        BLE_TEST_CMD_SOFT_TEST_SUB_MODE_CAT1,\r
+                        0x14,\r
+                        &send_data,\r
+                        1);\r
             }\r
             \r
             break;\r
index 0ff8da9..aa954be 100644 (file)
@@ -502,6 +502,7 @@ static SLEEP_T sleep_data = {0};
 static NAP_T nap_data = {0};
 static int state_num = 0;
 static uint32_t day_timestamp = 0;
+static uint32_t current_day = 0;
 static uint8_t fall_asleep_state_num = 0;
 #endif
 
@@ -1247,6 +1248,7 @@ void MsgCenterNotifyInactivityProc(const Topic topic, Request *req)
         timeinfo = localtime(&rawtime);
         uapi_get_timestampe_ss(&timestamp);
         day_timestamp = timestamp - (timeinfo->tm_hour * 60 * 60 + timeinfo->tm_min * 60 + timeinfo->tm_sec);
+        current_day = timeinfo->tm_mday;
     }
 #endif
     OHOS::SLEEP_STATE_T state_data = {0};
@@ -1306,6 +1308,10 @@ void MsgCenterNotifyInactivityProc(const Topic topic, Request *req)
             if(state_num < SLEEP_STATUS_LENGTH)
             {
                 sleep_data.sleep_status[state_num].timestamp = day_timestamp + cywee_Inactivity_Info->hour * 60 * 60 + cywee_Inactivity_Info->minute * 60;
+                if(current_day != cywee_Inactivity_Info->day)
+                {
+                    sleep_data.sleep_status[state_num].timestamp -= 24 * 60 * 60;
+                }
                 sleep_data.sleep_status[state_num].stat = cywee_Inactivity_Info->status;
                 if(sleep_data.sleep_status[state_num].stat == 7 || sleep_data.sleep_status[state_num].stat == 13)
                 {
@@ -1315,7 +1321,7 @@ void MsgCenterNotifyInactivityProc(const Topic topic, Request *req)
                 if(sleep_data.sleep_status[state_num].stat == 0) //0进入睡眠  1潜睡 2深睡 3清醒 4结束睡眠 6入睡 7出睡最后一笔输出 8未出睡最后一笔输出 12快速动眼 13取消入睡
                 {
                     sleep_data.fall_asleep_timestamp = sleep_data.sleep_status[state_num].timestamp;
-                    fall_asleep_state_num = state_num;
+                    //fall_asleep_state_num = state_num;
                 }
                 else if(sleep_data.sleep_status[state_num].stat == 4)
                 {
@@ -1358,7 +1364,7 @@ void MsgCenterNotifyInactivityAccumulateTimeProc(const Topic topic, Request* req
     {
         memset(&sleep_data,0,sizeof(SLEEP_T));
         state_num = 0;
-        fall_asleep_state_num = 0;
+        //fall_asleep_state_num = 0;
         uapi_dev_runtime_set_absolute_static_status(0);
         return;
     }
@@ -1387,11 +1393,11 @@ void MsgCenterNotifyInactivityAccumulateTimeProc(const Topic topic, Request* req
     }
     else if(cywee_Inactivity_Accumulate_Time_Info->output_number == INACTIVITY_MODE_SLEEPING_ACCUMULATE_TIME_OUTPUT)
     {
-        if(sleep_data.fall_asleep_timestamp > sleep_data.wake_up_timestamp)
-        {
-            sleep_data.fall_asleep_timestamp -= 24 * 60 * 60;
-            sleep_data.sleep_status[fall_asleep_state_num].timestamp = sleep_data.fall_asleep_timestamp;
-        }
+        // if(sleep_data.fall_asleep_timestamp > sleep_data.wake_up_timestamp && sleep_data.wake_up_timestamp != 0)
+        // {
+        //     sleep_data.fall_asleep_timestamp -= 24 * 60 * 60;
+        //     sleep_data.sleep_status[fall_asleep_state_num].timestamp = sleep_data.fall_asleep_timestamp;
+        // }
 
         sleep_data.total_time = cywee_Inactivity_Accumulate_Time_Info->total_time;
         sleep_data.total_deep_sleep_time = cywee_Inactivity_Accumulate_Time_Info->total_deep_sleep_time;
@@ -1403,7 +1409,7 @@ void MsgCenterNotifyInactivityAccumulateTimeProc(const Topic topic, Request* req
         set_sleep_data(&sleep_data);
         memset(&sleep_data,0,sizeof(SLEEP_T));
         state_num = 0;
-        fall_asleep_state_num = 0;
+        //fall_asleep_state_num = 0;
     }
 #endif
     free(cywee_Inactivity_Accumulate_Time_Info);
index d596327..9508a37 100644 (file)
@@ -168,6 +168,7 @@ void cywee_get_acc_switch(int cmd)
 
 void cywee_set_sedentary_switch(int cmd)
 {
+    CWM_OS_dbgPrintf("cywee_set_sedentary_switch : %d \n",cmd);
     //设置久坐 0关,1开
     memset(&scl, 0, sizeof(scl));
     scl.iData[0] = 1;
@@ -916,9 +917,9 @@ void CWM_AP_SensorListen(pSensorEVT_t sensorEVT) {
 
                 c_activity_result_extre_info_t.avg_step_freq = (int)sensorEVT->fData[1];
                 c_activity_result_extre_info_t.avg_step_len = (float)sensorEVT->fData[2];
-                c_activity_result_extre_info_t.avg_pace = (int)sensorEVT->fData[3];
+                c_activity_result_extre_info_t.avg_pace = (int)(sensorEVT->fData[3] * 60);
                 c_activity_result_extre_info_t.max_step_freq = (int)sensorEVT->fData[4];
-                c_activity_result_extre_info_t.max_pace = (int)sensorEVT->fData[5];
+                c_activity_result_extre_info_t.avg_pace = (int)(sensorEVT->fData[5] * 60);
                 c_activity_result_extre_info_t.activity_zone = (int)sensorEVT->fData[10];
                 c_activity_result_extre_info_t.ativity_zone_moderate_duration = (int)sensorEVT->fData[11];
                 c_activity_result_extre_info_t.ativity_zone_high_duration = (int)sensorEVT->fData[12];
@@ -954,7 +955,7 @@ void CWM_AP_SensorListen(pSensorEVT_t sensorEVT) {
                 c_activity_result_t.calories = (int)sensorEVT->fData[3];
                 c_activity_result_t.step_frequency = (int)sensorEVT->fData[5];
                 c_activity_result_t.step_length = (float)sensorEVT->fData[6];
-                c_activity_result_t.pace = (int)sensorEVT->fData[7];
+                c_activity_result_t.pace = (int)(sensorEVT->fData[7] * 60);
                 c_activity_result_t.hrs = hrs;
                 hrs = 0; //每次上报完 清除心率值
                 cywee_func(CYWEE_MSG_TYPE_ACTIVITY_UPDATE,&c_activity_result_t,sizeof(cywee_activity_result_t));
index 2d85842..81d8809 100644 (file)
@@ -947,7 +947,7 @@ errcode_t uapi_get_YYMMDD_Time(char *p_time, char separator)
  * @param {uint8_t} n天前
  * @brief 获取日期
  */
-errcode_t uapi_get_YYMMDD_Time_extend(char *p_time, char separator,uint8_t day)
+errcode_t uapi_get_YYMMDD_Time_extend(char *p_time, char separator,int8_t day)
 {
     if (p_time == NULL)
     {
@@ -3371,6 +3371,25 @@ static chiinfo_mac_pair g_chipinfo_map[]={
 {0x0106,"74094417cf5b57f10a03787521820100"},
 {0x0107,"74094417ff4014470a0378750d820100"},
 {0x0108,"74094417b9da89830a03787549820100"},
+{0x0109,"{740944174a9de6930a03787545820100"}, 
+{0x010A,"{d45dd6171ff620c00a03780fe7820100"}, 
+{0x010B,"{74094417c92f1fe60a0378758f820100"}, 
+{0x010C,"{74094417ee3af42e0a03781de7810100"}, 
+{0x010D,"{74094417f0667a790a03781d21820100"}, 
+{0x010E,"{74094417362b8f0f0a037875ab810100"}, 
+{0x010F,"{74094417754dfa9c0a0378752d820100"}, 
+{0x0110,"{74094417c7ffc35c0a0378758b820100"}, 
+{0x0111,"{740944177f823b050a037875a7820100"}, 
+{0x0112,"{740944176bd237e50a0378756f820100"}, 
+{0x0113,"{74094417495ffa650a03787509820100"}, 
+{0x0114,"{74094417ba6da93b0a03787529820100"}, 
+{0x0115,"{740944170b743f830a03781d4d820100"}, 
+{0x0116,"{740944178d93d96b0a03781de9810100"}, 
+{0x0117,"{7409441799e6b3490a03781d4d820100"}, 
+{0x0118,"{7409441763fb49cc0a03787585820100"}, 
+{0x0119,"{d45dd61716c627340a03780f45830100"}, 
+{0x011A,"{74094417cd43a5360a03781d81820100"}, 
+{0x011B,"{74094417b8bfcc3c0a0378752d820100"}, 
 };
 
 errcode_t change_mac_from_chipinfo_map(void)
@@ -3454,6 +3473,8 @@ void uapi_custom_set_uart_rx_enable_flag(bool enable_uart)
 {
     g_enable_uart_rx = enable_uart;
 }
+
+
 #define SLEEP_FLAG_PATH "/user/userdata/sleep_flag.bin"
 
 void uapi_save_sleep_flag(uint8_t *data,uint16_t len)
index 4f1cda2..eacc91c 100644 (file)
@@ -68,7 +68,7 @@ errcode_t uapi_set_time_from_cat1(char* cat1time);
 /**获取日期*/
 errcode_t uapi_get_yyyymmddhhmmss_Date(char *date);
 /*获取日期扩展版*/
-errcode_t uapi_get_YYMMDD_Time_extend(char *p_time, char separator,uint8_t day);
+errcode_t uapi_get_YYMMDD_Time_extend(char *p_time, char separator,int8_t day);
 
 /*获取日期*/
 errcode_t uapi_get_YYMMDD_Time(char *p_time, char separator);
index 137c84d..0fad262 100755 (executable)
@@ -43,7 +43,7 @@ AudioSession AudioManager::MakeSessionId()
 bool AudioManager::SetVolume(AudioStreamType streamType, int32_t volume)
 {
     CHK_NULL_RETURN(impl_, false, "impl_ is nullptr");
-    
+
     if(streamType == AUDIO_STREAM_MUSIC)
     {
         if(volume == 0) 
@@ -55,15 +55,25 @@ bool AudioManager::SetVolume(AudioStreamType streamType, int32_t volume)
         else 
             volume = 30 + (volume - 1) * 40 / 99;
     }
+    else if(streamType == AUDIO_STREAM_VOICE_CALL_BT_SCO || streamType == AUDIO_STREAM_VOICE_CALL_VOLTE)
+    {
+        if(volume < 1) 
+            volume = 40;
+        else if(volume > 100) 
+            volume = 100;
+        else 
+            volume = 40 + (volume - 1) * 60 / 99;
+    }
     return impl_->SetVolume(streamType, volume);
 }
 
 int32_t AudioManager::GetVolume(AudioStreamType streamType)
 {
     CHK_NULL_RETURN(impl_, AUDIO_ERROR, "impl_ is nullptr");
+    int32_t volume = impl_->GetVolume(streamType);
+
     if(streamType == AUDIO_STREAM_MUSIC)
     {
-        int32_t volume = impl_->GetVolume(streamType);
         if(volume == 0) 
             return 0;
         if(volume < 30) 
@@ -72,8 +82,18 @@ int32_t AudioManager::GetVolume(AudioStreamType streamType)
             return 100;
         return ((volume - 30) * 99 / 40) + 1;
     }
+    else if(streamType == AUDIO_STREAM_VOICE_CALL_BT_SCO || streamType == AUDIO_STREAM_VOICE_CALL_VOLTE)
+    {
+        if(volume < 40) 
+            return 1;
+        else if(volume > 100) 
+            return 100;
+        else 
+            return ((volume - 30) * 99 / 60) + 1;
+    }
+
     else
-        return impl_->GetVolume(streamType);
+        return volume;
 
 }