From 2d204d9e7140ffc29ac4715a68035e19982b7b19 Mon Sep 17 00:00:00 2001 From: penglei <1624952103@qq.com> Date: Sun, 20 Oct 2024 18:06:56 +0800 Subject: [PATCH] =?utf8?q?=E4=BC=98=E5=8C=96=E5=B0=8F=E7=9D=A1=E6=95=B0?= =?utf8?q?=E6=8D=AE=E5=AD=98=E5=82=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../drivers/peripheral/cywee/src/main_dml.c | 15 ++++-- .../drivers/peripheral/utils/custom_utils.c | 48 +++++++++++++++++-- 2 files changed, 54 insertions(+), 9 deletions(-) diff --git a/code/sdk/drivers/peripheral/cywee/src/main_dml.c b/code/sdk/drivers/peripheral/cywee/src/main_dml.c index 8c6c634d3..5bee5e31a 100644 --- a/code/sdk/drivers/peripheral/cywee/src/main_dml.c +++ b/code/sdk/drivers/peripheral/cywee/src/main_dml.c @@ -150,10 +150,18 @@ void clean_sleep_data(void) void cywee_save_nap_data(cywee_inactivity_accumulate_time_t c_inactivity_accumulate_time_t) { - char day[12] = {0}; - uapi_get_YYMMDD_Time(day, '\0'); + if (access(nap_file_path, 0) == -1) //如果小睡文件不存在,创建睡眠文件夹 + { + memset(dir_path,0,sizeof(dir_path)); + memset(day,0,sizeof(day)); + memset(nap_file_path,0,sizeof(nap_file_path)); + + uapi_get_YYMMDD_Time(day, '\0'); + sprintf_s(dir_path, 64, SLEEP_DIR_PATH, day); + uapi_create_folder(dir_path); + sprintf_s(nap_file_path, 64, NAP_PATH, day); + } - sprintf_s(nap_file_path, 64, NAP_PATH, day); uint32_t size = uapi_get_file_size(nap_file_path); @@ -756,7 +764,6 @@ void cywee_time_sync(void) uapi_get_YYMMDD_Time_extend(day, '\0', 0); sprintf_s(dir_path, 64, SLEEP_DIR_PATH, day); - uapi_create_folder("user/userdata/sleep"); uapi_create_folder(dir_path); } diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.c b/code/sdk/drivers/peripheral/utils/custom_utils.c index ee4e0ee5f..f7cc52571 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.c +++ b/code/sdk/drivers/peripheral/utils/custom_utils.c @@ -2872,18 +2872,56 @@ void uapi_vibrator_test(uint32_t test_time) } } -void uapi_create_folder(char *dir_path) +//创建指定路径文件夹 +void uapi_create_folder(char *dir_path) { + if(dir_path == NULL) + return; + + char *path_copy = strdup(dir_path); + char *token; + char *saveptr; + + token = strtok_r(path_copy, "/", &saveptr); + if (token == NULL) + { + free(path_copy); + return; + } + + char current_path[256] = ""; + strcat(current_path, token); + strcat(current_path, "/"); + struct stat info; - if (stat(dir_path, &info) != 0) + if (stat(current_path, &info)!= 0) + { + if (mkdir(current_path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)!= 0) + { + PRINT("mkdir %s failed\n", current_path); + free(path_copy); + return; + } + } + + while ((token = strtok_r(NULL, "/", &saveptr))!= NULL) { - if(mkdir(dir_path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) + strcat(current_path, token); + strcat(current_path, "/"); + if (stat(current_path, &info)!= 0) { - PRINT("mkdir %s failed \n",dir_path); + if (mkdir(current_path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)!= 0) + { + PRINT("mkdir %s failed\n", current_path); + free(path_copy); + return; + } } } -} + free(path_copy); + PRINT("mkdir %s succed\n", dir_path); +} //获取小睡数据长度(协议用) uint32_t uapi_get_file_size(char *filepath) -- 2.17.1