小睡数据修改待测试 1123/4
authorhcj <1224667075@qq.com>
Tue, 8 Oct 2024 10:44:40 +0000 (18:44 +0800)
committerhcj <1224667075@qq.com>
Tue, 8 Oct 2024 10:44:40 +0000 (18:44 +0800)
code/sdk/application/wearable/fd230app/nativeui/makephone/src/CallerDisplayView.cpp
code/sdk/application/wearable/fd230app/nativeui/makephone/src/CallingView.cpp
code/sdk/application/wearable/fd230app/nativeui/makephone/src/WaitingHintsView.cpp
code/sdk/application/wearable/fd230app/nativeui/phone/src/PhoneDirView.cpp
code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepModel.h
code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepModel.cpp
code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp

index aba6b9f..cc778f5 100644 (file)
@@ -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);
index e354eab..85a9633 100644 (file)
@@ -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);
index d6f8faa..7298a82 100644 (file)
@@ -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);
index 0e82dd0..7576df7 100644 (file)
@@ -98,7 +98,7 @@ namespace OHOS
             //buf[0]=i+48;\r
             buttonconfig.ViewId =number_str[i];\r
             \r
-            buttonconfig.ImageSrc = addressbook_t.Contact_t[i].sex ? PHONE_DIR_BOY:PHONE_DIR_GIRL;\r
+            buttonconfig.ImageSrc = addressbook_t.Contact_t[i].sex==1 ? PHONE_DIR_BOY:PHONE_DIR_GIRL;\r
             buttonconfig.label_x=107;\r
             buttonconfig.label_y=0;\r
             buttonconfig.Fontsize=30;\r
index 82e65a6..6036225 100644 (file)
@@ -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"
index 0df910b..9db12f8 100644 (file)
@@ -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);
index b4337a2..885dda3 100644 (file)
@@ -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;
                     }
                     
                 }