diff --git a/common/util.cc b/common/util.cc index 5ffd6e4099..18da822334 100644 --- a/common/util.cc +++ b/common/util.cc @@ -12,6 +12,10 @@ #include #include #include +#include +#include +#include +#include #ifdef __linux__ #include @@ -271,4 +275,20 @@ std::string check_output(const std::string& command) { return result; } +const std::chrono::system_clock::time_point _MIN_DATE = std::chrono::system_clock::from_time_t(std::mktime(new std::tm{0, 0, 0, 30, 2, 2024 - 1900})); + +std::chrono::system_clock::time_point min_date() { + std::filesystem::path systemd_path("/lib/systemd/systemd"); + if (std::filesystem::exists(systemd_path)) { + auto ftime = std::filesystem::last_write_time(systemd_path); + auto stime = std::chrono::time_point_cast(ftime - std::filesystem::file_time_type::clock::now() + std::chrono::system_clock::now()); + return stime + std::chrono::hours(24); + } + return _MIN_DATE; +} + +bool system_time_valid() { + return std::chrono::system_clock::now() > min_date(); +} + } // namespace util diff --git a/common/util.h b/common/util.h index 186873ac21..c818db2ec1 100644 --- a/common/util.h +++ b/common/util.h @@ -99,6 +99,8 @@ inline void sleep_for(const int milliseconds) { } } +bool system_time_valid(); + } // namespace util class ExitHandler { diff --git a/selfdrive/ui/qt/maps/map.cc b/selfdrive/ui/qt/maps/map.cc index e5ac5480fb..cb494efb57 100644 --- a/selfdrive/ui/qt/maps/map.cc +++ b/selfdrive/ui/qt/maps/map.cc @@ -122,6 +122,8 @@ void MapWindow::updateState(const UIState &s) { const SubMaster &sm = *(s.sm); update(); + qDebug() << "time valid:" << util::system_time_valid(); + if (sm.updated("liveLocationKalman")) { auto locationd_location = sm["liveLocationKalman"].getLiveLocationKalman(); auto locationd_pos = locationd_location.getPositionGeodetic();