oveRTOS C++ API
C++20 RAII wrappers for the oveRTOS C API
Loading...
Searching...
No Matches
net_sntp.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2026 Kamil Lulko <kamil.lulko@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 *
6 * This file is part of oveRTOS.
7 */
8
14#pragma once
15
16#include <ove/net_sntp.h>
17#include <ove/error.hpp>
18
19#ifdef CONFIG_OVE_NET_SNTP
20
21namespace ove::sntp
22{
23
33struct Config {
34 const char *server{"pool.ntp.org"};
35 uint64_t timeout_ns{OVE_SEC(5)};
36};
37
44[[nodiscard]] inline Result<void> sync(const Config &cfg = {}) noexcept
45{
46 ove_sntp_config_t c{cfg.server, cfg.timeout_ns};
47 return from_rc(ove_sntp_sync(&c));
48}
49
56[[nodiscard]] inline Result<int64_t> get_offset_us() noexcept
57{
58 int64_t offset_us = 0;
59 const int rc = ove_sntp_get_offset_us(&offset_us);
60 return from_rc(rc, offset_us);
61}
62
68[[nodiscard]] inline Result<uint32_t> get_utc() noexcept
69{
70 uint32_t utc_s = 0;
71 const int rc = ove_sntp_get_utc(&utc_s);
72 return from_rc(rc, utc_s);
73}
74
75} /* namespace ove::sntp */
76
77#endif /* CONFIG_OVE_NET_SNTP */
Strong ove::Error type, Result<T> alias, and std::error_code interop for the oveRTOS C++ binding.
C++ wrappers around the oveRTOS SNTP client API.
Definition net_sntp.hpp:22
Result< uint32_t > get_utc() noexcept
Get current UTC time in seconds since Unix epoch.
Definition net_sntp.hpp:68
Result< void > sync(const Config &cfg={}) noexcept
Synchronize with an NTP time server.
Definition net_sntp.hpp:44
Result< int64_t > get_offset_us() noexcept
Get the UTC offset from the last successful sync.
Definition net_sntp.hpp:56
Result< void > from_rc(int rc) noexcept
Lifts a substrate rc-code into a Result<void>.
Definition error.hpp:254
std::expected< T, Error > Result
std::expected-based result alias.
Definition error.hpp:139
SNTP client configuration with C++ defaults.
Definition net_sntp.hpp:33
uint64_t timeout_ns
Definition net_sntp.hpp:35
const char * server
Definition net_sntp.hpp:34