add seconds since epoch to datetime struct
This commit is contained in:
@ -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: //<2F><EFBFBD>?
|
||||
case 21: //<2F>?
|
||||
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;
|
||||
|
Reference in New Issue
Block a user