diff --git a/nicsensor.sh b/nicsensor.sh index 948dc85..0c44a65 100755 --- a/nicsensor.sh +++ b/nicsensor.sh @@ -652,8 +652,6 @@ convert_emc1413_data(){ # remove data prefix '0x' hex_value1=$(echo "$1" | awk '{sub(/^0x/,""); print}') hex_value2=$(echo "$2" | awk '{sub(/^0x/,""); print}') - - # bc calculator recognized upper case only, change data to upper case upper_hex_value1=$(echo "$hex_value1" | awk '{ for(i=1; i<=length($0); i++){ if(tolower(substr($0,i,1)) ~ /^[a-f]$/) @@ -672,15 +670,9 @@ convert_emc1413_data(){ } print "" }') - - # change data from hex to dec dec_value1=$(echo "ibase=16; $upper_hex_value1" | bc) dec_value2=$(echo "ibase=16; $upper_hex_value2" | bc) - - # calculate tempreture temp=$(echo "scale=4; $dec_value1 + ($dec_value2 / 32 * 0.125 )" | bc) - - # print result to consol format_temp=$(echo "$temp" | awk '{ if ($0 ~ /^\./) print "0" $0; else print $0 }') fmt_print "log" $INFO "$3 - Hex data : $hex_value1 $hex_value2" @@ -691,7 +683,6 @@ convert_emc1413_data(){ # Get the sensor data, then parse raw data read_emc1413_channel_value(){ fmt_print "log" $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` res_td2_h=`i2ctransfer -y $i2c_bus w1@$chip_slave $REG_emc1413_TD2_H r1` @@ -699,18 +690,13 @@ read_emc1413_channel_value(){ res_td3_h=`i2ctransfer -y $i2c_bus w1@$chip_slave $REG_emc1413_TD3_H r1` res_td3_l=`i2ctransfer -y $i2c_bus w1@$chip_slave $REG_emc1413_TD3_L r1` reset_pca9548 $i2c_bus $pca9548_slave - - # record i2c raw data to log fmt_print "log" $INFO "channel 1 : $res_td1_h $res_td1_l" fmt_print "log" $INFO "channel 2 : $res_td2_h $res_td2_l" fmt_print "log" $INFO "channel 3 : $res_td3_h $res_td3_l" - - # start parse raw data echo ">>> The emc1413 value is:" convert_emc1413_data $res_td1_h $res_td1_l "$EMC1413_Channel0_name" convert_emc1413_data $res_td2_h $res_td2_l "$EMC1413_Channel1_name" convert_emc1413_data $res_td3_h $res_td3_l "$EMC1413_Channel2_name" - } process_emc1413(){ @@ -733,7 +719,6 @@ check_adc128_init(){ 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` - fmt_print "log" $INFO "After Set status, the REG 0x00 value is $res_adc128_setstart" fi } @@ -751,8 +736,6 @@ convert_adc128_data(){ hex_value1=$(echo "$1" | awk '{sub(/^0x/,""); print}') hex_value2=$(echo "$2" | awk '{sub(/^0x/,""); print}') merge_value="${hex_value1}${hex_value2}" - - # 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]$/) @@ -762,12 +745,9 @@ convert_adc128_data(){ } print "" }') - - # calculate dec value then print it to console dec_val=$(echo "ibase=16; $upper_hex_value" | bc) volt=$(echo "scale=4; $dec_val / 16 / 4096 * 2.65 / $4" | bc) format_volt=$(echo "$volt" | awk '{ if ($0 ~ /^\./) print "0" $0; else print $0 }') - fmt_print "log" $INFO "$3 - Hex data: $upper_hex_value" echo "$3 : $format_volt V" } @@ -775,7 +755,6 @@ convert_adc128_data(){ # Get the sensor data, then parse raw data read_adc128_channel_value(){ fmt_print "log" $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` res_ch2=`i2ctransfer -y $i2c_bus w1@$chip_slave $REG_adc128_ch2 r2` @@ -785,8 +764,6 @@ read_adc128_channel_value(){ res_ch6=`i2ctransfer -y $i2c_bus w1@$chip_slave $REG_adc128_ch6 r2` res_ch7=`i2ctransfer -y $i2c_bus w1@$chip_slave $REG_adc128_ch7 r2` reset_pca9548 $i2c_bus $pca9548_slave - - # record i2c raw data to log fmt_print "log" $INFO "channel0 : $res_ch0" fmt_print "log" $INFO "channel1 : $res_ch1" fmt_print "log" $INFO "channel2 : $res_ch2" @@ -795,8 +772,6 @@ read_adc128_channel_value(){ fmt_print "log" $INFO "channel5 : $res_ch5" fmt_print "log" $INFO "channel6 : $res_ch6" fmt_print "log" $INFO "channel7 : $res_ch7" - - # start parse raw data echo ">>> The ADC128 value is :" convert_adc128_data $res_ch0 "$ADC128_Channel0_name" $votage_division_factor_0 convert_adc128_data $res_ch1 "$ADC128_Channel1_name" $votage_division_factor_1 @@ -809,7 +784,6 @@ read_adc128_channel_value(){ } process_adc128(){ - # check if chip adc128 need init check_adc128_init read_adc128_channel_value } @@ -833,8 +807,6 @@ convert_ina3221_data(){ hex_value1=$(echo "$1" | awk '{sub(/^0x/,""); print}') hex_value2=$(echo "$2" | awk '{sub(/^0x/,""); print}') merge_value="${hex_value1}${hex_value2}" - - # 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]$/) @@ -844,8 +816,6 @@ convert_ina3221_data(){ } print "" }') - - # change data from hex to dec dec_val=$(echo "ibase=16; $upper_hex_value" | bc) if [ $4 -eq $INA3221_BUS_VOLT ];then @@ -853,7 +823,6 @@ convert_ina3221_data(){ format_volt=$(echo "$volt" | awk '{ if ($0 ~ /^\./) print "0" $0; else print $0 }') fmt_print "log" $INFO "Channel $3 - bus volt - hex value: $upper_hex_value" echo "$6 : $format_volt V" - if [ $3 -eq 0 ];then ina3221_ch0_volt=$format_volt elif [ $3 -eq 1 ];then @@ -865,12 +834,10 @@ convert_ina3221_data(){ elif [ $4 -eq $INA3221_SHUNT_VOLT ];then current_mv=$(echo "scale=4; $dec_val / 8 * 40 / 1000" | bc) current=$(echo "scale=4; $current_mv / $5" | bc) - format_current=$(echo "$current" | awk '{ if ($0 ~ /^\./) print "0" $0; else print $0 }') format_current_mv=$(echo "$current_mv" | awk '{ if ($0 ~ /^\./) print "0" $0; else print $0 }') fmt_print "log" $INFO "Channel $3 - shunt volt - hex value: $upper_hex_value" echo "$6 : $format_current A, shunt volt: $format_current_mv mV, shunt resistor: $5 mOhm" - if [ $3 -eq 0 ];then ina3221_ch0_current=$format_current elif [ $3 -eq 1 ];then @@ -880,17 +847,13 @@ convert_ina3221_data(){ fi elif [ $4 -eq $INA3221_POWER ];then - # calculate power power_ch0=$(echo "scale=4; $ina3221_ch0_volt * $ina3221_ch0_current" | bc) power_ch1=$(echo "scale=4; $ina3221_ch1_volt * $ina3221_ch1_current" | bc) power_ch2=$(echo "scale=4; $ina3221_ch2_volt * $ina3221_ch2_current" | bc) - format_power_ch0=$(echo "$power_ch0" | awk '{ if ($0 ~ /^\./) print "0" $0; else print $0 }') format_power_ch1=$(echo "$power_ch1" | awk '{ if ($0 ~ /^\./) print "0" $0; else print $0 }') format_power_ch2=$(echo "$power_ch2" | awk '{ if ($0 ~ /^\./) print "0" $0; else print $0 }') - total_power=$(echo "scale=4; $power_ch0 + $power_ch1 + $power_ch2" | bc) - echo "$INA3221_Channel0_name : $format_power_ch0 W" echo "$INA3221_Channel1_name : $format_power_ch1 W" echo "$INA3221_Channel2_name : $format_power_ch2 W" @@ -901,7 +864,6 @@ convert_ina3221_data(){ # Get the sensor data, then parse raw data read_ina3221_channel_value(){ fmt_print "log" $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` res_ch2=`i2ctransfer -y $i2c_bus w1@$chip_slave $REG_ina3221_ch3 r2` @@ -909,27 +871,22 @@ read_ina3221_channel_value(){ res_bus1=`i2ctransfer -y $i2c_bus w1@$chip_slave $REG_ina3221_bus2 r2` res_bus2=`i2ctransfer -y $i2c_bus w1@$chip_slave $REG_ina3221_bus3 r2` reset_pca9548 $i2c_bus $pca9548_slave - # record i2c raw data to log fmt_print "log" $INFO "channel 0 shunt volt: $res_ch0" fmt_print "log" $INFO "channel 1 shunt volt: $res_ch1" fmt_print "log" $INFO "channel 2 shunt volt: $res_ch2" - fmt_print "log" $INFO "Channel 0 bus volt : $res_bus0" fmt_print "log" $INFO "Channel 1 bus volt : $res_bus1" fmt_print "log" $INFO "Channel 2 bus volt : $res_bus2" - # start parse raw data echo ">>> The INA3221 shunt value is :" convert_ina3221_data $res_ch0 0 $INA3221_SHUNT_VOLT $shunt_resistor_0 "$INA3221_Channel0_name" convert_ina3221_data $res_ch1 1 $INA3221_SHUNT_VOLT $shunt_resistor_1 "$INA3221_Channel1_name" convert_ina3221_data $res_ch2 2 $INA3221_SHUNT_VOLT $shunt_resistor_2 "$INA3221_Channel2_name" - echo ">>> The INA3221 bus value is :" convert_ina3221_data $res_bus0 0 $INA3221_BUS_VOLT null "$INA3221_Channel0_name" convert_ina3221_data $res_bus1 1 $INA3221_BUS_VOLT null "$INA3221_Channel1_name" convert_ina3221_data $res_bus2 2 $INA3221_BUS_VOLT null "$INA3221_Channel2_name" - echo ">>> The INA3221 bus power is :" convert_ina3221_data 0 0 0 $INA3221_POWER } @@ -950,8 +907,6 @@ convert_tmp468_data(){ hex_value1=$(echo "$1" | awk '{sub(/^0x/,""); print}') hex_value2=$(echo "$2" | awk '{sub(/^0x/,""); print}') merge_value="${hex_value1}${hex_value2}" - - # 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]$/) @@ -961,23 +916,18 @@ convert_tmp468_data(){ } print "" }') - - # change data from hex to dec dec_val=$(echo "ibase=16; $upper_hex_value" | bc) temp=$(echo "scale=4; $dec_val / 8 * 0.0625" | bc) echo "$3 : $temp " - } read_tmp468_value(){ fmt_print "log" $INFO "Start Read tmp468 channel data ..." - res_tmp468=`i2ctransfer -y $i2c_bus w1@$chip_slave $REG_tmp468 r18` reset_pca9548 $i2c_bus $pca9548_slave fmt_print "log" $INFO "Tmp468 raw data: $res_tmp468" - tmp468_res1_h=`echo $res_tmp468 | awk '{print $1}'` tmp468_res1_l=`echo $res_tmp468 | awk '{print $2}'` tmp468_res2_h=`echo $res_tmp468 | awk '{print $3}'` @@ -1027,8 +977,6 @@ 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}" - - # 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]$/) @@ -1038,8 +986,6 @@ convert_tmp112_data(){ } print "" }') - - # change data from hex to dec dec_val=$(echo "ibase=16; $upper_hex_value" | bc) binary_number=$(echo "ibase=16;obase=2;$upper_hex_value" | bc) @@ -1076,7 +1022,6 @@ process_tmp112(){ # --------------------------------------------------------- # do a customization command write_read_chip(){ - # Modify i2c cmd which write to cpld if need cmd_wr=$option_data res_wr=`$cmd_wr` reset_pca9548 $i2c_bus $pca9548_slave @@ -1086,7 +1031,6 @@ write_read_chip(){ } process_chip(){ - # write and read cpld write_read_chip } @@ -1198,11 +1142,9 @@ write_fru(){ } process_fru(){ - # write and read fru if [ "$option_data" = "write" ];then write_fru else - # default action is read read_fru fi } @@ -1221,12 +1163,10 @@ start_get_sensor(){ # set global varible by server type set_configuration record_config_info - # if we have 9641 on i2c, then do it if [ $is_have_pca9641 -eq 1 ];then get_pca9641_control fi - switch_pca9548_channel fi @@ -1275,16 +1215,13 @@ detect_on_5280m7(){ i2c_bus=12 pca9641_slave="0x41" get_pca9641_control - do_i2c_detect $i2c_bus 0x72 0x02 1 0 do_i2c_detect $i2c_bus 0x72 0x04 2 1 do_i2c_detect $i2c_bus 0x72 0x08 3 2 reset_pca9548 $i2c_bus 0x72 - i2c_bus=13 pca9641_slave="0x42" get_pca9641_control - do_i2c_detect $i2c_bus 0x72 0x02 1 3 do_i2c_detect $i2c_bus 0x72 0x04 2 4 do_i2c_detect $i2c_bus 0x72 0x08 3 5 @@ -1298,22 +1235,18 @@ detect_on_5468m7(){ fmt_print "console" $INFO "Please check if script has update version" exit 1 fi - i2c_bus=13 pca9641_slave="0x31" get_pca9641_control - do_i2c_detect $i2c_bus 0x70 0x01 0 0 do_i2c_detect $i2c_bus 0x70 0x02 1 1 do_i2c_detect $i2c_bus 0x70 0x04 2 2 do_i2c_detect $i2c_bus 0x70 0x08 3 3 do_i2c_detect $i2c_bus 0x70 0x10 4 4 reset_pca9548 $i2c_bus 0x70 - i2c_bus=14 pca9641_slave="0x42" get_pca9641_control - do_i2c_detect $i2c_bus 0x71 0x01 0 5 do_i2c_detect $i2c_bus 0x71 0x02 1 6 do_i2c_detect $i2c_bus 0x71 0x04 2 7 @@ -1329,7 +1262,6 @@ detect_on_donghu(){ fmt_print "console" $INFO "Please check if script has update version" exit 1 fi - i2c_bus=3 do_i2c_detect $i2c_bus 0x70 0x80 7 0 do_i2c_detect $i2c_bus 0x70 0x40 6 1 @@ -1348,15 +1280,12 @@ detect_on_yichun(){ fmt_print "console" $INFO "Please check if script has update version" exit 1 fi - i2c_bus=12 do_i2c_detect $i2c_bus 0x74 0x02 2 0 reset_pca9548 $i2c_bus 0x74 - i2c_bus=13 do_i2c_detect $i2c_bus 0x74 0x02 2 1 reset_pca9548 $i2c_bus 0x74 - i2c_bus=14 do_i2c_detect $i2c_bus 0x74 0x02 2 2 reset_pca9548 $i2c_bus 0x74 @@ -1368,7 +1297,6 @@ detect_on_qiandaohu(){ fmt_print "console" $INFO "Please check if script has update version" exit 1 fi - i2c_bus=3 do_i2c_detect $i2c_bus 0x70 0x08 3 0 do_i2c_detect $i2c_bus 0x70 0x04 2 1 @@ -1379,7 +1307,6 @@ detect_on_qiandaohu(){ do_i2c_detect $i2c_bus 0x70 0x10 4 6 do_i2c_detect $i2c_bus 0x70 0x20 5 7 reset_pca9548 $i2c_bus 0x70 - i2c_bus=6 do_i2c_detect $i2c_bus 0x71 0x08 3 8 do_i2c_detect $i2c_bus 0x71 0x04 2 9 @@ -1394,17 +1321,14 @@ detect_on_5688m7(){ fmt_print "console" $INFO "Please check if script has update version" exit 1 fi - i2c_bus=12 pca9641_slave="0x31" get_pca9641_control - do_i2c_detect $i2c_bus 0x71 0x01 0 0 do_i2c_detect $i2c_bus 0x71 0x02 1 1 do_i2c_detect $i2c_bus 0x71 0x04 2 2 do_i2c_detect $i2c_bus 0x71 0x08 3 3 reset_pca9548 $i2c_bus 0x71 - do_i2c_detect $i2c_bus 0x72 0x01 0 4 do_i2c_detect $i2c_bus 0x72 0x02 1 5 do_i2c_detect $i2c_bus 0x72 0x04 2 6 @@ -1414,14 +1338,12 @@ detect_on_5688m7(){ debug_user_defined_detect(){ fmt_print "console" $INFO "Detect by user-defined" - # default execute fmt_print "console" $INFO "Default detect on the default i2c: $i2c_bus" i2cdetect -y $i2c_bus } start_detect_device(){ - # In debug mode, do customization detect action if [ $DEBUG_MODE -ne 0 ];then fmt_print "console" $INFO "In debug mode now"