修改睡眠状态存储数组长度为50,添加AT指令打印睡眠存储信息 862/1
authorpenglei <1624952103@qq.com>
Tue, 3 Sep 2024 08:20:46 +0000 (16:20 +0800)
committerpenglei <1624952103@qq.com>
Tue, 3 Sep 2024 08:20:46 +0000 (16:20 +0800)
about watch 添加cywee算法版本

code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepModel.h
code/sdk/application/wearable/fd230app/nativeui/system/include/SystemAboutTheWatchView.h
code/sdk/application/wearable/fd230app/nativeui/system/src/SystemAboutTheWatchView.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.c
code/sdk/drivers/peripheral/utils/custom_utils.h
code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c

index 88c848f..15ff479 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-07-04 20:12:47
+ * @LastEditTime: 2024-09-03 14:30:14
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepModel.h
  * @Description:
  *
@@ -32,6 +32,8 @@
 
 #define SLEEP_DATA_DIR "user/userdata/sleep/"
 
+#define SLEEP_STATUS_LENGTH 50
+
 namespace OHOS
 {
 #pragma pack(1)
@@ -51,7 +53,7 @@ namespace OHOS
 
     typedef struct
     {
-        SLEEP_STATE_T sleep_status[20];
+        SLEEP_STATE_T sleep_status[SLEEP_STATUS_LENGTH];
         uint8_t status_num;
         uint32_t fall_asleep_timestamp; // 入睡
         uint32_t wake_up_timestamp;     // 出睡
index fc542a3..8916e25 100644 (file)
@@ -1,8 +1,8 @@
 /*\r
  * @Author: luozheng 1732036298@qq.com\r
  * @Date: 2024-03-30 09:14:38\r
- * @LastEditors: SnickerSun snickersun@163.com\r
- * @LastEditTime: 2024-07-25 11:37:34\r
+ * @LastEditors: penglei 1624952103@qq.com\r
+ * @LastEditTime: 2024-08-31 18:57:13\r
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/system/include/SystemAboutTheWatchView.h\r
  */\r
 #ifndef SYSTEM_ABOUT_VIEW_H\r
@@ -64,7 +64,8 @@ namespace OHOS
         UILabel *FONT = nullptr;\r
         UILabel *HWVERTitle = nullptr;\r
         UILabel *HWVER = nullptr;\r
-\r
+        UILabel *CyweeVersionTitle = nullptr;\r
+        UILabel *CyweeVersion = nullptr;\r
         bool initViewStatus{false};\r
     };\r
 }\r
index 96a72f3..e6fd435 100644 (file)
@@ -24,6 +24,8 @@
 #define WATCH_IMEI_VALUE_TOP (WATCH_IMEI_TOP + WATCH_ABOUT_TITLE_HEIGHT)\r
 #define WATCH_FONT_TOP (WATCH_IMEI_VALUE_TOP + WATCH_ABOUT_VALUE_HEIGHT)\r
 #define WATCH_FONT_VALUE_TOP (WATCH_FONT_TOP + WATCH_ABOUT_TITLE_HEIGHT)\r
+#define WATCH_CYWEEVER_TOP (WATCH_FONT_VALUE_TOP + WATCH_ABOUT_VALUE_HEIGHT)\r
+#define WATCH_CYWEEVER_TOP_VALUE_TOP (WATCH_CYWEEVER_TOP + WATCH_ABOUT_TITLE_HEIGHT)\r
 \r
 namespace OHOS\r
 {\r
@@ -120,6 +122,11 @@ namespace OHOS
             delete HWVER;\r
             HWVER = nullptr;\r
 \r
+            delete CyweeVersionTitle;\r
+            CyweeVersionTitle = nullptr;\r
+            delete CyweeVersion;\r
+            CyweeVersion = nullptr;\r
+\r
             delete SystemAboutTheWatchScrollView;\r
             SystemAboutTheWatchScrollView = nullptr;\r
         }\r
@@ -576,10 +583,46 @@ namespace OHOS
         }\r
         HWVER->SetTextColor(Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0x87));\r
         SystemAboutTheWatchScrollView->Add(HWVER);\r
+        /* -------------------------------------------------------------------------- */ \r
+        Config = {\r
+            .left = TITLE_LABEL_X,\r
+            .top = WATCH_CYWEEVER_TOP,\r
+            .width = TITLE_LABEL_W,\r
+            .height = TITLE_LABEL_H,\r
+            .fontSize = TITLE_LABEL_FONTSIZE,\r
+            .lineHeigh = TITLE_LABEL_LINEHEIGHT,\r
+            .text = "Cywee Version",\r
+            .lineBreakMode = UILabel::LINE_BREAK_MARQUEE,\r
+        };\r
+        CyweeVersionTitle = InitLabel(Config);\r
+        if (CyweeVersionTitle == nullptr)\r
+        {\r
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemAboutTheWatchView::CyweeVersionTitle new fail!");\r
+            return nullptr;\r
+        }\r
+        SystemAboutTheWatchScrollView->Add(CyweeVersionTitle);\r
+/* -------------------------------------------------------------------------- */\r
+        char cywee_version[20] = {0};\r
+        uapi_cywee_get_version(cywee_version, sizeof(cywee_version));\r
+        Config = {\r
+            .left = LABEL_X,\r
+            .top = WATCH_CYWEEVER_TOP_VALUE_TOP,\r
+            .width = LABEL_W,\r
+            .height = LABEL_H,\r
+            .fontSize = LABEL_FONTSIZE,\r
+            .lineHeigh = LABEL_LINEHEIGHT,\r
+            .text = cywee_version,\r
+            .lineBreakMode = UILabel::LINE_BREAK_WRAP,\r
+        };\r
+        CyweeVersion = InitLabel(Config);\r
+        if (CyweeVersion == nullptr)\r
+        {\r
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemAboutTheWatchView::CyweeVersion new fail!");\r
+            return nullptr;\r
+        }\r
+        CyweeVersion->SetTextColor(Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0x87));\r
+        SystemAboutTheWatchScrollView->Add(CyweeVersion);\r
 \r
-\r
-\r
-        \r
         /* -------------------------------------------------------------------------- */\r
         initViewStatus = true;\r
         return SystemAboutTheWatchScrollView;\r
index f5381c2..e259cdb 100644 (file)
@@ -1271,7 +1271,7 @@ void MsgCenterNotifyInactivityProc(const Topic topic, Request *req)
             // {
             //     sleep_data.wake_up_timestamp = day_timestamp + cywee_Inactivity_Info->hour * 60 * 60 + cywee_Inactivity_Info->minute * 60;
             // }
-            if(state_num < 20)
+            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;
                 sleep_data.sleep_status[state_num].stat = cywee_Inactivity_Info->status;
index 364b373..17200cb 100644 (file)
@@ -1008,7 +1008,8 @@ int cywee_main_dml(void)
     cywee_installized = 1;
 
 #ifdef CYWEE_MAC_ACTIVE
-    uapi_cywee_get_mac_key(SEC_FILE_ADDR,78);
+    uint16_t len = 78;
+    uapi_cywee_get_mac_key(SEC_FILE_ADDR,&len);
 #endif
     int i;
     memset(&scl, 0, sizeof(scl));
index 499a8c9..65161e9 100644 (file)
@@ -390,7 +390,8 @@ void startup_post_init_task(void)
     }
     uapi_gei_btmac_and_chipinfo();
 
-    uapi_get_file_data("user/userdata/timestamp_of_day.bin",&day,1);
+    uint8_t len = 1;
+    uapi_get_file_data("user/userdata/timestamp_of_day.bin",&day,&len);
     time(&rawtime);
     timeinfo = localtime(&rawtime);
     if(day > 0 && day != timeinfo->tm_mday)
@@ -2549,20 +2550,38 @@ uint8_t uapi_get_cywee_active_state(void)
     return cywee_get_active_state();
 }
 
-void uapi_get_file_data(char *path,uint8_t *data,uint16_t len)
+void uapi_get_file_data(char *path,uint8_t *data,uint16_t *len)
 {
-    FILE * fp = fopen(path,"rb");
-    if(fp==NULL)
+    FILE *file;
+    uint16_t fileSize;
+
+    file = fopen(path, "rb"); 
+    if (file == NULL) 
     {
         PRINT("read open %s failed\n",path);
         return;
     }
-    int ret = fread(data,1,len,fp);
-    if(ret != len)
+
+    if(*len == 0)
     {
-        PRINT("fread failed %d\n",ret);
+        // 获取文件大小
+        fseek(file, 0, SEEK_END);
+        fileSize = ftell(file);
+        fseek(file, 0, SEEK_SET);
+        *len = fileSize;
     }
-    fclose(fp);
+    else
+        fileSize = *len;
+
+    size_t bytesRead = fread(data, 1, fileSize, file);
+    if (bytesRead != fileSize) 
+    {
+        PRINT("fread failed \n");
+        fclose(file);
+        return ;
+    }
+    fclose(file);
+    return;
 }
 
 void uapi_save_file_data(char *path,uint8_t *data,uint16_t len,char *mode)
@@ -2717,7 +2736,7 @@ uint8_t DEFAULT_MAC_KEY[78] = {
     0x92, 0x6a, 0x8c, 0xe9, 0x45, 0x70, 0x00, 0x62, 0xc9, 0x21, 0xef, 0x8b, 0x26, 0xdf, 
 };
 #endif
-void uapi_cywee_get_mac_key(uint8_t *key_data,uint16_t len)
+void uapi_cywee_get_mac_key(uint8_t *key_data,uint16_t *len)
 {
 #ifdef CYWEE_MAC_ACTIVE
     if(access(CYWEE_MAC_KEY_PATH, F_OK) == -1)
@@ -2828,6 +2847,130 @@ void uapi_get_a5133_rxdata_timestamp(uint32_t *timestamp)
 #endif
 }
 
+void uapi_analysis_sleep_data(char * path)
+{
+    uint16_t datelen = 0;
+    uint8_t sleep_data[256] = {0}; 
+    
+    uint32_t asleep_time = 0;
+    uint32_t wake_up_time = 0;
+    uint16_t total_time = 0;
+    uint16_t total_deep_sleep_time = 0;
+    uint16_t total_mild_sleep_time = 0;
+    uint16_t total_rem_sleep_time = 0;
+    uint16_t total_wake_time = 0;
+    uint32_t timestampe = 0;
+    int status = -1;
+    uint8_t index = 0;
+    char timestampe_str[10] = {0};
+    char status_str[10] = {0};
+
+    uapi_get_file_data(path,sleep_data,&datelen);
+
+    if(datelen == 0)
+        return;
+
+    asleep_time = *(uint32_t*)&sleep_data[1];
+       wake_up_time = *(uint32_t*)&sleep_data[5];
+
+    total_time = sleep_data[9] * 60 + sleep_data[10];
+    total_deep_sleep_time = sleep_data[11]  * 60 + sleep_data[12];
+    total_mild_sleep_time = sleep_data[13]  * 60 + sleep_data[14];
+    total_rem_sleep_time = sleep_data[15] * 60 + sleep_data[16];
+    total_wake_time = sleep_data[17] * 60 + sleep_data[18];
+
+    char asleep_time_str[10] = {0};
+    uapi_get_TIME_STR(asleep_time,asleep_time_str,".",":",DATE_H_M);
+
+    char wake_up_time_str[10] = {0};
+    uapi_get_TIME_STR(wake_up_time,wake_up_time_str,".",":",DATE_H_M);
+
+    PRINT("path : %s \n",path);
+    PRINT("入睡时间 : %s \n",asleep_time_str);
+    PRINT("出睡时间 : %s \n",wake_up_time_str);
+    PRINT("总时长 : %d 分钟\n",total_time);
+    PRINT("深睡时长 : %d 分钟\n",total_deep_sleep_time);
+    PRINT("浅睡时长 : %d 分钟\n",total_mild_sleep_time);
+    PRINT("快速眼动时长 : %d 分钟\n",total_rem_sleep_time);
+    PRINT("清醒时长 : %d 分钟\n",total_wake_time);
+    datelen -= 19;
+    index = 19;
+    while(datelen)
+    {
+        memset(timestampe_str,0,sizeof(timestampe_str));
+        memset(status_str,0,sizeof(status_str));
+        timestampe = *(uint32_t*)&sleep_data[index];
+        uapi_get_TIME_STR(timestampe,timestampe_str,".",":",DATE_H_M);
+        status = sleep_data[index + 4];
+        //0进入睡眠  1潜睡 2深睡 3清醒 4结束睡眠 6入睡 7出睡最后一笔输出 8未出睡最后一笔输出 12快速动眼 13取消入睡
+        switch(status)
+        {
+            case 0:
+                strcpy(status_str,"进入睡眠");
+                break;
+            case 1:
+                strcpy(status_str,"浅睡");
+                break;
+            case 2:
+                strcpy(status_str,"深睡");
+                break;
+            case 3:
+                strcpy(status_str,"清醒");
+                break;
+            case 4:
+                strcpy(status_str,"结束睡眠");
+                break;
+            case 6:
+                strcpy(status_str,"入睡(平躺60分钟触发)");
+                break;
+            case 7:
+                strcpy(status_str,"出睡最后一笔输出");
+                break;
+            case 12:
+                strcpy(status_str,"快速动眼");
+                break;
+            case 13:
+                strcpy(status_str,"取消入睡");
+                break;
+            default:
+                break;
+
+        }
+
+        PRINT("时间 :  %d %s  状态:%s\n",timestampe,timestampe_str,status_str);
+        index+=5;
+        datelen -= 5;
+    }
+}
+
+
+void uapi_get_sleep_date_on_log(char *time)
+{
+    char *str = "user/userdata/sleep/%s";
+    DIR *dir;
+    struct dirent *entry;
+    char filePath[64];
+    char directoryPath[64] = {0};
+
+    sprintf(directoryPath,str,time);
+
+    dir = opendir(directoryPath);
+    if (dir == NULL) 
+    {
+        PRINT("open directory failed %s\n",directoryPath);
+        return;
+    }
+
+    while ((entry = readdir(dir)) != NULL) 
+    {
+        if (strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0) 
+        {       
+            snprintf(filePath, sizeof(filePath), "%s/%s", directoryPath, entry->d_name);
+            uapi_analysis_sleep_data(filePath);
+        }
+    }
+    closedir(dir);
+}
 
 extern void save_file_main(void);
 
index c119ce4..8672f87 100644 (file)
@@ -242,7 +242,8 @@ void uapi_cywee_time_sync(void);
 void uapi_cywee_get_chipinfo(char *databuf,uint8_t len);
 void uapi_cywee_get_version(char *databuf,uint8_t len);
 void uapi_cywee_save_mac_key(const uint8_t *key_data,uint16_t len);
-void uapi_cywee_get_mac_key(uint8_t *key_data,uint16_t len);
+void uapi_cywee_get_mac_key(uint8_t *key_data,uint16_t *len);
+void uapi_get_sleep_date_on_log(char *time);
 void uapi_ppg_get_id(uint8_t *chip_id);
 
 
@@ -259,7 +260,7 @@ void uapi_efuse_test_write(uint8_t *data,uint32_t byte_number,uint8_t len);
 void uapi_efuse_test_read(uint32_t byte_number,uint8_t len);
 void uapi_gei_btmac_and_chipinfo(void);
 uint8_t uapi_get_cywee_active_state(void);
-void uapi_get_file_data(char *path,uint8_t *data,uint16_t len);
+void uapi_get_file_data(char *path,uint8_t *data,uint16_t *len);
 void uapi_save_file_data(char *path,uint8_t *data,uint16_t len,char *mode);
 uint8_t uapi_get_cywee_static_state(void);
 void uapi_get_a5133_rxdata(uint8_t *databuf,uint8_t len);
index ad6cf20..8125bdf 100644 (file)
@@ -526,17 +526,6 @@ static uint32_t custom_cywee_time_sync(uint8_t *para, uint32_t paraLen, char *st
     return ERRCODE_SUCC;
 }
 
-static uint32_t custom_cywee_get_sleep_data(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
-{
-
-    UNUSED(strCommonCmd);
-
-    uapi_cywee_get_sleep_data();
-
-    return ERRCODE_SUCC;
-}
-
-
 static uint32_t custom_utils_lzmadec(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
 {
     UNUSED(strCommonCmd);
@@ -906,7 +895,8 @@ static uint32_t custom_get_aging_data(uint8_t *para, uint32_t paraLen, char *str
     UNUSED(strCommonCmd);
 
     uint8_t aging_data[4] = {0};
-    uapi_get_file_data("user/userdata/aging_test.bin",aging_data,4);
+    uint8_t datalen = 4;
+    uapi_get_file_data("user/userdata/aging_test.bin",aging_data,&datalen);
     return ERRCODE_SUCC;
 }
 static uint32_t custom_cat1_start_ota_pyupdate(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
@@ -1161,6 +1151,33 @@ static uint32_t custom_cywee_save_mac_key(uint8_t *para, uint32_t paraLen, char
     return ERRCODE_SUCC;
 }
 
+static uint32_t custom_get_sleep(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
+{
+
+    UNUSED(strCommonCmd);
+    uint8_t argv[CUSTOM_UTILS_MAX_ARGC][CUSTOM_UTILS_MAX_ARGV_LEN] = { 0 };
+    uint32_t argc = 0;
+    uint8_t send_data[8] = {0};
+
+
+    int ret = ConvertCmdToParam(para, paraLen, argv, &argc);
+    if (ret != CUSTOM_UTILS_SUCCESS) {
+        wstp_print("CUSTOM_UTILSTEST ATCMD Convert Command Failed\n");
+        return ERRCODE_FAIL;
+    }
+
+    if (argc != 1) {
+        wstp_print("CUSTOM_UTILSTEST power_test ATCMD Set Parameter Failed argc %d\r\nPM_DSP_POWER_UP_AND_RUN=2  PM_DSP_POWER_OFF=3\r\n",argc);
+        return ERRCODE_FAIL;
+    }
+
+    char *time = (char*)argv[0];
+    uapi_get_sleep_date_on_log(time);
+
+    return ERRCODE_SUCC;
+}
+
+
 static const at_cmd_table_t g_custom_utils_cmd[] = {
     { (char *)"AT^CUSTOM_SN",      custom_utils_setsn, (char *)"123456789ABCDEF2345678" },
     { (char *)"AT^CUSTOM_SN_REQ",  custom_utils_getsn, (char *)" " },
@@ -1200,7 +1217,7 @@ static const at_cmd_table_t g_custom_utils_cmd[] = {
 
     { (char *)"AT^CYWEETIMESYNC",      custom_cywee_time_sync, (char *)" " },
 
-    { (char *)"AT^CYWEEGETSLEEPDATA",      custom_cywee_get_sleep_data, (char *)" " },
+    { (char *)"AT^GETSLEEP",      custom_get_sleep, (char *)" " },
     { (char *)"AT^LZMADEC",      custom_utils_lzmadec, (char *)" " },
     { (char *)"AT^PDUDEC",      custom_utils_pdudec, (char *)" " },
     { (char *)"AT^SNTP",      custom_test_sntp, (char *)" " },