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

The pps-serial.cpp file contains functions and structures for accessing 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.

Data Structures

struct  serialLocalVars
 

Functions

bool getUTCfromGPSmessages (const char *msgbuf, timeCheckParams *tcp, time_t *gmtSeconds)
 
int waitForGPSmessages (char *msgbuf, timeCheckParams *tcp, struct timeval *t_gmt, time_t *gmtSeconds)
 
int getTimeOffsetOverSerial (int *timeDif, timeCheckParams *tcp)
 
void doSerialTimeCheck (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...
 

Detailed Description

The pps-serial.cpp file contains functions and structures for accessing time updates via the serial port.

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-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 423 of file pps-serial.cpp.

Here is the caller graph for this function:

◆ doSerialTimeCheck()

void doSerialTimeCheck ( timeCheckParams tcp)

Requests the time difference between system and GPS from getTimeOffsetOverSerial().

If the time difference is zero, returns the zero result in tcp->serverTimeDiff[0] and ends the request.

Otherwise a second request is made to verify the first non-zero result. If the two results are identical then the time difference is returned in tcp->serverTimeDiff[0]. If not, zero is returned and an error message is written to pps-client.log.

If a system error occurs while reading the serial port, zero is returned in tcp->serverTimeDiff[0] and an error message is written to pps-client.log.

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

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

Here is the call 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 473 of file pps-serial.cpp.

Here is the caller graph for this function:

◆ getTimeOffsetOverSerial()

int getTimeOffsetOverSerial ( int *  timeDif,
timeCheckParams tcp 
)

Reads the UTC time from the $GPRMC message of a connected GPS receiver through the serial port, converts the time to local time and compares it with local time read from the system clock.

Parameters
[out]timeDifTime difference in seconds from the system time to the GPS time.
[in,out]tcpA struct pointer used to pass thread data.
Returns
1 if a time difference was generated, 0 if not or -1 on a system error.

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

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

◆ getUTCfromGPSmessages()

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

Processes a block of GPS messages to find a GPRMC message and extract the UTC 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 58 of file pps-serial.cpp.

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 a second identical time difference. If the time difference repeats, the result is valid and is returned in g.serialTimeError. Otherwise the first difference was an error and g.serialTimeError returns 0.

Returns
0 or -1 on a system error.

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

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

◆ waitForGPSmessages()

int waitForGPSmessages ( char *  msgbuf,
timeCheckParams tcp,
struct timeval *  t_gmt,
time_t *  gmtSeconds 
)

Waits for the serial port to buffer enough messages that a GPRMC can usually be found among those. Because the message stream is collected at a relatively slow 9600 baud some steams will take too long to be fully read and processed within one second. For that reason messages are read for only about 250 ms. This insures the messages that are read occur in the second for which the time is required.

Parameters
[out]msgbufThe buffer to read the GPS messages.
[in,out]tcpA struct pointer used to pass thread data.
[out]t_gmtThe time when the serial port starts buffering messages.
[out]gmtSecondsThe time in UTC seconds on the local clock when the serial port starts buffering messages.
Returns
1 on success, 0 if no GPS messages or -1 on a system error.

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

Here is the call graph for this function:
Here is the caller 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.