PPS-Client
2.0.0
Client for synchronizing the system clock to a GPS PPS source
|
This file contains functions and structures for accessing time updates via the NIST UDP time service. More...
#include "../client/pps-client.h"
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... | |
This file contains functions and structures for accessing time updates via the NIST UDP time service.
Definition in file pps-sntp.cpp.
#define ADDR_LEN 17 |
Definition at line 26 of file pps-sntp.cpp.
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().
[out] | tcp | Struct pointer for passing data. |
Definition at line 371 of file pps-sntp.cpp.
Referenced by waitForPPS().
void copyToLog | ( | char * | logbuf, |
const char * | msg | ||
) |
Definition at line 43 of file pps-sntp.cpp.
References STRBUF_SZ.
Referenced by getNISTTime().
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.
[in,out] | tcp | struct 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.
void freeNISTThreads | ( | timeCheckParams * | tcp | ) |
Releases threads and deletes memory used by makeNISTTimeQuery();
[in] | tcp | The 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().
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.
[in] | id | An 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] | strbuf | A buffer to hold server messages. |
[in] | logbuf | A buffer to hold messages for the error log. |
[out] | timeDiff | The time correction to be made. |
[in] | nistTime_file | Filename to be used to transfer data from the shell to this program. Contains output from the udp-time-client shell command. |
Definition at line 80 of file pps-sntp.cpp.
References copyToLog(), NIST_MSG_SZ, nistTime_file, num, sysCommand(), and writeFileMsgToLogbuf().
Referenced by doTimeCheck().
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.
Definition at line 196 of file pps-sntp.cpp.
References MAX_SERVERS.
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.
[in,out] | tcp | Struct pointer for passing data. |
Definition at line 300 of file pps-sntp.cpp.
Referenced by waitForPPS().
void updateLog | ( | char * | buf, |
int | numServers | ||
) |
Updates the PPS-Client log with any errors reported by threads querying NIST time servers.
[out] | buf | The message buffer shared by the threads. |
[in] | numServers | The number of NIST servers. |
Definition at line 277 of file pps-sntp.cpp.
References LOGBUF_SZ, and writeToLogNoTimestamp().
struct ppsFiles f |
PPS-Client internal files.
PPS-Client internal files.
Definition at line 58 of file pps-files.cpp.
Referenced by accessDaemon(), createPIDfile(), daemonSaveArray(), getChildPID(), getConfigs(), getLinuxVersion(), getRootHome(), getRPiCPU(), getSharedConfigs(), loadLastState(), ppsIsRunning(), processWriteRequest(), saveLastState(), showStatusEachSecond(), writeStatusStrings(), writeTimestamp(), writeToLog(), and writeToLogNoTimestamp().
struct G g |
Declares the global variables defined in pps-client.h.
Definition at line 53 of file pps-client.cpp.
Referenced by buildRawErrorDistrib(), clampJitter(), detectDelaySpike(), detectExteralSystemClockChange(), detectMissedPPS(), doTimeFixups(), getAcquireState(), getIntegral(), getMovingAverage(), getTimeSlew(), initialize(), integralIsReady(), main(), makeAverageIntegral(), makeTimeCorrection(), readPPS_SetTime(), removeNoise(), savePPStime(), setClockFractionalSecond(), setClockToGPStime(), setClocktoNISTtime(), setHardLimit(), setSyncDelay(), and waitForPPS().