From: SnickerSun Date: Tue, 9 Apr 2024 11:00:20 +0000 (+0800) Subject: 优化和融合get_rtc函数解决编译问题 X-Git-Tag: release_V1.2.70_20241020_135402~1200^2~8 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=f1537a78d8b59539478b4405f81ef070d190c4dd;p=mirrors%2FFD230.git 优化和融合get_rtc函数解决编译问题 --- diff --git a/code/sdk/application/wearable/service/factorytest_service/factorytest_protocol.c b/code/sdk/application/wearable/service/factorytest_service/factorytest_protocol.c index d3d6a1b2e..08b09b231 100644 --- a/code/sdk/application/wearable/service/factorytest_service/factorytest_protocol.c +++ b/code/sdk/application/wearable/service/factorytest_service/factorytest_protocol.c @@ -23,7 +23,7 @@ #include "mag_service.h" #include "nandflash_config.h" #include "string.h" - +#include "custom_utils.h" #pragma pack(1) typedef struct factorytest_cmd_header_t { @@ -299,38 +299,38 @@ void ble_leaklight_check_timer_callback(void) leaklight_flag++; } -void get_rtc(uint32_t *msc) -{ - char time_data[64] = {0}; - uint8_t send_data1[20] = {0}; - uint8_t send_data2[7] = {0}; - - uint8_t i = 0; - get_system_time(time_data); - uint8_t len = strlen(time_data); - //1970-01-01 00:00:26 - PRINT("time_data : %s , len : %d\r\n",time_data,len); - - for (int j = 0; j < len; j ++) - { - if(time_data[j] >= '0' && time_data[j] <= '9' ) - { - send_data1[i++] = (time_data[j] - '0'); - } - } +// void get_rtc(uint32_t *msc) +// { +// char time_data[64] = {0}; +// uint8_t send_data1[20] = {0}; +// uint8_t send_data2[7] = {0}; + +// uint8_t i = 0; +// get_system_time(time_data); +// uint8_t len = strlen(time_data); +// //1970-01-01 00:00:26 +// PRINT("time_data : %s , len : %d\r\n",time_data,len); + +// for (int j = 0; j < len; j ++) +// { +// if(time_data[j] >= '0' && time_data[j] <= '9' ) +// { +// send_data1[i++] = (time_data[j] - '0'); +// } +// } - i = 0; - for(int j = 0; j < 14 ; j+=2) - { - send_data2[i++] = send_data1[j] * 10 + send_data1[j+1]; - } - - *msc = ((((send_data2[0] * 100 + send_data2[1] - 1970) * 365 - + (send_data2[2] -1)* 30 + (send_data2[3] - 1) ) * 24 - + send_data2[4]) * 60 + send_data2[5]) * 60 - + send_data2[6]; - -} +// i = 0; +// for(int j = 0; j < 14 ; j+=2) +// { +// send_data2[i++] = send_data1[j] * 10 + send_data1[j+1]; +// } + +// *msc = ((((send_data2[0] * 100 + send_data2[1] - 1970) * 365 +// + (send_data2[2] -1)* 30 + (send_data2[3] - 1) ) * 24 +// + send_data2[4]) * 60 + send_data2[5]) * 60 +// + send_data2[6]; + +// } void aging_task(void) { diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.c b/code/sdk/drivers/peripheral/utils/custom_utils.c index 1171de756..ca12878e6 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.c +++ b/code/sdk/drivers/peripheral/utils/custom_utils.c @@ -909,12 +909,17 @@ uint32_t secondsSinceEpoch(int year,int month,int day,int hour,int min,int sec) 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); + + time_t rawtime; + struct tm* timeinfo; + time(&rawtime); + timeinfo = localtime(&rawtime); + *msc = secondsSinceEpoch(timeinfo->tm_year + 1900, + timeinfo->tm_mon + 1, + timeinfo->tm_mday, + timeinfo->tm_hour, + timeinfo->tm_min, + timeinfo->tm_sec); PRINT("msc : %d \r\n",*msc); }