Other Parts Discussed in Thread: EK-TM4C1294XL
Thread 中讨论的其他器件:EK-TM4C1294XL
工具/软件:TI-RTOS
您好!
我将 EK-TM4C1294XL 板与 TI-RTOS 版本2.16.1.14配合使用、并使用 https 示例。
在初始化 https 任务时,调用函数 startNTP (),并接收当前时间。 现在、我想在运行时更改 NTP 地址并使用此新 NTP 地址。 但每次我再次调用 startNTP 函数时、getaddrinfo 函数都会返回-2、并且我无法使用新的 NTP 地址。
要更新 NTP 地址、我需要做什么?
void startntp (void)(空)
{
内转台;
Int 电流位置;
time_t ts;
struct sockaddr_in ntpAddr;
struct addrinfo 提示;
struct addrinfo *Addrs;
struct addrinfo *currAddr;
Semaphore_Params semParams;
//semaphore_pend (semNtpHandle、BIOS_WAIT_FOREVE);
memset (&hinds、0、sizeof (struct addrinfo));
hines.ai_family = AF_iNet;
hints.ai_socktype = sock_DGRAM;
RET = getaddrinfo (ntp_Hostname、ntp_port、NULL、Addr);
如果(ret!= 0){
printError ("startNTP:NTP 主机无法解析!"、ret);
返回;
}
currPos = 0;
对于(currAddr = Addr;currAddr!= NULL;currAddr = currAddr->ai_next)
{
if (currPos < ntp_servers_size)
{
ntpAddr =*(struct sockaddr_in *)(currAddr->ai_addr);
memcpy (ntpServers + currPos、&ntpAddr、sizeof (struct sockaddr_in));
currPos += sizeof (struct sockaddr_in);
}
否则{
中断;
}
}
freedrinfo (地址);
RET = SNTP (seconds_get、seconds_set、timeUpdateHook、(struct sockaddr *)&ntpServers、ntpservers、 0);
如果(ret =0){
printError ("startntp:SNTP cannot be started!"、-1);
}
Semaphore_Params_init (semParams);
semParams.mode = Semaphore_Mode_binary;
SemHandle = Semaphore_create (0、SemParams、NULL);
if (semHandle == NULL){
printError ("startNTP:无法创建信标!"、-1);
}
sntp_forceTimeSync();
bool 超时= Semaphore_pend (semHandle、1000);
//超时=0 -> Keine NTP Verbindung
//超时== 1 -> Erfoldreiche NTP Verbindung
TS =时间(空);
systime = ts;
System_printf ("当前时间:%s\n"、ctim(&ts));
system_flush();
}