static constexpr uint16_t PROGRESS_VALUE_MAX = 10;
static BloodOxygenPresenter *g_pMainView;
/* -------------------------------------------------------------------------- */
- // 获取当前的"时间分"
- uint64_t BloodOxygenPresenter::GetCurrentTime()
+ // 获取当前的时间戳
+ uint32_t BloodOxygenPresenter::GetCurrentTime()
{
-
- // time_t now = time(0);
- // struct tm *tblock = localtime(&now);
-
- /*优化为更安全的localtime_r()*/
- struct timeval tv;
- gettimeofday(&tv, NULL);
- struct tm tblock;
- localtime_r(&tv.tv_sec, &tblock);
-
- uint64_t current_time = tblock.tm_hour * 60 + tblock.tm_min;
- return current_time;
+ uint32_t time;
+ if (uapi_get_timestampe_ss(&time) != ERRCODE_SUCC)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to get timestamp");
+ return 0;
+ }
+ return time;
}
// 获取时间差,现在传进来的是两个时间戳
- int BloodOxygenPresenter::GetTDOA(uint64_t new_time, uint64_t old_time)
+ int BloodOxygenPresenter::GetTDOA(uint32_t new_time, uint32_t old_time)
{
if (new_time == old_time || old_time > new_time)
{
return 0;
}
-
- int time_diff = new_time - old_time;
- return time_diff;
+ int time_diff_seconds = new_time - old_time;
+ // 转换为分钟的差值
+ int time_diff_minutes = time_diff_seconds / 60;
+ return time_diff_minutes;
}
/* -------------------------------------------------------------------------- */
#include <ctime>
namespace OHOS
{
- static HealthService *g_pHealthService = nullptr;
- static constexpr const char *HEALTH_JSON_PATH_HEART = "/user/userdata/health/heart/";
-
- static constexpr const char *HEALTH_JSON_PATH_OXYGEN = "/user/userdata/health/oxygen/";
+ static HealthService *g_pHealthService = nullptr;
+ /*获取日期*/
std::string GetCurrentDate()
{
time_t now = time(0);
strftime(date, sizeof(date), "%Y%m%d", ltm);
return std::string(date);
}
- //static char *JSON_F_buf=NULL;
- const char *GET_HEALTH_JSON_PATH_C_STR_HEART()
- {
- return HEALTH_JSON_PATH_HEART;
- }
-
- const char *GET_HEALTH_JSON_PATH_C_STR_OXYGEN()
- {
- return HEALTH_JSON_PATH_OXYGEN;
- }
-
+ // static char *JSON_F_buf=NULL;
cJSON *heart_root = NULL;
cJSON *oxygen_root = NULL;
HealthService::HealthService()
WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HealthService::HealthService");
g_pHealthService = this;
}
-
HealthService::~HealthService()
{
g_pHealthService = nullptr;
}
-
HealthService *HealthService::GetInstance()
{
static HealthService instance;
return &instance;
}
+
+ static constexpr const char *HEALTH_JSON_PATH = "/user/userdata/health/";
+ static constexpr const char *HEALTH_JSON_PATH_HEART = "/user/userdata/health/heart/";
+ static constexpr const char *HEALTH_JSON_PATH_OXYGEN = "/user/userdata/health/oxygen/";
+
/* --------------------------------- 文件IO操作 --------------------------------- */
/*创建文件夹*/
bool HealthService::CreateHealthFolder()
{
struct stat info;
+ // 判断HEALTH_JSON_PATH是否存在 不存在就创建
+ if (stat(HEALTH_JSON_PATH, &info) != 0)
+ {
+ if (mkdir(HEALTH_JSON_PATH, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0)
+ {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "mkdir HEALTH_JSON_PATH is error");
+ return false; // Failed to create folder
+ }
+ }
+ // 判断HEALTH_JSON_PATH_HEART是否存在 不存在就创建
if (stat(HEALTH_JSON_PATH_HEART, &info) != 0)
{
if (mkdir(HEALTH_JSON_PATH_HEART, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0)
{
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "mkdir HEALTH_JSON_PATH_HEART is error");
return false; // Failed to create folder
}
}
+ // 判断HEALTH_JSON_PATH_OXYGEN是否存在 不存在就创建
if (stat(HEALTH_JSON_PATH_OXYGEN, &info) != 0)
{
if (mkdir(HEALTH_JSON_PATH_OXYGEN, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0)
{
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "mkdir HEALTH_JSON_PATH_OXYGEN is error");
return false; // Failed to create folder
}
}
return true;
}
- /*获取日期*/
-
/*生成文件*/
std::string GetJsonFilePath(uint8_t type)
{
std::string currentDate = GetCurrentDate();
- if(type==HEALTH_TYPE_HEART)
+
+ if (type == HEALTH_TYPE_HEART)
{
return std::string(HEALTH_JSON_PATH_HEART) + currentDate + ".json";
}
{
return std::string(HEALTH_JSON_PATH_OXYGEN) + currentDate + ".json";
}
-
}
-
-
+ const char *GET_HEALTH_JSON_PATH_C_STR_HEART()
+ {
+ return HEALTH_JSON_PATH_HEART;
+ }
+ const char *GET_HEALTH_JSON_PATH_C_STR_OXYGEN()
+ {
+ return HEALTH_JSON_PATH_OXYGEN;
+ }
bool HealthService::LoadJsonData(uint8_t type)
{
// 创建健康数据文件夹
-
- if(!CreateHealthFolder())
+ if (!CreateHealthFolder())
{
return false;
}
-
-
// 获取当天日期对应的JSON文件路径
std::string jsonFilePath = GetJsonFilePath(type);
std::ifstream inFile(jsonFilePath);
- cJSON *defaultJson=NULL;
+ cJSON *defaultJson = NULL;
if (!inFile.is_open())
{
+#if 0
// 如果文件不存在,则创建一个包含默认值的JSON文件
- if(type==HEALTH_TYPE_HEART)
+ if (type == HEALTH_TYPE_HEART)
{
defaultJson = cJSON_Parse("{\
\"heart_latest_data\": {\
]\
}");
}
- else if(type==HEALTH_TYPE_OXYGEN)
+ else if (type == HEALTH_TYPE_OXYGEN)
{
defaultJson = cJSON_Parse("{\
\"spo2_latest_data\": {\
]\
}");
}
-
std::ofstream outFile(jsonFilePath);
if (!outFile.is_open())
{
cJSON_free(defaultJsonString);
cJSON_Delete(defaultJson);
inFile.open(jsonFilePath); // 重新打开文件
+#endif
}
// 读取JSON文件内容
std::string jsonDataString((std::istreambuf_iterator<char>(inFile)), std::istreambuf_iterator<char>());
const char *jsonData = jsonDataString.c_str();
- if(type==HEALTH_TYPE_HEART)
+ if (type == HEALTH_TYPE_HEART)
{
- heart_root = cJSON_Parse(jsonData);
+ heart_root = cJSON_Parse(jsonData);
}
- if(type==HEALTH_TYPE_OXYGEN)
+ if (type == HEALTH_TYPE_OXYGEN)
{
- oxygen_root = cJSON_Parse(jsonData);
+ oxygen_root = cJSON_Parse(jsonData);
}
-
-
return true;
}
#if 0
HeartRateData *data = new HeartRateData();
cJSON *latestData = cJSON_GetObjectItem(heart_root, "heart_latest_data");
data->Heart = cJSON_GetObjectItem(latestData, "value")->valueint;
- data->timestamp = cJSON_GetObjectItem(latestData, "timestamp")->valuedouble;
+ data->timestamp = cJSON_GetObjectItem(latestData, "timestamp")->valueint;
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ReadHeartRateData: value %d timestamp%d", data->Heart, data->timestamp);
cJSON_Delete(heart_root);
return data;
}
return true;
}
- bool HealthService::UpdateJsonData( uint8_t type)
+ bool HealthService::UpdateJsonData(uint8_t type)
{
std::string jsonFilePath = GetJsonFilePath(type);
std::ofstream outFile(jsonFilePath);
{
return false;
}
- char *jsonData=NULL;
+ char *jsonData = NULL;
- if(type==HEALTH_TYPE_HEART)
- jsonData = cJSON_Print(heart_root);
+ if (type == HEALTH_TYPE_HEART)
+ jsonData = cJSON_Print(heart_root);
else
- jsonData = cJSON_Print(oxygen_root);
+ jsonData = cJSON_Print(oxygen_root);
if (jsonData == NULL)
{
+/***
+ * @Date: 2024-04-17 16:49:23
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-06-13 17:09:11
+ * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartPresenter.cpp
+ */
#include "common/task_manager.h"
#include "components/ui_label.h"
#include "heartrate/include/HeartBandoffView.h"
#include "health_service.h"
#include "cywee_service.h"
+#include "custom_utils.h"
#define HEARTKEYABLE 0
static constexpr uint16_t PROGRESS_VALUE_MIN = 0;
static constexpr uint16_t PROGRESS_VALUE_MAX = 10;
- uint64_t HeartPresenter::GetCurrentTime()
+ uint32_t HeartPresenter::GetCurrentTime()
{
- // time_t now = time(0);
- // struct tm *tblock = localtime(&now);
-
+#if 0
/*优化为更安全的localtime_r()*/
struct timeval tv;
gettimeofday(&tv, NULL);
struct tm tblock;
localtime_r(&tv.tv_sec, &tblock);
- uint64_t current_time = tblock.tm_hour * 60 + tblock.tm_min;
+ uint32_t current_time = tblock.tm_hour * 60 + tblock.tm_min;
return current_time;
+#endif
+ uint32_t time;
+ if (uapi_get_timestampe_ss(&time) != ERRCODE_SUCC)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to get timestamp");
+ return 0;
+ }
+ return time;
}
- int HeartPresenter::GetTDOA(uint64_t new_time, uint64_t old_time)
+ int HeartPresenter::GetTDOA(uint32_t new_time, uint32_t old_time)
{
if (new_time == old_time || old_time > new_time)
{
return 0;
}
-
- int time_diff = new_time - old_time;
- return time_diff;
+ int time_diff_seconds = new_time - old_time;
+ // 转换为分钟的差值
+ int time_diff_minutes = time_diff_seconds / 60;
+ return time_diff_minutes;
}
HeartPresenter::HeartPresenter()