feat(master : nicsensor) 支持通过命令配置关键变量

This commit is contained in:
leimingsheng 2025-07-25 15:23:55 +08:00
parent e2ccb19dd3
commit 7b6ae2a932

@ -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