mcu_hi3321_watch/tjd/service/service_stress.c
2025-05-26 20:15:20 +08:00

133 lines
4.5 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*----------------------------------------------------------------------------
* Copyright (c) TJD Technologies Co., Ltd. 2020. All rights reserved.
*
* Description: service_stress.c
*
* Author: wuchangxin
*
* Create: 2024-6-29
*--------------------------------------------------------------------------*/
#include "service_stress.h"
#include "calendar.h"
#include "cmsis_os2.h"
#include "common_def.h"
#include "hr_api.h"
#include "rtc_api.h"
#include "securec.h"
#include "service_hrsensor.h"
#include "soc_osal.h"
#include "sql_fit.h"
#include "sys_config.h"
#include "sys_typedef.h"
#include "task_service_timer.h"
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
/**********************************************************************************************************************
* DEFINE
*/
#define ENABLE_PRINT_INFO 1
#if ENABLE_PRINT_INFO
#define static_print_info(...) sys_hr_log_i(__VA_ARGS__) // 一般信息打印宏控制
#define static_print_warn(...) sys_hr_log_w(__VA_ARGS__) // 警告信息打印一般常开
#define static_print_error(...) sys_hr_log_e(__VA_ARGS__) // 错误信息打印一般常开
#else
#define static_print_info(...)
#define static_print_warn(...)
#define static_print_error(...)
#endif
#define STRESS_RANDOM_VALUE 50 // 暂时由心率值-50换算成压力值
#define CUSTOM_TIME 1000 * 60 * 60
#define VALID_VALUE storeArray[i * 12] - STRESS_RANDOM_VALUE
/**********************************************************************************************************************
* VARIABLES
*/
/**********************************************************************************************************************
* LOCAL FUNCTIONS
*/
uint32_t tjd_task_service_stress_get_curtime_index(void)
{
struct rtc_time local_time;
tjd_driver_rtc_get_ops()->get_rtc_time(&local_time);
uint32_t totalMinutes = local_time.tm_hour * 60 + local_time.tm_min;
// 计算索引值每5分钟一个索引
uint32_t index = totalMinutes / 5;
return index;
}
struct rtc_time tjd_task_service_stress_get_curtime(void)
{
struct rtc_time local_time;
tjd_driver_rtc_get_ops()->get_rtc_time(&local_time);
return local_time;
}
static void tjd_task_service_stress_store_data(void)
{
static int cxin = 0;
struct rtc_time localTime;
tjd_driver_rtc_get_ops()->get_rtc_time(&localTime);
bool ifNull = sql_fit_get_hr_max(localTime.tm_wday);
uint8_t stressMax = sql_fit_get_hr_max(localTime.tm_wday) - STRESS_RANDOM_VALUE * ifNull;
uint8_t stressMin = sql_fit_get_hr_min(localTime.tm_wday) - 40;
uint8_t stressCur = (stressMax + stressMin) / 2;
stressCur = (stressCur <= 0 || stressCur >= 100 ? (stressCur < 1 ? 0 : 99) : stressCur);
struct rtc_time local_time = tjd_task_service_stress_get_curtime();
sql_fit_set_stress_curdata(local_time.tm_hour, stressCur);
if (local_time.tm_hour == 23) {
uint8_t day = sql_fit_get_stress_record_day();
sql_fit_reset_stress_day_arry(day);
sql_fit_set_stress_record_day((day + 1) % 7);
}
}
signed int tjd_task_service_timer_stress_handle(void *param)
{
tjd_task_service_stress_store_data();
return CUSTOM_TIME;
}
/**********************************************************************************************************************
* PUBLIC FUNCTIONS
*/
signed int tjd_service_timer_stress_start_send(void *param)
{
queue_default_info_t msg_data = {tjd_task_service_timer_stress_handle, NULL, CUSTOM_TIME, NULL};
int ret = osal_msg_queue_write_copy(tjd_task_service_timer_get_queue_id(), (void *)&msg_data,
sizeof(queue_default_info_t), 0);
if (ret != OSAL_SUCCESS) {
static_print_error("[%s] osal_msg_queue_write_copy fail", __func__);
}
return ret;
}
signed int tjd_service_timer_stress_end_send(void *param)
{
queue_default_info_t msg_data = {tjd_task_service_timer_stress_handle, NULL, 0, NULL};
int ret = osal_msg_queue_write_copy(tjd_task_service_timer_get_queue_id(), (void *)&msg_data,
sizeof(queue_default_info_t), 0);
if (ret != OSAL_SUCCESS) {
static_print_error("[%s] osal_msg_queue_write_copy fail", __func__);
}
return ret;
}
void tjd_task_service_timer_stress_all_day_open(void)
{
// struct rtc_time local_time = tjd_task_service_stress_get_curtime_index();
// printf("[%s]+++++[%d:%d:%d]+++++++\n", __func__, local_time.tm_hour, local_time.tm_min, local_time.tm_sec);
// if(local_time.tm_min == 0) {
tjd_service_timer_stress_start_send(NULL);
// }
}