[chrony-users] Get time and pps status from Java |
[ Thread Index |
Date Index
| More chrony.tuxfamily.org/chrony-users Archives
]
- To: chrony-users@xxxxxxxxxxxxxxxxxxxx
- Subject: [chrony-users] Get time and pps status from Java
- From: Thangalin <thangalin@xxxxxxxxx>
- Date: Tue, 14 Dec 2021 11:13:34 -0800
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:from:date:message-id:subject:to; bh=lvZxPkNNC0Qh9YUVxyZEKpcNau5IAA4JRnKvGNXgmqs=; b=mD6oLlE8RSutx5xvUHNmNvcMfxzN4BDAUMi5FznTW3iDdShQCMqc5ilWULuqdd2VfX 3dUMAUTXdw90gLxZOO8M1EKfxGKephZbqyrbVq3dREwobMPZzdERCTUip2au8psRGcsB 7K+UyPawzWtUhHoqReaiEoSZYI5pizoQcsY+ggs3h4pJKWc0b8ck7WT4U0STKn9zlmA6 sqym0te+SZCpjqTgbE8oDlBPHc3Fyv/5s5jWt4i2rAF6Py4m07hv0fIgKd/PUgvR1S99 nhPiDhf2cSfSQMi2HYwa37gRLqmrjVZU1+cXTfWCih7/yANbeauRyCVjbJkzx8MJtqsN XIeQ==
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
<https://github.com/zolyfarkas/spf4j/blob/master/spf4j-core/src/main/java/org/spf4j/net/SntpClient.java>'s
client.
For example, when 1PPS is not locked, the ntpq command returns:
remote refid st t when poll reach delay offset
jitter
==============================================================================
*127.127.1.0 .LOCL. 2 l 4 16 377 0.000 0.000
0.002
127.127.22.1 .PPS. 0 l - 8 0 0.000 0.000
0.000
When 1PPS is locked, it returns (fudged IP):
remote refid st t when poll reach delay offset
jitter
==============================================================================
*192.168.66.196 129.6.15.28 2 u 12 16 377 0.238 +0.639
0.027
127.127.1.0 .LOCL. 2 l 19h 16 0 0.000 +0.000
0.000
o127.127.22.1 .PPS. 0 l 1 16 377 0.000 -0.001
0.002
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*,
status 0x2107 (PLL,PPSFREQ,PPSTIME,*PPSSIGNAL*,NANO),
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.