Midnight Sun Firmware
Loading...
Searching...
No Matches
NTPClient

Class that represents the netowrk-time-protocol client that synchronizes with a server. More...

#include <ntp_client.h>

Collaboration diagram for NTPClient:

Public Member Functions

 NTPClient ()
 Constructs a NTPClient object. More...
 
void NTPClientProcedure ()
 Thread procedure for handling NTP synchronization. More...
 
void startSynchronization (const std::string &serverAddress)
 Starts NTP synchronization of the client. More...
 

Private Attributes

int m_NTPSocket
 
std::string m_serverAddress
 
NTPPacket m_serverResponse
 
pthread_t m_NTPClientThreadId
 
std::atomic< bool > m_isSynchronizing
 

Static Private Attributes

static constexpr int NTP_PORT = 123
 
static constexpr int NTP_SYNC_PERIOD_S = 60
 

Detailed Description

Class that represents the netowrk-time-protocol client that synchronizes with a server.

This class is responsible for fetching stratum 2 time and synchronizing itself The client shall account for timing errors/differences every NTP_SYNC_PERIOD_S

Constructor & Destructor Documentation

◆ NTPClient()

NTPClient ( )

Constructs a NTPClient object.

Initializes the NTP client. The constructor sets up internal variables

Member Function Documentation

◆ NTPClientProcedure()

void NTPClientProcedure ( )

Thread procedure for handling NTP synchronization.

This thread shall run at the NTP_SYNC_PERIOD_S frequency

◆ startSynchronization()

void startSynchronization ( const std::string &  serverAddress)

Starts NTP synchronization of the client.

This function will spawn the NTPClientProcedure thread

Parameters
serverAddressThe address of the NTP server to bind to

Member Data Documentation

◆ m_isSynchronizing

std::atomic<bool> m_isSynchronizing
private

Boolean flag to indicate the synchronization status of the client

◆ m_NTPClientThreadId

pthread_t m_NTPClientThreadId
private

Thread Id for synchronizing the client

◆ m_NTPSocket

int m_NTPSocket
private

The NTP servers socket FD

◆ m_serverAddress

std::string m_serverAddress
private

The NTP servers address for fetching stratum 2 data (ie: 127.0.0.1)

◆ m_serverResponse

NTPPacket m_serverResponse
private

NTP Packet to store the servers timing data

◆ NTP_PORT

constexpr int NTP_PORT = 123
staticconstexprprivate

Universal port for network-time-protocol

◆ NTP_SYNC_PERIOD_S

constexpr int NTP_SYNC_PERIOD_S = 60
staticconstexprprivate

Client synchronization period


The documentation for this class was generated from the following files: