Compare commits
2 Commits
f8730808d1
...
WolfgangsO
Author | SHA1 | Date | |
---|---|---|---|
0957fc4830
|
|||
27f646860d |
@@ -71,7 +71,7 @@ uint16_t ntp_retry_cnt=0; //counting the ntp retry number
|
|||||||
48) UTC+13:00 Tonga
|
48) UTC+13:00 Tonga
|
||||||
49) UTC+14:00 Kiribati (Line Islands)
|
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;
|
tstamp seconds = 0;
|
||||||
uint8_t i=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];
|
seconds = (seconds << 8) | buf[idx + i];
|
||||||
}
|
}
|
||||||
|
uint64_t rawSeconds = seconds;
|
||||||
|
|
||||||
switch (time_zone)
|
switch (time_zone)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
@@ -132,7 +134,7 @@ void get_seconds_from_ntp_server(uint8_t *buf, uint16_t idx)
|
|||||||
case 20:
|
case 20:
|
||||||
seconds -= 1*3600;
|
seconds -= 1*3600;
|
||||||
break;
|
break;
|
||||||
case 21: //<2F><EFBFBD>?
|
case 21: //<2F>?
|
||||||
case 22:
|
case 22:
|
||||||
break;
|
break;
|
||||||
case 23:
|
case 23:
|
||||||
@@ -213,6 +215,8 @@ void get_seconds_from_ntp_server(uint8_t *buf, uint16_t idx)
|
|||||||
|
|
||||||
//calculation for date
|
//calculation for date
|
||||||
calcdatetime(seconds);
|
calcdatetime(seconds);
|
||||||
|
|
||||||
|
return rawSeconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SNTP_init(uint8_t s, uint8_t *ntp_server, uint8_t tz, uint8_t *buf)
|
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
|
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);
|
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->yy = Nowdatetime.yy;
|
||||||
time->mo = Nowdatetime.mo;
|
time->mo = Nowdatetime.mo;
|
||||||
time->dd = Nowdatetime.dd;
|
time->dd = Nowdatetime.dd;
|
||||||
|
@@ -56,6 +56,7 @@ typedef struct _datetime
|
|||||||
uint8_t hh;
|
uint8_t hh;
|
||||||
uint8_t mm;
|
uint8_t mm;
|
||||||
uint8_t ss;
|
uint8_t ss;
|
||||||
|
uint64_t seconds;
|
||||||
} datetime;
|
} datetime;
|
||||||
|
|
||||||
#define ntp_port 123 //ntp server port number
|
#define ntp_port 123 //ntp server port number
|
||||||
@@ -63,7 +64,7 @@ typedef struct _datetime
|
|||||||
#define UTC_ADJ_HRS 9 // SEOUL : GMT+9
|
#define UTC_ADJ_HRS 9 // SEOUL : GMT+9
|
||||||
#define EPOCH 1900 // NTP start year
|
#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);
|
void SNTP_init(uint8_t s, uint8_t *ntp_server, uint8_t tz, uint8_t *buf);
|
||||||
int8_t SNTP_run(datetime *time);
|
int8_t SNTP_run(datetime *time);
|
||||||
tstamp changedatetime_to_seconds(void);
|
tstamp changedatetime_to_seconds(void);
|
||||||
|
4
Makefile
4
Makefile
@@ -2,7 +2,7 @@ WIZCHIP?=W5500
|
|||||||
ENABLE_DHCP?=yes
|
ENABLE_DHCP?=yes
|
||||||
ENABLE_DNS?=yes
|
ENABLE_DNS?=yes
|
||||||
ENABLE_HTTPSERVER?=yes
|
ENABLE_HTTPSERVER?=yes
|
||||||
ENABLE_MQTT?=yes
|
ENABLE_MQTT?=no
|
||||||
ENABLE_SNTP?=yes
|
ENABLE_SNTP?=yes
|
||||||
|
|
||||||
CFLAGS?=-mcpu=cortex-m3 -mthumb -Og -fdata-sections -ffunction-sections -g -gdwarf-2
|
CFLAGS?=-mcpu=cortex-m3 -mthumb -Og -fdata-sections -ffunction-sections -g -gdwarf-2
|
||||||
@@ -51,9 +51,9 @@ endif
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
all: $(OBJS)
|
all: $(OBJS)
|
||||||
$(AR) rcs w5500.a $^
|
$(AR) rcs w5500.a $^
|
||||||
|
cp w5500.a ../build/
|
||||||
|
|
||||||
$(OBJDIR)/%.o: %.c
|
$(OBJDIR)/%.o: %.c
|
||||||
$(CC) $(CFLAGS) -c $< -o $@
|
$(CC) $(CFLAGS) -c $< -o $@
|
||||||
|
Reference in New Issue
Block a user