fix(script : nicsensor.sh) 修正大部分脚本输出命令为format类

This commit is contained in:
leimingsheng 2024-11-07 10:40:53 +08:00
parent 14129aae22
commit 0b57277e4b

@ -453,7 +453,7 @@ convert_emc1413_data(){
# 读取EMC1413芯片每个通道的数据,随后调用数据处理函数进行数据解析并输出
read_emc1413_channel_value(){
echo "Start EMC1413 channel data ..." >> $log
format_log_print $INFO "Start EMC1413 channel data ..."
res_td1_h=`i2ctransfer -y $i2c_bus w1@$chip_slave $REG_emc1413_TD1_H r1`
res_td1_l=`i2ctransfer -y $i2c_bus w1@$chip_slave $REG_emc1413_TD1_L r1`
@ -463,9 +463,9 @@ read_emc1413_channel_value(){
res_td3_l=`i2ctransfer -y $i2c_bus w1@$chip_slave $REG_emc1413_TD3_L r1`
# 将 I2C 读取的 raw 数据记录到调试日志中
echo "channel 1 : $res_td1_h $res_td1_l" >> $log
echo "channel 2 : $res_td2_h $res_td2_l" >> $log
echo "channel 3 : $res_td3_h $res_td3_l" >> $log
format_log_print $INFO "channel 1 : $res_td1_h $res_td1_l"
format_log_print $INFO "channel 2 : $res_td2_h $res_td2_l"
format_log_print $INFO "channel 3 : $res_td3_h $res_td3_l"
# start parse raw data
echo ">>> The emc1413 value is:"
@ -490,17 +490,17 @@ process_emc1413(){
check_adc128_init(){
# Get Reg 0x00 status
res_adc128_status=`i2cget -y $i2c_bus $chip_slave $REG_adc128_config`
echo "REG adc128 STATUS : $res_adc128_status" >> $log
format_log_print $INFO "REG adc128 STATUS : $res_adc128_status"
# if stauts is not 0x01 (Start Monitor) ,then do init
if [ "$res_adc128_status" != "0x01" ];then
echo "Start Init ADC128 Chip" >> $log
format_log_print $INFO "Start Init ADC128 Chip"
# Init ADC128 work as mode 1 (0x02)
res_adc128_advance=`i2ctransfer -y $i2c_bus w2@$chip_slave $REG_adc128_advance 0x02`
# Set ADC128 on start (0x01)
res_adc128_setstart=`i2ctransfer -y $i2c_bus w2@$chip_slave $REG_adc128_config 0x01 r1`
echo "After Set status, the REG 0x00 value is $res_adc128_setstart" >> $log
format_log_print $INFO "After Set status, the REG 0x00 value is $res_adc128_setstart"
fi
}
@ -536,7 +536,7 @@ convert_adc128_data(){
# 读取ADC128芯片每个通道的数据,随后调用数据处理函数进行数据解析并输出
read_adc128_channel_value(){
echo "Start Read ADC128 channel data ..." >> $log
format_log_print $INFO "Start Read ADC128 channel data ..."
res_ch0=`i2ctransfer -y $i2c_bus w1@$chip_slave $REG_adc128_ch0 r2`
res_ch1=`i2ctransfer -y $i2c_bus w1@$chip_slave $REG_adc128_ch1 r2`
@ -548,14 +548,14 @@ read_adc128_channel_value(){
res_ch7=`i2ctransfer -y $i2c_bus w1@$chip_slave $REG_adc128_ch7 r2`
# 将 I2C 读取的 raw 数据记录到调试日志中
echo "channel0 : $res_ch0" >> $log
echo "channel1 : $res_ch1" >> $log
echo "channel2 : $res_ch2" >> $log
echo "channel3 : $res_ch3" >> $log
echo "channel4 : $res_ch4" >> $log
echo "channel5 : $res_ch5" >> $log
echo "channel6 : $res_ch6" >> $log
echo "channel7 : $res_ch7" >> $log
format_log_print $INFO "channel0 : $res_ch0"
format_log_print $INFO "channel1 : $res_ch1"
format_log_print $INFO "channel2 : $res_ch2"
format_log_print $INFO "channel3 : $res_ch3"
format_log_print $INFO "channel4 : $res_ch4"
format_log_print $INFO "channel5 : $res_ch5"
format_log_print $INFO "channel6 : $res_ch6"
format_log_print $INFO "channel7 : $res_ch7"
# start parse raw data
echo ">>> The ADC128 value is :"
@ -673,7 +673,7 @@ convert_ina3221_data(){
# 读取INA3221芯片每个通道的数据,随后调用数据处理函数进行数据解析并输出
read_ina3221_channel_value(){
echo "Start Read INA3221 channel data ..." >> $log
format_log_print $INFO "Start Read INA3221 channel data ..."
res_ch0=`i2ctransfer -y $i2c_bus w1@$chip_slave $REG_ina3221_ch1 r2`
res_ch1=`i2ctransfer -y $i2c_bus w1@$chip_slave $REG_ina3221_ch2 r2`
@ -684,13 +684,13 @@ read_ina3221_channel_value(){
# 将 I2C 读取的 raw 数据记录到调试日志中
echo "channel 0 shunt volt: $res_ch0" >> $log
echo "channel 1 shunt volt: $res_ch1" >> $log
echo "channel 2 shunt volt: $res_ch2" >> $log
format_log_print $INFO "channel 0 shunt volt: $res_ch0"
format_log_print $INFO "channel 1 shunt volt: $res_ch1"
format_log_print $INFO "channel 2 shunt volt: $res_ch2"
echo "Channel 0 bus volt : $res_bus0" >> $log
echo "Channel 1 bus volt : $res_bus1" >> $log
echo "Channel 2 bus volt : $res_bus2" >> $log
format_log_print $INFO "Channel 0 bus volt : $res_bus0"
format_log_print $INFO "Channel 1 bus volt : $res_bus1"
format_log_print $INFO "Channel 2 bus volt : $res_bus2"
# start parse raw data
echo ">>> The INA3221 shunt value is :"
@ -726,8 +726,8 @@ write_read_chip(){
cmd_wr=$option_data
res_wr=`$cmd_wr`
echo ">>> Chip Command: $cmd_wr"
echo ">>> The Result : $res_wr"
format_print $INFO ">>> Chip Command: $cmd_wr"
format_print $INFO ">>> The Result : $res_wr"
}
# chip处理逻辑
@ -747,18 +747,18 @@ process_chip(){
parse_fru_write_data(){
# 判断fru文件是否存在于当前目录
if [ -e $fru_file_name ];then
echo "Fru file exist!" >> $log
format_log_print $INFO "Fru file exist!"
else
echo "Fru file not exist!" >> $log
echo "Fru file not exist in current directory!"
echo "Error: Operation Failed!"
format_log_print $ERROR "Fru file not exist!"
format_print $WARNING "Fru file not exist in current directory!"
format_print $ERROR "Operation Failed!"
exit 1
fi
# 计算需要写入的fru文件大小
fru_write_size=`ls -lht | grep $fru_file_name | awk '{print $5}'`
echo "Fru File [$fru_file_name] size = $fru_write_size Bytes"
echo "Fru File [$fru_file_name] size = $fru_write_size Bytes" >> $log
format_print $INFO "Fru File [$fru_file_name] size = $fru_write_size Bytes"
format_log_print $INFO "Fru File [$fru_file_name] size = $fru_write_size Bytes"
# 获取fru文件的 raw data
fru_raw_data=`hexdump -C $fru_file_name | awk '{
@ -766,7 +766,7 @@ parse_fru_write_data(){
print $i
}
}'`
echo "Fru Raw Data: $fru_raw_data" >> $log
format_log_print $INFO "Fru Raw Data: $fru_raw_data"
# 将raw data解析为可被 i2ctransfer 写入的数据
fru_write_data=`echo $fru_raw_data | awk -v size=$fru_write_size '{
@ -818,7 +818,7 @@ write_fru(){
# 组装command并发送
write_command="i2ctransfer -y $i2c_bus w$i2c_write_byte@$chip_slave $fru_offset $fru_write_data"
write_res=`$write_command`
echo "Exec Command: $write_command" >> $log
format_log_print $INFO "Exec Command: $write_command"
}
@ -871,7 +871,7 @@ start_get_sensor(){
elif [ "$sensor_type" == "fru" ];then
process_fru
else
echo "Error: Unsupport Sensor Type !!!"
format_print $ERROR "Unsupport Sensor Type !!!"
print_usage
fi
}
@ -884,15 +884,15 @@ detect_on_5280m7(){
pca9641_slave="0x41"
get_pca9641_controll
echo ">>> PCIe slot 0 : bus12 9548channel 1"
format_print $INFO "PCIe slot 0 : bus12 9548channel 1"
i2ctransfer -y $i2c_bus w1@0x72 0x02
i2cdetect -y $i2c_bus
echo ">>> PCIe slot 1 : bus12 9548channel 2"
format_print $INFO "PCIe slot 1 : bus12 9548channel 2"
i2ctransfer -y $i2c_bus w1@0x72 0x04
i2cdetect -y $i2c_bus
echo ">>> PCIe slot 2 : bus12 9548channel 3"
format_print $INFO "PCIe slot 2 : bus12 9548channel 3"
i2ctransfer -y $i2c_bus w1@0x72 0x08
i2cdetect -y $i2c_bus
@ -900,15 +900,15 @@ detect_on_5280m7(){
pca9641_slave="0x42"
get_pca9641_controll
echo ">>> PCIe slot 3 : bus13 9548channel 1"
format_print $INFO "PCIe slot 3 : bus13 9548channel 1"
i2ctransfer -y $i2c_bus w1@0x72 0x02
i2cdetect -y $i2c_bus
echo ">>> PCIe slot 4 : bus13 9548channel 2"
format_print $INFO "PCIe slot 4 : bus13 9548channel 2"
i2ctransfer -y $i2c_bus w1@0x72 0x04
i2cdetect -y $i2c_bus
echo ">>> PCIe slot 5 : bus13 9548channel 3"
format_print $INFO "PCIe slot 5 : bus13 9548channel 3"
i2ctransfer -y $i2c_bus w1@0x72 0x08
i2cdetect -y $i2c_bus
}
@ -921,23 +921,23 @@ detect_on_5468m7(){
pca9641_slave="0x31"
get_pca9641_controll
echo ">>> PCIe slot 0 : bus13 9548channel 0"
format_print $INFO "PCIe slot 0 : bus13 9548channel 0"
i2ctransfer -y $i2c_bus w1@0x70 0x01
i2cdetect -y $i2c_bus
echo ">>> PCIe slot 1 : bus13 9548channel 1"
format_print $INFO "PCIe slot 1 : bus13 9548channel 1"
i2ctransfer -y $i2c_bus w1@0x70 0x02
i2cdetect -y $i2c_bus
echo ">>> PCIe slot 2 : bus13 9548channel 2"
format_print $INFO "PCIe slot 2 : bus13 9548channel 2"
i2ctransfer -y $i2c_bus w1@0x70 0x04
i2cdetect -y $i2c_bus
echo ">>> PCIe slot 3 : bus13 9548channel 3"
format_print $INFO "PCIe slot 3 : bus13 9548channel 3"
i2ctransfer -y $i2c_bus w1@0x70 0x08
i2cdetect -y $i2c_bus
echo ">>> PCIe slot 4 : bus13 9548channel 4"
format_print $INFO "PCIe slot 4 : bus13 9548channel 4"
i2ctransfer -y $i2c_bus w1@0x70 0x10
i2cdetect -y $i2c_bus
@ -945,27 +945,27 @@ detect_on_5468m7(){
pca9641_slave="0x42"
get_pca9641_controll
echo ">>> PCIe slot 5 : bus14 9548channel 0"
format_print $INFO "PCIe slot 5 : bus14 9548channel 0"
i2ctransfer -y $i2c_bus w1@0x71 0x01
i2cdetect -y $i2c_bus
echo ">>> PCIe slot 6 : bus14 9548channel 1"
format_print $INFO "PCIe slot 6 : bus14 9548channel 1"
i2ctransfer -y $i2c_bus w1@0x71 0x02
i2cdetect -y $i2c_bus
echo ">>> PCIe slot 7 : bus14 9548channel 2"
format_print $INFO "PCIe slot 7 : bus14 9548channel 2"
i2ctransfer -y $i2c_bus w1@0x71 0x04
i2cdetect -y $i2c_bus
echo ">>> PCIe slot 8 : bus14 9548channel 3"
format_print $INFO "PCIe slot 8 : bus14 9548channel 3"
i2ctransfer -y $i2c_bus w1@0x71 0x08
i2cdetect -y $i2c_bus
echo ">>> PCIe slot 9 : bus14 9548channel 4"
format_print $INFO "PCIe slot 9 : bus14 9548channel 4"
i2ctransfer -y $i2c_bus w1@0x71 0x10
i2cdetect -y $i2c_bus
echo ">>> PCIe slot 10 : bus14 9548channel 5"
format_print $INFO "PCIe slot 10 : bus14 9548channel 5"
i2ctransfer -y $i2c_bus w1@0x71 0x20
i2cdetect -y $i2c_bus
}
@ -975,35 +975,35 @@ detect_on_donghu(){
i2c_bus=3
echo ">>> PCIe slot 0 : bus3 9548channel 7"
format_print $INFO "PCIe slot 0 : bus3 9548channel 7"
i2ctransfer -y $i2c_bus w1@0x70 0x80
i2cdetect -y $i2c_bus
echo ">>> PCIe slot 1 : bus3 9548channel 6"
format_print $INFO "PCIe slot 1 : bus3 9548channel 6"
i2ctransfer -y $i2c_bus w1@0x70 0x40
i2cdetect -y $i2c_bus
echo ">>> PCIe slot 2 : bus3 9548channel 5"
format_print $INFO "PCIe slot 2 : bus3 9548channel 5"
i2ctransfer -y $i2c_bus w1@0x70 0x20
i2cdetect -y $i2c_bus
echo ">>> PCIe slot 3 : bus3 9548channel 4"
format_print $INFO "PCIe slot 3 : bus3 9548channel 4"
i2ctransfer -y $i2c_bus w1@0x70 0x10
i2cdetect -y $i2c_bus
echo ">>> PCIe slot 4 : bus3 9548channel 3"
format_print $INFO "PCIe slot 4 : bus3 9548channel 3"
i2ctransfer -y $i2c_bus w1@0x70 0x08
i2cdetect -y $i2c_bus
echo ">>> PCIe slot 5 : bus3 9548channel 2"
format_print $INFO "PCIe slot 5 : bus3 9548channel 2"
i2ctransfer -y $i2c_bus w1@0x70 0x04
i2cdetect -y $i2c_bus
echo ">>> PCIe slot 6 : bus3 9548channel 1"
format_print $INFO "PCIe slot 6 : bus3 9548channel 1"
i2ctransfer -y $i2c_bus w1@0x70 0x02
i2cdetect -y $i2c_bus
echo ">>> PCIe slot 7 : bus3 9548channel 0"
format_print $INFO "PCIe slot 7 : bus3 9548channel 0"
i2ctransfer -y $i2c_bus w1@0x70 0x01
i2cdetect -y $i2c_bus
}
@ -1011,17 +1011,17 @@ detect_on_donghu(){
# 在 yichun 上扫描每个pcie slot下的I2C设备
detect_on_yichun(){
i2c_bus=12
echo ">>> PCIe slot 0 : bus12 9546channel 2"
format_print $INFO "PCIe slot 0 : bus12 9546channel 2"
i2ctransfer -y $i2c_bus w1@0x74 0x02
i2cdetect -y $i2c_bus
i2c_bus=13
echo ">>> PCIe slot 1 : bus13 9546channel 2"
format_print $INFO "PCIe slot 1 : bus13 9546channel 2"
i2ctransfer -y $i2c_bus w1@0x74 0x02
i2cdetect -y $i2c_bus
i2c_bus=14
echo ">>> PCIe slot 2 : bus14 9546channel 2"
format_print $INFO "PCIe slot 2 : bus14 9546channel 2"
i2ctransfer -y $i2c_bus w1@0x74 0x02
i2cdetect -y $i2c_bus
}
@ -1032,12 +1032,12 @@ start_detect_device(){
# debug mode下进行detect操作仅对当前链路进行detect
if [ $DEBUG_MODE -ne 0 ];then
echo "In debug mode now, only detect i2c_bus$i2c_bus:"
format_print $INFO "In debug mode now, only detect i2c_bus$i2c_bus:"
i2cdetect -y $i2c_bus
exit 0
fi
echo ">>>>>> Detect on server : $server_type"
format_print $INFO "Detect on server : $server_type"
if [ $server_type == "5280m7" ];then
detect_on_5280m7
@ -1048,7 +1048,7 @@ start_detect_device(){
elif [ $server_type == "yichun" ];then
detect_on_yichun
else
echo "Error: Unsupport Server Type !!!"
format_print $ERROR "Unsupport Server Type !!!"
fi
}