linuxptp icon indicating copy to clipboard operation
linuxptp copied to clipboard

ts2phc: Enable CLOCK_REALTIME Synchronization with NMEA Sentences

Open orosiferenc3 opened this issue 1 year ago • 0 comments

Problem

The goal is to synchronize the system clock (CLOCK_REALTIME) with GNSS/GPS. Typically, this is achieved by using ts2phc to sync a hardware clock (PHC) to GPS and then using phc2sys to synchronize the system clock with the PHC, as described in this article.

image

However, on my modem, neither a hardware clock nor a PPS device is available. Instead, I directly synchronized the system clock with GPS.

Solution

  • ts2phc always attempts to initialize a PPS pin, which is unnecessary when using NMEA sentences. Additionally, CLOCK_REALTIME does not support PPS pins. To prevent this, we need to return early in ts2phc_pps_sink.c (line 191) before checking the number of PHC pins.
  • Since there is no PHC, the system clock's timestamp must be manually set. This is handled by retrieving the time in ts2phc.c (line 483).
  • Another key change is in ts2phc.c (line 826), where an equal sign (=) was added. This is necessary because, when using NMEA, there is no PPS signal, but clock synchronization is still required.

Testing

The changes were tested on a real device with GNSS/GPS, and synchronization worked as expected. To manually test, you can create a pipe (e.g., /tmp/nmea_pipe) and send NMEA-like sentences into it (only RMC sentences are required). Then, run ts2phc with the serial port set to the previously created pipe:

./ts2phc -c CLOCK_REALTIME -s nmea -mq -l 7 --ts2phc.nmea_serialport /tmp/nmea_pipe --leapfile ./leap-seconds.list --clock_servo nullf

orosiferenc3 avatar Mar 04 '25 14:03 orosiferenc3