diff --git a/Internet/SNTP/sntp.c b/Internet/SNTP/sntp.c index 5b9c463..e0c41b4 100644 --- a/Internet/SNTP/sntp.c +++ b/Internet/SNTP/sntp.c @@ -71,7 +71,7 @@ uint16_t ntp_retry_cnt=0; //counting the ntp retry number 48) UTC+13:00 Tonga 49) UTC+14:00 Kiribati (Line Islands) */ -void get_seconds_from_ntp_server(uint8_t *buf, uint16_t idx) +uint64_t get_seconds_from_ntp_server(uint8_t *buf, uint16_t idx) { tstamp seconds = 0; uint8_t i=0; @@ -79,6 +79,8 @@ void get_seconds_from_ntp_server(uint8_t *buf, uint16_t idx) { seconds = (seconds << 8) | buf[idx + i]; } + uint64_t rawSeconds = seconds; + switch (time_zone) { case 0: @@ -132,7 +134,7 @@ void get_seconds_from_ntp_server(uint8_t *buf, uint16_t idx) case 20: seconds -= 1*3600; break; - case 21: //� + case 21: //�? case 22: break; case 23: @@ -213,6 +215,8 @@ void get_seconds_from_ntp_server(uint8_t *buf, uint16_t idx) //calculation for date calcdatetime(seconds); + + return rawSeconds; } void SNTP_init(uint8_t s, uint8_t *ntp_server, uint8_t tz, uint8_t *buf) @@ -262,7 +266,7 @@ int8_t SNTP_run(datetime *time) if (RSR_len > MAX_SNTP_BUF_SIZE) RSR_len = MAX_SNTP_BUF_SIZE; // if Rx data size is lager than TX_RX_MAX_BUF_SIZE recvfrom(NTP_SOCKET, data_buf, RSR_len, (uint8_t *)&destip, &destport); - get_seconds_from_ntp_server(data_buf,startindex); + time->seconds = get_seconds_from_ntp_server(data_buf,startindex); time->yy = Nowdatetime.yy; time->mo = Nowdatetime.mo; time->dd = Nowdatetime.dd; diff --git a/Internet/SNTP/sntp.h b/Internet/SNTP/sntp.h index cfc05b9..0afb99a 100644 --- a/Internet/SNTP/sntp.h +++ b/Internet/SNTP/sntp.h @@ -56,6 +56,7 @@ typedef struct _datetime uint8_t hh; uint8_t mm; uint8_t ss; + uint64_t seconds; } datetime; #define ntp_port 123 //ntp server port number @@ -63,7 +64,7 @@ typedef struct _datetime #define UTC_ADJ_HRS 9 // SEOUL : GMT+9 #define EPOCH 1900 // NTP start year -void get_seconds_from_ntp_server(uint8_t *buf, uint16_t idx); +uint64_t get_seconds_from_ntp_server(uint8_t *buf, uint16_t idx); void SNTP_init(uint8_t s, uint8_t *ntp_server, uint8_t tz, uint8_t *buf); int8_t SNTP_run(datetime *time); tstamp changedatetime_to_seconds(void);