#!/pkg/bin/ksh
# ---------------------------------------------------------------------
# show_tech_platform_specific_timing - Platform specific show tech-support for Fretta timing
# Cisco_user: Dacharla Somasundar(dasomasu)
# Copyright (c) 2019 by cisco Systems, Inc.
# All rights reserved.
#--------------------------------------------------------------------

. /pkg/bin/show_tech_main_fragment

# Parse the arguments to the script.
__cardtype="unspecified"

while [ "$#" -gt "0" ]; do
   case "$1" in
        -t) __cardtype="$2"; shift 2;;
        *)  default_parser_function "$@"; shift $#;;
    esac
done

if [ "$__cardtype" == "unspecified" ]; then
    __cardtype=`node_type`
fi

cmd_index=1
sys_exec[$cmd_index]='show spp trace platform common all'
sys__ksh[$cmd_index]='spp_fretta_show_ltrace -A'
((cmd_index++))

sys_exec[$cmd_index]='show controllers timing driver trace all location $location'
sys__ksh[$cmd_index]='show_tmgctrl_trace -D -h $fq_nodeid'
((cmd_index++))

# For RP2-E, print the SPLL 1 and 2 input-clocks as well
if [ -e "/pkg/bin/zl30772_1_2_precisa2.txt" ]; then

    sys_exec[$cmd_index]='show controllers timing input-clock spll 1 status location $location'
    sys__ksh[$cmd_index]='tmgctrl_core_show_ctrl -C -H $fq_nodeid -S 1'
    ((cmd_index++))

    sys_exec[$cmd_index]='show controllers timing input-clock spll 2 status location $location'
    sys__ksh[$cmd_index]='tmgctrl_core_show_ctrl -C -H $fq_nodeid -S 2'
    ((cmd_index++))

fi

# For RP2-E, print the SPLL 1 and 2 status as well
if [ -e "/pkg/bin/zl30772_1_2_precisa2.txt" ]; then
    rm -rf /tmp/spll*_dump.txt

    sys_exec[$cmd_index]='show controllers timing pll dump location $location'
    sys__ksh[$cmd_index]='tmgctrl_core_show_ctrl -D -H $fq_nodeid'
    ((cmd_index++))
    
    sys_exec[$cmd_index]='SPLL0 dump:'
    sys__ksh[$cmd_index]='cat /tmp/spll0_dump.txt'
    ((cmd_index++))

    sys_exec[$cmd_index]='SPLL1 dump:'
    sys__ksh[$cmd_index]='cat /tmp/spll1_dump.txt'
    ((cmd_index++))

    sys_exec[$cmd_index]='SPLL2 dump:'
    sys__ksh[$cmd_index]='cat /tmp/spll2_dump.txt'
    ((cmd_index++))

else
    sys_exec[$cmd_index]='show controllers timing pll dump location $location'
    sys__ksh[$cmd_index]='tmgctrl_core_show_ctrl -D -H $fq_nodeid;'
    ((cmd_index++))
fi


# For RP2-E, print the SPLL 1 and 2 status as well
if [ -e "/pkg/bin/zl30772_1_2_precisa2.txt" ]; then

    sys_exec[$cmd_index]='show controllers timing pll spll 1 status location $location'
    sys__ksh[$cmd_index]='tmgctrl_core_show_ctrl -P -H $fq_nodeid -S 1'
    ((cmd_index++))

    sys_exec[$cmd_index]='show controllers timing pll spll 2 status location $location'
    sys__ksh[$cmd_index]='tmgctrl_core_show_ctrl -P -H $fq_nodeid -S 2'
    ((cmd_index++))
fi

if [ -e "/var/log/ctrace/eth_ptp" ]; then
    sys_exec[$cmd_index]='show eth_ptp trace traces'
    sys__ksh[$cmd_index]='/pkg/bin/ctracedec -Atkgw eth_ptp/eth_ptp_info eth_ptp/eth_ptp_err'
    ((cmd_index++))
fi

sys_exec[$cmd_index]=''
sys__ksh[$cmd_index]=''

display() {

    # Get the card_type: SYS|RP|DRP|LC.
    if [ "$__cardtype" == "SYS" ]; then
        exec_commands sys
    else
        case "$__cardtype" in
        "DRP"|"RP")
            exec_commands rp
            ;;
        esac
    fi

}

. /pkg/bin/show_tech_file_fragment
