2025-04-19 09:30:40 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @file FluxTimer.c
|
|
|
|
|
|
* @brief 时间同步源文件
|
|
|
|
|
|
*
|
|
|
|
|
|
* 用于芯片内部时钟同步(Not Used)
|
|
|
|
|
|
*
|
|
|
|
|
|
* @author wang xiang en
|
|
|
|
|
|
* @date 2025-04-19
|
|
|
|
|
|
* @version 版本号
|
|
|
|
|
|
* @copyright 版权声明((C)2025, YUWELL MEDTECH Co.ltd)
|
|
|
|
|
|
*/
|
2025-03-27 14:57:30 +08:00
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
#include "FluxTime.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include "ui.h"
|
|
|
|
|
|
#include "esp_err.h"
|
|
|
|
|
|
#include "esp_log.h"
|
|
|
|
|
|
|
|
|
|
|
|
/*包含SNTP的头文件*/
|
|
|
|
|
|
#include "lwip/apps/sntp.h"
|
|
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
2025-04-21 14:06:52 +08:00
|
|
|
|
/* 更新SD卡信息中的时间戳 */
|
|
|
|
|
|
#include "FluxSD.h"
|
2025-03-28 10:13:22 +08:00
|
|
|
|
|
2025-04-19 09:30:40 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @brief 时间同步函数
|
|
|
|
|
|
*
|
|
|
|
|
|
* 用于时间同步操作,无网络环境无法使用。
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param[in] arg not used
|
|
|
|
|
|
*/
|
2025-03-27 14:57:30 +08:00
|
|
|
|
void time_synic_task(void *arg)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
/*用来进行显示的字符串*/
|
|
|
|
|
|
char strftime_buf[64];
|
2025-03-28 10:13:22 +08:00
|
|
|
|
char time_str[64];
|
2025-04-19 09:30:40 +08:00
|
|
|
|
|
2025-03-27 14:57:30 +08:00
|
|
|
|
/*大数*/
|
|
|
|
|
|
time_t now = 0;
|
|
|
|
|
|
/*时间结构体*/
|
|
|
|
|
|
struct tm timeinfo = {0};
|
|
|
|
|
|
|
2025-04-21 14:06:52 +08:00
|
|
|
|
//ESP_LOGI("SNTP..........","SNTP task start");
|
2025-03-27 14:57:30 +08:00
|
|
|
|
|
|
|
|
|
|
while (1)
|
2025-03-28 10:13:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
/*1秒钟更新一下显示时间*/
|
|
|
|
|
|
vTaskDelay(SYSTEM_TIME_UPDATE_INTERVAL_SEC*1000 / portTICK_PERIOD_MS);
|
|
|
|
|
|
|
2025-03-27 14:57:30 +08:00
|
|
|
|
time(&now);
|
|
|
|
|
|
localtime_r(&now, &timeinfo);
|
|
|
|
|
|
|
|
|
|
|
|
strftime(strftime_buf, sizeof(strftime_buf), "%c", &timeinfo);
|
|
|
|
|
|
|
|
|
|
|
|
lv_label_set_text_fmt(ui_pageTimeDebug_labelHearderTime,"%s",strftime_buf);
|
|
|
|
|
|
|
2025-04-21 14:06:52 +08:00
|
|
|
|
//ESP_LOGI("SNTP","The current date/time in China is: %s", strftime_buf);
|
|
|
|
|
|
|
|
|
|
|
|
/* 更新时间信息 */
|
|
|
|
|
|
sdData.current_time = now;
|
|
|
|
|
|
//sdData.current_time_tm = timeinfo;
|
|
|
|
|
|
memcpy(sdData.strftime_buf,strftime_buf,sizeof(strftime_buf));
|
2025-03-27 14:57:30 +08:00
|
|
|
|
|
2025-04-19 09:30:40 +08:00
|
|
|
|
/* 更新时间信息 */
|
2025-03-28 10:13:22 +08:00
|
|
|
|
lv_label_set_text_fmt(ui_pageHome_labelTime,"%d:%d",timeinfo.tm_hour,timeinfo.tm_min);
|
|
|
|
|
|
lv_label_set_text_fmt(ui_pageTime_time,"%d:%d:%d",timeinfo.tm_hour,timeinfo.tm_min,timeinfo.tm_sec);
|
|
|
|
|
|
lv_label_set_text_fmt(ui_pageTime_date,"%d-%d-%d %d",timeinfo.tm_year+1900,timeinfo.tm_mon+1,timeinfo.tm_mday,timeinfo.tm_wday);
|
|
|
|
|
|
|
2025-03-27 14:57:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-19 09:30:40 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @brief 时间获取API
|
|
|
|
|
|
*
|
|
|
|
|
|
* 将时间转换为字符串上交
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return 时间字符串提交函数
|
|
|
|
|
|
*/
|
2025-03-28 10:13:22 +08:00
|
|
|
|
char* get_time_str(void)
|
2025-03-27 14:57:30 +08:00
|
|
|
|
{
|
|
|
|
|
|
char strftime_buf[64];
|
|
|
|
|
|
time_t now = 0;
|
|
|
|
|
|
struct tm timeinfo = {0};
|
2025-04-19 09:30:40 +08:00
|
|
|
|
|
|
|
|
|
|
/* 获取时间 */
|
2025-03-27 14:57:30 +08:00
|
|
|
|
time(&now);
|
2025-04-19 09:30:40 +08:00
|
|
|
|
|
|
|
|
|
|
/* 获取时间字符串 */
|
2025-03-27 14:57:30 +08:00
|
|
|
|
localtime_r(&now, &timeinfo);
|
2025-04-19 09:30:40 +08:00
|
|
|
|
|
|
|
|
|
|
/* 返回时间字符串 */
|
2025-03-27 14:57:30 +08:00
|
|
|
|
strftime(strftime_buf, sizeof(strftime_buf), "%c", &timeinfo);
|
|
|
|
|
|
return strftime_buf;
|
2025-04-21 14:06:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-06 10:42:49 +08:00
|
|
|
|
#if SYSTEM_TIME_TEST_ENABLE
|
|
|
|
|
|
static void soft_timer_callback_func(void)
|
|
|
|
|
|
{
|
|
|
|
|
|
//printf("soft timer callback\n");
|
|
|
|
|
|
|
|
|
|
|
|
/* 向SD卡写入时间戳 */
|
|
|
|
|
|
WRITE_LOG_TO_SD("soft timer callback");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 软件定时器精度测试任务
|
|
|
|
|
|
*
|
|
|
|
|
|
* 验证使用FreeRTOS软件定时器可以保证气阀开启周期为 0.2s (开启0.2s后再关闭)
|
|
|
|
|
|
*
|
|
|
|
|
|
* @note cpu利用率拉升至100%,同时定义执行五次,周期为0.2s的定时器(调度器周期为1ms)
|
|
|
|
|
|
* ,使用GPIO输出模拟气阀切换,每次切换向SD卡中写入当前时间戳,持续运行读取当前日志。
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param[in] arg not used
|
|
|
|
|
|
*/
|
|
|
|
|
|
void soft_timer_task(void* arg)
|
|
|
|
|
|
{
|
|
|
|
|
|
/* 定时器初始化 */
|
|
|
|
|
|
TimerHandle_t soft_timer = xTimerCreate("soft_timer_cb", pdMS_TO_TICKS(10), pdTRUE, NULL, &soft_timer_callback_func);
|
|
|
|
|
|
|
|
|
|
|
|
/* 立即启动定时器 */
|
|
|
|
|
|
xTimerStart(soft_timer, 0);
|
2025-05-07 11:13:39 +08:00
|
|
|
|
|
|
|
|
|
|
char* log_buf = (char*)malloc(16*1024);
|
2025-05-06 10:42:49 +08:00
|
|
|
|
while (1)
|
|
|
|
|
|
{
|
|
|
|
|
|
/* 延时1s */
|
2025-05-07 11:13:39 +08:00
|
|
|
|
vTaskDelay(5000/portTICK_PERIOD_MS);
|
|
|
|
|
|
|
|
|
|
|
|
vTaskList(log_buf);
|
|
|
|
|
|
ESP_LOGI("TAG", "\n任务名称 任务状态 优先级 剩余栈 任务号\n%s", log_buf);
|
2025-05-06 10:42:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
#endif
|