4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

gpsd + ntpdでStratum 1(GPSD NG版)

Last updated at Posted at 2016-02-17

きっかけ

PPS対応GPSを用意し、ldattach PPS /dev/ttyS0/dev/pps0を生成し、ntpdのType20Type22でStratum 1を運用されている方は多いだろう。
ただ、この運用の場合、ttyS0はntpdが占有し、GPSはNTP以外の目的に使えない。

gpsd

ttyS0から取れたGPSのNMEAを広く活用できるようにするのがgpsdで、ntpdとも連携できる優れものだ。
ただ、自分の環境では、まれにjitterのスパイクが発生したのと、気がついたらntpdと連携できなくなっていたので、/dev/pps0運用に戻してしまった。

gpsd再び

ところが、やっぱりntpdを使いながら、gpsdを使いたい。Ntripを使って位置の精度がどれくらい変わるか、見てみたい。そして、gpsdは、Ntripに対応している。

ntpdでgpsdを使う

ググるとたくさん出てくるが、みなType28の共有メモリ(SHM)ドライバを用いている。ところが、これを使うと、ntpq -pで見た時に、delay, offset, jitter全て0.000になってしまい、GPSに同期しない。(課題1)

gpsdでPPS

そもそも、gpsmonでgpsdの出力データを眺めると、PPS:の後が空白で、PPS情報が取れていない。(課題2)
まずは、gpsdでPPSを使えるように、課題2を解決する。

課題2

情報源が不足しているので、こちらの長い文章をひたすら一言一句読む。すると、

If you’re going to use gpsd for time service, you must run in -n mode so the clock will be updated even when no clients are active.

なんて書いてある。これか?
ArchLinuxの場合、/etc/gpsdを編集し、gpsd -nで起動できるようにする。

/etc/gpsd
# Default settings for gpsd.
START_DAEMON="true"
GPSD_OPTIONS="-n"
DEVICES="/dev/gps0"
USBAUTO="true"

gpsmonで見ると、PPS:に数値が入る。わーい。

gpsd -nでもPPSにならない場合

一旦gpsdを止めて、ldattach PPS /dev/ttyS0した後、ppstest /dev/pps0でPPSになることを確認してから、killall ldattachして、gpsd走らせると、何故かPPSになる気がする…。

課題1

次に、課題1に戻る。
GPSはArchLinux上で運用しているので、ArchWikiを確認すると、なんとType46なんていうものがある。こちらを確認すると、GPSD NGと言うようで、

It is important to understand that this driver works best using a GPS device with PPS support.

とのこと。SHMの代わりにJSONでPPSごと取ってくるようだ。これか?

先ほどのArchWikiの通りに設定する。

/etc/ntp.conf
server 127.127.46.0 
fudge 127.127.46.0 time1 0.0 time2 0.0 refid GPS

ところが、ntpq -pで見ても、一向にPPSらしい値にならない…気がする…。

もういちどこちらを見直すと、The Mode Wordの1に、

This mode is a possible choice for receivers that provide a PPS signal most of the time

との記載がある。mode 1にすれば良いのか?

/etc/ntp.conf
server 127.127.46.0 
fudge 127.127.46.0 mode 1 time1 0.0 time2 0.0 refid GPS

確認

しばらく放置して…。

$ ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*GPSD_JSON(0)    .GPS.            0 l   15   16  377    0.000   -0.002   0.001

こうでなくっちゃね! でもPPS同期を示すoじゃなく*なのね…気になる。

ntpdのソースの確認

refclock_gpsdjson.c
    /* dispatch to the mode-dependent processing functions */
    switch (up->mode) {
        default:
        case MODE_OP_STI:
                eval_serial(peer, pp, up);
            break;

    case MODE_OP_STRICT:
                eval_strict(peer, pp, up);
                break;

defaultはmode 0か?

gpsdを経由すると、SHMでなくても、やっぱり9時間毎にスパイクが発生する…
ntp_offset-day.png

ツッコミ

Ntripやってないじゃん!

4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?