style(master : nicsensor) 精简脚本注释及格式
This commit is contained in:
parent
3710481735
commit
86e92f0302
42
nicsensor.sh
42
nicsensor.sh
@ -177,14 +177,6 @@ print_usage(){
|
|||||||
echo ""
|
echo ""
|
||||||
}
|
}
|
||||||
|
|
||||||
print_chip_command_format(){
|
|
||||||
echo "Command Format : ./nicsensor.sh [slot] chip [slave] [i2c_command]"
|
|
||||||
}
|
|
||||||
|
|
||||||
print_fru_command_format(){
|
|
||||||
echo "Command Format : ./nicsensor.sh [slot] fru [slave] write [fru_file]"
|
|
||||||
}
|
|
||||||
|
|
||||||
# print format message to console
|
# print format message to console
|
||||||
# @Param1 message level [Info Warning Error]
|
# @Param1 message level [Info Warning Error]
|
||||||
# @Param2 message content
|
# @Param2 message content
|
||||||
@ -283,12 +275,10 @@ try_get_server_type(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
init_debuglog(){
|
init_debuglog(){
|
||||||
# only save one running log
|
|
||||||
if [ -e $log ];then
|
if [ -e $log ];then
|
||||||
rm $log
|
rm $log
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# print time header
|
|
||||||
res_date=`date +%Y-%m-%dT%H:%M:%S`
|
res_date=`date +%Y-%m-%dT%H:%M:%S`
|
||||||
format_log_print $INFO "Start Time : $res_date"
|
format_log_print $INFO "Start Time : $res_date"
|
||||||
format_log_print $INFO "Script Version : $SCRIPT_VERSION"
|
format_log_print $INFO "Script Version : $SCRIPT_VERSION"
|
||||||
@ -308,7 +298,6 @@ init_debuglog(){
|
|||||||
|
|
||||||
# Before start test, record configurtion to log
|
# Before start test, record configurtion to log
|
||||||
record_config_info(){
|
record_config_info(){
|
||||||
|
|
||||||
format_log_print $INFO "PCIE slot : $nic_slot"
|
format_log_print $INFO "PCIE slot : $nic_slot"
|
||||||
format_log_print $INFO "I2C Bus: $i2c_bus"
|
format_log_print $INFO "I2C Bus: $i2c_bus"
|
||||||
if [ $is_have_pca9641 -eq 1 ];then
|
if [ $is_have_pca9641 -eq 1 ];then
|
||||||
@ -325,7 +314,6 @@ record_config_info(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
get_pca9641_control(){
|
get_pca9641_control(){
|
||||||
|
|
||||||
# Request 9641 lock
|
# Request 9641 lock
|
||||||
res_lock=`i2ctransfer -y $i2c_bus w2@$pca9641_slave $REG_pca9641_controll 0x81 r1`
|
res_lock=`i2ctransfer -y $i2c_bus w2@$pca9641_slave $REG_pca9641_controll 0x81 r1`
|
||||||
format_log_print $INFO "After request 9641 lock, The REG value is $res_lock"
|
format_log_print $INFO "After request 9641 lock, The REG value is $res_lock"
|
||||||
@ -346,7 +334,6 @@ get_pca9641_control(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch_pca9548_channel(){
|
switch_pca9548_channel(){
|
||||||
|
|
||||||
# set 9548 channel
|
# set 9548 channel
|
||||||
res_setchannel=`i2ctransfer -y $i2c_bus w1@$pca9548_slave $pca9548_channel`
|
res_setchannel=`i2ctransfer -y $i2c_bus w1@$pca9548_slave $pca9548_channel`
|
||||||
format_log_print $INFO "After switch channel"
|
format_log_print $INFO "After switch channel"
|
||||||
@ -371,7 +358,7 @@ pre_exec_hook(){
|
|||||||
if [ "$sensor_type" = "chip" ];then
|
if [ "$sensor_type" = "chip" ];then
|
||||||
if [ $param_num -le 3 ];then
|
if [ $param_num -le 3 ];then
|
||||||
format_print $ERROR "Command Format illegal"
|
format_print $ERROR "Command Format illegal"
|
||||||
print_chip_command_format
|
echo "Command Format : ./nicsensor.sh [slot] chip [slave] [i2c_command]"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@ -384,7 +371,7 @@ pre_exec_hook(){
|
|||||||
# is option_data(fru file name) valid?
|
# is option_data(fru file name) valid?
|
||||||
if [ "$option_data2" = "" ];then
|
if [ "$option_data2" = "" ];then
|
||||||
format_print $ERROR "Please provide fru file name"
|
format_print $ERROR "Please provide fru file name"
|
||||||
print_fru_command_format
|
echo "Command Format : ./nicsensor.sh [slot] fru [slave] write [fru_file]"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -397,10 +384,7 @@ pre_exec_hook(){
|
|||||||
# Set i2c configuration
|
# Set i2c configuration
|
||||||
# ---------------------------------------------------------
|
# ---------------------------------------------------------
|
||||||
set_configuration_5280m7(){
|
set_configuration_5280m7(){
|
||||||
|
|
||||||
# set pca9641 address && I2C BUS
|
|
||||||
if [ $nic_type = "ocp" ];then
|
if [ $nic_type = "ocp" ];then
|
||||||
# Case - OCP
|
|
||||||
is_have_pca9641=0
|
is_have_pca9641=0
|
||||||
pca9548_slave="0x70"
|
pca9548_slave="0x70"
|
||||||
i2c_bus=3
|
i2c_bus=3
|
||||||
@ -415,7 +399,6 @@ set_configuration_5280m7(){
|
|||||||
format_print $WARNING "Unspecified card slot!"
|
format_print $WARNING "Unspecified card slot!"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
# Case - PCIe
|
|
||||||
is_have_pca9641=1
|
is_have_pca9641=1
|
||||||
if [ $slot_number -le 2 ];then
|
if [ $slot_number -le 2 ];then
|
||||||
pca9641_slave="0x41"
|
pca9641_slave="0x41"
|
||||||
@ -447,12 +430,10 @@ set_configuration_5280m7(){
|
|||||||
|
|
||||||
set_configuration_5468m7(){
|
set_configuration_5468m7(){
|
||||||
if [ $nic_type = "ocp" ];then
|
if [ $nic_type = "ocp" ];then
|
||||||
# Case - OCP
|
|
||||||
format_print $ERROR "Unsupport OCP Nic on $server_type"
|
format_print $ERROR "Unsupport OCP Nic on $server_type"
|
||||||
format_print $INFO "Please check if script has update version"
|
format_print $INFO "Please check if script has update version"
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
# Case - PCIe
|
|
||||||
is_have_pca9641=1
|
is_have_pca9641=1
|
||||||
if [ $slot_number -le 4 ];then
|
if [ $slot_number -le 4 ];then
|
||||||
pca9641_slave="0x31"
|
pca9641_slave="0x31"
|
||||||
@ -494,12 +475,10 @@ set_configuration_5468m7(){
|
|||||||
|
|
||||||
set_configuration_donghu(){
|
set_configuration_donghu(){
|
||||||
if [ $nic_type = "ocp" ];then
|
if [ $nic_type = "ocp" ];then
|
||||||
# Case - OCP
|
|
||||||
format_print $ERROR "Unsupport OCP Nic on $server_type"
|
format_print $ERROR "Unsupport OCP Nic on $server_type"
|
||||||
format_print $INFO "Please check if script has update version"
|
format_print $INFO "Please check if script has update version"
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
# Case - PCIe
|
|
||||||
is_have_pca9641=0
|
is_have_pca9641=0
|
||||||
i2c_bus=3
|
i2c_bus=3
|
||||||
pca9548_slave="0x70"
|
pca9548_slave="0x70"
|
||||||
@ -527,12 +506,10 @@ set_configuration_donghu(){
|
|||||||
|
|
||||||
set_configuration_yichun(){
|
set_configuration_yichun(){
|
||||||
if [ $nic_type = "ocp" ];then
|
if [ $nic_type = "ocp" ];then
|
||||||
# Case - OCP
|
|
||||||
format_print $ERROR "Unsupport OCP Nic on $server_type"
|
format_print $ERROR "Unsupport OCP Nic on $server_type"
|
||||||
format_print $INFO "Please check if script has update version"
|
format_print $INFO "Please check if script has update version"
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
# Case - PCIe
|
|
||||||
is_have_pca9641=0
|
is_have_pca9641=0
|
||||||
pca9548_slave="0x74"
|
pca9548_slave="0x74"
|
||||||
if [ $slot_number -eq 0 ];then
|
if [ $slot_number -eq 0 ];then
|
||||||
@ -552,12 +529,10 @@ set_configuration_yichun(){
|
|||||||
|
|
||||||
set_configuration_qiandaohu(){
|
set_configuration_qiandaohu(){
|
||||||
if [ $nic_type = "ocp" ];then
|
if [ $nic_type = "ocp" ];then
|
||||||
# Case - OCP
|
|
||||||
format_print $ERROR "Unsupport OCP Nic on $server_type"
|
format_print $ERROR "Unsupport OCP Nic on $server_type"
|
||||||
format_print $INFO "Please check if script has update version"
|
format_print $INFO "Please check if script has update version"
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
# Case - PCIe
|
|
||||||
is_have_pca9641=0
|
is_have_pca9641=0
|
||||||
if [ $slot_number -le 7 ];then
|
if [ $slot_number -le 7 ];then
|
||||||
i2c_bus=3
|
i2c_bus=3
|
||||||
@ -598,12 +573,10 @@ set_configuration_qiandaohu(){
|
|||||||
|
|
||||||
set_configuration_5688m7(){
|
set_configuration_5688m7(){
|
||||||
if [ $nic_type = "ocp" ];then
|
if [ $nic_type = "ocp" ];then
|
||||||
# Case - OCP
|
|
||||||
format_print $ERROR "Unsupport OCP Nic on $server_type"
|
format_print $ERROR "Unsupport OCP Nic on $server_type"
|
||||||
format_print $INFO "Please check if script has update version"
|
format_print $INFO "Please check if script has update version"
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
# Case - PCIe
|
|
||||||
is_have_pca9641=1
|
is_have_pca9641=1
|
||||||
pca9641_slave="0x31"
|
pca9641_slave="0x31"
|
||||||
i2c_bus=12
|
i2c_bus=12
|
||||||
@ -636,7 +609,6 @@ set_configuration_5688m7(){
|
|||||||
|
|
||||||
# Base on the server type, set i2c conf
|
# Base on the server type, set i2c conf
|
||||||
set_configuration(){
|
set_configuration(){
|
||||||
|
|
||||||
format_log_print $INFO "Server Type : $server_type"
|
format_log_print $INFO "Server Type : $server_type"
|
||||||
parse_nic_slot
|
parse_nic_slot
|
||||||
|
|
||||||
@ -720,7 +692,6 @@ convert_emc1413_data(){
|
|||||||
|
|
||||||
# Get the sensor data, then parse raw data
|
# Get the sensor data, then parse raw data
|
||||||
read_emc1413_channel_value(){
|
read_emc1413_channel_value(){
|
||||||
|
|
||||||
format_log_print $INFO "Start EMC1413 channel data ..."
|
format_log_print $INFO "Start EMC1413 channel data ..."
|
||||||
|
|
||||||
res_td1_h=`i2ctransfer -y $i2c_bus w1@$chip_slave $REG_emc1413_TD1_H r1`
|
res_td1_h=`i2ctransfer -y $i2c_bus w1@$chip_slave $REG_emc1413_TD1_H r1`
|
||||||
@ -1126,7 +1097,6 @@ process_chip(){
|
|||||||
# ---------------------------------------------------------
|
# ---------------------------------------------------------
|
||||||
# parse fru file to hex string which can be used in i2ctransfer
|
# parse fru file to hex string which can be used in i2ctransfer
|
||||||
parse_fru_write_data(){
|
parse_fru_write_data(){
|
||||||
|
|
||||||
if [ -e $fru_file_name ];then
|
if [ -e $fru_file_name ];then
|
||||||
format_log_print $INFO "Fru file exist!"
|
format_log_print $INFO "Fru file exist!"
|
||||||
else
|
else
|
||||||
@ -1159,7 +1129,6 @@ parse_fru_write_data(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
read_fru(){
|
read_fru(){
|
||||||
|
|
||||||
res_fru=`i2ctransfer -y $i2c_bus w2@$chip_slave $fru_offset r256`
|
res_fru=`i2ctransfer -y $i2c_bus w2@$chip_slave $fru_offset r256`
|
||||||
reset_pca9548 $i2c_bus $pca9548_slave
|
reset_pca9548 $i2c_bus $pca9548_slave
|
||||||
|
|
||||||
@ -1247,9 +1216,7 @@ handle_reserve(){
|
|||||||
# ---------------------------------------------------------
|
# ---------------------------------------------------------
|
||||||
# END of CHIP Function
|
# END of CHIP Function
|
||||||
# ---------------------------------------------------------
|
# ---------------------------------------------------------
|
||||||
|
|
||||||
start_get_sensor(){
|
start_get_sensor(){
|
||||||
|
|
||||||
# switch pca9641 and pca9548
|
# switch pca9641 and pca9548
|
||||||
# if enable debug mode, will not do this action.
|
# if enable debug mode, will not do this action.
|
||||||
if [ $DEBUG_MODE -eq 0 ];then
|
if [ $DEBUG_MODE -eq 0 ];then
|
||||||
@ -1490,20 +1457,16 @@ start_detect_device(){
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
# ---------------------------------------------------------
|
# ---------------------------------------------------------
|
||||||
# Start Execute Script(main)
|
# Start Execute Script(main)
|
||||||
# ---------------------------------------------------------
|
# ---------------------------------------------------------
|
||||||
|
|
||||||
pre_exec_hook
|
pre_exec_hook
|
||||||
|
|
||||||
if [ "$1" = "version" ];then
|
if [ "$1" = "version" ];then
|
||||||
echo "Script Version : $SCRIPT_VERSION"
|
echo "Script Version : $SCRIPT_VERSION"
|
||||||
echo "Debug Mode : $DEBUG_MODE"
|
echo "Debug Mode : $DEBUG_MODE"
|
||||||
echo "Disable Detect : $DISABLE_DETECT"
|
echo "Disable Detect : $DISABLE_DETECT"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$1" = "detect" ];then
|
if [ "$1" = "detect" ];then
|
||||||
if [ "$2" = "ocp" ];then
|
if [ "$2" = "ocp" ];then
|
||||||
nic_type="ocp"
|
nic_type="ocp"
|
||||||
@ -1517,7 +1480,6 @@ if [ "$1" = "detect" ];then
|
|||||||
start_detect_device
|
start_detect_device
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $param_num -le 2 ];then
|
if [ $param_num -le 2 ];then
|
||||||
print_usage
|
print_usage
|
||||||
else
|
else
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user