#!/bin/false
# For AGC devices

initGPSVar() {
    GPSENABLED=no
    . '/etc/telem-gps.conf'
    PORT="${PORT:-C4}"
}

isGPSttyEnabled() {
    if [ -f '/etc/telem-gps.conf' ]; then
        (
            initGPSVar
            # test
            [ "${GPSENABLED}" = "yes" ] || return 1
            # AGC AGW has C4 and C1 (rev5+) for GPS
            [ "${PORT}" = "C1" ] || [ "${PORT}" = "C4" ] || return 1
        )
        return
    fi
    false
}

getPPSdev() {
    # Usually pps0 is pps, but imx6dl has ptp0 as pps0
    # so we need to use ppsfind
    local PPS_NAME="$(ppsfind pps | cut -d: -f1)"
    echo "/dev/${PPS_NAME:-pps0}"
}

getGPStty() {
    initGPSVar
    local HW_XML='/usr/local/etc/telem/hw-run.xml'
    ls $(grep "index=\"${PORT:1:1}\"" "${HW_XML}" | sed 's/^.*name=\"\([^ ]*\)\".*/\1/') | grep tty
}
