21#ifndef __FPSDK_COMMON_TIME_HPP__
22#define __FPSDK_COMMON_TIME_HPP__
114 double TocMs(
const bool reset =
false);
117 std::chrono::time_point<std::chrono::steady_clock> t0_;
134 RosTime(
const uint32_t sec,
const uint32_t nsec);
502 GloTime(
const int N4,
const int Nt,
const double TOD);
535 UtcTime(
const int year,
const int month,
const int day,
const int hour,
const int min,
const double sec);
737 static Time FromClockTai();
Duration & operator+=(const int64_t nsec)
Add nanoseconds to durationn.
bool operator!=(const Duration &rhs) const
Not equal.
bool AddNSec(const int64_t nsec)
Add nanoseconds to duration.
Duration & operator+=(const double sec)
Add seconds to duration.
bool SetSecNSec(const int32_t sec, const int32_t nsec)
Set duration from seconds and nanoseconds.
Duration operator+(const double sec) const
Sum duration and seconds.
Duration operator*(double scale) const
Multiply (scale) duration.
Duration & operator-=(const int64_t nsec)
Subtract nanoseconds from duration.
static Duration FromSecNSec(const int32_t sec, const int32_t nsec)
Make Duration from seconds and nanoseconds.
int32_t sec_
Seconds part of duration.
static Duration FromNSec(const int64_t nsec)
Make Duration from nanoseconds.
bool IsZero() const
Check if duration is zero.
Duration operator-(const Duration &rhs) const
Subtract duration and duration.
bool SubDur(const Duration &dur)
Substract duration from duration.
bool operator<=(const Duration &rhs) const
Smaller or equal than.
void Sleep() const
Sleep for the duration (if > 0)
Duration()
Constructor, zero duration.
Duration & operator*=(double scale)
Multiply (scale) duration.
Duration & operator-=(const Duration &rhs)
Subtract duration from duration.
std::chrono::nanoseconds GetChronoNano() const
Get duration as std::chrono::nanoseconds.
bool SetSec(const double sec)
Set duration from seconds.
std::chrono::milliseconds GetChronoMilli() const
Get duration as std::chrono::milliseconds.
double GetSec(const int prec=9) const
Get duration as seconds.
Duration operator-(const double sec) const
Subtract duration and seconds.
bool AddDur(const Duration &dur)
Add duration to duration.
int64_t GetNSec() const
Get duration as nanoseconds.
bool SubSec(const double sec)
Substract seconds from duration.
bool operator>(const Duration &rhs) const
Greater than.
Duration operator-(const int64_t nsec) const
Subtract duration and nanoseconds.
bool AddSec(const double sec)
Add seconds to duration.
Duration & operator+=(const Duration &rhs)
Add duration to duration.
int32_t nsec_
Nanoseconds part of duration (should be in range 0-999999999)
bool Scale(const double sec)
Scale (multiply) duration.
Duration operator+(const Duration &rhs) const
Sum duration and duration.
std::string Stringify(const int prec=3) const
Stringify duration, for debugging.
Duration operator+(const int64_t nsec) const
Sum duration and nanoseconds.
bool SetNSec(const int64_t nsec)
Set duration from nanoseconds.
Duration operator-() const
Reverse sign.
bool SubNSec(const int64_t nsec)
Substract nanoseconds from duration.
static Duration FromSec(const double sec)
Make Duration from seconds.
bool operator==(const Duration &rhs) const
Equal.
Duration & operator-=(const double sec)
Subtract seconds from durationn.
bool operator>=(const Duration &rhs) const
Greater or equal than.
bool operator<(const Duration &rhs) const
Smaller than.
Helper to measure wallclock time.
double TocMs(const bool reset=false)
Get elapsed wallclock time in [ms].
Duration Toc(const bool reset=false)
Get elapsed wallclock time.
void Tic()
(Re-)start measurement
UtcTime GetUtcTime(const int prec=9) const
Get time as UTC time (UTC)
double GetDayOfYear(const int prec=12) const
Get day of year.
Time operator-(const Duration &rhs) const
Subtract time and duration.
bool SetUtcTime(const UtcTime &utctime)
Set time from UTC time (UTC)
std::string StrUtcTime(const int prec=3) const
Stringify as year, month, day, hour, minute and second time (UTC)
Time & operator+=(const int64_t nsec)
Add nanoseconds to time.
static Time FromSec(const double sec)
From seconds (atomic)
bool SetTai(const std::time_t tai)
Set time from TAI time (CLOCK_TAI)
bool SetClockRealtime()
Set time from system clock current (now) system time (CLOCK_REALTIME)
Time operator+(const Duration &rhs) const
Sum time and duration.
Time & operator+=(const double sec)
Add seconds to time.
bool SetPosix(const std::time_t posix)
Set time from POSIX time (POSIX, seconds)
bool operator<=(const Time &rhs) const
Smaller or equal than.
static const Time MIN
Minimum representable time.
GloTime GetGloTime(const int prec=9) const
Get time as GLONASS time (UTC + 3h)
static Time FromNSec(const uint64_t nsec)
Time from nanoseconds (atomic)
static const Time ZERO
Zero (invalid, uninitialised) time.
RosTime GetRosTime() const
Get time as ROS time (POSIX)
std::string StrWnoTow(const WnoTow::Sys sys=WnoTow::Sys::GPS, const int prec=3) const
Stringify as GNSS time (atomic)
static Time FromRosTime(const RosTime &rostime)
From ROS time (POSIX)
uint32_t nsec_
Nanoseconds part of time (should be in range 0-999999999)
int GetLeapseconds() const
Get leapseconds (TAI - UTC)
static Time FromPosix(const std::time_t posix)
From POSIX time (POSIX, seconds)
std::chrono::milliseconds GetChronoMilli() const
Get time as std::chrono::duration (milliseconds since epoch) (POSIX)
Time()
Constructor, empty (invalid) time.
bool SetCurrentLeapseconds(const int value) const
Set or change current leapseconds.
bool SetSec(const double sec)
Set time from seconds (atomic)
bool IsZero() const
Check if time is zero (invalid)
Time & operator-=(const int64_t nsec)
Subtract nanoseconds from time.
std::chrono::nanoseconds GetChronoNano() const
Get time as std::chrono::nanoseconds (nanoseconds since epoch) (POSIX)
bool SetGloTime(const GloTime &glotime)
Set time from GLONASS time (UTC + 3h)
bool SubDur(const Duration &dur)
Substract duration from time.
Duration operator-(const Time &rhs) const
Subtract time and time.
static Time FromPosixNs(const uint64_t posix_ns)
From POSIX time (POSIX, nanoseconds)
bool operator>(const Time &rhs) const
Greater than.
Time & operator-=(const Duration &rhs)
Subtract duration from time.
uint32_t sec_
Seconds part of time (atomic seconds since 1970-01-01 00:00:00 UTC)
static Time FromUtcTime(const UtcTime &utctime)
From UTC time (UTC)
static Time FromGloTime(const GloTime &glotime)
From GLONASS time (UTC + 3h)
bool SetPosixNs(const uint64_t posix_ns)
Set time from POSIX time (POSIX, nanoseconds)
bool SubSec(const double sec)
Substract seconds from time.
Time operator+(const int64_t nsec) const
Sum time and nanoseconds.
bool AddSec(const double sec)
Add seconds to time.
bool AddNSec(const int64_t nsec)
Add nanoseconds to time.
bool SubNSec(const int64_t nsec)
Substract nanoseconds from time.
bool operator<(const Time &rhs) const
Smaller than.
static Time FromSecNSec(const uint32_t sec, const uint32_t nsec)
Time from seconds and nanoseconds (atomic)
static Time FromTai(const std::time_t tai)
From TAI time (CLOCK_TAI)
bool Diff(const Time &other, Duration &diff) const
Calculate difference between times.
bool SetSecNSec(const uint32_t sec, const uint32_t nsec)
Set time from seconds and nanoseconds (atomic)
Time & operator-=(const double sec)
Subtract seconds from time.
uint64_t GetNSec() const
Get time as nanoseconds (atomic)
static Time FromWnoTow(const WnoTow &wnotow)
From GNSS time (atomic)
Time operator-(const double sec) const
Subtract time and seconds.
static Time FromClockRealtime()
From system clock current (now) system time (CLOCK_REALTIME)
Time & operator+=(const Duration &rhs)
Add duration to time.
double GetPosixSec(const int prec=9) const
Get time as POSIX seconds (POSIX)
bool SetRosTime(const RosTime &rostime)
Set time from ROS time (POSIX)
bool AddDur(const Duration &dur)
Add duration to time.
bool operator==(const Time &rhs) const
Equal.
static const Time MAX
Maximum representable time.
bool operator>=(const Time &rhs) const
Greater or equal than.
std::time_t GetPosix() const
Get time as POSIX time (POSIX, seconds)
bool SetNSec(const uint64_t nsec)
Set time from nanoseconds (atomic)
Time operator-(const int64_t nsec) const
Subtract time and nanoseconds.
bool SetWnoTow(const WnoTow &wnotow)
Set time from GNSS (GPS, Galileo, BeiDou) time (atomic)
static Time FromPosixSec(const double posix_sec)
From POSIX seconds (POSIX)
std::time_t GetTai() const
Get time as TAI time (CLOCK_TAI)
bool SetPosixSec(const double posix_sec)
Set time from POSIX seconds (POSIX)
bool operator!=(const Time &rhs) const
Not equal.
double GetSec(const int prec=9) const
Get time as seconds (atomic)
WnoTow GetWnoTow(const WnoTow::Sys sys=WnoTow::Sys::GPS, const int prec=9) const
Get time as GNSS (GPS, Galileo, BeiDou) time (atomic)
uint64_t GetPosixNs() const
Get time as POSIX time (POSIX, nanoseconds)
std::string StrIsoTime(const int prec=0) const
Stringify as ISO 8601 time (UTC)
Time operator+(const double sec) const
Sum time and seconds.
static constexpr int SEC_IN_MIN_I
Constants.
static constexpr double SEC_IN_MIN_D
Number of seconds in a minute (double) = 60.0.
static constexpr int SEC_IN_WEEK_I
Number of seconds in a week (integer) = 604800.
static constexpr double SEC_IN_WEEK_D
Number of seconds in a week (double) = 604800.0.
uint64_t GetMillis()
Get milliseconds [ms], monotonic time.
static constexpr int SEC_IN_DAY_I
Number of seconds in a day (integer) = 86400.
static constexpr double SEC_IN_HOUR_D
Number of seconds in an hour (double) = 3600.0.
static constexpr double SEC_IN_DAY_D
Number of seconds in a day (double) = 86400.0.
double GetSecs()
Get seconds [s], monotonic time.
static constexpr int SEC_IN_HOUR_I
Number of seconds in an hour (integer) = 3600.
static constexpr int SANE_NT_MIN
Minimum sane Nt_ value.
GloTime(const int N4, const int Nt, const double TOD)
Constructor.
static constexpr double SANE_TOD_MAX
Maximum sane TOD_ value.
int Nt_
Day in four-year interval (SANE_NT_MIN - SANE_NT_MAX)
double TOD_
Time of day (in Москва time zone) [s] (SANE_TOD_MIN - SANE_TOD_MAX)
int N4_
Four-year interval, 1=1996..1999, 2=2000..2003, ... (SANE_N4_MIN - SANE_N4_MAX)
static constexpr double SANE_TOD_MIN
Minimum sane TOD_ value.
static constexpr int SANE_NT_MAX
Maximum sane Nt_ value.
static constexpr int SANE_N4_MIN
Minimum sane N4_ value.
static constexpr int SANE_N4_MAX
Maximum sane N4_ value, good enough for the next centuries.
Minimal ros::Time() / rplcpp::Time implementation (that doesn't throw)
uint64_t ToNSec() const
Convert to nanoseconds.
bool operator==(const RosTime &rhs) const
Equal.
RosTime(const uint32_t sec, const uint32_t nsec)
Constructor.
uint32_t nsec_
Nanoseconds part of time (should be in range 0-999999999)
uint32_t sec_
Seconds part of time.
double ToSec() const
Convert to seconds.
bool IsZero() const
Check if time is zero (invalid, unset)
UtcTime(const int year, const int month, const int day, const int hour, const int min, const double sec)
Constructor.
GNSS atomic time representation: week number (wno) and time of week (tow) used by GPS,...
double tow_
Time of week [s] (SANE_TOW_MIN - SANE_TOW_MAX, if normalised)
static constexpr double SANE_TOW_MAX
Maximum sane tow_ value.
int wno_
Week number [-] (>= SANE_WNO_MIN, if normalised)
static constexpr int SANE_WNO_MIN
Minimum sane wno_ value.
static constexpr double SANE_TOW_MIN
Minimum sane tow_ value.
@ GPS
GPS (also: SBAS, QZSS)
@ GAL
Galileo system time (GST)
WnoTow(const Sys sys=Sys::GPS)
Constructor.
static constexpr int SANE_WNO_MAX
Maximum sane wno_ value, good enough for the next centuries.
WnoTow(const int wno, const double tow, const Sys sys=Sys::GPS)
Constructor.
const char * SysStr() const
Stringify time system (for debugging)