Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: UAVCAN UAVCAN_Subscriber
test_clock.cpp
00001 /* 00002 * Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com> 00003 */ 00004 00005 #include <iostream> 00006 #include <cerrno> 00007 #include <chrono> 00008 #include <uavcan_linux/uavcan_linux.hpp> 00009 00010 static std::string systime2str(const std::chrono::system_clock::time_point& tp) 00011 { 00012 const auto tt = std::chrono::system_clock::to_time_t(tp); 00013 return std::ctime(&tt); 00014 } 00015 00016 int main() 00017 { 00018 uavcan_linux::SystemClock clock; 00019 00020 /* 00021 * Auto-detected clock adjustment mode 00022 */ 00023 std::cout << "Clock adjustment mode: "; 00024 switch (clock.getAdjustmentMode()) 00025 { 00026 case uavcan_linux::ClockAdjustmentMode::SystemWide: 00027 { 00028 std::cout << "SystemWide"; 00029 break; 00030 } 00031 case uavcan_linux::ClockAdjustmentMode::PerDriverPrivate: 00032 { 00033 std::cout << "PerDriverPrivate"; 00034 break; 00035 } 00036 default: 00037 { 00038 std::abort(); 00039 break; 00040 } 00041 } 00042 std::cout << std::endl; 00043 00044 /* 00045 * Test adjustment 00046 */ 00047 double sec = 0; 00048 std::cout << "Enter system time adjustment in seconds (fractions allowed): " << std::endl; 00049 std::cin >> sec; 00050 00051 const auto before = std::chrono::system_clock::now(); 00052 try 00053 { 00054 clock.adjustUtc(uavcan::UtcDuration::fromUSec(sec * 1e6)); 00055 } 00056 catch (const uavcan_linux::Exception& ex) 00057 { 00058 std::cout << ex.what() << std::endl; 00059 std::cout << strerror(ex.getErrno()) << std::endl; 00060 return 1; 00061 } 00062 const auto after = std::chrono::system_clock::now(); 00063 00064 std::cout << "Time before: " << systime2str(before) << "\n" 00065 << "Time after: " << systime2str(after) << "\n" 00066 << "Millisecond diff (after - before): " 00067 << std::chrono::duration_cast<std::chrono::milliseconds>(after - before).count() << std::endl; 00068 00069 return 0; 00070 }
Generated on Tue Jul 12 2022 17:17:34 by
