From de5b58d770ac739008fc14a75752a250ad24aa71 Mon Sep 17 00:00:00 2001 From: xiaojiazhu Date: Mon, 25 Dec 2023 17:40:41 +0800 Subject: [PATCH] Fixed:setting time and date failed bug. --- .../sifar/code/source/mcu/sf_mcu_client.c | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/code/lib/source/sifar/code/source/mcu/sf_mcu_client.c b/code/lib/source/sifar/code/source/mcu/sf_mcu_client.c index 028855846..81d28c648 100644 --- a/code/lib/source/sifar/code/source/mcu/sf_mcu_client.c +++ b/code/lib/source/sifar/code/source/mcu/sf_mcu_client.c @@ -2169,9 +2169,44 @@ void sf_set_module_sleep_flag(UINT8 flag) #endif } +#include +static SINT32 sf_sys_rtc_time_set_v2(SF_PARA_TIME_S* pstDateTime) +{ + // SF_COMM_CHECK_POINTER(pstDateTime,SF_FAILURE); + + SINT32 fdRtc = -1; + + SINT32 ret = SF_SUCCESS; + + fdRtc = open(DEFAULT_RTC_DEVICE, O_RDWR); + if (fdRtc < 0) + { + printf("[ERR]open %s error:%d\n", DEFAULT_RTC_DEVICE, fdRtc); + return SF_FAILURE; + } + + struct rtc_time rtctm; + rtctm.tm_year = pstDateTime->Year - 1900; + rtctm.tm_mon = pstDateTime->Mon - 1; + rtctm.tm_mday = pstDateTime->Day; + rtctm.tm_hour = pstDateTime->Hour; + rtctm.tm_min = pstDateTime->Min; + rtctm.tm_sec = pstDateTime->Sec; + + ret=ioctl(fdRtc, RTC_SET_TIME, &rtctm); + if (ret < 0) + { + printf("[ERR]ioctl get rtc time error:%d\n", ret); + } + close(fdRtc); + system("hwclock -s"); + return ret; +} SINT32 sf_sys_rtc_time_set(SF_PARA_TIME_S* pstDateTime) { - + sf_sys_rtc_time_set_v2(pstDateTime); + return SUCCESS; + // printf(" gui set time : %04d-%02d-%02d %02d:%02d:%02d\n", pstDateTime->Year, pstDateTime->Mon, pstDateTime->Day, pstDateTime->Hour, pstDateTime->Min, pstDateTime->Sec); struct tm Curr_DateTime = {0}; Curr_DateTime.tm_year = pstDateTime->Year; Curr_DateTime.tm_mon = pstDateTime->Mon; @@ -2181,6 +2216,8 @@ SINT32 sf_sys_rtc_time_set(SF_PARA_TIME_S* pstDateTime) Curr_DateTime.tm_sec = pstDateTime->Sec; hwclock_set_time(TIME_ID_CURRENT, *(struct tm*)&Curr_DateTime, 0); + // Curr_DateTime = hwclock_get_time(TIME_ID_CURRENT); + // printf(" gui get time : %04d-%02d-%02d %02d:%02d:%02d\n", Curr_DateTime.tm_year, Curr_DateTime.tm_mon, Curr_DateTime.tm_mday, Curr_DateTime.tm_hour, Curr_DateTime.tm_min, Curr_DateTime.tm_sec); return SUCCESS; }