#!/bin/bash
# console-config/src/lib-scripts/timing-dm24.sh
#
#  Copyright: ©2013–2014, Güralp Systems Ltd.
#  Author: Laurence Withers <lwithers@guralp.com>
#  License: GPLv3
#
# Set up to acquire Linux system time through a CD24/DM24 with RTStatus. We
# enable NTP and the ntpshmgsl intermediary. We also offer to run a script to
# enable RTStatus on all attached digitisers.
#



dm24_setup() {
    # Show confirmation dialog. Also offers to enable RTStatus on all
    # connected digitisers.
    dialog --title "CD24/DM24 connected to GPS" \
        --separate-output --checklist \
        "CD24 or DM24 digitiser modules will synchronise their data output \
to an attached GPS receiver. The Linux system clock (not used for data, but \
for log messages) will synchronise to the data." \
        10 "${DIALOG_DEFAULT_W}" 0 \
        "rtstatus" "Enable RTStatus now on all CD24/DM24s" "on" \
    2> "${DIALOG_RESULTFILE}"
    [ $? -eq 0 ] || return 1

    clear
    [ -s "${DIALOG_RESULTFILE}" ] && rtstatus-enable

    # Enact configuration save. This is a fixed configuration.
    (
        write_ntp_preamble
        cat <<EOF
# SHM managed by ntpshmgsl
server 127.127.28.1 minpoll 4 maxpoll 4
fudge 127.127.28.1 refid GSL
EOF
    ) | write_config_file "${NTP_CONFIG}"

    write_timing_config "dm24_gps" "true" "true" "false"

    svc timing restart

    serial_clear_input
    serial_clear_output
    serial_clear_xlate

    exit 0
}



# vim: ts=4:sw=4:expandtab:syntax=sh
