/** * If Kiss-of-Death is received (or another packet parsing error), * try the next server or retry the current server and increase the retry * timeout if only one server is available. * (implicitly, SNTP_MAX_SERVERS > 1) * * @param arg is unused (only necessary to conform to sys_timeout) */ static void sntp_try_next_server(void* arg) { u8_t old_server, i; LWIP_UNUSED_ARG(arg); old_server = sntp_current_server; for (i = 0; i < SNTP_MAX_SERVERS - 1; i++) { sntp_current_server++; if (sntp_current_server >= SNTP_MAX_SERVERS) { sntp_current_server = 0; } if (!ip_addr_isany(&sntp_servers[sntp_current_server].addr) #if SNTP_SERVER_DNS || (sntp_servers[sntp_current_server].name != NULL) #endif ) { LWIP_DEBUGF(SNTP_DEBUG_STATE, ("sntp_try_next_server: Sending request to server %"U16_F"\n", (u16_t)sntp_current_server)); /* new server: reset retry timeout */ SNTP_RESET_RETRY_TIMEOUT(); /* instantly send a request to the next server */ sntp_request(NULL); return; } } /* no other valid server found */ sntp_current_server = old_server; sntp_retry(NULL); }
/** * Initialize this module. * Send out request instantly or after SNTP_STARTUP_DELAY(_FUNC). */ void sntp_init(void) { #ifdef SNTP_SERVER_ADDRESS #if SNTP_SERVER_DNS sntp_setservername(0, SNTP_SERVER_ADDRESS); #else #error SNTP_SERVER_ADDRESS string not supported SNTP_SERVER_DNS==0 #endif #endif /* SNTP_SERVER_ADDRESS */ if (sntp_pcb == NULL) { SNTP_RESET_RETRY_TIMEOUT(); sntp_pcb = udp_new(); LWIP_ASSERT("Failed to allocate udp pcb for sntp client", sntp_pcb != NULL); if (sntp_pcb != NULL) { udp_recv(sntp_pcb, sntp_recv, NULL); #if SNTP_STARTUP_DELAY sys_timeout((u32_t)SNTP_STARTUP_DELAY_FUNC, sntp_request, NULL); #else sntp_request(NULL); #endif } } }
/** * If Kiss-of-Death is received (or another packet parsing error), * try the next server or retry the current server and increase the retry * timeout if only one server is available. * * @param arg is unused (only necessary to conform to sys_timeout) */ static void sntp_try_next_server(void* arg) { LWIP_UNUSED_ARG(arg); /*os_sprintf(deb,"Trying next server\r\n"); uart0_sendStr(deb);*/ if (sntp_num_servers > 1) { /* new server: reset retry timeout */ SNTP_RESET_RETRY_TIMEOUT(); sntp_current_server++; if (sntp_current_server >= sntp_num_servers) { sntp_current_server = 0; } LWIP_DEBUGF(SNTP_DEBUG_STATE, ("sntp_try_next_server: Sending request to server %"U16_F"\n", (u16_t)sntp_current_server)); os_sprintf(deb,"sntp_try_next_server: Sending request to server %"U16_F"\n", (u16_t)sntp_current_server); //uart0_sendStr(deb); /* instantly send a request to the next server */ sntp_request(NULL); } else { /* os_sprintf(deb,"Retrying null\n"); uart0_sendStr(deb);*/ sntp_retry(NULL); } }
/** * SNTP thread */ static void sntp_thread(void *arg) { LWIP_UNUSED_ARG(arg); while (1) { dns_gethostbyname(SNTP_SERVER_NAME, &SNTPaddr, sntp_server_found, NULL); vTaskSuspend(NULL); sntp_request(); sys_msleep(SNTP_UPDATE_DELAY); } }
/** * SNTP thread */ static void sntp_thread(void *arg) { LWIP_UNUSED_ARG(arg); while(1) { sntp_request(); sys_msleep(SNTP_UPDATE_DELAY); } }
/** * Initialize this module when using raw API. * Send out request instantly or after SNTP_STARTUP_DELAY. */ void sntp_init(void) { SNTP_RESET_RETRY_TIMEOUT(); sntp_pcb = udp_new(); LWIP_ASSERT("Failed to allocate udp pcb for sntp client", sntp_pcb != NULL); if (sntp_pcb != NULL) { udp_recv(sntp_pcb, sntp_recv, NULL); #if SNTP_STARTUP_DELAY sys_timeout((u32_t)SNTP_STARTUP_DELAY, sntp_request, NULL); #else sntp_request(NULL); #endif } }
void sntp_run(void *arg) { CMD_LOG(1, "<net> <sntp> <request>\n"); if (sntp_request(NULL) != 0) { CMD_LOG(1, "<net> <sntp> <response : fail>\n"); goto exit; } sntp_time *time = (sntp_time *)sntp_obtain_time(); CMD_LOG(1, "<net> <sntp> <response : success>\n"); CMD_LOG(1,"sntp(%u %u %u ",time->week, time->mon, time->day); CMD_LOG(1,"%u:%u:%u %u)\n", time->hour, time->min, time->sec, time->year); exit: SNTP_THREAD_EXIT(&g_sntp_thread); }
/** * If Kiss-of-Death is received (or another packet parsing error), * try the next server or retry the current server and increase the retry * timeout if only one server is available. * * @param arg is unused (only necessary to conform to sys_timeout) */ static void sntp_try_next_server(void* arg) { LWIP_UNUSED_ARG(arg); if (sntp_num_servers > 1) { /* New server: reset retry timeout */ SNTP_RESET_RETRY_TIMEOUT(); sntp_current_server++; if (sntp_current_server >= sntp_num_servers) { sntp_current_server = 0; } LWIP_DEBUGF(SNTP_DEBUG_STATE, ("sntp_try_next_server: Sending request to server %"U16_F"\n", (u16_t)sntp_current_server)); /* Instantly send a request to the next server */ sntp_request(NULL); } else { sntp_retry(NULL); } }
/** * Initialize this module. * Send out request instantly or after SNTP_STARTUP_DELAY. */ void sntp_init(int tz) { LWIP_DEBUGF(SNTP_DEBUG_WARN_STATE,"Sntp initializing TZ: GMT%s%02d...\n",tz > 0 ? "+" : "",tz); ets_uart_printf("Sntp initializing...\n"); sntp_tz = tz; if (sntp_pcb == NULL) { os_timer_setfn(&ntp_timer,ntp_time_update,NULL); SNTP_RESET_RETRY_TIMEOUT(); sntp_pcb = udp_new(); LWIP_ASSERT("Failed to allocate udp pcb for sntp client", sntp_pcb != NULL); if (sntp_pcb != NULL) { udp_recv(sntp_pcb, sntp_recv, NULL); #if SNTP_STARTUP_DELAY sys_timeout((u32_t)SNTP_STARTUP_DELAY, sntp_request, NULL); #else sntp_request(NULL); #endif } } }