22 #ifndef PPS_CLIENT_OLD_PPS_CLIENT_H_ 23 #define PPS_CLIENT_OLD_PPS_CLIENT_H_ 34 #include <sys/timex.h> 36 #include <sys/types.h> 41 #define PTHREAD_STACK_REQUIRED 16384 42 #define USECS_PER_SEC 1000000 43 #define SECS_PER_MINUTE 60 44 #define SECS_PER_5_MIN 300 45 #define SECS_PER_10_MIN 600 46 #define SECS_PER_HOUR 3600 47 #define SECS_PER_DAY 86400 48 #define NUM_5_MIN_INTERVALS 288 49 #define FIVE_MINUTES 5 50 #define PER_MINUTE (1.0 / (double)SECS_PER_MINUTE) 51 #define SETTLE_TIME (2 * SECS_PER_10_MIN) 54 #define INTEGRAL_GAIN 0.63212 55 #define SHOW_INTRPT_DATA_INTVL 6 56 #define INV_DELAY_SAMPLES_PER_MIN (1.0 / (double)SECS_PER_MINUTE) 57 #define FREQDIFF_INTRVL 5 59 #define OFFSETFIFO_LEN 80 60 #define NUM_INTEGRALS 10 61 #define PER_NUM_INTEGRALS (1.0 / (double)NUM_INTEGRALS) 63 #define ADJTIMEX_SCALE 65536.0 65 #define INTERRUPT_LATENCY 6 67 #define RAW_ERROR_ZERO 20 68 #define MIN_PEAK_RATIO 0.05 69 #define MAX_VALLEY_RATIO 0.99 70 #define RAW_ERROR_DECAY 0.98851 72 #define INTERRUPT_LOST 15 75 #define CHECK_TIME 1024 76 #define BLOCK_FOR_10 10 78 #define CHECK_TIME_SERIAL 600 82 #define NOISE_FACTOR 0.354 83 #define NOISE_LEVEL_MIN 4 87 #define MAX_LINE_LEN 50 91 #define SNTP_MSG_SZ 200 92 #define CONFIG_FILE_SZ 10000 95 #define ERROR_DISTRIB_LEN 121 96 #define JITTER_DISTRIB_LEN 121 97 #define INTRPT_DISTRIB_LEN 121 99 #define HARD_LIMIT_NONE 32768 100 #define HARD_LIMIT_1024 1024 101 #define HARD_LIMIT_4 4 102 #define HARD_LIMIT_1 1 103 #define HARD_LIMIT_05 0.5 108 #define MAX_CONFIGS 32 110 #define ERROR_DISTRIB 1 // Configuration file Keys 111 #define ALERT_PPS_LOST 2 112 #define JITTER_DISTRIB 4 114 #define INTERRUPT_DISTRIB 16 115 #define SYSDELAY_DISTRIB 32 116 #define EXIT_LOST_PPS 64 118 #define OUTPUT_GPIO 256 119 #define INTRPT_GPIO 512 122 #define SERIAL_PORT 4096 247 bool doSerialsettime;
248 int blockDetectClockChange;
258 unsigned int config_select;
266 double lastFreqOffset;
267 double freqOffsetSum;
270 unsigned int lastActiveCount;
311 int waitForNTPServers(
void);
321 struct saveFileData {
324 const char *filename;
332 void initSerialLocalData(
void);
349 int read_logerr(
int fd,
char *,
int,
const char *);
350 void writeInterruptDistribFile(
void);
365 void buildInterruptJitterDistrib(
int);
372 int getTimeErrorOverSerial(
int *);
void writeToLog(char *logbuf)
double slewAccum
Accumulates G.rawError in getTimeSlew() and is used to determine G.avgSlew.
bool doReadSerial
Flag to read serial messages from serial port.
void buildInterruptDistrib(int intrptDelay)
#define OFFSETFIFO_LEN
Length of G.correctionFifo which contains the data used to generate G.avgCorrection.
char * logbuf
Space for returned log messages.
void recordOffsets(int timeCorrection)
bool isControlling
Set "true" by getAcquireState() when the control loop can begin to control the system clock frequency...
void showStatusEachSecond(void)
void recordFrequencyVars(void)
int tm[6]
Returns the interrupt calibration reception and response times from the PPS-Client device driver...
struct timex t3
Passes G.timeCorrection to the system function adjtimex() in makeTimeCorrection().
double freqOffset
System clock frequency correction calculated as G.integralTimeCorrection * G.integralGain.
#define INTRPT_DISTRIB_LEN
double integral[NUM_INTEGRALS]
Array of integrals constructed by makeAverageIntegral().
double t_mono_now
Current monotonic count of passing seconds.
void writeTimestamp(double timestamp)
double integralTimeCorrection
Integral or average integral of G.timeCorrection returned by getIntegral();.
unsigned int ppsCount
Advancing count of G.rawErrorDistrib[] entries made by detectDelayPeak().
int rawError
Set equal to G.interruptTime - G.sysDelay in makeTimeCorrection().
void freeSNTPThreads(timeCheckParams *tcp)
bool configHasValue(int config_val, void *value)
#define JITTER_DISTRIB_LEN
bool interruptLost
Set "true" when a PPS interrupt time fails to be received.
int zeroError
The controller error resulting from removing jitter noise from G.rawError in removeNoise().
unsigned int activeCount
Advancing count of controller cycles once G.isControlling is "true".
char linuxVersion[20]
Array for recording the Linux version.
void makeSNTPTimeQuery(timeCheckParams *tcp)
int integralCount
Counts the integrals formed over the last 10 controller cycles and signals when all integrals in G...
int correctionAccum
Accumulates G.timeCorrection values from G.correctionFifo in getAverageCorrection() in order to gener...
double avgSlew
Average slew value determined by getTimeSlew() from the average of G.slewAccum each time G...
int serverIndex
Identifying index from the list of active SNTP servers.
int sysCommand(const char *cmd)
int read_logerr(int fd, char *buf, int sz, const char *filename)
void buildSysDelayDistrib(int sysDelay)
double avgCorrection
A one-minute rolling average of G.timeCorrection values generated by getAverageCorrection().
unsigned int intrptCount
Advancing count of intrptErrorDistrib[] entries made by detectDelayPeak().
int writeFileMsgToLogbuf(const char *filename, char *logbuf)
char * strbuf
Space for messages and query strings.
int rv
Return value of thread.
int consensusTimeError
Consensus value of whole-second time corrections for DST or leap seconds from Internet SNTP servers...
int timeCorrection
Time correction value constructed in makeTimeCorrection() by dividing G.zeroError by G...
int * serverTimeDiff
Time difference between local time and server time.
#define NUM_INTEGRALS
Number of integrals used by makeAverageIntegral() to calculate the one minute clock frequency correct...
int accessDaemon(int argc, char *argv[])
int allocInitializeSerialThread(timeCheckParams *tcp)
double avgIntegral
One-minute average of the integrals in G.integral[].
bool configWasRead
True if pps-client.conf was read at least once.
int correctionFifo[OFFSETFIFO_LEN]
Contains the G.timeCorrection values from over the previous 60 seconds.
double delayMedian
Median of G.intrptDelay values calculated in getInterruptDelay().
void TERMhandler(int sig)
bool isVerbose
Enables continuous printing of PPS-Client status params when "true".
void writeSysdelayDistribFile(void)
void buildErrorDistrib(int timeCorrection)
bool slewIsLow
Set to "true" in getAcquireState() when G.avgSlew is less than SLEW_MAX. This is a precondition for g...
int getDriverGPIOvals(void)
void writeOffsets(const char *filename)
int correctionFifo_idx
Advances G.correctionFifo on each controller cycle in integralIsReady() which returns "true" every 60...
void freeSerialThread(timeCheckParams *tcp)
#define ERROR_DISTRIB_LEN
#define NUM_5_MIN_INTERVALS
Number of five minute intervals in 24 hours.
int slewAccum_cnt
Count of the number of times G.rawError has been summed into G.slewAccum.
int sysDelayShift
Assigned from G.delayShift and subtracted from G.rawError in correctDelayPeak() when a delay shift oc...
pthread_attr_t attr
Thread attribute object.
int noiseLevel
PPS time delay value beyond which a delay is defined to be a delay spike.
int bufferStateParams(void)
bool isDelaySpike
Set "true" by detectDelaySpike() when G.rawError exceeds G.noiseLevel.
unsigned int seq_num
Advancing count of the number of PPS interrupt timings that have been received.
int t_count
Whole seconds counted at the time of G.t_now.
int writeFileMsgToLog(const char *filename)
int allocNTPServerList(timeCheckParams *tcp)
double rawErrorDistrib[ERROR_DISTRIB_LEN]
The distribution used to detect a delay shift in detectDelayPeak().
int delayShift
Interval of a delay shift when one is detected by detectDelayPeak().
char * serialPort
The serial port filename when serial time is used.
time_t getServerTime(const char *server, int id, char *strbuf, char *logbuf)
Struct for passing arguments to and from threads querying SNTP time servers or GPS receivers...
int intrptDelay
Value of the interrupt delay calibration measurement received from the PPS-Client device driver...
int invProportionalGain
Controller proportional gain configured inversely to use as an int divisor.
bool * threadIsBusy
True while thread is waiting for or processing a time query.
int nDelaySpikes
Current count of continuous delay spikes made by detectDelaySpike().
Struct for program-wide global variables showing those important to the controller.
int outputGPIO
The calibrate GPIO output number read from pps-client.conf and passed to the driver.
void writeToLogNoTimestamp(char *logbuf)
int t_now
Whole seconds of current time reported by gettimeofday().
int intrptError
Set equal to "intrptDelay - sysDelay" in getInterruptDelay().
int allocInitializeSNTPThreads(timeCheckParams *tcp)
double t_mono_last
Last recorded monotonic count used to determine a lost PPS update.
int open_logerr(const char *filename, int flags)
int makeSerialTimeQuery(timeCheckParams *tcp)
char * buf
Space for the active SNTP server list.
int interruptLossCount
Records the number of consecutive lost PPS interrupt times.
int delayPeakLen
Counts the length of a delay peak that is being corrected in correctDelayPeak().
struct timeval t
Time of system response to the PPS interrupt. Received from the PPS-Client device driver...
int hardLimit
An adaptive limit value determined by setHardLimit() and applied to G.rawError by clampJitter() as th...
void buildJitterDistrib(int rawError)
#define FREQDIFF_INTRVL
The number of minutes between Allan deviation samples of system clock frequency correction.
struct timespec setSyncDelay(int timeAt, int fracSec)
bool disableDelayShift
Suspends delay shift correction in correctDelayPeak() when G.delayPeakLen exceeds MAX_SPIKES...
int writeStatusStrings(void)
int correctionFifoCount
Signals that G.correctionFifo contains a full count of G.timeCorrection values.
int intrptGPIO
The calibrate GPIO interrupt number read from pps-client.conf and passed to the driver.
int driver_load(int ppsGPIO, int outputGPIO, int intrptGPIO)
int ppsGPIO
The PPS GPIO interrupt number read from pps-client.conf and passed to the driver. ...
double zeroAccum
Accumulator to test nearness to zero in isNearZero()
bool interruptReceived
Set "true" when makeTimeCorrection() processes an interrupt time from the PPS-Client device driver...
int delayMinIdx
If a delay shift occurs, the minimum value preceding the delay peak in rawErrorDistrib[].
char ** ntp_server
The active SNTP server list when SNTP is used.
void bufferStatusMsg(const char *msg)
int interruptTime
Fractional second part of G.t received from PPS-Client device driver.
double integralGain
Current controller integral gain.
void initFileLocalData(void)
pthread_t * tid
Thread id.