PPS-Client  2.0.0
Client for synchronizing the system clock to a GPS PPS source
Classes | Macros | Functions | Variables
pps-sntp.cpp File Reference

This file contains functions and structures for accessing time updates via the NIST UDP time service. More...

#include "../client/pps-client.h"
Include dependency graph for pps-sntp.cpp:

Go to the source code of this file.

Classes

struct  nistLocalVars
 

Macros

#define ADDR_LEN   17
 

Functions

void copyToLog (char *logbuf, const char *msg)
 
int getNISTTime (int id, char *strbuf, char *logbuf, time_t *timeDiff, char *nistTime_file)
 
void doTimeCheck (timeCheckParams *tcp)
 
int getTimeConsensusAndCount (void)
 
void updateLog (char *buf, int numServers)
 
void makeNISTTimeQuery (timeCheckParams *tcp)
 
int allocInitializeNISTThreads (timeCheckParams *tcp)
 
void freeNISTThreads (timeCheckParams *tcp)
 

Variables

struct G g
 Declares the global variables defined in pps-client.h. More...
 
struct ppsFiles f
 PPS-Client internal files. More...
 

Detailed Description

This file contains functions and structures for accessing time updates via the NIST UDP time service.

Definition in file pps-sntp.cpp.

Macro Definition Documentation

◆ ADDR_LEN

#define ADDR_LEN   17

Definition at line 26 of file pps-sntp.cpp.

Function Documentation

◆ allocInitializeNISTThreads()

int allocInitializeNISTThreads ( timeCheckParams tcp)

Allocates memory and initializes threads that will be used by makeNISTTimeQuery() to query NIST time servers. Thread must be released and memory deleted by calling freeNISTThreads().

Parameters
[out]tcpStruct pointer for passing data.
Returns
0 on success or -1 on error.

Definition at line 371 of file pps-sntp.cpp.

Referenced by waitForPPS().

Here is the caller graph for this function:

◆ copyToLog()

void copyToLog ( char *  logbuf,
const char *  msg 
)

Definition at line 43 of file pps-sntp.cpp.

References STRBUF_SZ.

Referenced by getNISTTime().

Here is the caller graph for this function:

◆ doTimeCheck()

void doTimeCheck ( timeCheckParams tcp)

Requests a date/time from a NIST time server in a detached thread that exits after filling the timeCheckParams struct, tcp, with the requested information and any error info.

Parameters
[in,out]tcpstruct pointer for passing data.

Definition at line 167 of file pps-sntp.cpp.

References getNISTTime(), timeCheckParams::logbuf, LOGBUF_SZ, timeCheckParams::nistTime_file, timeCheckParams::serverIndex, timeCheckParams::serverTimeDiff, timeCheckParams::strbuf, STRBUF_SZ, and timeCheckParams::threadIsBusy.

Here is the call graph for this function:

◆ freeNISTThreads()

void freeNISTThreads ( timeCheckParams tcp)

Releases threads and deletes memory used by makeNISTTimeQuery();

Parameters
[in]tcpThe struct pointer that was used for passing data.

Definition at line 412 of file pps-sntp.cpp.

References timeCheckParams::attr, timeCheckParams::buf, timeCheckParams::logbuf, and timeCheckParams::strbuf.

Referenced by waitForPPS().

Here is the caller graph for this function:

◆ getNISTTime()

int getNISTTime ( int  id,
char *  strbuf,
char *  logbuf,
time_t *  timeDiff,
char *  nistTime_file 
)

Gets the time correction relative to the local clock setting in whole seconds provided by a NIST time server using the UDP protocol and queried by this shell command:

$ udp-time-client -u[n]

where [n] is the id described below. The timeDiff is assumed to be correct only if it is received within the current second. Because of internet delays and other errors UDP time servers do not always respond within a second. Consequently this function is used to query four timer serverss and a consensis of the possible error is obtained from them. The consensis error is added to the whole seconds of the system clock.

Parameters
[in]idAn identifer recognized by udp-time-client to select a server and used for constructing a filename for server messages. id is in the range 1 to 4.
[in]strbufA buffer to hold server messages.
[in]logbufA buffer to hold messages for the error log.
[out]timeDiffThe time correction to be made.
[in]nistTime_fileFilename to be used to transfer data from the shell to this program. Contains output from the udp-time-client shell command.
Returns
0 or -1 on error.

Definition at line 80 of file pps-sntp.cpp.

References copyToLog(), NIST_MSG_SZ, nistTime_file, num, sysCommand(), and writeFileMsgToLogbuf().

Referenced by doTimeCheck().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getTimeConsensusAndCount()

int getTimeConsensusAndCount ( void  )

Takes a consensus of the time error between local time and the time reported by NIST servers and reports the error as G.consensusTimeError.

Returns
The number of NIST servers reporting.

Definition at line 196 of file pps-sntp.cpp.

References MAX_SERVERS.

◆ makeNISTTimeQuery()

void makeNISTTimeQuery ( timeCheckParams tcp)

At an interval defined by CHECK_TIME, queries a list of NIST servers for date/time using detached threads so that delays in server responses do not affect the operation of the waitForPPS() loop.

Called each second.

Parameters
[in,out]tcpStruct pointer for passing data.

Definition at line 300 of file pps-sntp.cpp.

Referenced by waitForPPS().

Here is the caller graph for this function:

◆ updateLog()

void updateLog ( char *  buf,
int  numServers 
)

Updates the PPS-Client log with any errors reported by threads querying NIST time servers.

Parameters
[out]bufThe message buffer shared by the threads.
[in]numServersThe number of NIST servers.

Definition at line 277 of file pps-sntp.cpp.

References LOGBUF_SZ, and writeToLogNoTimestamp().

Here is the call graph for this function:

Variable Documentation

◆ f

struct ppsFiles f

◆ g

struct G g