PPS-Client
2.0.0
Client for synchronizing the system clock to a GPS PPS source
|
This file contains functions and structures for accessing GPS time updates via the serial port. More...
#include "../client/pps-client.h"
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... | |
This file contains functions and structures for accessing GPS time updates via the serial port.
Definition in file pps-serial.cpp.
#define MAX_NOT_READY 60 |
Definition at line 30 of file pps-serial.cpp.
#define MSG_WAIT_TIME 990000 |
Definition at line 27 of file pps-serial.cpp.
#define SECS_PER_HOUR 3600 |
Definition at line 28 of file pps-serial.cpp.
#define VERIFY_NUM 10 |
Definition at line 29 of 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 417 of file pps-serial.cpp.
Referenced by waitForPPS().
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 464 of file pps-serial.cpp.
References timeCheckParams::attr, timeCheckParams::serialPort, and timeCheckParams::strbuf.
Referenced by waitForPPS().
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.
[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 75 of file pps-serial.cpp.
Referenced by read_save().
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.
Definition at line 312 of file pps-serial.cpp.
Referenced by waitForPPS().
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();
[in] | captureTime | The time in microseconds into the current second at wich the $GPRMC message was captured and converted. |
[in] | tcp | A struct pointer used to pass thread data. |
Definition at line 177 of file pps-serial.cpp.
References getUTCfromGPSmessages().
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.
[in,out] | tcp | A 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().
int saveTimestamps | ( | int | gmt0Seconds, |
int | gmtSeconds, | ||
int | tv_usec, | ||
timeCheckParams * | tcp | ||
) |
Saves timestamps of local time and GPS time to tcp->gmtTime_file.
[in] | gmt0Seconds | The GPS timestamp. |
[in] | gmtSeconds | The local time timestamp |
[in] | tcp | Structure containing the gmtTime_file filename. |
Definition at line 142 of file pps-serial.cpp.
References timeCheckParams::gmtTime_file, timeCheckParams::strbuf, and writeToLog().
struct ppsFiles f |
struct G g |
Declares the global variables defined in pps-client.h.
Definition at line 53 of file pps-client.cpp.