Skip to content

Commit 6a09f9b

Browse files
Merge pull request #269 from HyperloopUPV-H8/fix/sntp
changes to work on ST-LIB::start()
2 parents ae1c283 + 8c1a676 commit 6a09f9b

4 files changed

Lines changed: 18 additions & 1 deletion

File tree

Inc/HALAL/Services/Communication/SNTP/SNTP.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ class SNTP{
1313
public:
1414
static void sntp_update(uint8_t address_head, uint8_t address_second, uint8_t address_third, uint8_t address_last);
1515
static void sntp_update(string ip);
16+
static void sntp_update();
1617

1718
};

Middlewares/Third_Party/LwIP/src/include/lwip/apps/sntp_opts.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ EXTERNC u32_t get_rtc_us();
5656
#define SUBSECONDS_PER_SECOND 32767
5757
#define TRANSFORMATION_FACTOR (SUBSECONDS_PER_SECOND/999999.0)
5858
#define SNTP_COMP_ROUNDTRIP 1
59-
#define SNTP_UPDATE_DELAY 3600000
59+
#define SNTP_UPDATE_DELAY 60000
6060

6161
void set_time(uint32_t sec, uint32_t us){
6262
struct timeval tv;

Src/HALAL/HALAL.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ void HALAL::start(string ip, string subnet_mask, string gateway, UART::Periphera
6363

6464
#ifdef HAL_TIM_MODULE_ENABLED
6565
Encoder::start();
66+
SNTP::sntp_update();
6667
Time::start_rtc();
6768
TimerPeripheral::start();
6869
Time::start();

Src/HALAL/Services/Communication/SNTP/SNTP.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#define SUBSECONDS_PER_SECOND 32767
1616
#define TRANSFORMATION_FACTOR (SUBSECONDS_PER_SECOND/999999.0)
17+
#define TARGET_IP "192.168.1.3"
1718

1819
void SNTP::sntp_update(uint8_t address_head, uint8_t address_second, uint8_t address_third, uint8_t address_last){
1920
sntp_setoperatingmode(SNTP_OPMODE_POLL);
@@ -23,6 +24,20 @@ void SNTP::sntp_update(uint8_t address_head, uint8_t address_second, uint8_t add
2324
sntp_init();
2425
}
2526

27+
void SNTP::sntp_update(string ip) {
28+
sntp_setoperatingmode(SNTP_OPMODE_POLL);
29+
IPV4 target(ip);
30+
sntp_setserver(0,&target.address);
31+
sntp_init();
32+
}
33+
34+
void SNTP::sntp_update(){
35+
sntp_setoperatingmode(SNTP_OPMODE_POLL);
36+
IPV4 target(TARGET_IP);
37+
sntp_setserver(0,&target.address);
38+
sntp_init();
39+
}
40+
2641
void set_rtc(uint16_t counter, uint8_t second, uint8_t minute, uint8_t hour, uint8_t day, uint8_t month, uint16_t year){
2742
Time::set_rtc_data(counter, second, minute, hour, day, month, year);
2843
}

0 commit comments

Comments
 (0)