timesync.cxx
1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <string>
#include <thread>
#include "uav_core.h"
#include "uav_logger.h"
#include "uav_platform.h"
#include "uav_data_type.h"
#include "uav_time_sync.h"
#include "uav_sdk_app_info.h"
static void timesync_routine(void)
{
int64_t timestamp = 0;
UAV_TimeSync_Init();
//wait register success
if(false == wait_register_ready(100)){
LOG_ERROR("waitHandShakeRegister failed");
return;
}
while(1)
{
if(true == UAV_TimeSync_NTP(timestamp))
LOG_INFO("timestamp:{}", timestamp);
else
LOG_ERROR("UAV_TimeSync_NTP failed");
std::this_thread::sleep_for(std::chrono::seconds(1));
}
}
int main(int argc, char *argv[])
{
T_AUserInfo usrInfo;
logger_init(std::string(argv[1]));
if(false == uav_sdk_app_info_init(&usrInfo)) {
LOG_ERROR("uav_sdk_app_info_init failed");
return -1;
}
UAV_Core_Init(&usrInfo);
UAV_Core_SetAlias("timeSync");
// UAV_Uart_Init("/dev/pts/20",115200);
UAV_Network_Init(LOCALHOST_ETHERNET);
std::thread timesync(timesync_routine);
timesync.detach();
return UAV_Core_ApplicationStart();
}