PPS-Client
1.4.0
Client for synchronizing the system clock to a GPS PPS source
|
The pps-serial.cpp file contains functions and structures for accessing time updates via the serial port. More...
#include "../client/pps-client.h"
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... | |
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.
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().
[out] | tcp | Struct pointer for passing data. |
Definition at line 423 of file pps-serial.cpp.
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.
[in,out] | tcp | A struct pointer used to pass thread data. |
Definition at line 279 of file pps-serial.cpp.
void freeSerialThread | ( | timeCheckParams * | tcp | ) |
Releases thread and deletes memory used by makeSerialTimeQuery();
[in] | tcp | The struct pointer that was used for passing data. |
Definition at line 473 of file pps-serial.cpp.
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.
[out] | timeDif | Time difference in seconds from the system time to the GPS time. |
[in,out] | tcp | A struct pointer used to pass thread data. |
Definition at line 226 of file pps-serial.cpp.
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.
[in] | msgbuf | The block of GPS messages to process. |
[in,out] | tcp | A struct pointer used to pass thread data. |
[out] | gmtSeconds | The UTC time in seconds. |
Definition at line 58 of file pps-serial.cpp.
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.
Definition at line 365 of file pps-serial.cpp.
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.
[out] | msgbuf | The buffer to read the GPS messages. |
[in,out] | tcp | A struct pointer used to pass thread data. |
[out] | t_gmt | The time when the serial port starts buffering messages. |
[out] | gmtSeconds | The time in UTC seconds on the local clock when the serial port starts buffering messages. |
Definition at line 144 of file pps-serial.cpp.
struct G g |
Declares the global variables defined in pps-client.h.
Definition at line 53 of file pps-client.cpp.