Fixed:setting time and date failed bug.

This commit is contained in:
xiaojiazhu 2023-12-25 17:40:41 +08:00
parent f6034b6add
commit de5b58d770

View File

@ -2169,9 +2169,44 @@ void sf_set_module_sleep_flag(UINT8 flag)
#endif #endif
} }
#include <linux/rtc.h>
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) 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}; struct tm Curr_DateTime = {0};
Curr_DateTime.tm_year = pstDateTime->Year; Curr_DateTime.tm_year = pstDateTime->Year;
Curr_DateTime.tm_mon = pstDateTime->Mon; 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; Curr_DateTime.tm_sec = pstDateTime->Sec;
hwclock_set_time(TIME_ID_CURRENT, *(struct tm*)&Curr_DateTime, 0); 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; return SUCCESS;
} }