From c11cd9317aea6f7d8d5dc34607e6d4a9282b73e2 Mon Sep 17 00:00:00 2001 From: leimingsheng Date: Sun, 27 Apr 2025 10:31:53 +0800 Subject: [PATCH] =?UTF-8?q?refactor(master=20:=20nicsensor)=E5=B0=86?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E6=A0=A1=E9=AA=8C=E7=AD=89=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E7=A7=BB=E5=85=A5=E5=88=B0pre=5Fexec=5Fhook=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nicsensor.sh | 58 ++++++++++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/nicsensor.sh b/nicsensor.sh index 2a088a9..c75366e 100755 --- a/nicsensor.sh +++ b/nicsensor.sh @@ -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