nicsensor/tool/plugin/plugin_tmp468.sh

29 lines
865 B
Bash
Raw Normal View History

2025-01-06 14:00:14 +08:00
#!/bin/sh
# @Param1 tmp468 data high 8bit
# @Param2 tmp468 data high 8bit
# @Param3 customization channel name
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]$/)
printf toupper(substr($0,i,1));
else
printf substr($0,i,1);
}
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 "
}
convert_tmp468_data $1 $2 $3