Midnight Sun Firmware
Loading...
Searching...
No Matches
ntp_client.h
1#pragma once
2
3/************************************************************************************************
4 * @file ntp_client.h
5 *
6 * @brief Header file defining the NTPClient class
7 *
8 * @date 2025-01-04
9 * @author Aryan Kashem
10 ************************************************************************************************/
11
12/* Standard library Headers */
13#include <atomic>
14#include <chrono>
15#include <ctime>
16#include <string>
17
18/* Inter-component Headers */
19#include <arpa/inet.h>
20#include <fcntl.h>
21#include <pthread.h>
22#include <sys/socket.h>
23#include <unistd.h>
24
25#include "network_time_protocol.h"
26
27/* Intra-component Headers */
28
41class NTPClient {
42 private:
43 static constexpr int NTP_PORT = 123;
44 static constexpr int NTP_SYNC_PERIOD_S = 60;
47 std::string m_serverAddress;
50 std::atomic<bool> m_isSynchronizing;
52 public:
57 NTPClient();
58
63 void NTPClientProcedure();
64
70 void startSynchronization(const std::string &serverAddress);
71};
72
Class that represents the netowrk-time-protocol client that synchronizes with a server.
Definition: ntp_client.h:41
NTPPacket m_serverResponse
Definition: ntp_client.h:48
void NTPClientProcedure()
Thread procedure for handling NTP synchronization.
Definition: ntp_client.cc:20
static constexpr int NTP_PORT
Definition: ntp_client.h:43
std::string m_serverAddress
Definition: ntp_client.h:47
int m_NTPSocket
Definition: ntp_client.h:46
std::atomic< bool > m_isSynchronizing
Definition: ntp_client.h:50
static constexpr int NTP_SYNC_PERIOD_S
Definition: ntp_client.h:44
pthread_t m_NTPClientThreadId
Definition: ntp_client.h:49
void startSynchronization(const std::string &serverAddress)
Starts NTP synchronization of the client.
Definition: ntp_client.cc:91
NTPClient()
Constructs a NTPClient object.
Definition: ntp_client.cc:99
Structure representing an NTP packet.
Definition: network_time_protocol.h:68