diff --git a/nicsensor.sh b/nicsensor.sh index 4818d73..77e87b7 100755 --- a/nicsensor.sh +++ b/nicsensor.sh @@ -1,5 +1,5 @@ #!/bin/sh -SCRIPT_VERSION="1.8.5" +SCRIPT_VERSION="1.8.6" # --------------------------------------------------------- # Project Feature Varible (Change if need) # --------------------------------------------------------- @@ -139,6 +139,9 @@ INFO="Info" WARNING="Warning" ERROR="Error" log="/tmp/nicsensor_debug.log" +pmbus_op="get" +hex_pmbus_cmd=0xff +hex_pmbus_size=0 # --------------------------------------------------------- # Script Function Defination # --------------------------------------------------------- @@ -443,6 +446,23 @@ pre_exec_hook(){ echo "Command Format : ./nicsensor.sh [slot] pmbus [slave] [pmbus_command]" exit 1 fi + + # Pmbus Command need pre-process + PMBUS_PLUGIN="./pmbus_cmd_list.sh" + if [ -e ${PMBUS_PLUGIN} ];then + str_pmbus_cmd=$option_data + hex_pmbus_cmd=`$PMBUS_PLUGIN "code" $str_pmbus_cmd` + + if [ "$hex_pmbus_cmd" = "0xff" ];then + fmt_print "console" $ERROR "Unsupport PMBUS Command : $str_pmbus_cmd" + exit 1 + fi + + hex_pmbus_size=`$PMBUS_PLUGIN "size" $str_pmbus_cmd` + pmbus_op=`$PMBUS_PLUGIN "operation" $str_pmbus_cmd` + else + fmt_print "console" $ERROR "Can't find pmbus plugin file, please copy pmbus_cmd_list.sh to here!" + fi fi # if the action is fru write, need pre-process fru data @@ -1247,32 +1267,21 @@ process_fru(){ # --------------------------------------------------------- # PMBUS Function # --------------------------------------------------------- -#@Param1 : Pmbus Command, hex data -#@Param2 : Pmbus reading size, BYTE(1)|WORD(2)|BLOCK(3)|RAW(4) +#@Param1 : Operation Type, get|set +#@Param2 : Pmbus Command, hex data +#@Param3 : Pmbus reading size, BYTE(1)|WORD(2)|BLOCK(3)|RAW(4) transfer_pmbus_command(){ - pmbus_res=`i2ctransfer -y $i2c_bus w1@$chip_slave $1 r$2` - reset_pca9548 $i2c_bus $pca9548_slave - fmt_print "console" $INFO "$option_data ,Command Code:$pmbus_res" - fmt_print "console" $INFO "Result: $pmbus_res" + if [ "$1" = "get" ];then + pmbus_res=`i2ctransfer -y $i2c_bus w1@$chip_slave $2 r$3` + reset_pca9548 $i2c_bus $pca9548_slave + fmt_print "console" $INFO "$option_data ,Command Code:$pmbus_res" + fmt_print "console" $INFO "Result: $pmbus_res" + fi } # Do pmbus test if plugin avalible process_pmbus(){ - PMBUS_PLUGIN="./pmbus_cmd_list.sh" - if [ -e ${PMBUS_PLUGIN} ];then - str_pmbus_cmd=$option_data - hex_pmbus_cmd=`$PMBUS_PLUGIN "code" $str_pmbus_cmd` - - if [ "$hex_pmbus_cmd" = "0xff" ];then - fmt_print "console" $ERROR "Unsupport PMBUS Command : $str_pmbus_cmd" - exit 1 - fi - - hex_pmbus_size=`$PMBUS_PLUGIN "size" $str_pmbus_cmd` - transfer_pmbus_command $hex_pmbus_cmd $hex_pmbus_size - else - fmt_print "console" $ERROR "Can't find pmbus plugin file, please copy pmbus_cmd_list.sh to here!" - fi + transfer_pmbus_command $pmbus_op $hex_pmbus_cmd $hex_pmbus_size } # This function is temporarily retained for future functional expansion diff --git a/pmbus_cmd_list.sh b/pmbus_cmd_list.sh index d012807..5be4c34 100644 --- a/pmbus_cmd_list.sh +++ b/pmbus_cmd_list.sh @@ -35,16 +35,16 @@ pmbus_command_help(){ echo " 3) E.G. : ./nicsensor.sh pcie1 pmbus 0x60 READ_TEMPERATURE_1" echo "" echo " *****************Pmbus Support Command List********************" - echo " Command Name Code Read Size " - echo " READ_VIN 0x88 Word " - echo " READ_IIN 0x89 Word " - echo " READ_VOUT 0x8b Word " - echo " READ_IOUT 0x8c Word " - echo " READ_TEMPERATURE_1 0x8d Word " - echo " READ_TEMPERATURE_2 0x8e Word " - echo " READ_TEMPERATURE_3 0x8f Word " - echo " READ_POUT 0x96 Word " - echo " READ_PIN 0x97 Word " + echo " Command Name Code op_type Read Size " + echo " READ_VIN 0x88 get Word " + echo " READ_IIN 0x89 get Word " + echo " READ_VOUT 0x8b get Word " + echo " READ_IOUT 0x8c get Word " + echo " READ_TEMPERATURE_1 0x8d get Word " + echo " READ_TEMPERATURE_2 0x8e get Word " + echo " READ_TEMPERATURE_3 0x8f get Word " + echo " READ_POUT 0x96 get Word " + echo " READ_PIN 0x97 get Word " echo " ***************************************************************" echo "" } @@ -85,6 +85,42 @@ find_pmbus_hex_code(){ echo $hex_cmd } +find_pmbus_operation_type(){ + case ${str_cmd} in + "READ_VIN") + op_type="get" + ;; + "READ_IIN") + op_type="get" + ;; + "READ_VOUT") + op_type="get" + ;; + "READ_IOUT") + op_type="get" + ;; + "READ_TEMPERATURE_1") + op_type="get" + ;; + "READ_TEMPERATURE_2") + op_type="get" + ;; + "READ_TEMPERATURE_3") + op_type="get" + ;; + "READ_POUT") + op_type="get" + ;; + "READ_PIN") + op_type="get" + ;; + *) + op_type="" + ;; + esac + echo $op_type +} + find_pmbus_read_size(){ case ${str_cmd} in "READ_VIN") @@ -127,6 +163,9 @@ main(){ "code") find_pmbus_hex_code ;; + "operation") + find_pmbus_operation_type + ;; "size") find_pmbus_read_size ;;