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

This file contains functions and structures for saving and loading files intended for PPS-Client status monitoring and analysis. More...

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

Go to the source code of this file.

Functions

int sysCommand (const char *cmd)
 
char * getString (int key)
 
bool hasString (int key, const char *string)
 
bool isEnabled (int key)
 
bool isDisabled (int key)
 
void couldNotOpenMsgTo (char *logbuf, const char *filename, const char *location)
 
void errorReadingMsgTo (char *logbuf, const char *filename)
 
void writeToLogNoTimestamp (char *logbuf)
 
void writeToLog (char *logbuf, const char *location)
 
void bufferStatusMsg (const char *msg)
 
int writeStatusStrings (void)
 
int read_logerr (int fd, char *buf, int sz, const char *filename)
 
int open_logerr (const char *filename, int flags, const char *location)
 
int saveLastState (void)
 
int loadLastState (void)
 
int writeFileMsgToLogbuf (const char *filename, char *logbuf)
 
int writeFileMsgToLog (const char *filename)
 
pid_t getChildPID (void)
 
bool ppsIsRunning (void)
 
int createPIDfile (void)
 
int readConfigFile (const char *fconfig)
 
void writeDistribution (int distrib[], int len, int scaleZero, int count, int *last_epoch, const char *distrib_file, const char *last_distrib_file)
 
void writeJitterDistribFile (void)
 
void writeErrorDistribFile (void)
 
void writeOffsets (const char *filename)
 
void writeFrequencyVars (const char *filename)
 
int saveDoubleArray (double distrib[], const char *filename, int len, int arrayZero)
 
int processWriteRequest (void)
 
int getSharedConfigs (void)
 
int getConfigs (void)
 
void writeTimestamp (double timestamp)
 
int alignNumbersAfter (const char *token, char *buf, int len)
 
int alignTokens (const char *refToken, int offset, const char *token, char *buf, int len)
 
int bufferStateParams (void)
 
void removeConfigKeys (const char *key1, const char *key2, char *fbuf)
 
char * getLinuxVersion (void)
 
int getRPiCPU (void)
 
int assignProcessorAffinity (void)
 
int getSeqNum (const char *pbuf)
 
void showStatusEachSecond (void)
 
void INThandler (int sig)
 
bool missingArg (int argc, char *argv[], int i)
 
int daemonSaveArray (const char *requestStr, const char *filename)
 
void printAcceptedArgs (void)
 
int parseSaveDataRequest (int argc, char *argv[], const char *requestStr)
 
int accessDaemon (int argc, char *argv[])
 
void buildErrorDistrib (int timeCorrection)
 
void buildJitterDistrib (int rawError)
 
void TERMhandler (int sig)
 
void HUPhandler (int sig)
 
void recordFrequencyVars (void)
 
void recordOffsets (int timeCorrection)
 
int find_source (const char *path, pps_handle_t *handle, int *avail_mode)
 
int readPPSTimestamp (pps_handle_t *handle, int *avail_mode, int *tm)
 
int getRootHome (void)
 

Variables

struct G g
 Declares the global variables defined in pps-client.h. More...
 
const char * config_file = "/XXXX/pps-client.conf"
 The PPS-Client configuration file. More...
 
const char * last_distrib_file = "/pps-error-distrib"
 Stores the completed distribution of offset corrections. More...
 
const char * distrib_file = "/pps-error-distrib-forming"
 Stores a forming distribution of offset corrections. More...
 
const char * last_jitter_distrib_file = "/pps-jitter-distrib"
 Stores the completed distribution of offset corrections. More...
 
const char * jitter_distrib_file = "/pps-jitter-distrib-forming"
 Stores a forming distribution of offset corrections. More...
 
const char * log_file = "/pps-client.log"
 Stores activity and errors. More...
 
const char * old_log_file = "/pps-client.old.log"
 Stores activity and errors. More...
 
const char * pidFilename = "/pps-client.pid"
 Stores the PID of PPS-Client. More...
 
const char * assert_file = "/pps-assert"
 The timestamps of the time corrections each second. More...
 
const char * displayParams_file = "/pps-display-params"
 Temporary file storing params for the status display. More...
 
const char * arrayData_file = "/pps-save-data"
 Stores a request sent to the PPS-Client daemon. More...
 
const char * pps_msg_file = "/pps-msg"
 
const char * linuxVersion_file = "/linuxVersion"
 
const char * gmtTime_file = "/gmtTime"
 
const char * nistTime_file = "/nist_out"
 
const char * integral_state_file = "/.pps-last-state"
 
const char * home_file = "/Home"
 
const char * cpuinfo_file = "/cpuinfo"
 
const char * space = " "
 
const char * num = "0123456789."
 
const char * version
 Program v2.0.0 updated on 9 Jul 2020. More...
 
bool writeJitterDistrib = false
 
bool writeErrorDistrib = false
 
struct ppsFiles f
 PPS-Client internal files. More...
 
const char * valid_config []
 
struct saveFileData arrayData []
 

Detailed Description

This file contains functions and structures for saving and loading files intended for PPS-Client status monitoring and analysis.

Definition in file pps-files.cpp.

Function Documentation

◆ accessDaemon()

int accessDaemon ( int  argc,
char *  argv[] 
)

Provides command line access to the PPS-Client daemon.

Checks if program is running. If not, returns -1. If an error occurs returns -2. If the program is running then returns 0 and prints a message to that effect.

Recognizes data save requests (-s) and forwards these to the daemon interface.

If verbose flag (-v) is read then also displays status params of the running program to the terminal.

Parameters
[in]argcSystem command line arg
[in]argvSystem command line arg
Returns
0 on success, else as described.

Definition at line 2238 of file pps-files.cpp.

References f, getSharedConfigs(), INThandler(), missingArg(), parseSaveDataRequest(), ppsIsRunning(), printAcceptedArgs(), showStatusEachSecond(), and version.

Referenced by main().

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

◆ alignNumbersAfter()

int alignNumbersAfter ( const char *  token,
char *  buf,
int  len 
)

Provides formatting for console printf() strings.

Horizontally left-aligns a number following token, ignoring numeric sign, in a buffer generated by sprintf() by padding the buffer with spaces preceding the number to be aligned and returning the adjusted length of the buffer.

Parameters
[in]tokenThe token string preceding the number to be aligned.
[in,out]bufThe buffer containing the token.
[in]lenThe initial length of the buffer.
Returns
Adjusted length of the buffer.

Definition at line 1613 of file pps-files.cpp.

References g, and writeToLog().

Referenced by bufferStateParams().

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

◆ alignTokens()

int alignTokens ( const char *  refToken,
int  offset,
const char *  token,
char *  buf,
int  len 
)

Provides formatting for console printf() strings.

Horizontally aligns token by a fixed number of characters from the end of refToken by padding the buffer with spaces at the end of the number following refToken.

Parameters
[in]refTokenThe reference token which is followed by a number having a variable length.
[in]offsetThe number of characters in the adjusted buffer from the end of refToken to the start of token.
[in]tokenThe token to be aligned.
[out]bufThe buffer containing the tokens.
[in]lenthe initial length of the buffer.
Returns
The adjusted length of the buffer.

Definition at line 1654 of file pps-files.cpp.

References g, and writeToLog().

Referenced by bufferStateParams().

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

◆ assignProcessorAffinity()

int assignProcessorAffinity ( void  )

Segregate PPS-Client to a separate core from the other processes running on the processor.

Not all will be movable. Error messages are generated for the ones that can't be moved but those messages are suppressed.

Definition at line 1877 of file pps-files.cpp.

References g, G::nCores, sysCommand(), and G::useCore.

Referenced by initialize().

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

◆ bufferStateParams()

int bufferStateParams ( void  )

Records a state params string to a buffer, savebuf, that is saved to a tmpfs memory file by writeStatusStrings() along with other relevant messages recorded during the same second.

Returns
0 on success, else -1 on error.

Definition at line 1693 of file pps-files.cpp.

References alignNumbersAfter(), alignTokens(), G::avgCorrection, bufferStatusMsg(), G::clampAbsolute, G::freqOffset, g, G::hardLimit, G::interruptLossCount, and G::seq_num.

Referenced by waitForPPS().

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

◆ bufferStatusMsg()

void bufferStatusMsg ( const char *  msg)

Concatenates msg to a message buffer, savebuf, which is saved to a tmpfs memory file by writeStatusStrings() each second. These messages can be read and displayed to the command line by showStatusEachSecond().

Parameters
[in]msgPointer to the message to be concatenated.

Definition at line 407 of file pps-files.cpp.

References g, G::isVerbose, and MSGBUF_SZ.

Referenced by bufferStateParams(), main(), readPPS_SetTime(), writeToLog(), and writeToLogNoTimestamp().

Here is the caller graph for this function:

◆ buildErrorDistrib()

void buildErrorDistrib ( int  timeCorrection)

Constructs a distribution of time correction values with zero offset at middle index that can be saved to disk for analysis.

A time correction is the raw time error passed through a hard limitter to remove jitter and then scaled by the proportional gain constant.

Parameters
[in]timeCorrectionThe time correction value to be accumulated to a distribution.

Definition at line 2294 of file pps-files.cpp.

References ERROR_DISTRIB_LEN, and g.

Referenced by removeNoise().

Here is the caller graph for this function:

◆ buildJitterDistrib()

void buildJitterDistrib ( int  rawError)

Constructs a distribution of jitter that can be saved to disk for analysis.

Parameters
[in]rawErrorThe raw error jitter value to save to the distribution.

Definition at line 2316 of file pps-files.cpp.

References g, and JITTER_DISTRIB_LEN.

Referenced by removeNoise().

Here is the caller graph for this function:

◆ couldNotOpenMsgTo()

void couldNotOpenMsgTo ( char *  logbuf,
const char *  filename,
const char *  location 
)

Constructs an error message.

Definition at line 306 of file pps-files.cpp.

Referenced by open_logerr(), writeFileMsgToLogbuf(), writeToLog(), and writeToLogNoTimestamp().

Here is the caller graph for this function:

◆ createPIDfile()

int createPIDfile ( void  )

Creates a PID file for the PPS-Client daemon.

Returns
The PID.

Definition at line 875 of file pps-files.cpp.

References f, g, open_logerr(), and writeToLog().

Referenced by main().

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

◆ daemonSaveArray()

int daemonSaveArray ( const char *  requestStr,
const char *  filename 
)

Transmits a data save request to the PPS-Client daemon via data written to a tmpfs shared memory file.

Parameters
[in]requestStrThe request string.
[in]filenameThe shared memory file to write to.
Returns
0 on success, else -1 on error.

Definition at line 2123 of file pps-files.cpp.

References f, g, open_logerr(), and writeToLog().

Referenced by parseSaveDataRequest().

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

◆ errorReadingMsgTo()

void errorReadingMsgTo ( char *  logbuf,
const char *  filename 
)

Constructs an error message.

Definition at line 319 of file pps-files.cpp.

Referenced by read_logerr(), and writeFileMsgToLogbuf().

Here is the caller graph for this function:

◆ find_source()

int find_source ( const char *  path,
pps_handle_t handle,
int *  avail_mode 
)

Establishes a connection to the system PPS driver.

Parameters
[in]pathThe driver path. Usually /dev/pps0.
[out]handleA handle to the driver.
[out]avail_modeInfo needed when accessing the driver.
Returns
0 on success else -1 on fail.

Definition at line 2433 of file pps-files.cpp.

References g, and writeToLog().

Referenced by main().

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

◆ getChildPID()

pid_t getChildPID ( void  )

Reads the PID of the child process when the parent process needs to kill it.

Returns
The PID or -1 on error.

Definition at line 804 of file pps-files.cpp.

References f, g, open_logerr(), read_logerr(), and STRBUF_SZ.

Here is the call graph for this function:

◆ getConfigs()

int getConfigs ( void  )

Processes the files and configuration settings specified by the PPS-Client config file for the pps-client daemon.

Definition at line 1356 of file pps-files.cpp.

References arrayData_file, assert_file, config_file, cpuinfo_file, displayParams_file, distrib_file, G::doNISTsettime, G::doSerialsettime, ERROR_DISTRIB, ERROR_DISTRIB_LEN, EXIT_LOST_PPS, f, g, getString(), gmtTime_file, home_file, isDisabled(), isEnabled(), JITTER_DISTRIB, jitter_distrib_file, JITTER_DISTRIB_LEN, last_distrib_file, last_jitter_distrib_file, linuxVersion_file, log_file, LOGDIR, G::nCores, NIST, nistTime_file, old_log_file, pidFilename, pps_msg_file, PPSDELAY, PPSDEVICE, PPSPHASE, G::ppsPhase, PROCDIR, processWriteRequest(), readConfigFile(), RUNDIR, SEGREGATE, SERIAL, SERIAL_PORT, SHMDIR, TSTDIR, G::useCore, writeErrorDistrib, writeErrorDistribFile(), writeJitterDistrib, writeJitterDistribFile(), and G::zeroOffset.

Referenced by initialize(), and waitForPPS().

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

◆ getLinuxVersion()

char* getLinuxVersion ( void  )

Returns the Linux kernel version string corresponding to 'uname -r'.

Definition at line 1801 of file pps-files.cpp.

References f, g, G::linuxVersion, sysCommand(), and writeToLog().

Here is the call graph for this function:

◆ getRootHome()

int getRootHome ( void  )

Definition at line 2545 of file pps-files.cpp.

References f, g, integral_state_file, sysCommand(), and writeToLog().

Referenced by main().

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

◆ getRPiCPU()

int getRPiCPU ( void  )

Returns the principle version number of this CPU if it is a Raspberry Pi.

Returns
The CPU version number or 0 if not a Raspberry Pi.

Definition at line 1834 of file pps-files.cpp.

References CONFIG_FILE_SZ, f, g, open_logerr(), and writeToLog().

Referenced by initialize().

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

◆ getSeqNum()

int getSeqNum ( const char *  pbuf)

Extracts the sequence number G.seq_num from a char string and returns the value.

Parameters
[in]pbufThe string to search.
Returns
The sequence number.

Definition at line 1984 of file pps-files.cpp.

References num, and space.

Referenced by showStatusEachSecond().

Here is the caller graph for this function:

◆ getSharedConfigs()

int getSharedConfigs ( void  )

Gets the daemon internal file names and state params for accessDaemon(). Necessary because daemons can not directly share contents of variables.

Definition at line 1273 of file pps-files.cpp.

References arrayData_file, assert_file, config_file, displayParams_file, distrib_file, G::doNISTsettime, G::doSerialsettime, f, g, getString(), home_file, isDisabled(), isEnabled(), last_distrib_file, last_jitter_distrib_file, log_file, LOGDIR, NIST, old_log_file, pidFilename, pps_msg_file, readConfigFile(), RUNDIR, SERIAL, SERIAL_PORT, SHMDIR, and TSTDIR.

Referenced by accessDaemon().

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

◆ getString()

char* getString ( int  key)

Retrieves the string from the config file assigned to the valid_config string with value key.

Parameters
[in]keyThe config key corresponding to a string in the valid_config[] array above.
Returns
The string assigned to the key.

Definition at line 212 of file pps-files.cpp.

References g.

Referenced by getConfigs(), and getSharedConfigs().

Here is the caller graph for this function:

◆ hasString()

bool hasString ( int  key,
const char *  string 
)

Tests configuration strings from pps-client.conf for the specified string. To avoid searching the config file more than once, the config key is a bit position in G.config_select that is set or not set if the corresponding config string is found in the config file when it is first read. In that case an array G.configVals[], constructed when the config file was read, will contain the string from the config file that followed the valid_config. That string will be G.configVals[log2(key)].

Parameters
[in]keyThe config key corresponding to a string in the valid_config[] array above.
[in]stringThe string that must be matched by the string that follows the config string name from the valid_config[] array.
Returns
"true" if the string in the config file matches arg "string", else "false".

Definition at line 253 of file pps-files.cpp.

References g.

Referenced by isDisabled(), and isEnabled().

Here is the caller graph for this function:

◆ HUPhandler()

void HUPhandler ( int  sig)

Catches the SIGHUP signal, causing it to be ignored.

Parameters
[in]sigThe signal from the system.

Definition at line 2350 of file pps-files.cpp.

Referenced by waitForPPS().

Here is the caller graph for this function:

◆ INThandler()

void INThandler ( int  sig)

Responds to the ctrl-c key combination by setting the exit_loop flag. This causes an exit from the showStatusEachSecond() function.

Parameters
[in]sigThe signal returned by the system.

Definition at line 2091 of file pps-files.cpp.

References g.

Referenced by accessDaemon().

Here is the caller graph for this function:

◆ isDisabled()

bool isDisabled ( int  key)

Tests configuration strings from pps-client.conf for the "disable" keyword.

Parameters
[in]keyThe config key corresponding to a string in the valid_config[] array above.
Returns
"true" if the "disable" keyword is detected, else false.

Definition at line 289 of file pps-files.cpp.

References hasString().

Referenced by getConfigs(), and getSharedConfigs().

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

◆ isEnabled()

bool isEnabled ( int  key)

Tests configuration strings from pps-client.conf for the "enable" keyword.

Parameters
[in]keyThe config key corresponding to a string in the valid_config[] array above.
Returns
"true" if the "enable" keyword is detected, else "false".

Definition at line 275 of file pps-files.cpp.

References hasString().

Referenced by getConfigs(), and getSharedConfigs().

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

◆ loadLastState()

int loadLastState ( void  )

Loads the last state corresponding to the makeTimeCorrection() integrators on startup to allow rapid restart.

Definition at line 610 of file pps-files.cpp.

References G::activeCount, adjtimex(), ADJTIMEX_SCALE, G::avgIntegral, G::correctionAccum, G::correctionFifo, G::correctionFifo_idx, G::correctionFifoCount, f, G::freqOffset, g, G::hardLimit, G::integral, integral_state_file, G::integralCount, G::integralGain, G::integralTimeCorrection, G::isControlling, NUM_INTEGRALS, OFFSETFIFO_LEN, read_logerr(), SECS_PER_MINUTE, G::seq_num, G::slewIsLow, and G::t3.

Referenced by waitForPPS().

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

◆ missingArg()

bool missingArg ( int  argc,
char *  argv[],
int  i 
)

Checks for and reports on missing arguments in a command line request.

Parameters
[in]argcSystem command line arg
[in]argvSystem command line arg
[in]iThe arg index.
Returns
"true" if an argument is missing, else "false".

Definition at line 2106 of file pps-files.cpp.

Referenced by accessDaemon(), and parseSaveDataRequest().

Here is the caller graph for this function:

◆ open_logerr()

int open_logerr ( const char *  filename,
int  flags,
const char *  location 
)

Opens a file with error logging and sets standard file permissions for O_CREAT.

Parameters
[in]filenameThe file to open.
[in]flagsThe file open flags.
[in]locationThe name of the calling function.
Returns
The file descriptor.

Definition at line 486 of file pps-files.cpp.

References couldNotOpenMsgTo(), g, and writeToLog().

Referenced by createPIDfile(), daemonSaveArray(), getChildPID(), getRPiCPU(), saveDoubleArray(), saveLastState(), writeDistribution(), writeFrequencyVars(), writeOffsets(), writeStatusStrings(), and writeTimestamp().

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

◆ parseSaveDataRequest()

int parseSaveDataRequest ( int  argc,
char *  argv[],
const char *  requestStr 
)

Reads a command line save data request and either forwards the data to the daemon interface or prints entry errors back to the terminal.

Parameters
[in]argcSystem command line arg
[in]argvSystem command line arg
[in]requestStrThe request string.
Returns
0 on success, else -1 on error.

Definition at line 2172 of file pps-files.cpp.

References arrayData, daemonSaveArray(), g, missingArg(), printAcceptedArgs(), and STRBUF_SZ.

Referenced by accessDaemon().

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

◆ ppsIsRunning()

bool ppsIsRunning ( void  )

Uses a system call to pidof to see if PPS-Client is running.

Returns
If a PID for pps exists returns "true". Else returns "false".

Definition at line 831 of file pps-files.cpp.

References f, g, sysCommand(), and writeToLog().

Referenced by accessDaemon().

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

◆ printAcceptedArgs()

void printAcceptedArgs ( void  )

Prints a list to the terminal of the command line args for saving data that are recognized by PPS-Client.

Definition at line 2153 of file pps-files.cpp.

References arrayData.

Referenced by accessDaemon(), and parseSaveDataRequest().

Here is the caller graph for this function:

◆ processWriteRequest()

int processWriteRequest ( void  )

From within the daemon, reads the data label and filename of an array to write to disk from a request made from the command line with "pps-client -s [label] <filename>". Then matches the requestStr to the corresponding arrayData which is then passed to a routine that saves the array identified by the data label.

Returns
0 on success else -1 on fail.

Definition at line 1219 of file pps-files.cpp.

References arrayData, f, g, saveDoubleArray(), STRBUF_SZ, writeFrequencyVars(), writeOffsets(), and writeToLog().

Referenced by getConfigs().

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

◆ read_logerr()

int read_logerr ( int  fd,
char *  buf,
int  sz,
const char *  filename 
)

Reads a file with error logging.

Parameters
[in]fdThe file descriptor.
[out]bufThe buffer to hold the file data.
[in]szThe number of bytes to read.
[in]filenameThe filename of the file being read.
Returns
The number of bytes read.

Definition at line 466 of file pps-files.cpp.

References errorReadingMsgTo(), g, and writeToLog().

Referenced by getChildPID(), and loadLastState().

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

◆ readConfigFile()

int readConfigFile ( const char *  fconfig)

Reads the PPS-Client config file and sets bits in G.config_select to 1 or 0 corresponding to whether a particular G.configVals appears in the config file. The G.configVals from the file is then copied to fbuf and a pointer to that string is placed in the G.configVals array.

If the G.configVals did not occur in the config file then G.configVals has a NULL char* in the corresponding location.

Parameters
[in]fconfigRoot filename of pps-client.conf.
Returns
0 on success, else -1 on error.

Definition at line 922 of file pps-files.cpp.

Referenced by getConfigs(), and getSharedConfigs().

Here is the caller graph for this function:

◆ readPPSTimestamp()

int readPPSTimestamp ( pps_handle_t handle,
int *  avail_mode,
int *  tm 
)

Gets the PPS rising edge time from the Linux PPS driver.

Parameters
[in]handleThe handle to the system PPS driver.
[in]avail_modeInfo for the driver.
[out]tmThe timestamp obtained from the driver.
Returns
0 on success, else -1 on driver error.

Definition at line 2505 of file pps-files.cpp.

Referenced by readPPS_SetTime().

Here is the caller graph for this function:

◆ recordFrequencyVars()

void recordFrequencyVars ( void  )

Accumulates the clock frequency offset over the last 5 minutes and records offset difference each minute over the previous 5 minute interval. This function is called once each minute.

The values of offset difference, g.freqOffsetDiff[], are used to calculate the Allan deviation of the clock frequency offset which is determined so that it can be saved to disk. g.freqOffsetSum is used to calculate the average clock frequency offset in each 5 minute interval so that value can also be saved to disk.

Definition at line 2366 of file pps-files.cpp.

References FIVE_MINUTES, FREQDIFF_INTRVL, G::freqOffset, g, and NUM_5_MIN_INTERVALS.

Referenced by getIntegral().

Here is the caller graph for this function:

◆ recordOffsets()

void recordOffsets ( int  timeCorrection)

Each second, records the time correction that was applied to the system clock and also records the last clock frequency offset (in parts per million) that was applied to the system clock.

These values are recorded so that they may be saved to disk for analysis.

Parameters
[in]timeCorrectionThe time correction value to be recorded.

Definition at line 2412 of file pps-files.cpp.

References G::freqOffset, g, SECS_PER_10_MIN, and G::seq_num.

Referenced by makeTimeCorrection().

Here is the caller graph for this function:

◆ removeConfigKeys()

void removeConfigKeys ( const char *  key1,
const char *  key2,
char *  fbuf 
)

Removes all lines containing "key1 key2" from the text in fbuf.

Parameters
[in]key1
[in]key2
[out]fbufThe text buffer to process.

Definition at line 1755 of file pps-files.cpp.

◆ saveDoubleArray()

int saveDoubleArray ( double  distrib[],
const char *  filename,
int  len,
int  arrayZero 
)

Saves a distribution consisting of an array of doubles.

Parameters
[in]distribThe distribution array.
[in]filenameThe file to save to.
[in]lenThe length of the array.
[in]arrayZeroThe array index of distribution value zero.
Returns
0 on success, else -1 on error.

Definition at line 1177 of file pps-files.cpp.

References g, MAX_LINE_LEN, open_logerr(), and writeToLog().

Referenced by processWriteRequest().

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

◆ saveLastState()

int saveLastState ( void  )

Saves the state corresponding to the makeTimeCorrection() integrators on exit to allow rapid restart. These are saved to /root/.pps-last-state on the RPi or whatever the root home directory is on other processors.

Definition at line 509 of file pps-files.cpp.

References G::activeCount, G::avgIntegral, G::correctionAccum, G::correctionFifo, G::correctionFifo_idx, G::correctionFifoCount, f, G::freqOffset, g, G::hardLimit, G::integral, integral_state_file, G::integralCount, G::integralTimeCorrection, G::isControlling, NUM_INTEGRALS, OFFSETFIFO_LEN, open_logerr(), G::seq_num, G::slewIsLow, and writeToLog().

Referenced by waitForPPS().

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

◆ showStatusEachSecond()

void showStatusEachSecond ( void  )

Reads the state params saved to shared memory by the PPS-Client daemon and prints the param string to the console each second.

Definition at line 2004 of file pps-files.cpp.

References G::doNISTsettime, G::doSerialsettime, f, g, getSeqNum(), MSGBUF_SZ, and setSyncDelay().

Referenced by accessDaemon().

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

◆ sysCommand()

int sysCommand ( const char *  cmd)

system() function with error handling.

Definition at line 193 of file pps-files.cpp.

References g, and writeToLog().

Referenced by assignProcessorAffinity(), doTimeFixups(), getLinuxVersion(), getNISTTime(), getRootHome(), main(), ppsIsRunning(), and waitForPPS().

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

◆ TERMhandler()

void TERMhandler ( int  sig)

Responds to the SIGTERM signal by starting the exit sequence in the daemon.

Parameters
[in]sigThe signal from the system.

Definition at line 2337 of file pps-files.cpp.

References g, and writeToLog().

Referenced by waitForPPS().

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

◆ writeDistribution()

void writeDistribution ( int  distrib[],
int  len,
int  scaleZero,
int  count,
int *  last_epoch,
const char *  distrib_file,
const char *  last_distrib_file 
)

Writes an accumulating statistical distribution to disk and rolls over the accumulating data to a new file every epoch counts and begins a new distribution file. An epoch is 86,400 counts.

Parameters
[in]distribThe array containing the distribution.
[in]lenThe length of the array.
[in]scaleZeroThe array index corresponding to distribution zero.
[in]countThe current number of samples in the distribution.
[out]last_epochThe saved count of the previous epoch.
[in]distrib_fileThe filename of the last completed distribution file.
[in]last_distrib_fileThe filename of the currently forming distribution file.

Definition at line 1055 of file pps-files.cpp.

References distrib_file, g, last_distrib_file, open_logerr(), SECS_PER_DAY, and writeToLog().

Referenced by writeErrorDistribFile(), and writeJitterDistribFile().

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

◆ writeErrorDistribFile()

void writeErrorDistribFile ( void  )

Writes a distribution to disk approximately once a minute containing 60 additional time correction samples derived from the PPS interrupt. The distribution is rolled over to a new file every 24 hours.

Definition at line 1104 of file pps-files.cpp.

References ERROR_DISTRIB_LEN, g, SECS_PER_MINUTE, G::seq_num, SETTLE_TIME, and writeDistribution().

Referenced by getConfigs().

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

◆ writeFileMsgToLog()

int writeFileMsgToLog ( const char *  filename)

Writes the message saved in the file to pps-client.log.

Parameters
[in]filenameFile containg a message.
Returns
0 on success, else -1 on error;

Definition at line 794 of file pps-files.cpp.

References g, and writeFileMsgToLogbuf().

Here is the call graph for this function:

◆ writeFileMsgToLogbuf()

int writeFileMsgToLogbuf ( const char *  filename,
char *  logbuf 
)

Writes the message saved in the file to pps-client.log.

This function is used by threads in pps-sntp.cpp.

Parameters
[in]filenameFile containg a message.
[out]logbufThe log file buffer.
Returns
0 on success, else -1 on error;

Definition at line 750 of file pps-files.cpp.

References couldNotOpenMsgTo(), errorReadingMsgTo(), and LOGBUF_SZ.

Referenced by getNISTTime(), and writeFileMsgToLog().

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

◆ writeFrequencyVars()

void writeFrequencyVars ( const char *  filename)

Writes the last 24 hours of clock frequency offset and Allan deviation in each 5 minute interval indexed by the timestamp at each interval.

Parameters
[in]filenameThe file to write to.

Definition at line 1145 of file pps-files.cpp.

References g, NUM_5_MIN_INTERVALS, open_logerr(), and writeToLog().

Referenced by processWriteRequest().

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

◆ writeJitterDistribFile()

void writeJitterDistribFile ( void  )

Writes a distribution to disk approximately once a minute containing 60 additional jitter samples recorded at the occurrance of the PPS interrupt. The distribution is rolled over to a new file every 24 hours.

Definition at line 1090 of file pps-files.cpp.

References g, JITTER_DISTRIB_LEN, SECS_PER_MINUTE, G::seq_num, SETTLE_TIME, and writeDistribution().

Referenced by getConfigs().

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

◆ writeOffsets()

void writeOffsets ( const char *  filename)

Writes the previously completed list of 10 minutes of recorded time offsets and applied frequency offsets indexed by seq_num.

Parameters
[in]filenameThe file to write to.

Definition at line 1118 of file pps-files.cpp.

References g, open_logerr(), SECS_PER_10_MIN, and writeToLog().

Referenced by processWriteRequest().

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

◆ writeStatusStrings()

int writeStatusStrings ( void  )

Writes status strings accumulated in a message buffer, G.savebuf, from bufferStateParams() and other sources to a tmpfs memory file, displayParams_file, once each second. This file can be displayed in real time by invoking the PPS-Client program with the -v command line flag while the PPS-Client daemon is running.

Returns
0 on success, else -1 on error.

Definition at line 435 of file pps-files.cpp.

References f, g, open_logerr(), and writeToLog().

Referenced by waitForPPS().

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

◆ writeTimestamp()

void writeTimestamp ( double  timestamp)

Write a timestamp provided as a double to a temporary file each second.

Parameters
[in]timestampThe timestamp value.

Definition at line 1581 of file pps-files.cpp.

References f, g, open_logerr(), G::seq_num, STRBUF_SZ, and writeToLog().

Referenced by savePPStime().

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

◆ writeToLog()

void writeToLog ( char *  logbuf,
const char *  location 
)

Appends logbuf to the log file with a timestamp.

Parameters
[in,out]logbufPointer to the log buffer.

Definition at line 364 of file pps-files.cpp.

References bufferStatusMsg(), couldNotOpenMsgTo(), f, g, and STRBUF_SZ.

Referenced by alignNumbersAfter(), alignTokens(), createPIDfile(), daemonSaveArray(), detectExteralSystemClockChange(), detectMissedPPS(), find_source(), getLinuxVersion(), getRootHome(), getRPiCPU(), main(), open_logerr(), ppsIsRunning(), processWriteRequest(), read_logerr(), readPPS_SetTime(), saveDoubleArray(), saveGPSTime(), saveLastState(), saveTimestamps(), setClockFractionalSecond(), setClockToGPStime(), setClocktoNISTtime(), setSyncDelay(), sysCommand(), TERMhandler(), waitForPPS(), writeDistribution(), writeFrequencyVars(), writeOffsets(), writeStatusStrings(), and writeTimestamp().

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

◆ writeToLogNoTimestamp()

void writeToLogNoTimestamp ( char *  logbuf)

Appends logbuf to the log file.

Parameters
[in,out]logbufPointer to the log buffer.

Definition at line 332 of file pps-files.cpp.

References bufferStatusMsg(), couldNotOpenMsgTo(), and f.

Referenced by updateLog().

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

Variable Documentation

◆ arrayData

struct saveFileData arrayData[]
Initial value:
= {
{"rawError", g.rawErrorDistrib, "/var/local/pps-raw-error-distrib", ERROR_DISTRIB_LEN, 2, RAW_ERROR_ZERO},
{"frequency-vars", NULL, "/var/local/pps-frequency-vars", 0, 3, 0},
{"pps-offsets", NULL, "/var/local/pps-offsets", 0, 4, 0}
}

Data associations for PPS-Client command line save data requests with the -s flag.

Definition at line 289 of file pps-files.cpp.

Referenced by parseSaveDataRequest(), printAcceptedArgs(), and processWriteRequest().

◆ arrayData_file

const char* arrayData_file = "/pps-save-data"

Stores a request sent to the PPS-Client daemon.

Definition at line 37 of file pps-files.cpp.

Referenced by getConfigs(), and getSharedConfigs().

◆ assert_file

const char* assert_file = "/pps-assert"

The timestamps of the time corrections each second.

Definition at line 35 of file pps-files.cpp.

Referenced by getConfigs(), and getSharedConfigs().

◆ config_file

const char* config_file = "/XXXX/pps-client.conf"

The PPS-Client configuration file.

Definition at line 27 of file pps-files.cpp.

Referenced by getConfigs(), and getSharedConfigs().

◆ cpuinfo_file

const char* cpuinfo_file = "/cpuinfo"

Definition at line 44 of file pps-files.cpp.

Referenced by getConfigs().

◆ displayParams_file

const char* displayParams_file = "/pps-display-params"

Temporary file storing params for the status display.

Definition at line 36 of file pps-files.cpp.

Referenced by getConfigs(), and getSharedConfigs().

◆ distrib_file

const char* distrib_file = "/pps-error-distrib-forming"

Stores a forming distribution of offset corrections.

Definition at line 29 of file pps-files.cpp.

Referenced by getConfigs(), getSharedConfigs(), and writeDistribution().

◆ f

struct ppsFiles f

◆ g

struct G g

◆ gmtTime_file

const char* gmtTime_file = "/gmtTime"

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

Referenced by getConfigs().

◆ home_file

const char* home_file = "/Home"

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

Referenced by getConfigs(), and getSharedConfigs().

◆ integral_state_file

const char* integral_state_file = "/.pps-last-state"

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

Referenced by getRootHome(), loadLastState(), and saveLastState().

◆ jitter_distrib_file

const char* jitter_distrib_file = "/pps-jitter-distrib-forming"

Stores a forming distribution of offset corrections.

Definition at line 31 of file pps-files.cpp.

Referenced by getConfigs().

◆ last_distrib_file

const char* last_distrib_file = "/pps-error-distrib"

Stores the completed distribution of offset corrections.

Definition at line 28 of file pps-files.cpp.

Referenced by getConfigs(), getSharedConfigs(), and writeDistribution().

◆ last_jitter_distrib_file

const char* last_jitter_distrib_file = "/pps-jitter-distrib"

Stores the completed distribution of offset corrections.

Definition at line 30 of file pps-files.cpp.

Referenced by getConfigs(), and getSharedConfigs().

◆ linuxVersion_file

const char* linuxVersion_file = "/linuxVersion"

Definition at line 39 of file pps-files.cpp.

Referenced by getConfigs().

◆ log_file

const char* log_file = "/pps-client.log"

Stores activity and errors.

Definition at line 32 of file pps-files.cpp.

Referenced by getConfigs(), and getSharedConfigs().

◆ nistTime_file

const char* nistTime_file = "/nist_out"

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

Referenced by getConfigs(), and getNISTTime().

◆ num

const char* num = "0123456789."

Definition at line 47 of file pps-files.cpp.

Referenced by getNISTTime(), and getSeqNum().

◆ old_log_file

const char* old_log_file = "/pps-client.old.log"

Stores activity and errors.

Definition at line 33 of file pps-files.cpp.

Referenced by getConfigs(), and getSharedConfigs().

◆ pidFilename

const char* pidFilename = "/pps-client.pid"

Stores the PID of PPS-Client.

Definition at line 34 of file pps-files.cpp.

Referenced by getConfigs(), and getSharedConfigs().

◆ pps_msg_file

const char* pps_msg_file = "/pps-msg"

Definition at line 38 of file pps-files.cpp.

Referenced by getConfigs(), and getSharedConfigs().

◆ space

const char* space = " "

Definition at line 46 of file pps-files.cpp.

Referenced by getSeqNum().

◆ valid_config

const char* valid_config[]
Initial value:
= {
"error-distrib",
"alert-pps-lost",
"jitter-distrib",
"exit-lost-pps",
"pps-gpio",
"output-gpio",
"intrpt-gpio",
"nist",
"serial",
"serialPort",
"execdir",
"servicedir",
"configdir",
"docdir",
"rundir",
"shmdir",
"tstdir",
"logdir",
"zeroOffset",
"moduledir",
"ppsdevice",
"ppsphase",
"procdir",
"segregate"
}

Recognized configuration strings for the PPS-Client configuration file. These strings mirror the configuration file keys #defines in pps-client one-to-one and are identical to the strings in the config file. Usually the #define is the the same word in upper case but not always

Definition at line 74 of file pps-files.cpp.

◆ version

const char* version

Program v2.0.0 updated on 9 Jul 2020.

System call

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

Referenced by accessDaemon(), and waitForPPS().

◆ writeErrorDistrib

bool writeErrorDistrib = false

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

Referenced by getConfigs(), and removeNoise().

◆ writeJitterDistrib

bool writeJitterDistrib = false

Definition at line 57 of file pps-files.cpp.

Referenced by getConfigs(), and removeNoise().

G::rawErrorDistrib
double rawErrorDistrib[ERROR_DISTRIB_LEN]
The distribution of rawError values accumulated in buildRawErrorDistrib().
Definition: pps-client.h:203
ERROR_DISTRIB_LEN
#define ERROR_DISTRIB_LEN
Definition: pps-client.h:102
RAW_ERROR_ZERO
#define RAW_ERROR_ZERO
Index corresponding to rawError == 0 in buildRawErrorDistrib().
Definition: pps-client.h:73
g
struct G g
Declares the global variables defined in pps-client.h.
Definition: pps-client.cpp:55