mirror of
https://github.com/oopuuu/zTC1.git
synced 2025-12-12 13:08:13 +08:00
fix:优化rtc及sntp逻辑
fix:优化部分函数名 add:增加relay直接控制函数(未测试)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#define os_log(format, ...) custom_log("RTC", format, ##__VA_ARGS__)
|
||||
|
||||
#include "main.h"
|
||||
//#include "key.h"
|
||||
#include "user_gpio.h"
|
||||
#include "sntp.h"
|
||||
#include "user_sntp.h"
|
||||
|
||||
@@ -16,7 +16,7 @@ OSStatus user_sntp_get_time( )
|
||||
char ** pptr = NULL;
|
||||
struct in_addr ipp;
|
||||
|
||||
mico_rtc_time_t rtc_time;
|
||||
// mico_rtc_time_t rtc_time;
|
||||
|
||||
hostent_content = gethostbyname( "pool.ntp.org" );
|
||||
pptr = hostent_content->h_addr_list;
|
||||
@@ -28,10 +28,6 @@ OSStatus user_sntp_get_time( )
|
||||
ipp.s_addr = 0xd248912c;
|
||||
err = sntp_get_time( &ipp, ¤t_time );
|
||||
}
|
||||
if ( err != kNoErr )
|
||||
{
|
||||
os_log("sntp_get_time2 err = %d.", err);
|
||||
}
|
||||
|
||||
if ( err == kNoErr )
|
||||
{
|
||||
@@ -51,6 +47,7 @@ OSStatus user_sntp_get_time( )
|
||||
}
|
||||
else
|
||||
{
|
||||
os_log("sntp_get_time2 err = %d.", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -96,6 +93,8 @@ void rtc_thread( mico_thread_arg_t arg )
|
||||
LinkStatusTypeDef LinkStatus;
|
||||
mico_rtc_time_t rtc_time;
|
||||
|
||||
mico_utc_time_t utc_time;
|
||||
|
||||
while ( 1 )
|
||||
{ //<2F>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>wifi<66>ſ<EFBFBD>ʼ<EFBFBD><CABC>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD>
|
||||
micoWlanGetLinkStatus( &LinkStatus );
|
||||
@@ -114,25 +113,9 @@ void rtc_thread( mico_thread_arg_t arg )
|
||||
|
||||
while ( 1 )
|
||||
{
|
||||
if ( rtc_init == 0 || rtc_time.sec == 0 && rtc_time.min == 0 ) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ÿСʱУһ<D7BC><D2BB>
|
||||
{
|
||||
micoWlanGetLinkStatus( &LinkStatus );
|
||||
if ( LinkStatus.is_connected == 1 )
|
||||
{
|
||||
err = user_sntp_get_time( );
|
||||
if ( err == kNoErr ) rtc_init = 1;
|
||||
}
|
||||
}
|
||||
// MicoRtcGetTime( &rtc_time );
|
||||
// os_log("time:20%02d/%02d/%02d %d %02d:%02d:%02d",rtc_time.year,rtc_time.month,rtc_time.date,rtc_time.weekday,rtc_time.hr,rtc_time.min,rtc_time.sec);
|
||||
|
||||
os_log("rtc_thread");
|
||||
|
||||
mico_utc_time_t utc_time;
|
||||
mico_rtc_time_t rtc_time;
|
||||
|
||||
mico_time_get_utc_time( &utc_time );
|
||||
utc_time+= 28800;
|
||||
utc_time += 28800;
|
||||
struct tm * currentTime = localtime( (const time_t *) &utc_time );
|
||||
rtc_time.sec = currentTime->tm_sec;
|
||||
rtc_time.min = currentTime->tm_min;
|
||||
@@ -146,6 +129,19 @@ void rtc_thread( mico_thread_arg_t arg )
|
||||
// MicoRtcSetTime( &rtc_time ); //MicoRtc<74><63><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD>ʱ!
|
||||
os_log("time:20%02d/%02d/%02d %d %02d:%02d:%02d",rtc_time.year,rtc_time.month,rtc_time.date,rtc_time.weekday,rtc_time.hr,rtc_time.min,rtc_time.sec);
|
||||
|
||||
if ( rtc_init != 1 || (rtc_time.sec == 0 && rtc_time.min == 0) ) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ÿСʱУһ<D7BC><D2BB>
|
||||
{
|
||||
micoWlanGetLinkStatus( &LinkStatus );
|
||||
if ( LinkStatus.is_connected == 1 )
|
||||
{
|
||||
err = user_sntp_get_time( );
|
||||
if ( err == kNoErr )
|
||||
rtc_init = 1;
|
||||
else
|
||||
rtc_init = 2;
|
||||
}
|
||||
}
|
||||
|
||||
mico_rtos_thread_msleep( 900 );
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user