From 0331338a94e201d7f4190e3a83f9de3f68f18b42 Mon Sep 17 00:00:00 2001 From: hcj <1224667075@qq.com> Date: Tue, 8 Oct 2024 18:44:40 +0800 Subject: [PATCH] =?utf8?q?=E5=B0=8F=E7=9D=A1=E6=95=B0=E6=8D=AE=E4=BF=AE?= =?utf8?q?=E6=94=B9=E5=BE=85=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../makephone/src/CallerDisplayView.cpp | 2 +- .../nativeui/makephone/src/CallingView.cpp | 2 +- .../makephone/src/WaitingHintsView.cpp | 2 +- .../nativeui/phone/src/PhoneDirView.cpp | 2 +- .../nativeui/sleep/include/SleepModel.h | 2 +- .../nativeui/sleep/src/SleepModel.cpp | 22 ++- .../service/ble_service/blemoder/bletest.cpp | 180 +++++++----------- 7 files changed, 98 insertions(+), 114 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/makephone/src/CallerDisplayView.cpp b/code/sdk/application/wearable/fd230app/nativeui/makephone/src/CallerDisplayView.cpp index aba6b9fd0..cc778f5ca 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/makephone/src/CallerDisplayView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/makephone/src/CallerDisplayView.cpp @@ -125,7 +125,7 @@ bool CallerDisplayView::InitImageViewDisplay() uint8_t sex; if(get_phone_addrss_name(name_buf,CallerLogModel::GetInstance()->GetPhoneNumber().c_str(),&sex)) { - if(sex) + if(sex==1) imageperson->SetSrc(PHONE_DIR_BOY_1); else imageperson->SetSrc(PHONE_DIR_GIRL_1); diff --git a/code/sdk/application/wearable/fd230app/nativeui/makephone/src/CallingView.cpp b/code/sdk/application/wearable/fd230app/nativeui/makephone/src/CallingView.cpp index e354eabc3..85a963336 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/makephone/src/CallingView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/makephone/src/CallingView.cpp @@ -216,7 +216,7 @@ bool CallingView::InitImageViewDisplay() uint8_t sex; if(get_phone_addrss_name(name_buf,CallerLogModel::GetInstance()->GetPhoneNumber().c_str(),&sex)) { - if(sex) + if(sex==1) imageperson->SetSrc(PHONE_DIR_BOY_1); else imageperson->SetSrc(PHONE_DIR_GIRL_1); diff --git a/code/sdk/application/wearable/fd230app/nativeui/makephone/src/WaitingHintsView.cpp b/code/sdk/application/wearable/fd230app/nativeui/makephone/src/WaitingHintsView.cpp index d6f8faaa3..7298a8253 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/makephone/src/WaitingHintsView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/makephone/src/WaitingHintsView.cpp @@ -167,7 +167,7 @@ bool WaitingHintsView::InitImageViewDisplay() uint8_t sex; if(get_phone_addrss_name(name_buf,CallerLogModel::GetInstance()->GetPhoneNumber().c_str(),&sex)) { - if(sex) + if(sex==1) imageperson->SetSrc(PHONE_DIR_BOY_1); else imageperson->SetSrc(PHONE_DIR_GIRL_1); diff --git a/code/sdk/application/wearable/fd230app/nativeui/phone/src/PhoneDirView.cpp b/code/sdk/application/wearable/fd230app/nativeui/phone/src/PhoneDirView.cpp index 0e82dd01d..7576df7df 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/phone/src/PhoneDirView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/phone/src/PhoneDirView.cpp @@ -98,7 +98,7 @@ namespace OHOS //buf[0]=i+48; buttonconfig.ViewId =number_str[i]; - buttonconfig.ImageSrc = addressbook_t.Contact_t[i].sex ? PHONE_DIR_BOY:PHONE_DIR_GIRL; + buttonconfig.ImageSrc = addressbook_t.Contact_t[i].sex==1 ? PHONE_DIR_BOY:PHONE_DIR_GIRL; buttonconfig.label_x=107; buttonconfig.label_y=0; buttonconfig.Fontsize=30; 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 82e65a662..603622543 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepModel.h @@ -26,7 +26,7 @@ // #include "sleep/include/SleepControlPresenter.h" #include "string" -// #define NAPTEST +#define NAPTEST #define SLEEP_TIME_PATH "user/userdata/sleep/%s/sleep_time.bin" diff --git a/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepModel.cpp index 0df910bc5..9db12f853 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepModel.cpp @@ -148,22 +148,38 @@ namespace OHOS sprintf_s(nap_file_path, 64, NAP_PATH, day, creationTime); FILE *fp; + + fp = fopen(nap_file_path, "rb+"); //小睡数据全部存入一个文件 + uint32_t size=0; + if (fp) + { + fseek(fp, 0, SEEK_END); // 将文件指针移动到文件末尾 + uint32_t size= ftell(fp); // 获取当前文件指针位置,即文件大小 + fseek(fp, 0, SEEK_SET); // 将文件指针移回文件开头 + fclose(fp); + } + #ifdef NAPTEST fp = fopen(nap_file_path, "ab+"); //小睡数据全部存入一个文件 #else fp = fopen(nap_file_path, "wb+"); #endif - if (fp == NULL) + if(fp==NULL) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "save_nap_sleep_data %s fopen fail ", nap_file_path); return false; } + + uint8_t id=size/14; + uint8_t nap_size=14; + fwrite(&nap_size, 1, 2, fp); + + fwrite(&id, 1, 1, fp); -#ifndef NAPTEST uint8_t sleep_type = 0; //不存睡眠类型 改用文件名判断 fwrite(&sleep_type, 1, 1, fp); -#endif + uint32_t fall_asleep_timestamp = data->fall_asleep_timestamp; fwrite(&fall_asleep_timestamp, 1, 4, fp); diff --git a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp index b4337a2b4..885dda3c4 100644 --- a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp +++ b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp @@ -625,122 +625,81 @@ uint8_t ble_get_sleep_data(uint32_t file_size,uint8_t day_,uint8_t *data) uapi_get_YYMMDD_Time_extend(day,'\0', day_); sprintf_s(dir_path,64,SLEEP_DIR_PATH,day); - struct DIR *dir; - struct dirent *ent; - - uint32_t offset=0; uint8_t sleep_count=1; - if ((dir = opendir(dir_path)) != NULL) { - while ((ent = readdir(dir)) != NULL) + char file_path[128]={0}; + sprintf_s(file_path,128,"%s/%s",dir_path,"nap.bin"); + + FILE * fp = fopen(file_path,"rb+"); + if(fp==NULL) { - std::string fileName = ent->d_name; - if (fileName != "." && fileName != "..") - { - - if (ent->d_type == DT_REG || ent->d_type == DT_UNKNOWN ) // 普通文件 - { - if(fileName=="sleep_time.bin") - { - char file_path[128]={0}; - sprintf_s(file_path,128,"%s/%s",dir_path,ent->d_name); - - FILE * fp = fopen(file_path,"rb+"); - if(fp==NULL) - { - printf(" fopen fail %s\r\n",file_path); - return 1 ; - } - uint16_t sleep_file_size=0; - if (fp != NULL) - { - fseek(fp, 0, SEEK_END); // 将文件指针移动到文件末尾 - sleep_file_size = ftell(fp); // 获取当前文件指针位置,即文件大小 - sleep_file_size++; - fseek(fp, 0, SEEK_SET); // 将文件指针移回文件开头 - memcpy(data+offset,&sleep_file_size,2); - *(data+offset+2)=sleep_count; - sleep_count++; - - uint16_t read_size =fread(data+offset+3,1,sleep_file_size,fp); - - if((read_size+1)==sleep_file_size) - { - - } - - else - { - printf(" fread fail read_size:%d!= sleep_file_size:%d \r\n",read_size,sleep_file_size); - } - - fclose(fp); - char file_path[128]={0}; - sprintf_s(file_path,128,"%s/%s",dir_path,"sleep_status.bin"); - fp = fopen(file_path,"rb+"); - sleep_file_size=0; - if(fp) - { - fseek(fp, 0, SEEK_END); - sleep_file_size = ftell(fp); - fseek(fp, 0, SEEK_SET); - uint16_t read_size_status =fread(data+offset+3+read_size,1,sleep_file_size,fp); - read_size+=read_size_status; - memcpy(data+offset,&read_size,2); - fclose(fp); - - } - offset+=read_size; - offset+=3; + printf(" fopen fail %s\r\n",file_path); + } + else + { + uint16_t sleep_file_size=0; + fseek(fp, 0, SEEK_END); // 将文件指针移动到文件末尾 + sleep_file_size = ftell(fp); // 获取当前文件指针位置,即文件大小 + fseek(fp, 0, SEEK_SET); // 将文件指针移回文件开头 - } - } - else if(fileName!="sleep_status.bin") - { - printf("offset %d\r\n",offset); - char file_path[128]={0}; - sprintf_s(file_path,128,"%s/%s",dir_path,ent->d_name); - - FILE * fp = fopen(file_path,"rb+"); - if(fp==NULL) - { - printf(" fopen fail %s\r\n",file_path); - return 1 ; - } + int mod_value=0; + mod_value=sleep_file_size%14; + if(mod_value!=0) + return 0; + uint8_t nap_count=sleep_file_size/14; - uint16_t sleep_file_size=0; - if (fp != NULL) - { - fseek(fp, 0, SEEK_END); // 将文件指针移动到文件末尾 - sleep_file_size = ftell(fp); // 获取当前文件指针位置,即文件大小 - sleep_file_size++; - fseek(fp, 0, SEEK_SET); // 将文件指针移回文件开头 - memcpy(data+offset,&sleep_file_size,2); - *(data+offset+2)=sleep_count; - sleep_count++; - offset+=3; - uint16_t read_size =fread(data+offset,1,sleep_file_size,fp); + sleep_count=nap_count+1; + + uint16_t read_size =fread(data,1,sleep_file_size,fp); + offset+=read_size; + fclose(fp); + } + } + { + char file_path[128]={0}; + sprintf_s(file_path,128,"%s/%s",dir_path,"sleep_time.bin"); + FILE * fp = fopen(file_path,"rb+"); + if(fp) + { + uint16_t sleep_file_size=0; + + fseek(fp, 0, SEEK_END); // 将文件指针移动到文件末尾 + sleep_file_size = ftell(fp); // 获取当前文件指针位置,即文件大小 + sleep_file_size++; + fseek(fp, 0, SEEK_SET); // 将文件指针移回文件开头 - if((read_size+1)==sleep_file_size) - offset+=read_size; - else - printf(" fread fail read_size:%d!= sleep_file_size:%d \r\n",read_size,sleep_file_size); + memcpy(data+offset,&sleep_file_size,2); + *(data+offset+2)=sleep_count; + sleep_count++; + uint16_t read_size =fread(data+offset+3,1,sleep_file_size,fp); - fclose(fp); - } - } - - } + if((read_size+1)!=sleep_file_size) + { + printf(" fread fail read_size:%d!= sleep_file_size:%d \r\n",read_size,sleep_file_size); } - else if (ent->d_type == DT_DIR) // 目录 + + fclose(fp); + char file_path[128]={0}; + sprintf_s(file_path,128,"%s/%s",dir_path,"sleep_status.bin"); + fp = fopen(file_path,"rb+"); + sleep_file_size=0; + if(fp) { - continue; + fseek(fp, 0, SEEK_END); + sleep_file_size = ftell(fp); + fseek(fp, 0, SEEK_SET); + uint16_t read_size_status =fread(data+offset+3+read_size,1,sleep_file_size,fp); + read_size+=read_size_status; + memcpy(data+offset,&read_size,2); + fclose(fp); + } + offset+=read_size; + offset+=3; } } - closedir(dir); return offset; } @@ -811,7 +770,7 @@ uint8_t ble_get_sleep_data_dir(uint32_t *file_size,uint8_t day_) fclose(fp); } } - else + else if(fileName=="nap.bin") { char file_path[128]={0}; sprintf_s(file_path,128,"%s/%s",dir_path,ent->d_name); @@ -822,15 +781,24 @@ uint8_t ble_get_sleep_data_dir(uint32_t *file_size,uint8_t day_) printf(" fopen fail %s\r\n",file_path); return file_count; } - + uint32_t size=0; if (fp != NULL) { fseek(fp, 0, SEEK_END); // 将文件指针移动到文件末尾 - *file_size += ftell(fp)+3; // 获取当前文件指针位置,即文件大小 + size= ftell(fp); // 获取当前文件指针位置,即文件大小 fseek(fp, 0, SEEK_SET); // 将文件指针移回文件开头 fclose(fp); } - file_count++; + int mod_value=0; + + mod_value=size%14; + if(mod_value!=0) + return 0; + + uint8_t nap_count=size/14; + *file_size+=nap_count*14; + + file_count+=nap_count; } } -- 2.17.1