From 13944d8f06cc26a3dcfbe91f47ceeb9764e552ae Mon Sep 17 00:00:00 2001 From: leimingsheng Date: Mon, 6 Jan 2025 09:10:08 +0800 Subject: [PATCH] create plugin branch --- .gitignore | 2 +- tool/{ => fru_parse}/fru_parse.py | 0 tool/{ => fru_parse}/fru_parse_usage.txt | 0 tool/{ => fru_parse}/frudata.sample | 0 tool/plugin/plugin_adc128.sh | 34 ++++++++++++++++++++++++ 5 files changed, 35 insertions(+), 1 deletion(-) rename tool/{ => fru_parse}/fru_parse.py (100%) rename tool/{ => fru_parse}/fru_parse_usage.txt (100%) rename tool/{ => fru_parse}/frudata.sample (100%) create mode 100644 tool/plugin/plugin_adc128.sh diff --git a/.gitignore b/.gitignore index 8760a7d..895840f 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -/tool/frudata.txt \ No newline at end of file +/tool/fru_parse/frudata.txt \ No newline at end of file diff --git a/tool/fru_parse.py b/tool/fru_parse/fru_parse.py similarity index 100% rename from tool/fru_parse.py rename to tool/fru_parse/fru_parse.py diff --git a/tool/fru_parse_usage.txt b/tool/fru_parse/fru_parse_usage.txt similarity index 100% rename from tool/fru_parse_usage.txt rename to tool/fru_parse/fru_parse_usage.txt diff --git a/tool/frudata.sample b/tool/fru_parse/frudata.sample similarity index 100% rename from tool/frudata.sample rename to tool/fru_parse/frudata.sample diff --git a/tool/plugin/plugin_adc128.sh b/tool/plugin/plugin_adc128.sh new file mode 100644 index 0000000..6eb936b --- /dev/null +++ b/tool/plugin/plugin_adc128.sh @@ -0,0 +1,34 @@ +#!/bin/sh + +# process sensor data then print to console +# @Param 1 adc128 data high 8bit +# @Param 2 adc128 data low 8bit +# @Param 3 customization channel name +# @Param 4 division factor +convert_adc128_data(){ + # remove data prefix '0x' + 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 "" + }') + + # calculate dec value then print it to console + dec_val=$(echo "ibase=16; $upper_hex_value" | bc) + volt=$(echo "scale=4; $dec_val / 16 / 4096 * 2.65 / $4" | bc) + format_volt=$(echo "$volt" | awk '{ if ($0 ~ /^\./) print "0" $0; else print $0 }') + + echo "$3 : $format_volt v, hex value: $upper_hex_value" +} + +# E.G. convert_adc128_data 0x08 0x20 "3V3" "1" +convert_adc128_data $1 $2 $3 $4 \ No newline at end of file