优化多段睡眠文件存储,优化添加cywee密钥的AT指令 922/1
authorpenglei <1624952103@qq.com>
Mon, 9 Sep 2024 10:51:00 +0000 (18:51 +0800)
committerpenglei <1624952103@qq.com>
Mon, 9 Sep 2024 10:51:00 +0000 (18:51 +0800)
code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepModel.cpp
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_at_cmd.c

index 5fa4183..c481d6d 100644 (file)
@@ -1,8 +1,8 @@
 /*
  * @Author: penglei 1624952103@qq.com
  * @Date: SLEPPNOTIFY24-06-26 19:36:48
- * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-09-07 17:56:51
+ * @LastEditors: penglei 1624952103@qq.com
+ * @LastEditTime: 2024-09-09 18:25:14
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepModel.cpp
  * @Description:
  *
@@ -251,29 +251,34 @@ namespace OHOS
             memset(status_file_path,0,sizeof(status_file_path));
             sprintf_s(status_file_path, 64, SLEEP_STATUS_PATH, day);
             fp = fopen(status_file_path, "wb+");
-
+            if(fp == NULL)
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "save_sleep_data fopen fail");
+                return false;
+            }
             history_wake_up_timestamp = data->wake_up_timestamp;
+            fwrite(data->sleep_status, sizeof(SLEEP_STATE_T), data->status_num, fp);
         }
         else
         {        
-            fp = fopen(status_file_path, "ab+");
+            fp = fopen(status_file_path, "rb+");
+            if(fp == NULL)
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "save_sleep_data fopen fail");
+                return false;
+            }
+
             if(history_wake_up_timestamp != data->wake_up_timestamp)
             {
+                fseek(fp, -sizeof(SLEEP_STATE_T), SEEK_END);
                 SLEEP_STATE_T sleep_status = {0,0};
                 sleep_status.stat = 3; //清醒状态
-                sleep_status.timestamp = history_wake_up_timestamp + 60; //时间戳为上一次的出睡时间 加 1分钟
+                sleep_status.timestamp = history_wake_up_timestamp; //清醒状态时间为上一次的出睡时间
                 history_wake_up_timestamp = data->wake_up_timestamp; //更新历史出睡时间戳
-                fwrite(&sleep_status, sizeof(SLEEP_STATE_T), 1, fp);
+                fwrite(&sleep_status, sizeof(SLEEP_STATE_T), 1, fp); //替换历史出睡数据 改为清醒状态
+                fwrite(&data->sleep_status[1], sizeof(SLEEP_STATE_T), data->status_num - 1, fp); //跳过入睡状态写入文件
             }
         }
-
-        if (fp == NULL)
-        {
-            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "save_sleep_data fopen fail");
-            return false;
-        }
-        fwrite(data->sleep_status, sizeof(SLEEP_STATE_T), data->status_num, fp);
-
         fclose(fp);
         return true;
     }
index 61fed1c..e22e786 100644 (file)
@@ -1295,7 +1295,7 @@ void MsgCenterNotifyInactivityProc(const Topic topic, Request *req)
             {
                 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;
-                if(sleep_data.sleep_status[state_num].stat == 6 || sleep_data.sleep_status[state_num].stat == 13)
+                if(sleep_data.sleep_status[state_num].stat == 7 || sleep_data.sleep_status[state_num].stat == 13)
                 {
                     uapi_get_timestampe_ss(&timestamp);
                     sleep_data.sleep_status[state_num].timestamp = timestamp;
index 7460368..7d584c6 100644 (file)
@@ -834,6 +834,7 @@ void CWM_AP_SensorListen(pSensorEVT_t sensorEVT) {
                 {
                     uapi_dev_runtime_set_sleep_status(1);
                     uapi_get_timestampe_ss(&asleep_timestampe);
+                    break; //入睡通知不发消息,直接退出
                 }
                 else if(c_inactivity_result_t.status == 4 || c_inactivity_result_t.status == 13)
                 {
index be8844a..8981256 100644 (file)
@@ -51,6 +51,36 @@ static int ConvertCmdToParam(uint8_t *para, uint32_t paraLen,
     return CUSTOM_UTILS_SUCCESS;
 }
 
+#ifdef CYWEE_MAC_ACTIVE
+
+static int MyConvertCmdToParam(uint8_t *para, uint32_t paraLen,
+        uint8_t argv[CUSTOM_UTILS_MAX_ARGC][CUSTOM_UTILS_MAX_ARGV_LEN], uint32_t* argc)
+{
+    uint32_t pos = 0;
+    *argc = 0;
+    for (uint32_t i = 0; i < paraLen; i++) {
+        if ((para[i] == ' ' || para[i] == '\n') && pos != 0) {
+            argv[*argc][pos] = '\0';
+            *argc += 1;
+            pos = 0;
+            if (*argc >= CUSTOM_UTILS_MAX_ARGC) {
+                return CUSTOM_UTILS_FAILED;
+            }
+        } else if (para[i] != ','){
+            argv[*argc][pos] = para[i];
+            pos++;
+            if (pos >= CUSTOM_UTILS_MAX_ARGV_LEN) {
+                return CUSTOM_UTILS_FAILED;
+            }
+        }
+    }
+    if (pos != 0) {
+        *argc += 1;
+    }
+
+    return CUSTOM_UTILS_SUCCESS;
+}
+#endif
 
 static uint32_t custom_utils_setsn(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
 {
@@ -1129,12 +1159,13 @@ static uint32_t custom_cywee_save_mac_key(uint8_t *para, uint32_t paraLen, char
 {
 
     UNUSED(strCommonCmd);
+#ifdef CYWEE_MAC_ACTIVE
     uint8_t argv[CUSTOM_UTILS_MAX_ARGC][CUSTOM_UTILS_MAX_ARGV_LEN] = { 0 };
     uint32_t argc = 0;
-    uint8_t send_data[8] = {0};
-
+    uint8_t *send_data = NULL;
+    uint8_t *tmp_data = NULL;
 
-    int ret = ConvertCmdToParam(para, paraLen, argv, &argc);
+    int ret = MyConvertCmdToParam(para, paraLen, argv, &argc);
     if (ret != CUSTOM_UTILS_SUCCESS) {
         wstp_print("CUSTOM_UTILSTEST ATCMD Convert Command Failed\n");
         return ERRCODE_FAIL;
@@ -1145,9 +1176,41 @@ static uint32_t custom_cywee_save_mac_key(uint8_t *para, uint32_t paraLen, char
         return ERRCODE_FAIL;
     }
     int16_t len = atol((char*)argv[0]);
+    tmp_data = (uint8_t *)malloc(len * 2);
+    if(tmp_data == NULL)
+    {
+        wstp_print("MALLOC FAILED\r\n");
+        return ERRCODE_FAIL;
+    }
+
+    
+    for(int i = 0; i < len * 2; i++)
+    {
+        if(argv[1][i] >=65)
+            argv[1][i] = argv[1][i] - 65 + 10;
+        else
+            argv[1][i] = argv[1][i] - 48;
+        tmp_data[i] = argv[1][i];
+
+    }
+    send_data = (uint8_t *)malloc(len);
+    if(send_data == NULL)
+    {
+        free(tmp_data);
+        wstp_print("MALLOC FAILED\r\n");
+        return ERRCODE_FAIL;
+    }
 
-    uapi_cywee_save_mac_key(argv[1],len);
 
+    for(int i = 0,j = 0; i < len * 2 ; i+=2 , j++)
+    {
+        send_data[j] =  tmp_data[i] * 16 | tmp_data[i+1];
+        wstp_print("tmp_data[%d] : 0X%2X\n",j,send_data[j]);
+    }
+    uapi_cywee_save_mac_key(send_data,len);
+    free(send_data);
+    free(tmp_data);
+#endif
     return ERRCODE_SUCC;
 }