-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ntp server address to settings menu and ntp via dhcp support. Pre…
…pare manual ntp server ip entry. Add support for setting ntp ip addr manually via prusa_printer_settings.ini. Add ntp pool support.
- Loading branch information
Showing
15 changed files
with
118 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,50 @@ | ||
#include "sntp.h" | ||
#include "sntp_client.h" | ||
#include "netdev.h" | ||
#include "netif.h" | ||
#include "netdb.h" | ||
|
||
static ip_addr_t ntp_server; // testing ntp server located in Prague | ||
static uint32_t sntp_running = 0; // describes if sntp is currently running or not | ||
void sntp_client_init(void) { | ||
void sntp_client_static_init(const char *ntp_address) { | ||
sntp_setoperatingmode(SNTP_OPMODE_POLL); | ||
sntp_servermode_dhcp(0); | ||
sntp_setservername(0, ntp_address); | ||
sntp_init(); | ||
} | ||
|
||
/* TODO: enable DNS for ntp.pool.org as default sntp server*/ | ||
|
||
// TMP: ip of Czech CESNET NTP server tak.cesnet.cz | ||
if (ipaddr_aton("195.113.144.238", &ntp_server)) { | ||
sntp_setserver(0, &ntp_server); | ||
} | ||
void sntp_client_dhcp_init(const char *ntp_address) { | ||
sntp_setoperatingmode(SNTP_OPMODE_POLL); | ||
sntp_servermode_dhcp(1); | ||
#if LWIP_IPV4 | ||
#ifdef SNTP_SERVER_DNS | ||
sntp_setservername(1, "pool.ntp.org"); | ||
#else | ||
sntp_setservername(1, ntp_address); | ||
#endif | ||
#endif /* LWIP_IPV4 */ | ||
sntp_init(); | ||
} | ||
|
||
void sntp_client_step(void) { | ||
void sntp_client_step(bool ntp_via_dhcp, const char *ntp_address) { | ||
netdev_status_t eth = netdev_get_status(NETDEV_ETH_ID); | ||
netdev_status_t wifi = netdev_get_status(NETDEV_ESP_ID); | ||
|
||
if (!sntp_running && (eth == NETDEV_NETIF_UP || wifi == NETDEV_NETIF_UP)) { | ||
sntp_client_init(); | ||
if (ntp_via_dhcp) { | ||
sntp_client_dhcp_init(ntp_address); | ||
} else { | ||
sntp_client_static_init(ntp_address); | ||
} | ||
sntp_running = 1; | ||
} else if (sntp_running && eth != NETDEV_NETIF_UP && wifi != NETDEV_NETIF_UP) { | ||
sntp_stop(); | ||
sntp_running = 0; | ||
} | ||
} | ||
|
||
void sntp_client_stop() { | ||
if (sntp_running) { | ||
sntp_stop(); | ||
sntp_running = 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters