ptp同步:
用ptpd。对应的网口打开时钟协议即可。
时间戳格式化输出:
// 秒 毫秒 微秒 纳秒
std::cout << "i++ status :timestamp count" << scans[i].headers.at(102).timestamp.count() << std::endl;// 纳秒
int nacro = scans[i].headers.at(102).timestamp.count() % 1000000000; //纳秒
int micro = (scans[i].headers.at(102).timestamp.count() / 1000000) % 1000; //毫秒
time_t timeT = scans[i].headers.at(102).timestamp.count() / 1000000000; // 秒
struct tm* pTm;
pTm = localtime(&timeT);
char strTime[100];
sprintf(strTime, "%d-%02d-%02d %02d:%02d:%02d.%09d", 1900 + pTm->tm_year, 1 + pTm->tm_mon, pTm->tm_mday, pTm->tm_hour, pTm->tm_min, pTm->tm_sec, nacro);
std::cout << "i++ status :timestamp 格式化:" << strTime << std::endl;
char strTime2[100];
sprintf(strTime2, "%d-%02d-%02d %02d:%02d:%02d.%09d", pTm->tm_year, pTm->tm_mon, pTm->tm_mday, pTm->tm_hour, pTm->tm_min, pTm->tm_sec, nacro);
std::cout << "i++ status :timestamp 格式化:" << strTime2 << std::endl;