2025-01-06 14:00:14 +08:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
2025-02-21 11:10:37 +08:00
|
|
|
mode=$1
|
|
|
|
|
i2c_bus=$2
|
|
|
|
|
chip_slave=$3
|
|
|
|
|
server_platform=$4
|
2025-05-09 11:43:23 +08:00
|
|
|
server_type=$5
|
2025-02-21 11:10:37 +08:00
|
|
|
|
2025-03-13 16:34:05 +08:00
|
|
|
test_data1=$2
|
|
|
|
|
test_data2=$3
|
|
|
|
|
|
2025-02-21 11:10:37 +08:00
|
|
|
path=`pwd`
|
|
|
|
|
fmt_print="${path}/format_print.sh"
|
|
|
|
|
i2c_script="${path}/i2c_${server_platform}.sh"
|
2025-05-09 11:43:23 +08:00
|
|
|
server_script="${path}/platform_${server_type}.sh"
|
2025-02-21 11:10:37 +08:00
|
|
|
|
2025-03-13 16:34:05 +08:00
|
|
|
# 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 "---------------------------------------------------------"
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-06 14:00:14 +08:00
|
|
|
# @Param1 emc1413 data high 8bit
|
|
|
|
|
# @Param2 emc1413 data low 8bit
|
|
|
|
|
# @Param3 customization channel name
|
|
|
|
|
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]$/)
|
|
|
|
|
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"
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-21 11:10:37 +08:00
|
|
|
read_emc1413_data(){
|
2025-03-13 16:34:05 +08:00
|
|
|
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`
|
|
|
|
|
|
2025-05-09 11:43:23 +08:00
|
|
|
# After read option , reset pca9548
|
|
|
|
|
$server_script reset
|
|
|
|
|
|
2025-03-13 16:34:05 +08:00
|
|
|
$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"
|
2025-02-21 11:10:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "${mode}" in
|
|
|
|
|
"read")
|
|
|
|
|
read_emc1413_data
|
|
|
|
|
;;
|
2025-03-13 16:34:05 +08:00
|
|
|
"test")
|
|
|
|
|
test_emc1413_data
|
|
|
|
|
;;
|
|
|
|
|
"help")
|
|
|
|
|
print_help
|
|
|
|
|
;;
|
2025-02-21 11:10:37 +08:00
|
|
|
*)
|
|
|
|
|
$fmt_print "console" "Error" "[plugin_emc1413]Unexpected Input Param : $mode"
|
2025-03-13 16:34:05 +08:00
|
|
|
print_help
|
2025-02-21 11:10:37 +08:00
|
|
|
;;
|
|
|
|
|
esac
|