优化睡眠与小睡时间戳接收 477/1 477/head
authorpenglei <1624952103@qq.com>
Sat, 6 Jul 2024 10:45:42 +0000 (18:45 +0800)
committerpenglei <1624952103@qq.com>
Sat, 6 Jul 2024 10:45:42 +0000 (18:45 +0800)
code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp

index fc06cef..b4d3278 100644 (file)
@@ -424,10 +424,21 @@ void MsgCenterNotifyLowPowerAlarmProc(const Topic topic, Request* req)
 
 #endif
 #endif
+
+#ifdef FD230
+static SLEEP_T sleep_data = {0};
+static NAP_T nap_data = {0};
+static int state_num = 0;
+static uint32_t day_timestamp = 0;
+#endif
+
 void MsgCenterNotifyNextDayProc(const Topic topic, Request* req)
 {
     unused(topic);
     unused(req);
+#ifdef FD230
+    day_timestamp = 0;
+#endif
     AlarmClockModel::GetInstance()->NextDayNotify();
     if(!ConfigModel::GetInstance()->get_configData_int(OHOS::ConfigModel::CONFIGMODEL_ITEM_SLEEP))
     {
@@ -998,17 +1009,24 @@ void MsgCenterNotifyActivityExtraInfoProc(const Topic topic, Request* req)
 {
     unused(topic);
 }
-#ifdef FD230
-static SLEEP_T sleep_data = {0};
-static NAP_T nap_data = {0};
-#endif
-static int state_num = 0;
 
 void MsgCenterNotifyInactivityProc(const Topic topic, Request *req)
 {
     WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "MsgCenterNotifyInactivityProc !");
     unused(topic);
-    uint32_t timestamp = 0;
+#ifdef FD230
+    if(day_timestamp == 0)
+    {
+        uint32_t timestamp = 0;
+        time_t rawtime;
+        struct tm* timeinfo;
+        time(&rawtime);
+        timeinfo = localtime(&rawtime);
+        uapi_get_timestampe_ss(&timestamp);
+        day_timestamp = timestamp - (timeinfo->tm_hour * 60 * 60 + timeinfo->tm_min * 60 + timeinfo->tm_sec);
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, ", = %d", day_timestamp);
+    }
+#endif
     OHOS::SLEEP_STATE_T state_data = {0};
     cywee_inactivity_result_t *cywee_Inactivity_Info = (cywee_inactivity_result_t *)malloc(req->len);
     if (!cywee_Inactivity_Info)
@@ -1050,43 +1068,36 @@ void MsgCenterNotifyInactivityProc(const Topic topic, Request *req)
 
         //睡眠
         case INACTIVITY_MODE_SLEEPING_OUTPUT:
-
-            uapi_get_timestampe_ss(&timestamp);
-
 #ifdef FD230
-
             if(state_num < 20)
             {
-                sleep_data.sleep_status[state_num].timestamp = timestamp;
+                sleep_data.sleep_status[state_num].timestamp = day_timestamp + cywee_Inactivity_Info->hour * 60 * 60 + cywee_Inactivity_Info->minute * 60;
                 sleep_data.sleep_status[state_num].stat = cywee_Inactivity_Info->status;
-                state_num ++ ;
+                state_num ++;
             }
-
-            if(cywee_Inactivity_Info->status == 6) //0进入睡眠  1潜睡 2深睡 3清醒 4结束睡眠 6入睡 7出睡最后一笔输出 8未出睡最后一笔输出 12快速动眼 13取消入睡
+            if(cywee_Inactivity_Info->status == 0) //0进入睡眠  1潜睡 2深睡 3清醒 4结束睡眠 6入睡 7出睡最后一笔输出 8未出睡最后一笔输出 12快速动眼 13取消入睡
             {
-                sleep_data.fall_asleep_timestamp = timestamp;
+                sleep_data.fall_asleep_timestamp = day_timestamp + cywee_Inactivity_Info->hour * 60 * 60 + cywee_Inactivity_Info->minute * 60;
             }
             else if(cywee_Inactivity_Info->status == 4)
             {
-                sleep_data.wake_up_timestamp = timestamp;
+                sleep_data.wake_up_timestamp = day_timestamp + cywee_Inactivity_Info->hour * 60 * 60 + cywee_Inactivity_Info->minute * 60;
             }
 #endif
             break;
 
         //小睡
         case INACTIVITY_MODE_NAP_OUTPUT:
-            if(cywee_Inactivity_Info->status == 6) //0进入睡眠  1潜睡 2深睡 3清醒 4结束睡眠 6入睡 7出睡最后一笔输出 8未出睡最后一笔输出 12快速动眼 13取消入睡
+            if(cywee_Inactivity_Info->status == 0) //0进入睡眠  1潜睡 2深睡 3清醒 4结束睡眠 6入睡 7出睡最后一笔输出 8未出睡最后一笔输出 12快速动眼 13取消入睡
             {
-                uapi_get_timestampe_ss(&timestamp);
 #ifdef FD230
-                nap_data.fall_asleep_timestamp = timestamp;
+                nap_data.fall_asleep_timestamp = day_timestamp + cywee_Inactivity_Info->hour * 60 * 60 + cywee_Inactivity_Info->minute * 60;
 #endif
             }
             else if(cywee_Inactivity_Info->status == 14)
             {
-                uapi_get_timestampe_ss(&timestamp);
 #ifdef FD230
-                nap_data.wake_up_timestamp = timestamp;
+                nap_data.wake_up_timestamp = day_timestamp + cywee_Inactivity_Info->hour * 60 * 60 + cywee_Inactivity_Info->minute * 60;
 #endif
             }
             break;