增加心率血氧bin数据 396/6 396/head
authorCaisking <3449750381@qq.com>
Fri, 28 Jun 2024 07:25:51 +0000 (15:25 +0800)
committerCaisking <3449750381@qq.com>
Fri, 28 Jun 2024 07:25:51 +0000 (15:25 +0800)
code/sdk/application/wearable/fd230app/nativeui/heart_blood/health_service/health_service.cpp

index 2aef7b8..6e8abc5 100644 (file)
@@ -97,6 +97,14 @@ namespace OHOS
 
         return healthTypePath + currentDate + ".json";
     }
+    /*生成bin*/
+    std::string GetBinFilePath(uint8_t type)
+    {
+        std::string currentDate = GetCurrentDate();
+        const char *healthTypePath = (type == HEALTH_TYPE_HEART) ? HEALTH_JSON_PATH_HEART : HEALTH_JSON_PATH_OXYGEN;
+
+        return healthTypePath + currentDate + ".bin";
+    }
     // 加载 JSON 数据
     bool HealthService::LoadJsonData(uint8_t type)
     {
@@ -289,8 +297,17 @@ namespace OHOS
             ReleaseJsonData(HEALTH_TYPE_OXYGEN);
             return false;
         }
+        /*存储bin*/
+        std::string binFilePath = GetBinFilePath(HEALTH_TYPE_HEART);
+        FILE *fp = fopen(binFilePath.c_str(), "ab+");
+        if (fp == NULL)
+            return false;
+        fwrite(&data.timestamp, 1, 4, fp);
+        fwrite(&data.SPO2, 1, 1, fp);
+        fclose(fp);
 
         ReleaseJsonData(HEALTH_TYPE_OXYGEN);
+
         return true;
     }
 
@@ -370,6 +387,14 @@ namespace OHOS
             heart_root = nullptr;
             return false;
         }
+        /*存储bin*/
+        std::string binFilePath = GetBinFilePath(HEALTH_TYPE_HEART);
+        FILE *fp = fopen(binFilePath.c_str(), "ab+");
+        if (fp == NULL)
+            return false;
+        fwrite(&data.timestamp, 1, 4, fp);
+        fwrite(&data.Heart, 1, 1, fp);
+        fclose(fp);
 
         return true;
     }
@@ -415,4 +440,5 @@ namespace OHOS
         cJSON_free(jsonData);
         return true;
     }
+
 }
\ No newline at end of file