传输实时数据bug修复
authorhcj <1224667075@qq.com>
Wed, 10 Jul 2024 10:59:41 +0000 (18:59 +0800)
committerhcj <1224667075@qq.com>
Wed, 10 Jul 2024 10:59:41 +0000 (18:59 +0800)
code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp

index 876e958..900283a 100644 (file)
@@ -666,28 +666,41 @@ char * ble_sywee_history(uint8_t day,uint16_t *len ,uint8_t type)
         day_now_data_size=0;
     }
     FILE * fp = fopen(path_,"rb+");
+    uint32_t size=0;
     if(fp==NULL)
     {
-         printf(" fopen type  %d %s fail\r\n",type,path_);
+        printf(" fopen type  %d %s fail\r\n",type,path_);
+        if(day==0)
+        {
+            goto DAY_IS_0;
+        }
+        //printf(" fopen type  %d %s fail\r\n",type,path_);
         return NULL;
     }
-    uint32_t size;
+   
     if (fp != NULL)
     {
         fseek(fp, 0, SEEK_END); // 将文件指针移动到文件末尾
         size = ftell(fp);       // 获取当前文件指针位置,即文件大小
         fseek(fp, 0, SEEK_SET); // 将文件指针移回文件开头
     }
-    printf("size %d \r\n",size);
+   
+
+    DAY_IS_0:
 
+    printf("size %d \r\n",size);
     char * buf=(char *)malloc(size+day_now_data_size);
     if(buf==NULL)
     {
         printf("malloc fail\r\n");
         return buf;
     }
-    uint32_t ret= fread(buf,1,size,fp);
-
+    if(fp)
+    {
+        uint32_t ret= fread(buf,1,size,fp);
+        fclose(fp);
+    }
+    
     if(day==0)
     {
         time_t currtime;
@@ -699,7 +712,7 @@ char * ble_sywee_history(uint8_t day,uint16_t *len ,uint8_t type)
         struct tm *timeinfo;
         time(&currtime);
         timeinfo = localtime(&currtime);
-        //printf("localtime %d",timeinfo->tm_min);
+        printf("localtime %d",timeinfo->tm_min);
         creationTime-=(timeinfo->tm_min*60);
 
         switch (type)
@@ -731,6 +744,7 @@ char * ble_sywee_history(uint8_t day,uint16_t *len ,uint8_t type)
                     memcpy(buf+size,&creationTime,4);
                     size+=4;
                 }
+               
                 break;
             case 0x46://同步卡路里历史数据
                 value=get_now_hour_data(CYWEE_SAVE_DATA_CALORIES);
@@ -752,20 +766,24 @@ char * ble_sywee_history(uint8_t day,uint16_t *len ,uint8_t type)
                     size+=4;
                 }
                 break;
-                break;
             default:
                 break;
         }
 
     }
 
-    printf("fread %d \r\n",ret);
-    for(int i=0;i<ret;i++)
+    // printf("fread %d \r\n",ret);
+    for(int i=0;i<size;i++)
     {
         printf(" %02X",(uint8_t)buf[i]);
     }
     *len=size;
-    fclose(fp);
+    if(buf && size==0)
+    {
+        free(buf);
+        buf=NULL;
+    }
+   
     return buf;
 }