From 88488fab4b6ef486705042a6296bdbce668dc936 Mon Sep 17 00:00:00 2001 From: penglei <1624952103@qq.com> Date: Tue, 3 Sep 2024 16:20:46 +0800 Subject: [PATCH] =?utf8?q?=E4=BF=AE=E6=94=B9=E7=9D=A1=E7=9C=A0=E7=8A=B6?= =?utf8?q?=E6=80=81=E5=AD=98=E5=82=A8=E6=95=B0=E7=BB=84=E9=95=BF=E5=BA=A6?= =?utf8?q?=E4=B8=BA50=EF=BC=8C=E6=B7=BB=E5=8A=A0AT=E6=8C=87=E4=BB=A4?= =?utf8?q?=E6=89=93=E5=8D=B0=E7=9D=A1=E7=9C=A0=E5=AD=98=E5=82=A8=E4=BF=A1?= =?utf8?q?=E6=81=AF=20about=20watch=20=E6=B7=BB=E5=8A=A0cywee=E7=AE=97?= =?utf8?q?=E6=B3=95=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativeui/sleep/include/SleepModel.h | 6 +- .../system/include/SystemAboutTheWatchView.h | 7 +- .../system/src/SystemAboutTheWatchView.cpp | 49 +++++- .../msg_center/src/msg_center_customer.cpp | 2 +- .../drivers/peripheral/cywee/src/main_dml.c | 3 +- .../drivers/peripheral/utils/custom_utils.c | 161 +++++++++++++++++- .../drivers/peripheral/utils/custom_utils.h | 5 +- .../peripheral/utils/custom_utils_at_cmd.c | 43 +++-- 8 files changed, 242 insertions(+), 34 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepModel.h b/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepModel.h index 88c848f37..15ff479d2 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepModel.h @@ -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; // 出睡 diff --git a/code/sdk/application/wearable/fd230app/nativeui/system/include/SystemAboutTheWatchView.h b/code/sdk/application/wearable/fd230app/nativeui/system/include/SystemAboutTheWatchView.h index fc542a334..8916e25ed 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/system/include/SystemAboutTheWatchView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/system/include/SystemAboutTheWatchView.h @@ -1,8 +1,8 @@ /* * @Author: luozheng 1732036298@qq.com * @Date: 2024-03-30 09:14:38 - * @LastEditors: SnickerSun snickersun@163.com - * @LastEditTime: 2024-07-25 11:37:34 + * @LastEditors: penglei 1624952103@qq.com + * @LastEditTime: 2024-08-31 18:57:13 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/system/include/SystemAboutTheWatchView.h */ #ifndef SYSTEM_ABOUT_VIEW_H @@ -64,7 +64,8 @@ namespace OHOS UILabel *FONT = nullptr; UILabel *HWVERTitle = nullptr; UILabel *HWVER = nullptr; - + UILabel *CyweeVersionTitle = nullptr; + UILabel *CyweeVersion = nullptr; bool initViewStatus{false}; }; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemAboutTheWatchView.cpp b/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemAboutTheWatchView.cpp index 96a72f33b..e6fd4359f 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemAboutTheWatchView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemAboutTheWatchView.cpp @@ -24,6 +24,8 @@ #define WATCH_IMEI_VALUE_TOP (WATCH_IMEI_TOP + WATCH_ABOUT_TITLE_HEIGHT) #define WATCH_FONT_TOP (WATCH_IMEI_VALUE_TOP + WATCH_ABOUT_VALUE_HEIGHT) #define WATCH_FONT_VALUE_TOP (WATCH_FONT_TOP + WATCH_ABOUT_TITLE_HEIGHT) +#define WATCH_CYWEEVER_TOP (WATCH_FONT_VALUE_TOP + WATCH_ABOUT_VALUE_HEIGHT) +#define WATCH_CYWEEVER_TOP_VALUE_TOP (WATCH_CYWEEVER_TOP + WATCH_ABOUT_TITLE_HEIGHT) namespace OHOS { @@ -120,6 +122,11 @@ namespace OHOS delete HWVER; HWVER = nullptr; + delete CyweeVersionTitle; + CyweeVersionTitle = nullptr; + delete CyweeVersion; + CyweeVersion = nullptr; + delete SystemAboutTheWatchScrollView; SystemAboutTheWatchScrollView = nullptr; } @@ -576,10 +583,46 @@ namespace OHOS } HWVER->SetTextColor(Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0x87)); SystemAboutTheWatchScrollView->Add(HWVER); + /* -------------------------------------------------------------------------- */ + Config = { + .left = TITLE_LABEL_X, + .top = WATCH_CYWEEVER_TOP, + .width = TITLE_LABEL_W, + .height = TITLE_LABEL_H, + .fontSize = TITLE_LABEL_FONTSIZE, + .lineHeigh = TITLE_LABEL_LINEHEIGHT, + .text = "Cywee Version", + .lineBreakMode = UILabel::LINE_BREAK_MARQUEE, + }; + CyweeVersionTitle = InitLabel(Config); + if (CyweeVersionTitle == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemAboutTheWatchView::CyweeVersionTitle new fail!"); + return nullptr; + } + SystemAboutTheWatchScrollView->Add(CyweeVersionTitle); +/* -------------------------------------------------------------------------- */ + char cywee_version[20] = {0}; + uapi_cywee_get_version(cywee_version, sizeof(cywee_version)); + Config = { + .left = LABEL_X, + .top = WATCH_CYWEEVER_TOP_VALUE_TOP, + .width = LABEL_W, + .height = LABEL_H, + .fontSize = LABEL_FONTSIZE, + .lineHeigh = LABEL_LINEHEIGHT, + .text = cywee_version, + .lineBreakMode = UILabel::LINE_BREAK_WRAP, + }; + CyweeVersion = InitLabel(Config); + if (CyweeVersion == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemAboutTheWatchView::CyweeVersion new fail!"); + return nullptr; + } + CyweeVersion->SetTextColor(Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0x87)); + SystemAboutTheWatchScrollView->Add(CyweeVersion); - - - /* -------------------------------------------------------------------------- */ initViewStatus = true; return SystemAboutTheWatchScrollView; diff --git a/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp b/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp index f5381c272..e259cdbe6 100644 --- a/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp @@ -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; diff --git a/code/sdk/drivers/peripheral/cywee/src/main_dml.c b/code/sdk/drivers/peripheral/cywee/src/main_dml.c index 364b37393..17200cb85 100644 --- a/code/sdk/drivers/peripheral/cywee/src/main_dml.c +++ b/code/sdk/drivers/peripheral/cywee/src/main_dml.c @@ -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)); diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.c b/code/sdk/drivers/peripheral/utils/custom_utils.c index 499a8c93f..65161e975 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.c +++ b/code/sdk/drivers/peripheral/utils/custom_utils.c @@ -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); diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.h b/code/sdk/drivers/peripheral/utils/custom_utils.h index c119ce4f4..8672f8729 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.h +++ b/code/sdk/drivers/peripheral/utils/custom_utils.h @@ -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); diff --git a/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c b/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c index ad6cf2030..8125bdf88 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c +++ b/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c @@ -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 *)" " }, -- 2.17.1