|
SatCat5
|
High-precision timestamp for use with PTP / IEEE1588.
The "Time" object can be used to represent a time-difference or an absolute time in the TAI epoch, matching the finest resolution supported by IEEE1588-2019.
The internal representation is based on increments of 1/65536 nanoseconds, which is referred to as a "subnanosecond" or "subns".
Definition at line 41 of file ptp_time.h.
#include <ptp_time.h>
Public Member Functions | |
| constexpr | Time () |
| Default constructor. | |
| constexpr | Time (s64 subnanoseconds) |
| Single argument constructor is scaled in subnanoseconds. More... | |
| constexpr | Time (const Time &other) |
| Copy constructor. | |
| Time (u64 seconds, u32 nanoseconds, u16 subnanoseconds=0) | |
| Multi-argument constructor accepts seconds, nanoseconds, and subnanosecods. More... | |
| s64 | field_secs () const |
| Read the "seconds" field without intermediate rounding. | |
| u32 | field_nsec () const |
| Read the "nanoseconds" field, rounding down. More... | |
| u64 | field_subns () const |
| Read the raw "subnanoseconds" field. More... | |
| s64 | round_secs () const |
| Return "seconds" field after rounding to the nearest nanosecond. More... | |
| u32 | round_nsec () const |
| Return "nanoseconds" field after rounding to the nearest nanosecond. | |
| bool | read_from (satcat5::io::Readable *src) |
| Read the standard 10-byte timestamp from a PTP message (e.g., originTimestamp: u48 seconds + u32 nanoseconds) Note: Add correctionField separately to maintain full precision. | |
| void | write_to (satcat5::io::Writeable *dst) const |
| Read or write the 10-byte timestamp from a PTP message. More... | |
| void | log_to (satcat5::log::LogBuffer &wr) const |
| User-readable format for logging. More... | |
| u64 | correction () const |
| Get the correctionField value in subnanoseconds. More... | |
| s64 | to_datetime () const |
| Convert to SatCat5 date/time. More... | |
| s64 | delta_subns () const |
| Convert time-differences to the designated unit. More... | |
| s64 | delta_nsec () const |
| Convert time-differences to the designated unit. More... | |
| s64 | delta_usec () const |
| Convert time-differences to the designated unit. More... | |
| s64 | delta_msec () const |
| Convert time-differences to the designated unit. More... | |
| satcat5::ptp::Time | abs () const |
| Standard arithmetic operations. | |
| void | operator+= (const satcat5::ptp::Time &other) |
| Standard arithmetic operations. | |
| void | operator-= (const satcat5::ptp::Time &other) |
| Standard arithmetic operations. | |
| satcat5::ptp::Time | operator= (const satcat5::ptp::Time &other) |
| Standard arithmetic operations. | |
| satcat5::ptp::Time | operator+ (const satcat5::ptp::Time &other) const |
| Standard arithmetic operations. | |
| satcat5::ptp::Time | operator- (const satcat5::ptp::Time &other) const |
| Standard arithmetic operations. | |
| satcat5::ptp::Time | operator- () const |
| Standard arithmetic operations. | |
| void | operator*= (unsigned scale) |
| Scalar multiply and divide are used for weighted averaging. More... | |
| void | operator/= (unsigned scale) |
| Scalar multiply and divide are used for weighted averaging. More... | |
| satcat5::ptp::Time | operator* (unsigned scale) const |
| Scalar multiply and divide are used for weighted averaging. More... | |
| satcat5::ptp::Time | operator/ (unsigned scale) const |
| Scalar multiply and divide are used for weighted averaging. More... | |
| bool | operator== (const satcat5::ptp::Time &other) const |
| Standard comparison operators. | |
| bool | operator< (const satcat5::ptp::Time &other) const |
| Standard comparison operators. | |
| bool | operator> (const satcat5::ptp::Time &other) const |
| Standard comparison operators. | |
| bool | operator!= (const satcat5::ptp::Time &other) const |
| Standard comparison operators. | |
| bool | operator<= (const satcat5::ptp::Time &other) const |
| Standard comparison operators. | |
| bool | operator>= (const satcat5::ptp::Time &other) const |
| Standard comparison operators. | |
Protected Member Functions | |
| void | normalize () |
Protected Attributes | |
| s64 | m_secs |
| s64 | m_subns |
|
inlineexplicitconstexpr |
Single argument constructor is scaled in subnanoseconds.
This matches the format used for the PTP "correction" field.
Definition at line 49 of file ptp_time.h.
| Time::Time | ( | u64 | seconds, |
| u32 | nanoseconds, | ||
| u16 | subnanoseconds = 0 |
||
| ) |
Multi-argument constructor accepts seconds, nanoseconds, and subnanosecods.
This matches the format used for the PTP "timestamp" field.
Definition at line 21 of file ptp_time.cc.
|
inline |
Get the correctionField value in subnanoseconds.
For use with field_sec, field_nsec, or write_to methods.
Definition at line 108 of file ptp_time.h.
| s64 Time::delta_msec | ( | ) | const |
Convert time-differences to the designated unit.
The representable range is always at least +/- 24 hours. Times beyond the safe range will return INT64_MIN or INT64_MAX.
Definition at line 61 of file ptp_time.cc.
| s64 Time::delta_nsec | ( | ) | const |
Convert time-differences to the designated unit.
The representable range is always at least +/- 24 hours. Times beyond the safe range will return INT64_MIN or INT64_MAX.
Definition at line 57 of file ptp_time.cc.
| s64 Time::delta_subns | ( | ) | const |
Convert time-differences to the designated unit.
The representable range is always at least +/- 24 hours. Times beyond the safe range will return INT64_MIN or INT64_MAX.
Definition at line 55 of file ptp_time.cc.
| s64 Time::delta_usec | ( | ) | const |
Convert time-differences to the designated unit.
The representable range is always at least +/- 24 hours. Times beyond the safe range will return INT64_MIN or INT64_MAX.
Definition at line 59 of file ptp_time.cc.
|
inline |
Read the "nanoseconds" field, rounding down.
Use this method in combination with
Definition at line 66 of file ptp_time.h.
|
inline |
Read the raw "subnanoseconds" field.
This is equal to 65536 * field_nsec() + correction()
Definition at line 70 of file ptp_time.h.
| void Time::log_to | ( | satcat5::log::LogBuffer & | wr | ) | const |
User-readable format for logging.
Definition at line 83 of file ptp_time.cc.
| Time Time::operator* | ( | unsigned | scale | ) | const |
Scalar multiply and divide are used for weighted averaging.
Do not use scaling factors larger than ~10000 or it may overflow.
Definition at line 195 of file ptp_time.cc.
| void Time::operator*= | ( | unsigned | scale | ) |
Scalar multiply and divide are used for weighted averaging.
Do not use scaling factors larger than ~10000 or it may overflow.
Definition at line 157 of file ptp_time.cc.
| Time Time::operator/ | ( | unsigned | scale | ) | const |
Scalar multiply and divide are used for weighted averaging.
Do not use scaling factors larger than ~10000 or it may overflow.
Definition at line 201 of file ptp_time.cc.
| void Time::operator/= | ( | unsigned | scale | ) |
Scalar multiply and divide are used for weighted averaging.
Do not use scaling factors larger than ~10000 or it may overflow.
Definition at line 164 of file ptp_time.cc.
|
inline |
Return "seconds" field after rounding to the nearest nanosecond.
If you use round_nsec, then you should also use round_sec.
Definition at line 75 of file ptp_time.h.
| s64 Time::to_datetime | ( | ) | const |
| void Time::write_to | ( | satcat5::io::Writeable * | dst | ) | const |
Read or write the 10-byte timestamp from a PTP message.
(e.g., originTimestamp: u48 seconds + u32 nanoseconds) Note: User must write correction to the PTP correctionField to maintain full end-to-end precision.
Definition at line 77 of file ptp_time.cc.