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
|
|
|
|
|
|
|
|
|
|
path=`pwd`
|
|
|
|
|
fmt_print="${path}/format_print.sh"
|
|
|
|
|
i2c_script="${path}/i2c_${server_platform}.sh"
|
|
|
|
|
|
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(){
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "${mode}" in
|
|
|
|
|
"read")
|
|
|
|
|
read_emc1413_data
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
$fmt_print "console" "Error" "[plugin_emc1413]Unexpected Input Param : $mode"
|
|
|
|
|
;;
|
|
|
|
|
esac
|