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

The pps-sntp.cpp file contains functions and structures for accessing time updates via SNTP. More...

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

Go to the source code of this file.

Data Structures

struct  sntpLocalVars
 

Macros

#define ADDR_LEN   17
 

Functions

int allocNTPServerList (timeCheckParams *tcp)
 
void copyToLog (char *logbuf, const char *msg)
 
time_t getServerTime (const char *server, int id, char *strbuf, char *logbuf)
 
void doTimeCheck (timeCheckParams *tcp)
 
int getTimeConsensusAndCount (void)
 
void updateLog (char *buf, int numServers)
 
void makeSNTPTimeQuery (timeCheckParams *tcp)
 
int allocInitializeSNTPThreads (timeCheckParams *tcp)
 
void freeSNTPThreads (timeCheckParams *tcp)
 

Variables

struct G g
 Declares the global variables defined in pps-client.h. More...
 
const char * srv0 = "0.debian.pool.ntp.org"
 
const char * srv1 = "1.debian.pool.ntp.org"
 
const char * srv2 = "2.debian.pool.ntp.org"
 
const char * srv3 = "3.debian.pool.ntp.org"
 

Detailed Description

The pps-sntp.cpp file contains functions and structures for accessing time updates via SNTP.

Copyright (C) 2016-2018 Raymond S. Connell

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

Definition in file pps-sntp.cpp.

Macro Definition Documentation

◆ ADDR_LEN

#define ADDR_LEN   17

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

Function Documentation

◆ allocInitializeSNTPThreads()

int allocInitializeSNTPThreads ( timeCheckParams tcp)

Allocates memory and initializes threads that will be used by makeSNTPTimeQuery() to query SNTP time servers. Thread must be released and memory deleted by calling freeSNTPThreads().

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

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

Here is the caller graph for this function:

◆ allocNTPServerList()

int allocNTPServerList ( timeCheckParams tcp)

Allocates memory, reads the list of NTP servers above and partitions the memory into an array of server addresses that are returned by tcp->ntp_server[].

The memory MUST be released by the caller by calling "delete" on the tcp->buf param. That automatically frees the tcp->ntp_server[] array memory.

Parameters
[out]tcpStruct pointer for passing data to a thread.
Returns
The number of server addresses or -1 on error.

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

◆ copyToLog()

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

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

Here is the caller graph for this function:

◆ doTimeCheck()

void doTimeCheck ( timeCheckParams tcp)

Requests a date/time from an SNTP 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 233 of file pps-sntp.cpp.

Here is the call graph for this function:

◆ freeSNTPThreads()

void freeSNTPThreads ( timeCheckParams tcp)

Releases threads and deletes memory used by makeSNTPTimeQuery();

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

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

Here is the caller graph for this function:

◆ getServerTime()

time_t getServerTime ( const char *  server,
int  id,
char *  strbuf,
char *  logbuf 
)

Gets the time correction in whole seconds determined by an SNTP server.

Parameters
[in]serverThe server URL.
[in]idAn identifer for constructing a filename for server messages.
[in]strbufA buffer to hold server messages.
[in]logbufA buffer to hold messages for the error log.
Returns
The time correction to be made or -1 on error.

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

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 SNTP servers and reports the error as g.consensusTimeError.

Returns
The number of SNTP servers reporting.

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

◆ makeSNTPTimeQuery()

void makeSNTPTimeQuery ( timeCheckParams tcp)

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

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

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

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 SNTP time servers.

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

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

Here is the call graph for this function:

Variable Documentation

◆ g

struct G g

Declares the global variables defined in pps-client.h.

Definition at line 53 of file pps-client.cpp.

◆ srv0

const char* srv0 = "0.debian.pool.ntp.org"

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

◆ srv1

const char* srv1 = "1.debian.pool.ntp.org"

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

◆ srv2

const char* srv2 = "2.debian.pool.ntp.org"

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

◆ srv3

const char* srv3 = "3.debian.pool.ntp.org"

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