From: penglei <1624952103@qq.com> Date: Tue, 9 Apr 2024 08:36:44 +0000 (+0800) Subject: 优化蓝牙产测RTC查询 X-Git-Tag: release_V1.2.70_20241020_135402~1223 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=3315c6d9d9c128f11bd3efb93be1122ae0fc5068;p=mirrors%2FFD230.git 优化蓝牙产测RTC查询 --- diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.c b/code/sdk/drivers/peripheral/utils/custom_utils.c index 9548c9c51..1171de756 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.c +++ b/code/sdk/drivers/peripheral/utils/custom_utils.c @@ -867,6 +867,57 @@ void gsensor_get_single_data(gsenson_t *t) get_gsonsen_xyz(t); } + +// 判断是否为闰年 +int isLeapYear(int year) { + return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0); +} + +// 计算某年某月的天数 +int daysInMonth(int year, int month) { + const int days[12] = {31, 28 + isLeapYear(year), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + return days[month - 1]; +} + +// 计算时间距离1970å¹´1月1日00:00:00的秒数 +uint32_t secondsSinceEpoch(int year,int month,int day,int hour,int min,int sec) { + const int secondsPerMinute = 60; + const int secondsPerHour = 3600; + const int secondsPerDay = 86400; + const int secondsPerYear = 31536000; // 不考虑闰秒 + + long long seconds = 0; + + // 计算年份之间的秒数 + for (int i = 1970; i < year; ++i) { + seconds += isLeapYear(i) ? secondsPerYear + secondsPerDay : secondsPerYear; + } + + // 计算月份之间的秒数 + for (int i = 1; i < month; ++i) { + seconds += daysInMonth(year, i) * secondsPerDay; + } + + // 计算当月的秒数 + seconds += (day - 1) * secondsPerDay; + seconds += hour * secondsPerHour; + seconds += min * secondsPerMinute; + seconds += sec; + + return seconds; +} + +void get_rtc(uint32_t *msc) +{ + char time_data[64] = {0}; + int year,month,day,hour,min,sec; + uapi_get_yyyymmddhhmmss_Date(time_data); + PRINT("timedata : %s \r\n",time_data); + sscanf(time_data, "%4d%2d%2d%2d%2d%2d", &year, &month, &day, &hour, &min, &sec); + *msc = secondsSinceEpoch(year,month,day,hour,min,sec); + PRINT("msc : %d \r\n",*msc); +} + //#include "lis2doc_reg.h" #include "stdio.h" diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.h b/code/sdk/drivers/peripheral/utils/custom_utils.h index b1ff42fe8..221f7a9e5 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.h +++ b/code/sdk/drivers/peripheral/utils/custom_utils.h @@ -90,6 +90,8 @@ void battery_getvolpower(uint8_t *power); void flash_getid(uint32_t *id); void flash_erase(void); +void get_rtc(uint32_t *msc); + //进入recovery int enter_recovery(void); //设置bmp图片