nicsensor/tool/nicsensor_v2/plugin_emc1413.sh
leimingsheng 88f871c880 feat(master) update to 1.10 base dev 2
1.[新增功能]解耦脚本参数配置功能, 脚本配置全部放到project.config中
2.[新增功能]增加对pmbus set命令的支持
3.[新增功能]增加setup.sh, 用于一键部署脚本
4.[功能优化]代码结构目录重新归档
2026-04-17 17:09:43 +08:00

130 lines
4.0 KiB
Bash

#!/bin/sh
mode=$1
i2c_bus=$2
chip_slave=$3
server_platform=$4
server_type=$5
test_data1=$2
test_data2=$3
path=`pwd`
fmt_print="${path}/format_print.sh"
i2c_script="${path}/i2c_${server_platform}.sh"
server_script="${path}/platform_${server_type}.sh"
# EMC1413 channel name
EMC1413_Channel0_name="Channel0"
EMC1413_Channel1_name="Channel1"
EMC1413_Channel2_name="Channel2"
REG_emc1413_TD1_H="0x00"
REG_emc1413_TD1_L="0x29"
REG_emc1413_TD2_H="0x01"
REG_emc1413_TD2_L="0x10"
REG_emc1413_TD3_H="0x23"
REG_emc1413_TD3_L="0x24"
print_help(){
echo "---------------------------------------------------------"
echo "<option> read"
echo " Format : ./plugin_emc1413.sh read [i2c-bus] [slave] [platform]"
echo " Example: ./plugin_emc1413.sh read 13 0x42 m7"
echo "---------------------------------------------------------"
echo "<option> test"
echo " Format : ./plugin_emc1413.sh test [data1] [data2]"
echo " Example: ./plugin_emc1413.sh test 0x24 0x00"
echo "---------------------------------------------------------"
echo "<option> help"
echo " Format : ./plugin_emc1413.sh help"
echo " Example: ./plugin_emc1413.sh help"
echo "---------------------------------------------------------"
}
# @Param1 emc1413 data high 8bit
# @Param2 emc1413 data low 8bit
# @Param3 customization channel name
convert_emc1413_data(){
if [ "$3" = "disable" ];then
return
fi
# 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]$/)
printf toupper(substr($0,i,1));
else
printf substr($0,i,1);
}
print ""
}')
upper_hex_value2=$(echo "$hex_value2" | 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 ""
}')
# 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 }')
echo "$3 : $format_temp C, hex value : $hex_value1 $hex_value2"
}
read_emc1413_data(){
res_td1_h=`$i2c_script $i2c_bus 1 $chip_slave $REG_emc1413_TD1_H 1`
res_td1_l=`$i2c_script $i2c_bus 1 $chip_slave $REG_emc1413_TD1_L 1`
res_td2_h=`$i2c_script $i2c_bus 1 $chip_slave $REG_emc1413_TD2_H 1`
res_td2_l=`$i2c_script $i2c_bus 1 $chip_slave $REG_emc1413_TD2_L 1`
res_td3_h=`$i2c_script $i2c_bus 1 $chip_slave $REG_emc1413_TD3_H 1`
res_td3_l=`$i2c_script $i2c_bus 1 $chip_slave $REG_emc1413_TD3_L 1`
# After read option , reset pca9548
$server_script reset
$fmt_print "log" "Info" "[plugin_emc1413] TD1 : $res_td1_h $res_td1_l"
$fmt_print "log" "Info" "[plugin_emc1413] TD2 : $res_td2_h $res_td2_l"
$fmt_print "log" "Info" "[plugin_emc1413] TD3 : $res_td3_h $res_td3_l"
$fmt_print "console" "Info" "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"
}
test_emc1413_data(){
convert_emc1413_data $test_data1 $test_data2 "Temp"
}
case "${mode}" in
"read")
read_emc1413_data
;;
"test")
test_emc1413_data
;;
"help")
print_help
;;
*)
$fmt_print "console" "Error" "[plugin_emc1413]Unexpected Input Param : $mode"
print_help
;;
esac