#!/bin/bash
# -----------------------------------------------------------------------------
# show_tech_pd                     
#                                      
# Copyright (c) 2014-2015 by cisco Systems, Inc.
# All rights reserved.
#------------------------------------------------------------------------------

#
# Load the script provided by show-tech infra, which provides worker functions
#
source /opt/cisco/calvados/script/show_tech_main_fragment
#
# Parse the arguments to the script - card type and interface filter are the 
# only support options currently.  No need to use the default parser function,
# as this has been done by caller.
#
__cardtype="unspecified"
trace_only="0"
show_only="0"
not_sim="0"

while [ "$#" -gt "0" ]; do
    case "$1" in
        -T) trace_only="1"; shift 1;;
        -S) show_only="1"; shift 1;;
        -t) __cardtype="$2"; shift 2;;
        *) shift;;
    esac
done

if [ "$__cardtype" == "unspecified" ]; then
    __cardtype=`/opt/cisco/calvados/script/node_type`
fi

not_sim=`lspci | grep "Ethernet controller: Intel" | wc -l`

sys_hw_show_exec[1]='PEM driver show_power'
sys_hw_show__ksh[1]='/opt/cisco/calvados/sbin/asr9k_show_power -t'

rplc_show_exec[1]='dump envmon data structures'
rplc_show__ksh[1]='/opt/cisco/calvados/bin/envmon_test_asr9k -d'

rplc_show_exec[2]='pstack canbus_driver'
rplc_show__ksh[2]='pstack `pidof canbus_driver`'

rp_show_exec[1]='pstack i2c_server'
rp_show__ksh[1]='pstack `pidof i2c_server`'

#
# The display() function is the one that does all the work - called by us as 
# this is a worker script.
#
display() {
    print_main_heading "Platform Dependent envmon tech-support info"
        
    if [ "$__cardtype" = "SYS" ]; then
        if [ "$trace_only" = "0" ]; then
                if [ "$not_sim" != "0" ]; then
                     exec_commands sys_hw_show
                fi
        fi
    else
        case "$__cardtype" in
        "RP")
            exec_commands rplc_show
            exec_commands rp_show
            ;;

        "LC")
            exec_commands rplc_show
            ;;

        esac

   fi 
}

display
