feat(script : nicsensor.sh)update to version 1.3Intest Rev5

1.添加传感器tmp112的适配
This commit is contained in:
leimingsheng 2024-12-16 11:35:56 +08:00
parent 5510b0d96e
commit ef2c4495b0
3 changed files with 56 additions and 12 deletions

@ -1,6 +1,7 @@
# Script Version 1.3
Release Note
1.[新增功能]支持5280m7的OCP卡的使用
2.[新增功能]支持传感器tmp468和tmp112
# Script Version 1.2 20241102
Release Note:

@ -50,6 +50,9 @@ TMP468_Channel6_name="Remote6"
TMP468_Channel7_name="Remote7"
TMP468_Channel8_name="Remote8"
# TMP112 sensor name
TMP112_Sensor_name="tmp112"
# fru basic offset
fru_offset="0x00 0x00"
@ -130,7 +133,7 @@ ina3221_ch2_volt="0"
ina3221_ch0_current="0"
ina3221_ch1_current="0"
ina3221_ch2_current="0"
SCRIPT_VERSION="1.3 Intest Rev4"
SCRIPT_VERSION="1.3 Intest Rev5"
fru_file_name=$option_data2
fru_write_size=0
@ -150,7 +153,7 @@ print_usage(){
echo " Command Format : ./nicsensor.sh [slot] [sensor tpye] [slave]"
echo " Option Detail"
echo " [slot] : 0 1 2 3 4 5 ..."
echo " [sensor type] : emc1413, adc128, ina3221 tmp468"
echo " [sensor type] : emc1413, adc128, ina3221, tmp468, tmp112"
echo " [slave] : chip slave address , please provide 7 bit address"
echo " E.G. : ./nicsensor.sh 0 adc128 0x1f"
echo ""
@ -880,17 +883,54 @@ process_tmp468(){
# ---------------------------------------------------------
# Chip TMP112
# ---------------------------------------------------------
# @Param1 tmp112 data high 8bit
# @Param2 tmp112 data low 8bit
# @Param3 customization sensor name
convert_tmp112_data(){
hex_value1=$(echo "$1" | awk '{sub(/^0x/,""); print}')
hex_value2=$(echo "$2" | awk '{sub(/^0x/,""); print}')
merge_value="${hex_value1}${hex_value2}"
# read_tmp112_value(){
# }
# bc calculator recognized upper case only, change data to upper case
upper_hex_value=$(echo "$merge_value" | awk '{
for(i=1; i<=length($0); i++){
if(tolower(substr($0,i,1)) ~ /^[a-f]$/)
printf toupper(substr($0,i,1));
else
printf substr($0,i,1);
}
print ""
}')
# process_tmp112(){
# # tmp112 no need to init firsts
# change data from hex to dec
dec_val=$(echo "ibase=16; $upper_hex_value" | bc)
# # get chip tmp112 value
# read_tmp112_value
# }
binary_number=$(echo "ibase=16;obase=2;$upper_hex_value" | bc)
last_digit=$(echo $binary_number | cut -c 16)
if [ $last_digit -eq 0 ];then
temp=$(echo "scale=4; $dec_val / 16 * 0.0625" | bc)
elif [ $last_digit -eq 1];then
temp=$(echo "scale=4; ( $dec_val - 1 ) / 8 * 0.0625" | bc)
fi
echo "$3 : $temp"
}
read_tmp112_value(){
format_log_print $INFO "Start Read tmp112 channel data ..."
res_tmp112=`i2ctransfer -y $i2c_bus w1@$chip_slave $REG_tmp112 r2`
format_log_print $INFO "Tmp112 raw data: $res_tmp112"
format_print $INFO "Tmp112 read result:"
convert_tmp112_data $res_tmp112 $TMP112_Sensor_name
}
process_tmp112(){
# tmp112 no need to init firsts
# get chip tmp112 value
read_tmp112_value
}
# ---------------------------------------------------------
# CHIP
# ---------------------------------------------------------
@ -1040,6 +1080,9 @@ start_get_sensor(){
"tmp468")
process_tmp468
;;
"tmp112")
process_tmp112
;;
"chip")
process_chip
;;
@ -1047,7 +1090,7 @@ start_get_sensor(){
process_fru
;;
*)
format_print $ERROR "Unsupport Sensor Type !!!"
format_print $ERROR "Unsupport Sensor Type !!! - $sensor_type"
print_usage
;;
esac

@ -36,7 +36,7 @@
参数说明:
pcie_slot : 网卡所在的PCIE槽位, 填数字0,1,2,3,4,5
chip_type : 传感器芯片的类型, emc1413,adc128,ina3221
chip_type : 传感器芯片的类型, emc1413,adc128,ina3221,tmp268,tmp112
chip_slave: 传感器芯片的I2C地址(7bit)
举例说明:读取PCIE 1 上网卡的adc128芯片, 芯片slave地址为0x1f