From 4b09f4d53935e4f3eb814616166f3528bb43ecbb Mon Sep 17 00:00:00 2001 From: Zip <76966589@qq.com> Date: Mon, 7 Jan 2019 08:23:58 +0800 Subject: [PATCH] =?UTF-8?q?add:=E5=A2=9E=E5=8A=A0sntp=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TC1/TC1.mk | 7 ++++-- TC1/main.c | 5 +++-- TC1/mico_config.h | 8 +++---- TC1/{key.c => user_key.c} | 1 + TC1/{key.h => user_key.h} | 4 ++-- TC1/user_sntp.c | 45 +++++++++++++++++++++++++++++++++++++ TC1/user_sntp.h | 13 +++++++++++ TC1/{wifi.c => user_wifi.c} | 24 ++++++++------------ TC1/{wifi.h => user_wifi.h} | 4 ++-- mico-os.component | 1 + 10 files changed, 85 insertions(+), 27 deletions(-) rename TC1/{key.c => user_key.c} (99%) rename TC1/{key.h => user_key.h} (71%) create mode 100644 TC1/user_sntp.c create mode 100644 TC1/user_sntp.h rename TC1/{wifi.c => user_wifi.c} (84%) rename TC1/{wifi.h => user_wifi.h} (87%) create mode 100644 mico-os.component diff --git a/TC1/TC1.mk b/TC1/TC1.mk index cf9cf98..bd37b7d 100644 --- a/TC1/TC1.mk +++ b/TC1/TC1.mk @@ -25,5 +25,8 @@ NAME := App_TC1 $(NAME)_SOURCES := main.c\ - wifi.c\ - key.c \ No newline at end of file + user_wifi.c\ + user_key.c\ + user_sntp.c + +$(NAME)_COMPONENTS := protocols/SNTP \ No newline at end of file diff --git a/TC1/main.c b/TC1/main.c index b62f867..725f290 100644 --- a/TC1/main.c +++ b/TC1/main.c @@ -1,6 +1,7 @@ #include "main.h" -#include "key.h" -#include "wifi.h" + +#include "user_key.h" +#include "user_wifi.h" #define os_log(format, ...) custom_log("TC1", format, ##__VA_ARGS__) diff --git a/TC1/mico_config.h b/TC1/mico_config.h index 8f8aeab..2575f54 100644 --- a/TC1/mico_config.h +++ b/TC1/mico_config.h @@ -35,10 +35,10 @@ #define APP_INFO "MiCO BASIC Demo" -#define FIRMWARE_REVISION "MICO_BASIC_1_0" -#define MANUFACTURER "MXCHIP Inc." -#define SERIAL_NUMBER "20140606" -#define PROTOCOL "com.mxchip.basic" +#define FIRMWARE_REVISION "ZYC_BASIC_1_0" +#define MANUFACTURER "ZYC Inc." +#define SERIAL_NUMBER "20190105" +#define PROTOCOL "com.zyc.basic" /************************************************************************ * Application thread stack size */ diff --git a/TC1/key.c b/TC1/user_key.c similarity index 99% rename from TC1/key.c rename to TC1/user_key.c index 5b37e03..cb0f335 100644 --- a/TC1/key.c +++ b/TC1/user_key.c @@ -15,6 +15,7 @@ static void key_long_press(void) { os_log("key_long_press"); MicoGpioOutputHigh(MICO_GPIO_5); + } static void key_short_press(void) { diff --git a/TC1/key.h b/TC1/user_key.h similarity index 71% rename from TC1/key.h rename to TC1/user_key.h index 39ca13d..bf94601 100644 --- a/TC1/key.h +++ b/TC1/user_key.h @@ -1,6 +1,6 @@ -#ifndef __KEY_H_ -#define __KEY_H_ +#ifndef __USER_KEY_H_ +#define __USER_KEY_H_ #include "mico.h" diff --git a/TC1/user_sntp.c b/TC1/user_sntp.c new file mode 100644 index 0000000..6021100 --- /dev/null +++ b/TC1/user_sntp.c @@ -0,0 +1,45 @@ + +#define os_log(format, ...) custom_log("SNTP", format, ##__VA_ARGS__) + +#include "main.h" +//#include "key.h" +#include "user_sntp.h" + +/* Callback function when MiCO UTC time in sync to NTP server */ +static void sntp_time_call_back( void ) +{ + struct tm * currentTime; +// iso8601_time_t iso8601_time; + mico_utc_time_t utc_time; + mico_rtc_time_t rtc_time; + +// mico_time_get_iso8601_time( &iso8601_time ); +// os_log("sntp_time_synced: %.26s", (char*)&iso8601_time); + + mico_time_get_utc_time( &utc_time ); + utc_time+=28800; //+8:00 + currentTime = localtime( (const time_t *)&utc_time ); + rtc_time.sec = currentTime->tm_sec; + rtc_time.min = currentTime->tm_min; + rtc_time.hr = currentTime->tm_hour; + + rtc_time.date = currentTime->tm_mday; + rtc_time.weekday = currentTime->tm_wday; + rtc_time.month = currentTime->tm_mon + 1; + rtc_time.year = (currentTime->tm_year + 1900) % 100; + + MicoRtcSetTime( &rtc_time ); + + + MicoRtcGetTime(&rtc_time); + os_log("time:20%d/%d/%d %d %d:%d:%d",rtc_time.year,rtc_time.month,rtc_time.date,rtc_time.weekday,rtc_time.hr,rtc_time.min,rtc_time.sec); + +} + + +void sntp_init(void) +{ + struct in_addr ipp;ipp.s_addr=0xd248912c; + sntp_set_server_ip_address (0,ipp); + sntp_start_auto_time_sync (15000, sntp_time_call_back); +} diff --git a/TC1/user_sntp.h b/TC1/user_sntp.h new file mode 100644 index 0000000..225bafd --- /dev/null +++ b/TC1/user_sntp.h @@ -0,0 +1,13 @@ + +#ifndef __USER_SNTP_H_ +#define __USER_SNTP_H_ + + +#include "mico.h" +#include "MiCOKit_EXT.h" + +extern void sntp_init(void); + + + +#endif diff --git a/TC1/wifi.c b/TC1/user_wifi.c similarity index 84% rename from TC1/wifi.c rename to TC1/user_wifi.c index f048100..cba646f 100644 --- a/TC1/wifi.c +++ b/TC1/user_wifi.c @@ -1,6 +1,9 @@ +#include "user_wifi.h" + #include "main.h" -#include "wifi.h" -#include "key.h" +#include "mico_socket.h" +#include "user_sntp.h" +#include "user_key.h" #define os_log(format, ...) custom_log("WIFI", format, ##__VA_ARGS__) @@ -31,7 +34,7 @@ void wifi_start_easylink( ) micoWlanStartEasyLink( 20000 ); led( 1 ); } - +uint32_t ip=0xd248912c; //easylink 完成回调 void wifi_easylink_completed_handle( network_InitTypeDef_st *nwkpara, void * arg ) { @@ -60,22 +63,13 @@ void wifi_easylink_completed_handle( network_InitTypeDef_st *nwkpara, void * arg os_log("EasyLink stop"); micoWlanStopEasyLink( ); } + //wifi已连接获取到IP地址 回调 static void wifi_get_ip_callback( IPStatusTypedef *pnet, void * arg ) { os_log("got IP:%s", pnet->ip); wifi_status = WIFI_STATE_CONNECTED; -// /* Store SSID and KEY*/ -// mico_rtos_lock_mutex( &inContext->flashContentInRam_mutex ); -// memcpy( inContext->flashContentInRam.micoSystemConfig.ssid, nwkpara->wifi_ssid, maxSsidLen ); -// memset( inContext->flashContentInRam.micoSystemConfig.bssid, 0x0, 6 ); -// memcpy( inContext->flashContentInRam.micoSystemConfig.user_key, nwkpara->wifi_key, maxKeyLen ); -// inContext->flashContentInRam.micoSystemConfig.user_keyLength = strlen( nwkpara->wifi_key ); -// inContext->flashContentInRam.micoSystemConfig.dhcpEnable = true; -// mico_rtos_unlock_mutex( &inContext->flashContentInRam_mutex ); -// system_log("Get SSID: %s, Key: %s", inContext->flashContentInRam.micoSystemConfig.ssid, inContext->flashContentInRam.micoSystemConfig.user_key); - } //wifi连接状态改变回调 static void wifi_status_callback( WiFiEvent status, void *arg ) @@ -106,7 +100,7 @@ static void wifi_led_timer_callback( void* arg ) break; case WIFI_STATE_CONNECTING: - if ( num > 2 ) + if ( num > 1 ) { num = 0; led( -1 ); @@ -146,7 +140,7 @@ void wifi_init( void ) mico_system_notify_register( mico_notify_DHCP_COMPLETED, (void *) wifi_get_ip_callback, NULL ); //wifi连接状态改变回调 mico_system_notify_register( mico_notify_WIFI_STATUS_CHANGED, (void*) wifi_status_callback, NULL ); - + sntp_init(); //启动定时器开始进行wifi连接 if ( !mico_rtos_is_timer_running( &wifi_led_timer ) ) mico_rtos_start_timer( &wifi_led_timer ); diff --git a/TC1/wifi.h b/TC1/user_wifi.h similarity index 87% rename from TC1/wifi.h rename to TC1/user_wifi.h index 7785884..1931429 100644 --- a/TC1/wifi.h +++ b/TC1/user_wifi.h @@ -1,6 +1,6 @@ -#ifndef __WIFI_H_ -#define __WIFI_H_ +#ifndef __USER_WIFI_H_ +#define __USER_WIFI_H_ #include "mico.h" diff --git a/mico-os.component b/mico-os.component new file mode 100644 index 0000000..4ffa301 --- /dev/null +++ b/mico-os.component @@ -0,0 +1 @@ +https://code.aliyun.com/mico/mico-os.git/#6c465211d3ff8797cd835e400ec54a06530dd476