ユーザ用ツール

サイト用ツール


mae3xx_tips:ntpd_with_gps:start

GPSを用いた時刻同期 (MA-E350/KLxx)

通信モジュールとして KYM11 を搭載した機種では、通信モジュール内蔵の GPS を使用して Stratum-1 の NTP server にすることができます。


設定

パッケージの追加

GPS から出力されるデータ(NMEA 01831))を処理するため、gpsd を追加します。

Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                             Version                          Architecture Description
+++-================================-================================-============-===============================================================================
ii  gpsd                             3.9-3                            armhf        Global Positioning System - daemon
root@plum:~# apt-get install gpsd
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following package was automatically installed and is no longer required:
  libmodbus5
Use 'apt-get autoremove' to remove it.
The following extra packages will be installed:
  libbluetooth3 libgps20
Suggested packages:
  gpsd-clients
The following NEW packages will be installed:
  gpsd libbluetooth3 libgps20
0 upgraded, 3 newly installed, 0 to remove and 6 not upgraded.
Need to get 307 kB of archives.
After this operation, 777 kB of additional disk space will be used.
Do you want to continue? [Y/n] 


gpsd の設定

gpsd の init script の設定ファイル (/etc/default/gpsd) を編集します。

gpsd
# Default settings for gpsd.
# Please do not edit this file directly - use `dpkg-reconfigure gpsd' to
# change the options.
START_DAEMON="true"
GPSD_OPTIONS="-n"
DEVICES="/dev/ttyKYM11"
USBAUTO="true"
GPSD_SOCKET="/var/run/gpsd.sock"


KYM11 の設定

gpsd は、普通の GPS (NMEA 0183 を垂れ流す) を想定しているため、そのままでは KYM11 から NMEA 0183 データを取得できません。
そのため、gpsd を起動する前に、NMEA 0183 を垂れ流すように設定しておきます。

kym11_gps
#! /bin/bash
 
DEFAULT=/etc/default/gpsd
 
START_DAEMON="false"
DEVICES="/dev/ttyKYM11"
 
[ -r $DEFAULT ] && . $DEFAULT
 
if [ "$START_DAEMON" != "true" ]; then
    exit 1
fi
 
 
do_start()
{
    chat -v ABORT ERROR TIMEOUT 10 '' ATZ OK AT@74=user@au.au-net.ne.jp OK AT@75=au OK AT@70=3 OK AT@76=1 OK AT@77=0,1 OK AT@72 OK '' < $DEVICES > $DEVICES
    return 0
}
 
do_stop()
{
    chat -v ABORT ERROR TIMEOUT 10 '' AT@73 OK ATZ OK '' < $DEVICES > $DEVICES
    return 0
}
 
 
case "$1" in
  start)
    do_start
    ;;
  stop)
    do_stop
    ;;
  restart)
    do_stop
    do_start
    ;;
  *)
    echo "Usage: $0 {start|stop|restart}" >&2
    exit 3
    ;;
esac
 
:
root@plum:~# ./kym11_gps start


ntpd の設定

gpsd を時刻同期のソースとするよう、ntpd の設定ファイル (/etc/ntp.conf) を編集します。

ntp.conf
# /etc/ntp.conf, configuration for ntpd; see ntp.conf(5) for help
 
disable monitor
 
driftfile /var/lib/ntp/ntp.drift
 
 
# Enable this if you want statistics to be logged.
#statsdir /var/log/ntpstats/
 
〜〜〜 略 〜〜〜
server 127.127.28.0 minpoll 4 maxpoll 4    <----- 追加
fudge 127.127.28.0 time1 0.0 refid GPS     <----- 追加
〜〜〜 略 〜〜〜


daemon の起動

gpsd と ntpd を起動します。

root@plum:~# /etc/init.d/gpsd start
 * Starting GPS (Global Positioning System) daemon gpsd                                                 [ OK ] 
root@plum:~# /etc/init.d/ntp start
 * Starting NTP server ntpd                                                                             [ OK ] 
root@plum:~# 


ntpd の状態確認

ntpd が GPS を用いて時刻同期できているか、ntpq コマンドで確認してみます。

root@plum:~# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*SHM(0)          .GPS.            0 l   16   16    1    0.000   -1.088   0.001

先頭にアスタリスク(*)がついており、きちんと同期出来ていることが確認できました。


mae3xx_tips/ntpd_with_gps/start.txt · 最終更新: 2016/09/13 14:16 by admin