NTP client for measuring time offset.
More...
#include <ntp_client.hpp>
|
| | NtpClient (std::string server="pool.ntp.org", int port=123) |
| | Constructs NTP client with specified host and port.
|
| |
| bool | query () |
| | Queries the NTP server and updates the local offset.
|
| |
| bool | success () const noexcept |
| | Returns whether the last NTP query was successful.
|
| |
| int64_t | offset_us () const noexcept |
| | Returns the last measured offset in microseconds.
|
| |
| int64_t | delay_us () const noexcept |
| | Returns the last measured delay in microseconds.
|
| |
| int | stratum () const noexcept |
| | Returns the last received stratum value.
|
| |
| int64_t | utc_time_us () const noexcept |
| | Returns current UTC time in microseconds based on last NTP offset.
|
| |
| int64_t | utc_time_ms () const noexcept |
| | Returns current UTC time in milliseconds based on last NTP offset.
|
| |
| time_t | utc_time_sec () const noexcept |
| | Returns current UTC time as time_t (seconds since Unix epoch).
|
| |
| int | last_error_code () const noexcept |
| | Returns last socket error code (if any).
|
| |
| | NtpClient () |
| |
| | NtpClient () |
| |
NTP client for measuring time offset.
Definition at line 43 of file ntp_client.hpp.
◆ NtpClient() [1/3]
| time_shield::NtpClient::NtpClient |
( |
std::string | server = "pool.ntp.org", |
|
|
int | port = 123 ) |
|
inline |
Constructs NTP client with specified host and port.
- Parameters
-
| server | NTP server host name. |
| port | NTP server port. |
Definition at line 48 of file ntp_client.hpp.
◆ NtpClient() [2/3]
| time_shield::NtpClient::NtpClient |
( |
| ) |
|
|
inline |
◆ NtpClient() [3/3]
| time_shield::NtpClient::NtpClient |
( |
| ) |
|
|
inline |
◆ delay_us()
| int64_t time_shield::NtpClient::delay_us |
( |
| ) |
const |
|
inlinenoexcept |
Returns the last measured delay in microseconds.
- Returns
- Round-trip delay estimate in microseconds.
Definition at line 117 of file ntp_client.hpp.
◆ last_error_code()
| int time_shield::NtpClient::last_error_code |
( |
| ) |
const |
|
inlinenoexcept |
Returns last socket error code (if any).
- Returns
- Error code from last query attempt.
Definition at line 137 of file ntp_client.hpp.
◆ last_error_code_slot()
| static int & time_shield::NtpClient::last_error_code_slot |
( |
| ) |
|
|
inlinestaticprivatenoexcept |
◆ offset_us()
| int64_t time_shield::NtpClient::offset_us |
( |
| ) |
const |
|
inlinenoexcept |
Returns the last measured offset in microseconds.
- Returns
- Offset in microseconds (UTC - local realtime).
Definition at line 113 of file ntp_client.hpp.
◆ query()
| bool time_shield::NtpClient::query |
( |
| ) |
|
|
inline |
Queries the NTP server and updates the local offset.
- Returns
- True when response parsed successfully.
- Note
- Requires network connectivity and a reachable server.
Definition at line 61 of file ntp_client.hpp.
◆ stratum()
| int time_shield::NtpClient::stratum |
( |
| ) |
const |
|
inlinenoexcept |
Returns the last received stratum value.
- Returns
- NTP stratum value.
Definition at line 121 of file ntp_client.hpp.
◆ success()
| bool time_shield::NtpClient::success |
( |
| ) |
const |
|
inlinenoexcept |
Returns whether the last NTP query was successful.
- Returns
- True when the last query updated internal state.
Definition at line 109 of file ntp_client.hpp.
◆ utc_time_ms()
| int64_t time_shield::NtpClient::utc_time_ms |
( |
| ) |
const |
|
inlinenoexcept |
Returns current UTC time in milliseconds based on last NTP offset.
- Returns
- UTC time in milliseconds using last offset.
Definition at line 129 of file ntp_client.hpp.
◆ utc_time_sec()
| time_t time_shield::NtpClient::utc_time_sec |
( |
| ) |
const |
|
inlinenoexcept |
Returns current UTC time as time_t (seconds since Unix epoch).
- Returns
- UTC time in seconds since Unix epoch.
Definition at line 133 of file ntp_client.hpp.
◆ utc_time_us()
| int64_t time_shield::NtpClient::utc_time_us |
( |
| ) |
const |
|
inlinenoexcept |
Returns current UTC time in microseconds based on last NTP offset.
- Returns
- UTC time in microseconds using last offset.
Definition at line 125 of file ntp_client.hpp.
◆ k_default_timeout_ms
| const int time_shield::NtpClient::k_default_timeout_ms = 5000 |
|
staticprivate |
◆ m_delay_us
| std::atomic<int64_t> time_shield::NtpClient::m_delay_us |
|
private |
◆ m_host
| std::string time_shield::NtpClient::m_host |
|
private |
◆ m_is_success
| std::atomic<bool> time_shield::NtpClient::m_is_success |
|
private |
◆ m_offset_us
| std::atomic<int64_t> time_shield::NtpClient::m_offset_us |
|
private |
◆ m_port
| int time_shield::NtpClient::m_port |
|
private |
◆ m_stratum
| std::atomic<int> time_shield::NtpClient::m_stratum |
|
private |
The documentation for this class was generated from the following file: