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

This file contains functions and structures for accessing GPS time updates via the serial port. More...

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

Go to the source code of this file.

Classes

struct  serialLocalVars
 

Macros

#define MSG_WAIT_TIME   990000
 
#define SECS_PER_HOUR   3600
 
#define VERIFY_NUM   10
 
#define MAX_NOT_READY   60
 

Functions

bool getUTCfromGPSmessages (const char *msgbuf, timeCheckParams *tcp, time_t *gmt0Seconds)
 
int saveTimestamps (int gmt0Seconds, int gmtSeconds, int tv_usec, timeCheckParams *tcp)
 
void read_save (int captureTime, timeCheckParams *tcp)
 
void saveGPSTime (timeCheckParams *tcp)
 
int makeSerialTimeQuery (timeCheckParams *tcp)
 
int allocInitializeSerialThread (timeCheckParams *tcp)
 
void freeSerialThread (timeCheckParams *tcp)
 

Variables

struct G g
 Declares the global variables defined in pps-client.h. More...
 
struct ppsFiles f
 PPS-Client internal files. More...
 

Detailed Description

This file contains functions and structures for accessing GPS time updates via the serial port.

Definition in file pps-serial.cpp.

Macro Definition Documentation

◆ MAX_NOT_READY

#define MAX_NOT_READY   60

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

◆ MSG_WAIT_TIME

#define MSG_WAIT_TIME   990000

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

◆ SECS_PER_HOUR

#define SECS_PER_HOUR   3600

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

◆ VERIFY_NUM

#define VERIFY_NUM   10

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

Function Documentation

◆ allocInitializeSerialThread()

int allocInitializeSerialThread ( timeCheckParams tcp)

Allocates memory and initializes a thread that will be used by makeSerialimeQuery() to query the serial port. Thread must be released and memory deleted by calling freeSerialThread().

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

Definition at line 417 of file pps-serial.cpp.

Referenced by waitForPPS().

Here is the caller graph for this function:

◆ freeSerialThread()

void freeSerialThread ( timeCheckParams tcp)

Releases thread and deletes memory used by makeSerialTimeQuery();

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

Definition at line 464 of file pps-serial.cpp.

References timeCheckParams::attr, timeCheckParams::serialPort, and timeCheckParams::strbuf.

Referenced by waitForPPS().

Here is the caller graph for this function:

◆ getUTCfromGPSmessages()

bool getUTCfromGPSmessages ( const char *  msgbuf,
timeCheckParams tcp,
time_t *  gmt0Seconds 
)

Processes a block of GPS messages to find a GPRMC message and extract the local time in seconds.

Parameters
[in]msgbufThe block of GPS messages to process.
[in,out]tcpA struct pointer used to pass thread data.
[out]gmtSecondsThe UTC time in seconds.
Returns
true if a complete GPRMC message is found and the time was extracted. Else false.

Definition at line 75 of file pps-serial.cpp.

Referenced by read_save().

Here is the caller graph for this function:

◆ makeSerialTimeQuery()

int makeSerialTimeQuery ( timeCheckParams tcp)

Gets the time from a serial port connected to a GPS receiver or equivalent and returns the difference in seconds from the local time to the true GPS time.

If a difference is detected, the error is verified by looking for an identical time difference from the next ten time difference checks. If the time difference repeats at least a total of eight times, the result is valid and is returned in g.serialTimeError. Otherwise the difference was an error and g.serialTimeError remains 0.

Returns
0 or -1 on a system error.

Definition at line 312 of file pps-serial.cpp.

Referenced by waitForPPS().

Here is the caller graph for this function:

◆ read_save()

void read_save ( int  captureTime,
timeCheckParams tcp 
)

Converts a $GPRMC message s.ptimestr from the serial port to seconds and passes the result along with local time in seconds to read_save();

Parameters
[in]captureTimeThe time in microseconds into the current second at wich the $GPRMC message was captured and converted.
[in]tcpA struct pointer used to pass thread data.

Definition at line 177 of file pps-serial.cpp.

References getUTCfromGPSmessages().

Here is the call graph for this function:

◆ saveGPSTime()

void saveGPSTime ( timeCheckParams tcp)

Reads the GPS serial port once per second and saves the GPS time, gmt0Seconds, along with the local time, gmtSeconds, at which the GPS time was read, to a file that can be read by makeSerialTimeQuery().

Because read_save() is called within 500 usecs after the rollover of the second, that has the consequence that the data saved by this function is one second old by the time it is read by makeSerialTimeQuery().

However, the timestamps passed to saveTimestamps() allways correspond to the same second. So the only effect is to delay the reporting of a possible time error by one second.

Parameters
[in,out]tcpA struct pointer used to pass thread data.

Definition at line 228 of file pps-serial.cpp.

References timeCheckParams::serialPort, timeCheckParams::strbuf, and writeToLog().

Referenced by waitForPPS().

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

◆ saveTimestamps()

int saveTimestamps ( int  gmt0Seconds,
int  gmtSeconds,
int  tv_usec,
timeCheckParams tcp 
)

Saves timestamps of local time and GPS time to tcp->gmtTime_file.

Parameters
[in]gmt0SecondsThe GPS timestamp.
[in]gmtSecondsThe local time timestamp
[in]tcpStructure containing the gmtTime_file filename.

Definition at line 142 of file pps-serial.cpp.

References timeCheckParams::gmtTime_file, timeCheckParams::strbuf, and writeToLog().

Here is the call graph for this function:

Variable Documentation

◆ f

struct ppsFiles f

PPS-Client internal files.

PPS-Client internal files.

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

◆ g

struct G g

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

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