virtual void adjustUtc(uavcan::UtcDuration adjustment) { assert(this); const uint64_t prev_utc = utc; utc = uint64_t(int64_t(utc) + adjustment.toUSec()); last_adjustment = adjustment; std::cout << "Clock adjustment " << prev_utc << " --> " << utc << std::endl; }
bool performGradualAdjustment(const uavcan::UtcDuration adjustment) { gradual_adj_cnt_++; const std::int64_t usec = adjustment.toUSec(); timeval tv; tv.tv_sec = usec / Int1e6; tv.tv_usec = usec % Int1e6; return adjtime(&tv, nullptr) == 0; }
bool performStepAdjustment(const uavcan::UtcDuration adjustment) { step_adj_cnt_++; const std::int64_t usec = adjustment.toUSec(); timeval tv; if (gettimeofday(&tv, NULL) != 0) { return false; } tv.tv_sec += usec / Int1e6; tv.tv_usec += usec % Int1e6; return settimeofday(&tv, nullptr) == 0; }