PPS-Client
1.4.0
Client for synchronizing the system clock to a GPS PPS source
|
The pps-sntp.cpp file contains functions and structures for accessing time updates via SNTP. More...
#include "../client/pps-client.h"
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" |
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.
#define ADDR_LEN 17 |
Definition at line 23 of file pps-sntp.cpp.
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().
[out] | tcp | Struct pointer for passing data. |
Definition at line 416 of file pps-sntp.cpp.
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.
[out] | tcp | Struct pointer for passing data to a thread. |
Definition at line 58 of file pps-sntp.cpp.
void copyToLog | ( | char * | logbuf, |
const char * | msg | ||
) |
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.
[in,out] | tcp | struct pointer for passing data. |
Definition at line 233 of file pps-sntp.cpp.
void freeSNTPThreads | ( | timeCheckParams * | tcp | ) |
Releases threads and deletes memory used by makeSNTPTimeQuery();
[in] | tcp | The struct pointer that was used for passing data. |
Definition at line 456 of file pps-sntp.cpp.
time_t getServerTime | ( | const char * | server, |
int | id, | ||
char * | strbuf, | ||
char * | logbuf | ||
) |
Gets the time correction in whole seconds determined by an SNTP server.
[in] | server | The server URL. |
[in] | id | An identifer for constructing a filename for server messages. |
[in] | strbuf | A buffer to hold server messages. |
[in] | logbuf | A buffer to hold messages for the error log. |
Definition at line 119 of file pps-sntp.cpp.
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.
Definition at line 263 of file pps-sntp.cpp.
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.
[in,out] | tcp | Struct pointer for passing data. |
Definition at line 341 of file pps-sntp.cpp.
void updateLog | ( | char * | buf, |
int | numServers | ||
) |
Updates the PPS-Client log with any errors reported by threads querying SNTP time servers.
[out] | buf | The message buffer shared by the threads. |
[in] | numServers | The number of SNTP servers. |
Definition at line 321 of file pps-sntp.cpp.
struct G g |
Declares the global variables defined in pps-client.h.
Definition at line 53 of file pps-client.cpp.
const char* srv0 = "0.debian.pool.ntp.org" |
Definition at line 40 of file pps-sntp.cpp.
const char* srv1 = "1.debian.pool.ntp.org" |
Definition at line 41 of file pps-sntp.cpp.
const char* srv2 = "2.debian.pool.ntp.org" |
Definition at line 42 of file pps-sntp.cpp.
const char* srv3 = "3.debian.pool.ntp.org" |
Definition at line 43 of file pps-sntp.cpp.