From 7b6ae2a932eaa21ea3f7b78e00cd110c976f387d Mon Sep 17 00:00:00 2001 From: leimingsheng Date: Fri, 25 Jul 2025 15:23:55 +0800 Subject: [PATCH] =?UTF-8?q?feat(master=20:=20nicsensor)=20=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E9=80=9A=E8=BF=87=E5=91=BD=E4=BB=A4=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E5=85=B3=E9=94=AE=E5=8F=98=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nicsensor.sh | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/nicsensor.sh b/nicsensor.sh index 29c45a4..1c135bf 100755 --- a/nicsensor.sh +++ b/nicsensor.sh @@ -81,6 +81,11 @@ option_data=$4 option_data2=$5 param_num=$# +# Param alias +Param1=$1 +Param2=$2 +Param3=$3 + # REGISTER Table REG_pca9641_controll="0x01" REG_adc128_config="0x00" @@ -175,6 +180,14 @@ print_usage(){ echo " : ./nicsensor.sh pcie0 fru 0x57 read" echo " : ./nicsensor.sh pcie0 fru 0x57 write /tmp/fru.bin" echo "" + echo " Function 5 - Settings" + echo " 1) Command Format : ./nicsensor.sh [get/set] [property] [value]" + echo " 2) Option Detail" + echo " - [property] : debug, detect, server" + echo " - [value] : property's value" + echo " 3) E.G. : ./nicsensor.sh set server 5280m7" + echo " : ./nicsensor.sh set debug 1" + echo " : ./nicsensor.sh set detect 1" } # print format message to console|debuglog @@ -242,6 +255,50 @@ parse_nic_slot(){ fmt_print "log" $INFO "Slot Num : $slot_number" } +get_set_properties(){ + if [ "$Param2" = "server" ];then + target_file="/tmp/ns_servertype" + default_data=$server_type + elif [ "$Param2" = "debug" ];then + target_file="/tmp/ns_debugmode" + default_data=$DEBUG_MODE + elif [ "$Param2" = "detect" ];then + target_file="/tmp/ns_disabledetect" + default_data=$DISABLE_DETECT + else + fmt_print "console" $ERROR "Invalid Property : $Param2" + exit 1 + fi + + if [ "$Param1" = "get" ];then + if [ -e "$target_file" ];then + tmpdata=`cat $target_file` + fmt_print "console" $INFO "$Param2 : $tmpdata" + else + fmt_print "console" $INFO "$Param2 : $default_data" + fi + else + echo $Param3 > $target_file + fmt_print "console" $INFO "Set $Param3 -> $Param2 successfully" + fi + + exit 0 +} + +load_properties_from_cache(){ + if [ -e "/tmp/ns_servertype" ];then + server_type=`cat /tmp/ns_servertype` + fi + + if [ -e "/tmp/ns_debugmode" ];then + DEBUG_MODE=`cat /tmp/ns_debugmode` + fi + + if [ -e "/tmp/ns_disabledetect" ];then + DISABLE_DETECT=`cat /tm/ns_disabledetect` + fi +} + # According to boardid, parse server_type try_get_server_type(){ if [ -e "/tmp/ns_servertype" ];then @@ -287,6 +344,10 @@ init_debuglog(){ fmt_print "log" $INFO "Operation Type : i2c detect" elif [ "$nic_slot" = "version" ];then fmt_print "log" $INFO "Operation Type : get version" + elif [ "$nic_slot" = "get" ];then + fmt_print "log" $INFO "Operation Type : get property value" + elif [ "$nic_slot" = "set" ];then + fmt_print "log" $INFO "Operation Type : set property value" elif [ $param_num -lt 2 ];then fmt_print "log" $INFO "Operation Type : help info" else @@ -346,6 +407,11 @@ switch_pca9548_channel(){ pre_exec_hook(){ init_debuglog + if [ "$Param1" = "get" ] || [ "$Param1" = "set" ];then + get_set_properties + fi + + load_properties_from_cache # check server_type if is auto # if in debug mode, skip this check if [ "$server_type" = "auto" ] && [ $DEBUG_MODE -eq 0 ];then