Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Inc/HALAL/Services/Communication/SNTP/SNTP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ class SNTP{
public:
static void sntp_update(uint8_t address_head, uint8_t address_second, uint8_t address_third, uint8_t address_last);
static void sntp_update(string ip);
static void sntp_update();

};
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ EXTERNC u32_t get_rtc_us();
#define SUBSECONDS_PER_SECOND 32767
#define TRANSFORMATION_FACTOR (SUBSECONDS_PER_SECOND/999999.0)
#define SNTP_COMP_ROUNDTRIP 1
#define SNTP_UPDATE_DELAY 3600000
#define SNTP_UPDATE_DELAY 60000

void set_time(uint32_t sec, uint32_t us){
struct timeval tv;
Expand Down
1 change: 1 addition & 0 deletions Src/HALAL/HALAL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ void HALAL::start(string ip, string subnet_mask, string gateway, UART::Periphera

#ifdef HAL_TIM_MODULE_ENABLED
Encoder::start();
SNTP::sntp_update();
Time::start_rtc();
TimerPeripheral::start();
Time::start();
Expand Down
15 changes: 15 additions & 0 deletions Src/HALAL/Services/Communication/SNTP/SNTP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#define SUBSECONDS_PER_SECOND 32767
#define TRANSFORMATION_FACTOR (SUBSECONDS_PER_SECOND/999999.0)
#define TARGET_IP "192.168.1.3"

void SNTP::sntp_update(uint8_t address_head, uint8_t address_second, uint8_t address_third, uint8_t address_last){
sntp_setoperatingmode(SNTP_OPMODE_POLL);
Expand All @@ -23,6 +24,20 @@ void SNTP::sntp_update(uint8_t address_head, uint8_t address_second, uint8_t add
sntp_init();
}

void SNTP::sntp_update(string ip) {
sntp_setoperatingmode(SNTP_OPMODE_POLL);
IPV4 target(ip);
sntp_setserver(0,&target.address);
sntp_init();
}

void SNTP::sntp_update(){
sntp_setoperatingmode(SNTP_OPMODE_POLL);
IPV4 target(TARGET_IP);
sntp_setserver(0,&target.address);
sntp_init();
}

void set_rtc(uint16_t counter, uint8_t second, uint8_t minute, uint8_t hour, uint8_t day, uint8_t month, uint16_t year){
Time::set_rtc_data(counter, second, minute, hour, day, month, year);
}
Expand Down