fix(master : nicsensor) 修复 1.9.4 引入的执行时语法错误

This commit is contained in:
leimingsheng 2026-03-10 15:57:18 +08:00
parent 04c0342367
commit c7730923a1

@ -1,6 +1,5 @@
#!/bin/sh
set -euo pipefail
trap 'echo "Script terminated as line $LINENO , Please Check with command: cat /tmp/nicsensor.log"' ERR
set -eo pipefail
SCRIPT_VERSION="1.9.6"
# ---------------------------------------------------------
# Project Feature Varible (Change if need)
@ -160,7 +159,7 @@ log="/tmp/nicsensor_debug.log"
pmbus_op="get"
hex_pmbus_cmd=0xff
hex_pmbus_size=0
CONFIG_DIR="/tmp/ns/"
CONFIG_DIR="/tmp/nicsensor_config/"
# ---------------------------------------------------------
# Script Function Defination
# ---------------------------------------------------------
@ -954,7 +953,7 @@ convert_adc128_data(){
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"
fmt_print "log" $INFO "$3 - Hex data: 0x$merge_value"
echo "$3 : $format_volt V"
}
@ -1015,6 +1014,17 @@ convert_ina3221_data(){
merge_value="${hex_value1}${hex_value2}"
dec_val=$(hex_to_dec $merge_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 ""
}')
if [ $4 -eq $INA3221_BUS_VOLT ];then
volt=$(echo "scale=4; $dec_val / 8 * 40 / 10000 * 2" | bc)
format_volt=$(echo "$volt" | awk '{ if ($0 ~ /^\./) print "0" $0; else print $0 }')
@ -1167,6 +1177,16 @@ convert_tmp112_data(){
merge_value="${hex_value1}${hex_value2}"
dec_val=$(hex_to_dec $merge_value)
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 ""
}')
binary_number=$(echo "ibase=16;obase=2;$upper_hex_value" | bc)
bin_length=$(echo $binary_number | awk '{print length($0)}')
last_digit=$(echo $binary_number | cut -c $bin_length)