#!/bin/bash
# console-config/src/lib-scripts/timing-dm24-xlate.sh
#
#  Copyright: ©2014, Güralp Systems Ltd.
#  Author: Laurence Withers <lwithers@guralp.com>
#  License: GPLv3
#
# Time of day string sent serially to the EAM, which converts it into an NMEA
# compatible output stream that won't crash the DM24. PPS passes through
# hardware, not software. Needs an input port (for time of day) and an output
# port (for NMEA generated by ntp-to-nmea in timestamp-in mode).
#



dm24_xlate_setup() {
    serial_select_xlate
    if [ $? -ne 0 ]
    then
        echo "Configuration not changed."
        exit 1
    fi

    serial_select_output "timestamp-in"
    if [ $? -ne 0 ]
    then
        echo "Configuration aborted."
        serial_clear_function "Timestamp in" ""
        exit 1
    fi

    # In this mode, the PPS goes to the DM24 and we get it to emit RTStatus
    # as normal. Then NTP synchronises the EAM to the fine timing information
    # exposed in RTStatus.
    (
        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_xlate" "true" "true" "false"

    svc timing restart
    serial_clear_input

    echo "Configuration updated."
    exit 0
}



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