使用 gpsd 和 chrony 没有每秒脉冲

使用 gpsd 和 chrony 没有每秒脉冲

受到这个答案的启发:https://askubuntu.com/a/1374637我正在尝试让 chrony 从 GPSD 获取时间,而无需每秒脉冲。

我知道https://gpsd.gitlab.io/gpsd/gpsd-time-service-howto.html意味着您每秒需要一个脉冲:

GPSD、NTP 和提供 1PPS(每秒一个脉冲)输出的 GPS 接收器可用于建立高质量的 NTP 时间服务器。

据我所知,如果没有每秒脉冲,时间将受到9600波特率串行连接和(Linux)操作系统引入的抖动造成的延迟。

时间精确到 +/- 1 秒是可以接受的。

我添加了原始答案中的行(更改了串行端口):

refclock SHM 0 refid GPS precision 1e-1 offset 0 delay 0 stratum 2
refclock SOCK /var/run/chrony.ttymxc0.sock refid PPS

到 /etc/chrony.conf。

然后我在前台开始计时。它所报告的只是:

root@imx6ul-var-dart:~# chronyd -d
2022-09-08T09:27:25Z chronyd version 3.5 starting (+CMDMON +NTP +REFCLOCK +RTC -PRIVDROP -SCFILTER -SIGND +ASYNCDNS -SECHASH +IPV6 -DEBUG)
2022-09-08T09:27:25Z Frequency 0.000 +/- 1000000.000 ppm read from /var/lib/chrony/drift

它确实创建了套接字:

root@imx6ul-var-dart:~# ls -lA /run/chrony.ttymxc2.sock 
srwxr-xr-x 1 root root 0 Sep  8 09:27 /run/chrony.ttymxc2.sock

然后我在前台运行 gpsd:

root@imx6ul-var-dart:~# gpsd -N -D3 -F /run/gpsd.sock /dev/ttymxc2
gpsd:WARN: This system has a 32-bit time_t.  This gpsd will fail at 2038-01-19T03:14:07Z.
gpsd:INFO: launching (Version 3.23)
gpsd:INFO: listening on port gpsd
gpsd:INFO: stashing device /dev/ttymxc2 at slot 0
gpsd:INFO: running with effective group ID 20
gpsd:INFO: running with effective user ID 65534
gpsd:INFO: startup at 2022-09-08T09:37:52.000Z (1662629872)
gpsd:CLIENT: => client(0): {"class":"VERSION","release":"3.23","rev":"3.23","proto_major":3,"proto_minor":14}\x0d\x0a
gpsd:CLIENT: <= client(0): ?WATCH={"enable":true,"json":true};\x0a
gpsd:INFO: SER: opening GPS data source type 2 at '/dev/ttymxc2'
gpsd:INFO: SER: speed 9600, 8N1
gpsd:INFO: SER: speed 9600, 8O1
gpsd:INFO: SER: speed 9600, 8N1
gpsd:INFO: SER: speed 9600, 8N1
gpsd:INFO: SER: speed 9600, 8N1
gpsd:INFO: gpsd_activate(2): activated GPS (fd 8)
gpsd:CLIENT: => client(0): {"class":"DEVICES","devices":[{"class":"DEVICE","path":"/dev/ttymxc2","activated":"2022-09-08T09:38:02.070Z","native":0,"bps":9600,"parity":"N","stopbits":1,"cycle":1.00}]}\x0d\x0a{"class":"WATCH","enable":true,"json":true,"nmea":false,"raw":0,"scaled":false,"timing":false,"split24":false,"pps":false}\x0d\x0a
gpsd:INFO: /dev/ttymxc2 identified as type NMEA0183, 0 sec @ 9600bps
gpsd:CLIENT: => client(0): {"class":"DEVICE","path":"/dev/ttymxc2","driver":"NMEA0183","activated":"2022-09-08T09:38:02.073Z","native":0,"bps":9600,"parity":"N","stopbits":1,"cycle":1.00}\x0d\x0a
gpsd:WARN: NMEA0183: xxGSV field 3 value of 11 != actual count 7
gpsd:INFO: Sats used (0):
gpsd:CLIENT: => client(0): {"class":"SKY","device":"/dev/ttymxc2","nSat":7,"uSat":0,"satellites":[{"PRN":14,"el":27.0,"az":272.0,"ss":11.0,"used":false,"gnssid":0,"svid":14},{"PRN":17,"el":31.0,"az":309.0,"ss":32.0,"used":false,"gnssid":0,"svid":17},{"PRN":19,"el":3.0,"az":316.0,"ss":0.0,"used":false,"gnssid":0,"svid":19},{"PRN":21,"el":70.0,"az":96.0,"ss":13.0,"used":false,"gnssid":0,"svid":21},{"PRN":22,"el":38.0,"az":89.0,"ss":28.0,"used":false,"gnssid":0,"svid":22},{"PRN":24,"el":0.0,"az":357.0,"ss":0.0,"used":false,"gnssid":0,"svid":24},{"PRN":32,"el":31.0,"az":57.0,"ss":41.0,"used":false,"gnssid":0,"svid":32}]}\x0d\x0a
gpsd:WARN: NMEA0183: malformed GPGSV - fieldcount 18 % 4 != 0
gpsd:WARN: NMEA0183: xxGSV field 3 value of 9 != actual count 5
gpsd:INFO: Sats used (0):
gpsd:CLIENT: => client(0): {"class":"SKY","device":"/dev/ttymxc2","nSat":5,"uSat":0,"satellites":[{"PRN":76,"el":16.0,"az":340.0,"ss":33.0,"used":false,"gnssid":6,"svid":12},{"PRN":77,"el":0.0,"az":23.0,"ss":0.0,"used":false,"gnssid":6,"svid":13},{"PRN":83,"el":20.0,"az":115.0,"ss":9.0,"used":false,"gnssid":6,"svid":19},{"PRN":84,"el":77.0,"az":58.0,"ss":22.0,"used":false,"gnssid":6,"svid":20},{"PRN":85,"el":30.0,"az":309.0,"ss":29.0,"used":false,"gnssid":6,"svid":21}]}\x0d\x0a
gpsd:WARN: NMEA0183: can't use GLL time until after ZDA or RMC has supplied a year.
gpsd:CLIENT: => client(0): {"class":"TPV","device":"/dev/ttymxc2","mode":2,"lat":53.232661333,"lon":-2.098090167,"magvar":-1.0}\x0d\x0a
gpsd:INFO: PRN  1 az 309.0 el 80.0 (-0.134950,  0.109280,  0.984808)
gpsd:INFO: PRN  3 az 220.0 el 49.0 (-0.421707, -0.502570,  0.754710)
gpsd:INFO: PRN  8 az 161.0 el 31.0 ( 0.279066, -0.810468,  0.515038)
gpsd:INFO: PRN 14 az 272.0 el 27.0 (-0.890464,  0.031096,  0.453990)
gpsd:INFO: PRN 17 az 309.0 el 31.0 (-0.666144,  0.539433,  0.515038)
gpsd:INFO: PRN 21 az  96.0 el 70.0 ( 0.340147, -0.035751,  0.939693)
gpsd:INFO: PRN 22 az  89.0 el 38.0 ( 0.787891,  0.013753,  0.615661)
gpsd:INFO: PRN 32 az  57.0 el 31.0 ( 0.718881,  0.466847,  0.515038)
gpsd:INFO: Sats used (8):
gpsd:CLIENT: => client(0): {"class":"SKY","device":"/dev/ttymxc2","xdop":0.61,"ydop":0.84,"vdop":1.36,"tdop":1.27,"hdop":0.88,"gdop":2.47,"pdop":1.62,"nSat":11,"uSat":8,"satellites":[{"PRN":1,"el":80.0,"az":309.0,"ss":32.0,"used":true,"gnssid":0,"svid":1},{"PRN":3,"el":49.0,"az":220.0,"ss":12.0,"used":true,"gnssid":0,"svid":3},{"PRN":8,"el":31.0,"az":161.0,"ss":20.0,"used":true,"gnssid":0,"svid":8},{"PRN":10,"el":2.0,"az":53.0,"ss":14.0,"used":false,"gnssid":0,"svid":10},{"PRN":14,"el":27.0,"az":272.0,"ss":8.0,"used":true,"gnssid":0,"svid":14},{"PRN":17,"el":31.0,"az":309.0,"ss":32.0,"used":true,"gnssid":0,"svid":17},{"PRN":19,"el":3.0,"az":316.0,"ss":0.0,"used":false,"gnssid":0,"svid":19},{"PRN":21,"el":70.0,"az":96.0,"ss":14.0,"used":true,"gnssid":0,"svid":21},{"PRN":22,"el":38.0,"az":89.0,"ss":28.0,"used":true,"gnssid":0,"svid":22},{"PRN":24,"el":0.0,"az":357.0,"ss":0.0,"used":false,"gnssid":0,"svid":24},{"PRN":32,"el":31.0,"az":57.0,"ss":41.0,"used":true,"gnssid":0,"svid":32}]}\x0d\x0a
gpsd:INFO: PRN  1 az 309.0 el 80.0 (-0.134950,  0.109280,  0.984808)
gpsd:INFO: PRN  3 az 220.0 el 49.0 (-0.421707, -0.502570,  0.754710)
gpsd:INFO: PRN  8 az 161.0 el 31.0 ( 0.279066, -0.810468,  0.515038)
gpsd:INFO: PRN 14 az 272.0 el 27.0 (-0.890464,  0.031096,  0.453990)
gpsd:INFO: PRN 17 az 309.0 el 31.0 (-0.666144,  0.539433,  0.515038)
gpsd:INFO: PRN 21 az  96.0 el 70.0 ( 0.340147, -0.035751,  0.939693)
gpsd:INFO: PRN 22 az  89.0 el 38.0 ( 0.787891,  0.013753,  0.615661)
gpsd:INFO: PRN 32 az  57.0 el 31.0 ( 0.718881,  0.466847,  0.515038)
gpsd:INFO: PRN 68 az  44.0 el 44.0 ( 0.499695,  0.517450,  0.694658)
gpsd:INFO: PRN 75 az 285.0 el 14.0 (-0.937234,  0.251131,  0.241922)
gpsd:INFO: PRN 76 az 340.0 el 16.0 (-0.328771,  0.903291,  0.275637)
gpsd:INFO: PRN 83 az 115.0 el 20.0 ( 0.851651, -0.397131,  0.342020)
gpsd:INFO: PRN 84 az  58.0 el 77.0 ( 0.190769,  0.119206,  0.974370)
gpsd:INFO: PRN 85 az 309.0 el 30.0 (-0.673028,  0.545007,  0.500000)
gpsd:INFO: Sats used (14):
gpsd:CLIENT: => client(0): {"class":"SKY","device":"/dev/ttymxc2","xdop":0.46,"ydop":0.62,"vdop":1.36,"tdop":0.77,"hdop":0.88,"gdop":1.60,"pdop":1.62,"nSat":20,"uSat":14,"satellites":[{"PRN":1,"el":80.0,"az":309.0,"ss":32.0,"used":true,"gnssid":0,"svid":1},{"PRN":3,"el":49.0,"az":220.0,"ss":12.0,"used":true,"gnssid":0,"svid":3},{"PRN":8,"el":31.0,"az":161.0,"ss":20.0,"used":true,"gnssid":0,"svid":8},{"PRN":10,"el":2.0,"az":53.0,"ss":14.0,"used":false,"gnssid":0,"svid":10},{"PRN":14,"el":27.0,"az":272.0,"ss":8.0,"used":true,"gnssid":0,"svid":14},{"PRN":17,"el":31.0,"az":309.0,"ss":32.0,"used":true,"gnssid":0,"svid":17},{"PRN":19,"el":3.0,"az":316.0,"ss":0.0,"used":false,"gnssid":0,"svid":19},{"PRN":21,"el":70.0,"az":96.0,"ss":14.0,"used":true,"gnssid":0,"svid":21},{"PRN":22,"el":38.0,"az":89.0,"ss":28.0,"used":true,"gnssid":0,"svid":22},{"PRN":24,"el":0.0,"az":357.0,"ss":0.0,"used":false,"gnssid":0,"svid":24},{"PRN":32,"el":31.0,"az":57.0,"ss":41.0,"used":true,"gnssid":0,"svid":32},{"PRN":68,"el":44.0,"az":44.0,"ss":30.0,"used":true,"gnssid":6,"svid":4},{"PRN":69,"el":64.0,"az":144.0,"ss":0.0,"used":false,"gnssid":6,"svid":5},{"PRN":70,"el":12.0,"az":193.0,"ss":0.0,"used":false,"gnssid":6,"svid":6},{"PRN":75,"el":14.0,"az":285.0,"ss":28.0,"used":true,"gnssid":6,"svid":11},{"PRN":76,"el":16.0,"az":340.0,"ss":34.0,"used":true,"gnssid":6,"svid":12},{"PRN":77,"el":0.0,"az":23.0,"ss":0.0,"used":false,"gnssid":6,"svid":13},{"PRN":83,"el":20.0,"az":115.0,"ss":9.0,"used":true,"gnssid":6,"svid":19},{"PRN":84,"el":77.0,"az":58.0,"ss":22.0,"used":true,"gnssid":6,"svid":20},{"PRN":85,"el":30.0,"az":309.0,"ss":29.0,"used":true,"gnssid":6,"svid":21}]}\x0d\x0a
gpsd:CLIENT: => client(0): {"class":"TPV","device":"/dev/ttymxc2","mode":3,"time":"2022-09-08T09:20:35.000Z","ept":0.005,"lat":53.232662500,"lon":-2.098090333,"altHAE":84.6000,"altMSL":36.4000,"alt":36.4000,"epx":6.970,"epy":9.328,"epv":31.280,"magvar":-1.0,"speed":0.026,"geoidSep":48.200,"eph":16.720,"sep":30.780}\x0d\x0a

即使我使用-D6,也没有提及/run/chrony.ttymxc2.sock。

看起来 gpsd 甚至没有检查 /run/chrony.ttymxc2.sock 是否存在。

通过 chronyc,我看到:

root@imx6ul-var-dart:~# chronyc -n sources
210 Number of sources = 2
MS Name/IP address         Stratum Poll Reach LastRx Last sample               
===============================================================================
#? GPS                           0   4     0     -     +0ns[   +0ns] +/-    0ns
#? PPS                           0   4     0     -     +0ns[   +0ns] +/-    0ns

旁白:我不明白 gpsd 如何知道 chrony 套接字的名称,但 gpsd 似乎明确支持 chrony。 (对于枚举消费者的数据源来说,这是一个奇怪的设计,但 gpsd 是一个一流的项目,所以我确信这是有充分理由的。)

root@imx6ul-var-dart:~# strings /usr/sbin/gpsd | grep chrony
accepted chrony sock
PPS chrony_send %s @ %s Offset: %0.9f
/run/chrony.%s.sock
/tmp/chrony.%s.sock
PPS:%s chrony socket %s doesn't exist
PPS:%s connect chrony socket failed: %s, error: %d, errno: %d/%s
PPS:%s using chrony socket: %s

我也尝试过这些慢性配置但没有成功:

refclock SOCK /var/run/chrony.ttymxc2.sock refid GPS precision 1e-1 offset 0 delay 0 stratum 2
refclock SOCK /var/run/chrony.ttymxc2.sock refid PPS      

refclock SHM 0 offset 0.5 delay 0.2 refid NMEA

refclock SOCK /var/run/chrony.ttymxc2.sock refid GPS precision 1e-1 offset 0 delay 0

refclock SHM 0 offset 0.0 delay 0.2                                  
refclock SHM 1 offset 0.0 delay 0.0  

是否可以使用 gpsd 提供没有每秒脉冲的时间?

如果是的话,配置是什么?

答案1

它应该单独与该指令一起使用refclock SHM 0SHM 1并且SOCK仅适用于 PPS。

在 gpsd 日志中,有关于丢失 GPRMC 消息的提示。接收器需要配置为发送包含完整时间和日期的消息,以便 gpsd 能够将样本写入 SHM 0。

在您的接收器手册中应该有一个可以启用 GPRMC 和其他消息的命令。供应商还可能提供配置实用程序。例如,u-blox 接收器有 u-center。

答案2

James Browning 在 gpsd 邮件列表中提供了解决方案:

没有人正确阅读精美的文档(即使是我)

refclock SHM 0 poll 3 refid gps1
pool pool.ntp.org maxsources=3

driftfile /var/db/chrony/chrony.drift
bindcmdaddress /var/run/chrony/chrony.sock
rtcsync

对于 chrony 来说是一个好的起点。

我必须删除“pool”行,因为它没有在 chronyd 中解析。

相关内容