refactor(master : nicsensor)将参数校验等功能移入到pre_exec_hook中

This commit is contained in:
leimingsheng 2025-04-27 10:31:53 +08:00
parent d3ad01482a
commit c11cd9317a

@ -74,6 +74,8 @@ chip_slave=$3
option_data=$4
option_data2=$5
param_num=$#
# CHIP REGISTER
REG_pca9641_controll="0x01"
@ -552,8 +554,10 @@ init_debuglog(){
format_log_print $INFO "Debug Mode : $DEBUG_MODE"
format_log_print $INFO "Disable Detect : $DISABLE_DETECT"
if [ $nic_slot == "detect" ];then
if [ "$nic_slot" == "detect" ];then
format_log_print $INFO "Operation Tpye : i2c detect"
elif [ "$nic_slot" == "version" ];then
format_log_print $INFO "Operation Tpye : get version"
else
format_log_print $INFO "Operation Tpye : read sensor"
fi
@ -613,6 +617,31 @@ switch_pca9548_channel(){
# pre execute hook function
pre_exec_hook(){
init_debuglog
# is param legel?
if [ "$sensor_type" == "chip" ];then
if [ $param_num -le 3 ];then
format_print $ERROR "Command Format illegal"
print_chip_command_format
exit 1
fi
fi
# if the action is fru write, need pre-process fru data
if [ "$sensor_type" == "fru" ];then
if [ "$option_data" == "write" ];then
format_log_print $INFO "Opreation FRU Write"
# is option_data(fru file name) valid?
if [ "$option_data2" == "" ];then
format_print $ERROR "Please provide fru file name"
print_fru_command_format
exit 1
fi
parse_fru_write_data
fi
fi
}
# ---------------------------------------------------------
@ -1445,15 +1474,6 @@ if [ "$1" == "version" ];then
exit 0
fi
# is param legel?
if [ "$sensor_type" == "chip" ];then
if [ $# -le 3 ];then
format_print $ERROR "Command Format illegal"
print_chip_command_format
exit 1
fi
fi
if [ "$1" == "detect" ];then
if [ "$2" == "ocp" ];then
nic_type="ocp"
@ -1468,23 +1488,7 @@ if [ "$1" == "detect" ];then
exit 0
fi
# if the action is fru write, need pre-process fru data
if [ "$sensor_type" == "fru" ];then
if [ "$option_data" == "write" ];then
format_log_print $INFO "Opreation FRU Write"
# is option_data(fru file name) valid?
if [ "$option_data2" == "" ];then
format_print $ERROR "Please provide fru file name"
print_fru_command_format
exit 1
fi
parse_fru_write_data
fi
fi
if [ $# -le 2 ];then
if [ $param_num -le 2 ];then
print_usage
else
start_get_sensor