[chrony-users] Get time and pps status from Java

[ Thread Index | Date Index | More chrony.tuxfamily.org/chrony-users Archives ]

Hi there,

A Java application uses a ProcessBuilder to execute the ntpq and ntptime
commands to determine the following pieces of information:

   - 1PPS lock status
   - 1PPS connection status
   - Estimated error

Calling execve is an expensive operation and I'd like to swap it for a
relatively lightweight UDP call. Java libraries can send/receive NTP
messages over UDP, such as Apache Commons Net
<https://commons.apache.org/proper/commons-net/>, JavaSntpClient
<https://support.ntp.org/bin/view/Support/JavaSntpClient>, and spf4j

For example, when 1PPS is not locked, the ntpq command returns:

     remote           refid      st t when poll reach   delay   offset


*     .LOCL.           2 l    4   16  377    0.000    0.000
0.002    .PPS.            0 l    -    8    0    0.000    0.000

When 1PPS is locked, it returns (fudged IP):

     remote           refid      st t when poll reach   delay   offset


*      2 u   12   16  377    0.238   +0.639
0.027     .LOCL.           2 l  19h   16    0    0.000   +0.000

o127.127.22.1    .PPS.            0 l    1   16  377    0.000   -0.001

The output from the commands can be parsed and relayed to the rest of the
Java application.

Similarly, when the 1PPS signal has been lost (e.g., GPIO cable unplugged),
the ntptime command returns:

ntp_gettime() returns code 5 (ERROR)

  maximum error 206000 us, estimated error 0 us,

  status 0x2007 (PLL,PPSFREQ,PPSTIME,NANO),

Note the lack of *PPSSIGNAL*, which is present when the GPIO port is
carrying a signal:

ntp_adjtime() returns code 0 (OK)
  maximum error 206000 us, *estimated error 1 us*,


When the estimated error is between 5 and 10 us, we issue a warning. When
greater than 10 us, we take other actions. Again, this information is
parsed from by reading from standard output, which I'd like to avoid.

Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/