修复数据同步出现0 bug
authorhcj <1224667075@qq.com>
Tue, 6 Aug 2024 10:57:11 +0000 (18:57 +0800)
committerhcj <1224667075@qq.com>
Tue, 6 Aug 2024 10:57:11 +0000 (18:57 +0800)
code/sdk/drivers/peripheral/cywee/Inc/cywee_hal.h
code/sdk/drivers/peripheral/cywee/src/board_yh601s.c

index ac2d9c5..ad6b1fb 100644 (file)
@@ -40,7 +40,7 @@ extern void CWM_OS_free(void *ptr);
 extern void CWM_OS_saveData(int* data, uint32_t len,uint8_t type);
 extern  void CWM_OS_OneHourAgo_saveData(void* data, uint32_t len,uint8_t type);
 
-extern void CWM_OS_saveData_history(int* new_data,int *history ,uint32_t len,uint8_t type);
+extern void CWM_OS_saveData_history(void* new_data,void *history ,uint32_t len,uint8_t type);
 extern void CWM_OS_saveData_STAND_history(uint8_t *falg,uint32_t len);
 extern uint8_t get_stand_count(void);
 extern void CWM_OS_restoreData(int* data, uint32_t len,uint8_t type);
index 791174c..ef41962 100644 (file)
@@ -387,7 +387,7 @@ void CWM_OS_OneHourAgo_saveData(void* data, uint32_t len,uint8_t type){
 
 
 
-void CWM_OS_saveData_history(int* new_data,int *history ,uint32_t len,uint8_t type){
+void CWM_OS_saveData_history(void* new_data,void *history ,uint32_t len,uint8_t type){
 
     struct stat info;
 
@@ -402,19 +402,33 @@ void CWM_OS_saveData_history(int* new_data,int *history ,uint32_t len,uint8_t ty
     char timeday[12] = {0};
     uapi_get_YYMMDD_Time(timeday, '_');
 
+    int i_data=0;
+    float f_data=0;
+    uint16_t i_data_16=0;
+
     switch (type)
     {
     case CYWEE_DATA_CALORIES:
-       sprintf_s(path_,64,"%s%s.bin",CWM_HISTORY_DATA_CALORIES_PATH,timeday);
+        sprintf_s(path_,64,"%s%s.bin",CWM_HISTORY_DATA_CALORIES_PATH,timeday);
+
+        f_data=*(float*)new_data-*(float*)history;
+
         break;
     case CYWEE_DATA_STEP:
        sprintf_s(path_,64,"%s%s.bin",CWM_HISTORY_DATA_PATH,timeday);
+
+        i_data= *(int*)new_data-*(int*)history;//新数据减去旧数据,作为这一个小时的值
+
         break;
     case CYWEE_DATA_DISTANCE:
        sprintf_s(path_,64,"%s%s.bin",CWM_HISTORY_DATA_DISTANCE_PATH,timeday);
+       f_data=*(float*)new_data-*(float*)history;
+
         break;
     case CYWEE_DATA_FAT:
        sprintf_s(path_,64,"%s%s.bin",CWM_HISTORY_DATA_FAT_PATH,timeday);
+        i_data_16= *(uint16_t*)new_data-*(uint16_t*)history;//新数据减去旧数据,作为这一个小时的值
+
         break;
 
     default:
@@ -423,18 +437,19 @@ void CWM_OS_saveData_history(int* new_data,int *history ,uint32_t len,uint8_t ty
    
     CWM_OS_dbgPrintf(" save path %s \n",path_);
 
-    int data= *new_data-*history;//新数据减去旧数据,作为这一个小时的值
-    if(data<0)
+   
+    if(i_data<0 || f_data<0 ||i_data_16<0)
     {
-        data=0;
-        *history=0;
+        i_data=0;
+        f_data=0;
+        *(int*)history=0;
       
     }
-    if(data==0)
+    if(i_data==0 && f_data==0 && i_data_16==0)
     {
         return;
     }
-
+ 
     FILE * fp = fopen(path_,"ab+");
     if(fp==NULL)
     {
@@ -458,7 +473,12 @@ void CWM_OS_saveData_history(int* new_data,int *history ,uint32_t len,uint8_t ty
     }
 
     #ifndef ONE_TIME_CONUT_TOTAL
-        ret =fwrite(&data,1,len,fp);
+        if(i_data)
+        ret =fwrite(&i_data,1,len,fp);
+        else if(i_data_16)
+        ret =fwrite(&i_data_16,1,len,fp);
+        else if(f_data)
+        ret =fwrite(&f_data,1,len,fp);
     #else
         ret =fwrite(new_data,1,len,fp);
     #endif
@@ -466,9 +486,12 @@ void CWM_OS_saveData_history(int* new_data,int *history ,uint32_t len,uint8_t ty
     {
         CWM_OS_dbgPrintf("fwrite failed %d\n",ret);
     }
-    CWM_OS_dbgPrintf("fwrite data %d\n",data);
-
-    *history=*new_data;
+     if(i_data)
+    *(int*)history=*(int*)new_data;
+     else if(i_data_16)
+    *(uint16_t*)history=*(uint16_t*)new_data;
+    else if(f_data)
+    *(float*)history=*(float*)new_data;
 
     fclose(fp);
 }