diff --git a/tool/plugin/plugin_emc1413.sh b/tool/plugin/plugin_emc1413.sh new file mode 100644 index 0000000..6a7f011 --- /dev/null +++ b/tool/plugin/plugin_emc1413.sh @@ -0,0 +1,45 @@ +#!/bin/sh + +# @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" + +} + +convert_emc1413_data $1 $2 $3 \ No newline at end of file diff --git a/tool/plugin/plugin_ina3221.sh b/tool/plugin/plugin_ina3221.sh new file mode 100644 index 0000000..7cc124c --- /dev/null +++ b/tool/plugin/plugin_ina3221.sh @@ -0,0 +1,79 @@ +#!/bin/sh + +# @Param1 ina3221 data high 8bit +# @Param2 ina3221 data high 8bit +# @Param3 channel number +# @Param4 mode select 0 - shunt volt +# 1 - bus volt +# @Param5 shunt resistor(only used in mode shunt volt) +# @Param6 customization channel name +convert_ina3221_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) + + 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 }') + echo "$6 : $format_volt V, hex value: $upper_hex_value" + + if [ $3 -eq 0 ];then + ina3221_ch0_volt=$format_volt + elif [ $3 -eq 1 ];then + ina3221_ch1_volt=$format_volt + else + ina3221_ch2_volt=$format_volt + fi + + elif [ $4 -eq $INA3221_SHUNT_VOLT ];then + current_mv=$(echo "scale=4; $dec_val / 8 * 40 / 1000" | bc) + current=$(echo "scale=4; $current_mv / $5" | bc) + + format_current=$(echo "$current" | awk '{ if ($0 ~ /^\./) print "0" $0; else print $0 }') + format_current_mv=$(echo "$current_mv" | awk '{ if ($0 ~ /^\./) print "0" $0; else print $0 }') + + echo "$6 : $format_current A, shunt volt: $format_current_mv mV, shunt resistor: $5 mOhm, hex value: $upper_hex_value" + + if [ $3 -eq 0 ];then + ina3221_ch0_current=$format_current + elif [ $3 -eq 1 ];then + ina3221_ch1_current=$format_current + else + ina3221_ch2_current=$format_current + fi + + elif [ $4 -eq $INA3221_POWER ];then + # calculate power + power_ch0=$(echo "scale=4; $ina3221_ch0_volt * $ina3221_ch0_current" | bc) + power_ch1=$(echo "scale=4; $ina3221_ch1_volt * $ina3221_ch1_current" | bc) + power_ch2=$(echo "scale=4; $ina3221_ch2_volt * $ina3221_ch2_current" | bc) + + format_power_ch0=$(echo "$power_ch0" | awk '{ if ($0 ~ /^\./) print "0" $0; else print $0 }') + format_power_ch1=$(echo "$power_ch1" | awk '{ if ($0 ~ /^\./) print "0" $0; else print $0 }') + format_power_ch2=$(echo "$power_ch2" | awk '{ if ($0 ~ /^\./) print "0" $0; else print $0 }') + + total_power=$(echo "scale=4; $power_ch0 + $power_ch1 + $power_ch2" | bc) + + echo "$INA3221_Channel0_name : $format_power_ch0 W" + echo "$INA3221_Channel1_name : $format_power_ch1 W" + echo "$INA3221_Channel2_name : $format_power_ch2 W" + echo "total power: $total_power W" + fi +} + +convert_ina3221_data $1 $2 $3 $4 $5 $6 \ No newline at end of file diff --git a/tool/plugin/plugin_tmp112.sh b/tool/plugin/plugin_tmp112.sh new file mode 100644 index 0000000..290e4a5 --- /dev/null +++ b/tool/plugin/plugin_tmp112.sh @@ -0,0 +1,38 @@ +#!/bin/sh + +# @Param1 tmp112 data high 8bit +# @Param2 tmp112 data low 8bit +# @Param3 customization sensor name +convert_tmp112_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) + + 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) + if [ $last_digit -eq 0 ];then + temp=$(echo "scale=4; $dec_val / 16 * 0.0625" | bc) + elif [ $last_digit -eq 1 ];then + temp=$(echo "scale=4; ( $dec_val - 1 ) / 8 * 0.0625" | bc) + fi + + echo "$3 : $temp" +} + +# E.G. ./plugin_tmp112.sh 0x08 0x40 temp +convert_tmp112_data $1 $2 $3 \ No newline at end of file diff --git a/tool/plugin/plugin_tmp468.sh b/tool/plugin/plugin_tmp468.sh new file mode 100644 index 0000000..b80b96a --- /dev/null +++ b/tool/plugin/plugin_tmp468.sh @@ -0,0 +1,29 @@ +#!/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 \ No newline at end of file