Compare commits
No commits in common. "778c25787d6d74c5151dda4dfd585b6ce3cc8e59" and "13ae2836ba7fc1825c8a1dfce0d9359232bdfb01" have entirely different histories.
778c25787d
...
13ae2836ba
@ -1,23 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Get file conut first
|
||||
file_num=`ls -l | wc -l`
|
||||
|
||||
i=2
|
||||
|
||||
while true
|
||||
do
|
||||
i=$(($i+1))
|
||||
|
||||
# Get filename by ls and awk
|
||||
file=`ls -l | awk -v cnt=$i 'NR==cnt{print $9}'`
|
||||
cmd="chmod +x $file"
|
||||
echo "File ID: $i , $cmd"
|
||||
# perform chmod
|
||||
$cmd
|
||||
|
||||
if [ $i -eq $file_num ];then
|
||||
echo "Done to add exec auth for every file"
|
||||
break
|
||||
fi
|
||||
done
|
||||
@ -1,19 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
logfile="/tmp/nicsensor_debug.log"
|
||||
|
||||
direction=$1
|
||||
level=$2
|
||||
content=$3
|
||||
|
||||
case "${direction}" in
|
||||
"console")
|
||||
echo ">>> [$level] : $content"
|
||||
;;
|
||||
"log")
|
||||
echo "[$level] : $content" >> $logfile
|
||||
;;
|
||||
*)
|
||||
echo "Error In format_print.sh! Param : $direction"
|
||||
;;
|
||||
esac
|
||||
@ -1,20 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
i2c_bus=$1
|
||||
wc=$2
|
||||
slave=$3
|
||||
data=$4
|
||||
rc=$5
|
||||
|
||||
path=`pwd`
|
||||
fmt_print="${path}/format_print.sh"
|
||||
|
||||
if [ $rc -eq 0 ];then
|
||||
cmd=`i2c-test -b $i2c_bus -s $slave -w -d $data`
|
||||
else
|
||||
cmd=`i2c-test -b $i2c_bus -s $slave -m 1 -rc $rc -d $data | awk 'NR==2{for(i=1;i<=NF;i++){printf("0x%s ",$i)}}'`
|
||||
fi
|
||||
|
||||
$fmt_print "log" "Info" "[M6 i2c Command]: $cmd"
|
||||
$cmd
|
||||
|
||||
@ -1,19 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
i2c_bus=$1
|
||||
wc=$2
|
||||
slave=$3
|
||||
data=$4
|
||||
rc=$5
|
||||
|
||||
path=`pwd`
|
||||
fmt_print="${path}/format_print.sh"
|
||||
|
||||
if [ $rc -eq 0 ];then
|
||||
cmd="i2ctransfer -y $i2c_bus w$wc@$slave $data"
|
||||
else
|
||||
cmd="i2ctransfer -y $i2c_bus w$wc@$slave $data r$5"
|
||||
fi
|
||||
|
||||
$fmt_print "log" "Info" "[M7 i2c Command]: $cmd"
|
||||
$cmd
|
||||
@ -1,129 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
script_version="v2.0"
|
||||
server_type="5688m7"
|
||||
server_platform="m7"
|
||||
|
||||
slot_name=$1
|
||||
sensor_type=$2
|
||||
chip_slave=$3
|
||||
param_num=$#
|
||||
|
||||
nic_type=""
|
||||
slot_id=""
|
||||
|
||||
path=`pwd`
|
||||
server_script="${path}/platform_${server_type}.sh"
|
||||
sensor_script="${path}/plugin_${sensor_type}.sh"
|
||||
i2c_script="${path}/i2c_${server_platform}.sh"
|
||||
fmt_print="${path}/format_print.sh"
|
||||
|
||||
print_helper(){
|
||||
echo "======>>> nicsensor Scirpt Usage <<<======"
|
||||
echo "Genenral Usage : ./nicsensor.sh [slot] [sensor] [i2c slave]"
|
||||
echo "For Detect : ./nicsensor.sh detect [ocp/pcie]"
|
||||
echo "Current Server : $server_type"
|
||||
echo "Script Version : $script_version"
|
||||
}
|
||||
|
||||
perform_detect(){
|
||||
if [ ! -e $server_script ];then
|
||||
$fmt_print "console" "Error" "Server Script $server_script not exist! Maybe unsupport for now!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
$server_script "detect"
|
||||
}
|
||||
|
||||
conf_pre_check(){
|
||||
|
||||
if [ $param_num -lt 1 ];then
|
||||
print_helper
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ ! -e $fmt_print ];then
|
||||
echo "Missing file $fmt_print !!!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -e $server_script ];then
|
||||
$fmt_print "console" "Error" "Server Script $server_script not exist! Maybe unsupport for now!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -e $sensor_script ];then
|
||||
$fmt_print "console" "Error" "Sensor Script $sensor_script not exist! Maybe unsupport for now!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -e $i2c_script ];then
|
||||
$fmt_print "console" "Error" "$i2c_script not exist!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
res_date=`date +%Y-%m-%dT%H:%M:%S`
|
||||
$fmt_print "log" "Info" "Start Time : $res_date"
|
||||
$fmt_print "log" "Info" "Script Version : $script_version"
|
||||
$fmt_print "log" "Info" "Server Type : $server_type"
|
||||
$fmt_print "log" "Info" "Slot Name : $slot_name"
|
||||
}
|
||||
|
||||
parse_slot_name(){
|
||||
# Get nic type and slot id from slot name
|
||||
case "${slot_name}" in
|
||||
ocp*)
|
||||
nic_type="ocp"
|
||||
slot_id=`echo $slot_name | cut -c 4`
|
||||
;;
|
||||
pcie*)
|
||||
nic_type="pcie"
|
||||
slot_id=`echo $slot_name | cut -c 5-`
|
||||
;;
|
||||
*)
|
||||
$fmt_print "log" "Warning" "Undetermined nic type, default set to pcie"
|
||||
nic_type="pcie"
|
||||
slot_id=$slot_name
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
connect_i2c(){
|
||||
$server_script "connect" "$nic_type" "$slot_id"
|
||||
|
||||
if [ $? -ne 0 ];then
|
||||
$fmt_print "console" "Error" "Can't build i2c connection"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
start_sensor_reading(){
|
||||
$fmt_print "log" "Info" "start sensor reading"
|
||||
|
||||
$sensor_script "read" "${i2c_bus}" "${chip_slave}" "${server_platform}"
|
||||
}
|
||||
# ---------------------------------------------------------
|
||||
# Start Execute Script
|
||||
# ---------------------------------------------------------
|
||||
# init debug log
|
||||
if [ -e "/tmp/nicsensor_debug.log" ];then
|
||||
rm /tmp/nicsensor_debug.log
|
||||
fi
|
||||
|
||||
# check if is detect option
|
||||
if [ "$1" = "detect" ];then
|
||||
perform_detect
|
||||
exit 0
|
||||
fi
|
||||
|
||||
conf_pre_check
|
||||
|
||||
parse_slot_name
|
||||
|
||||
i2c_bus=`connect_i2c`
|
||||
if [ $? -ne 0 ];then
|
||||
$fmt_print "console" "Error" "An Error occured when build i2c connection with ${nic_type} ${slot_id}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
start_sensor_reading
|
||||
@ -1,173 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
action=$1
|
||||
nic_type=$2
|
||||
slot_id=$3
|
||||
|
||||
path=`pwd`
|
||||
i2c_script="${path}/i2c_m7.sh"
|
||||
fmt_print="${path}/format_print.sh"
|
||||
|
||||
pca9548_slave=""
|
||||
pca9641_slave=""
|
||||
i2c_bus=""
|
||||
pca9548_channel=""
|
||||
|
||||
is_have_pca9641=0
|
||||
|
||||
record_i2c_status(){
|
||||
$fmt_print "log" "Info" "[platform_5280m7] Start record i2c configuration"
|
||||
$fmt_print "log" "Info" "Nic Type: $nic_type"
|
||||
$fmt_print "log" "Info" "Nic slot: $slot_id"
|
||||
$fmt_print "log" "Info" "i2c bus: $i2c_bus"
|
||||
$fmt_print "log" "Info" "is have pca9641: $is_have_pca9641"
|
||||
$fmt_print "log" "Info" "pca9641 slave: $is_have_pca9641"
|
||||
$fmt_print "log" "Info" "pca9548 slave: $pca9548_slave"
|
||||
$fmt_print "log" "Info" "pca9548 channel: $pca9548_channel"
|
||||
}
|
||||
|
||||
set_i2c_config(){
|
||||
# set pca9641 address && I2C BUS
|
||||
if [ "${nic_type}" == "ocp" ];then
|
||||
is_have_pca9641=0
|
||||
pca9548_slave="0x70"
|
||||
i2c_bus=3
|
||||
else
|
||||
is_have_pca9641=1
|
||||
if [ $slot_id -le 2 ];then
|
||||
pca9641_slave="0x41"
|
||||
pca9548_slave="0x72"
|
||||
i2c_bus=12
|
||||
else
|
||||
pca9641_slave="0x42"
|
||||
pca9548_slave="0x72"
|
||||
i2c_bus=13
|
||||
fi
|
||||
fi
|
||||
|
||||
# set pca9548 switch channel
|
||||
if [ "${nic_type}" == "ocp" ];then
|
||||
if [ $slot_id -eq 0 ];then
|
||||
pca9548_channel="0x01"
|
||||
elif [ $slot_id -eq 1 ];then
|
||||
pca9548_channel="0x02"
|
||||
elif [ $slot_id -eq 2 ];then
|
||||
pca9548_channel="0x04"
|
||||
else
|
||||
$fmt_print "console" "Warning" "Unspecified card slot!"
|
||||
fi
|
||||
else
|
||||
if [ $slot_id -eq 0 ];then
|
||||
pca9548_channel="0x02"
|
||||
elif [ $slot_id -eq 1 ];then
|
||||
pca9548_channel="0x04"
|
||||
elif [ $slot_id -eq 2 ];then
|
||||
pca9548_channel="0x08"
|
||||
elif [ $slot_id -eq 3 ];then
|
||||
pca9548_channel="0x02"
|
||||
elif [ $slot_id -eq 4 ];then
|
||||
pca9548_channel="0x04"
|
||||
elif [ $slot_id -eq 5 ];then
|
||||
pca9548_channel="0x08"
|
||||
else
|
||||
$fmt_print "console" "Warning" "Unspecified card slot!"
|
||||
fi
|
||||
fi
|
||||
record_i2c_status
|
||||
}
|
||||
|
||||
get_pca9641_control(){
|
||||
$fmt_print "log" "Info" "[platform_5280m7] Start Get pca9641 control"
|
||||
|
||||
# Request 9641 lock
|
||||
res_lock=`i2ctransfer -y $i2c_bus w2@$pca9641_slave 0x01 0x81 r1`
|
||||
$fmt_print "log" "Info" "[platform_5280m7] After request 9641 lock, The REG value is $res_lock"
|
||||
|
||||
# Build 9641 Connection
|
||||
res_build=`i2ctransfer -y $i2c_bus w2@$pca9641_slave 0x01 0x85 r1`
|
||||
$fmt_print "log" "Info" "[platform_5280m7] After Build 9641 connection, The REG value is $res_build"
|
||||
|
||||
if [ "$res_build" != "0x87" ];then
|
||||
$fmt_print "console" "Error" "Cannot establish connection with pca9641 !!!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
select_pca9548_channel(){
|
||||
$fmt_print "log" "Info" "[platform_5280m7] Start Switch PCA9548"
|
||||
$i2c_script "$i2c_bus" 1 "$pca9548_slave" "$pca9548_channel" 0
|
||||
}
|
||||
|
||||
build_i2c_connect(){
|
||||
$fmt_print "log" "Info" "[platform_5280m7] Start build i2c connect"
|
||||
set_i2c_config
|
||||
|
||||
if [ $is_have_pca9641 -eq 1 ];then
|
||||
get_pca9641_control
|
||||
fi
|
||||
|
||||
select_pca9548_channel
|
||||
echo "$i2c_bus"
|
||||
}
|
||||
|
||||
# switch pca9548 channels then do i2cdetect one times
|
||||
# @Param1 i2c bus number
|
||||
# @Param2 pca9548 slave address
|
||||
# @Param3 pca9548 channel hex value
|
||||
# @Param4 pca9548 channel
|
||||
# @Param5 pcie slot number
|
||||
do_i2c_detect(){
|
||||
if [ "${nic_type}" == "ocp" ];then
|
||||
$fmt_print "log" "Info" "OCP slot $5 : bus$1 9548channel$4"
|
||||
else
|
||||
$fmt_print "log" "Info" "PCIe slot $5 : bus$1 9548channel$4"
|
||||
fi
|
||||
i2ctransfer -y $1 w1@$2 $3
|
||||
i2cdetect -y $1
|
||||
}
|
||||
|
||||
detect_on_server(){
|
||||
$fmt_print "console" "Info" "[platform_5280m7] Start i2c detect"
|
||||
|
||||
if [ "${nic_type}" == "ocp" ];then
|
||||
i2c_bus=3
|
||||
do_i2c_detect 3 0x70 0x01 0 0
|
||||
do_i2c_detect 3 0x70 0x02 1 1
|
||||
do_i2c_detect 3 0x70 0x04 2 2
|
||||
else
|
||||
i2c_bus=12
|
||||
pca9641_slave="0x41"
|
||||
get_pca9641_control
|
||||
|
||||
do_i2c_detect 12 0x72 0x02 1 0
|
||||
do_i2c_detect 12 0x72 0x04 2 1
|
||||
do_i2c_detect 12 0x72 0x08 3 2
|
||||
|
||||
i2c_bus=13
|
||||
pca9641_slave="0x42"
|
||||
get_pca9641_control
|
||||
|
||||
do_i2c_detect 13 0x72 0x02 1 3
|
||||
do_i2c_detect 13 0x72 0x04 2 4
|
||||
do_i2c_detect 13 0x72 0x08 3 5
|
||||
fi
|
||||
}
|
||||
|
||||
# ---------------------------------------------------
|
||||
# Start Execute Script
|
||||
# ---------------------------------------------------
|
||||
case "${action}" in
|
||||
"connect")
|
||||
build_i2c_connect
|
||||
;;
|
||||
"detect")
|
||||
detect_on_server
|
||||
;;
|
||||
*)
|
||||
$fmt_print "console" "Error" "[platform_5280m7] Unspecified Operation : $action"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
exit 0
|
||||
|
||||
@ -1,161 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
action=$1
|
||||
nic_type=$2
|
||||
slot_id=$3
|
||||
|
||||
path=`pwd`
|
||||
i2c_script="${path}/i2c_m7.sh"
|
||||
fmt_print="${path}/format_print.sh"
|
||||
|
||||
pca9548_slave=""
|
||||
pca9641_slave=""
|
||||
i2c_bus=""
|
||||
pca9548_channel=""
|
||||
|
||||
is_have_pca9641=0
|
||||
|
||||
record_i2c_status(){
|
||||
$fmt_print "log" "Info" "[platform_5688m7] Start record i2c configuration"
|
||||
$fmt_print "log" "Info" "Nic Type: $nic_type"
|
||||
$fmt_print "log" "Info" "Nic slot: $slot_id"
|
||||
$fmt_print "log" "Info" "i2c bus: $i2c_bus"
|
||||
$fmt_print "log" "Info" "is have pca9641: $is_have_pca9641"
|
||||
$fmt_print "log" "Info" "pca9641 slave: $is_have_pca9641"
|
||||
$fmt_print "log" "Info" "pca9548 slave: $pca9548_slave"
|
||||
$fmt_print "log" "Info" "pca9548 channel: $pca9548_channel"
|
||||
}
|
||||
|
||||
set_i2c_config(){
|
||||
# set pca9641 address && I2C BUS
|
||||
if [ "${nic_type}" == "ocp" ];then
|
||||
$fmt_print "console" "Error" "[platform_5688m7] Unsupport OCP Nic"
|
||||
exit 1
|
||||
else
|
||||
is_have_pca9641=1
|
||||
i2c_bus=12
|
||||
pca9641_slave="0x31"
|
||||
if [ $slot_id -le 3 ];then
|
||||
pca9548_slave="0x71"
|
||||
else
|
||||
pca9548_slave="0x72"
|
||||
fi
|
||||
fi
|
||||
|
||||
# set pca9548 switch channel
|
||||
if [ "${nic_type}" == "ocp" ];then
|
||||
$fmt_print "console" "Error" "[platform_5688m7] Unsupport OCP Nic"
|
||||
exit 1
|
||||
else
|
||||
if [ $slot_id -eq 0 ];then
|
||||
pca9548_channel="0x01"
|
||||
elif [ $slot_id -eq 1 ];then
|
||||
pca9548_channel="0x02"
|
||||
elif [ $slot_id -eq 2 ];then
|
||||
pca9548_channel="0x04"
|
||||
elif [ $slot_id -eq 3 ];then
|
||||
pca9548_channel="0x08"
|
||||
elif [ $slot_id -eq 4 ];then
|
||||
pca9548_channel="0x01"
|
||||
elif [ $slot_id -eq 5 ];then
|
||||
pca9548_channel="0x02"
|
||||
elif [ $slot_id -eq 6 ];then
|
||||
pca9548_channel="0x04"
|
||||
elif [ $slot_id -eq 7 ];then
|
||||
pca9548_channel="0x08"
|
||||
else
|
||||
$fmt_print "console" "Warning" "Unspecified card slot!"
|
||||
fi
|
||||
fi
|
||||
record_i2c_status
|
||||
}
|
||||
|
||||
get_pca9641_control(){
|
||||
$fmt_print "log" "Info" "[platform_5688m7] Start Get pca9641 control"
|
||||
|
||||
# Request 9641 lock
|
||||
res_lock=`i2ctransfer -y $i2c_bus w2@$pca9641_slave 0x01 0x81 r1`
|
||||
$fmt_print "log" "Info" "[platform_5688m7] After request 9641 lock, The REG value is $res_lock"
|
||||
|
||||
# Build 9641 Connection
|
||||
res_build=`i2ctransfer -y $i2c_bus w2@$pca9641_slave 0x01 0x85 r1`
|
||||
$fmt_print "log" "Info" "[platform_5688m7] After Build 9641 connection, The REG value is $res_build"
|
||||
|
||||
if [ "$res_build" != "0x87" ];then
|
||||
$fmt_print "console" "Error" "Cannot establish connection with pca9641 !!!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
select_pca9548_channel(){
|
||||
$fmt_print "log" "Info" "[platform_5688m7] Start Switch PCA9548"
|
||||
$i2c_script "$i2c_bus" 1 "$pca9548_slave" "$pca9548_channel" 0
|
||||
}
|
||||
|
||||
build_i2c_connect(){
|
||||
$fmt_print "log" "Info" "[platform_5688m7] Start build i2c connect"
|
||||
set_i2c_config
|
||||
|
||||
if [ $is_have_pca9641 -eq 1 ];then
|
||||
get_pca9641_control
|
||||
fi
|
||||
|
||||
select_pca9548_channel
|
||||
echo "$i2c_bus"
|
||||
}
|
||||
|
||||
# switch pca9548 channels then do i2cdetect one times
|
||||
# @Param1 i2c bus number
|
||||
# @Param2 pca9548 slave address
|
||||
# @Param3 pca9548 channel hex value
|
||||
# @Param4 pca9548 channel
|
||||
# @Param5 pcie slot number
|
||||
do_i2c_detect(){
|
||||
if [ "${nic_type}" == "ocp" ];then
|
||||
$fmt_print "console" "Info" "OCP slot $5 : bus$1 9548channel$4"
|
||||
else
|
||||
$fmt_print "console" "Info" "PCIe slot $5 : bus$1 9548channel$4"
|
||||
fi
|
||||
i2ctransfer -y $1 w1@$2 $3
|
||||
i2cdetect -y $1
|
||||
}
|
||||
|
||||
detect_on_server(){
|
||||
$fmt_print "console" "Info" "[platform_5688m7] Start i2c detect"
|
||||
|
||||
if [ "${nic_type}" == "ocp" ];then
|
||||
$fmt_print "console" "Error" "[platform_5688m7] Unsupport OCP Nic I2C Detect"
|
||||
else
|
||||
i2c_bus=12
|
||||
pca9641_slave="0x31"
|
||||
get_pca9641_control
|
||||
|
||||
do_i2c_detect $i2c_bus 0x71 0x01 0 0
|
||||
do_i2c_detect $i2c_bus 0x71 0x02 1 1
|
||||
do_i2c_detect $i2c_bus 0x71 0x04 2 2
|
||||
do_i2c_detect $i2c_bus 0x71 0x08 3 3
|
||||
do_i2c_detect $i2c_bus 0x72 0x01 0 4
|
||||
do_i2c_detect $i2c_bus 0x72 0x02 1 5
|
||||
do_i2c_detect $i2c_bus 0x72 0x04 2 6
|
||||
do_i2c_detect $i2c_bus 0x72 0x08 3 7
|
||||
fi
|
||||
}
|
||||
|
||||
# ---------------------------------------------------
|
||||
# Start Execute Script
|
||||
# ---------------------------------------------------
|
||||
case "${action}" in
|
||||
"connect")
|
||||
build_i2c_connect
|
||||
;;
|
||||
"detect")
|
||||
detect_on_server
|
||||
;;
|
||||
*)
|
||||
$fmt_print "console" "Error" "[platform_5688m7] Unspecified Operation : $action"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
exit 0
|
||||
|
||||
@ -1,167 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
# ADC128 Division factor
|
||||
votage_division_factor_0="1"
|
||||
votage_division_factor_1="1"
|
||||
votage_division_factor_2="1"
|
||||
votage_division_factor_3="0.8"
|
||||
votage_division_factor_4="0.6"
|
||||
votage_division_factor_5="0.6"
|
||||
votage_division_factor_6="0.2326"
|
||||
votage_division_factor_7="1"
|
||||
|
||||
# ADC128 channel name
|
||||
ADC128_Channel0_name="Channel0"
|
||||
ADC128_Channel1_name="Channel1"
|
||||
ADC128_Channel2_name="Channel2"
|
||||
ADC128_Channel3_name="Channel3"
|
||||
ADC128_Channel4_name="Channel4"
|
||||
ADC128_Channel5_name="Channel5"
|
||||
ADC128_Channel6_name="Channel6"
|
||||
ADC128_Channel7_name="Channel7"
|
||||
|
||||
mode=$1
|
||||
i2c_bus=$2
|
||||
chip_slave=$3
|
||||
server_platform=$4
|
||||
|
||||
# Only for test purpose
|
||||
test_data1=$2
|
||||
test_data2=$3
|
||||
test_factor=$4
|
||||
|
||||
path=`pwd`
|
||||
fmt_print="${path}/format_print.sh"
|
||||
i2c_script="${path}/i2c_${server_platform}.sh"
|
||||
|
||||
REG_adc128_config="0x00"
|
||||
REG_adc128_advance="0x0b"
|
||||
REG_adc128_status="0x0c"
|
||||
REG_adc128_ch0="0x20"
|
||||
REG_adc128_ch1="0x21"
|
||||
REG_adc128_ch2="0x22"
|
||||
REG_adc128_ch3="0x23"
|
||||
REG_adc128_ch4="0x24"
|
||||
REG_adc128_ch5="0x25"
|
||||
REG_adc128_ch6="0x26"
|
||||
REG_adc128_ch7="0x27"
|
||||
|
||||
print_help(){
|
||||
echo "---------------------------------------------------------"
|
||||
echo "<option> read"
|
||||
echo " Format : ./plugin_adc128.sh read [i2c-bus] [slave] [platform]"
|
||||
echo " Example: ./plugin_adc128.sh read 13 0x1f m7"
|
||||
echo "---------------------------------------------------------"
|
||||
echo "<option> test"
|
||||
echo " Format : ./plugin_adc128.sh test [data1] [data2] [factor]"
|
||||
echo " Example: ./plugin_adc128.sh test 0xc7 0x00 0.6"
|
||||
echo "---------------------------------------------------------"
|
||||
echo "<option> help"
|
||||
echo " Format : ./plugin_adc128.sh help"
|
||||
echo " Example: ./plugin_adc128.sh help"
|
||||
echo "---------------------------------------------------------"
|
||||
}
|
||||
|
||||
# adc128 chip init if need
|
||||
check_adc128_init(){
|
||||
# Get Reg 0x00 status
|
||||
res_adc128_status=`$i2c_script $i2c_bus 1 $chip_slave $REG_adc128_config 1`
|
||||
# format_log_print $INFO "REG adc128 STATUS : $res_adc128_status"
|
||||
$fmt_print "log" "Info" "[plugin_adc128] REG adc128 STATUS : $res_adc128_status"
|
||||
|
||||
# if stauts is not 0x01 (Start Monitor) ,then do init
|
||||
if [ "$res_adc128_status" != "0x01" ];then
|
||||
$fmt_print "log" "Info" "[plugin_adc128] Start Init ADC128 Chip"
|
||||
# Init ADC128 work as mode 1 (0x02)
|
||||
res_adc128_advance=`$i2c_script $i2c_bus 2 $chip_slave "$REG_adc128_advance 0x02" 0`
|
||||
# Set ADC128 on start (0x01)
|
||||
res_adc128_setstart=`$i2c_script $i2c_bus 2 $chip_slave "$REG_adc128_config 0x01" 1`
|
||||
|
||||
$fmt_print "log" "Info" "[plugin_adc128] After Set status, the REG 0x00 value is $res_adc128_setstart "
|
||||
fi
|
||||
}
|
||||
|
||||
# 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"
|
||||
}
|
||||
|
||||
read_adc128_data(){
|
||||
# check if chip adc128 need init
|
||||
check_adc128_init
|
||||
|
||||
res_ch0=`$i2c_script $i2c_bus 1 $chip_slave $REG_adc128_ch0 2`
|
||||
res_ch1=`$i2c_script $i2c_bus 1 $chip_slave $REG_adc128_ch1 2`
|
||||
res_ch2=`$i2c_script $i2c_bus 1 $chip_slave $REG_adc128_ch2 2`
|
||||
res_ch3=`$i2c_script $i2c_bus 1 $chip_slave $REG_adc128_ch3 2`
|
||||
res_ch4=`$i2c_script $i2c_bus 1 $chip_slave $REG_adc128_ch4 2`
|
||||
res_ch5=`$i2c_script $i2c_bus 1 $chip_slave $REG_adc128_ch5 2`
|
||||
res_ch6=`$i2c_script $i2c_bus 1 $chip_slave $REG_adc128_ch6 2`
|
||||
res_ch7=`$i2c_script $i2c_bus 1 $chip_slave $REG_adc128_ch7 2`
|
||||
|
||||
# record i2c raw data to log
|
||||
$fmt_print "log" "Info" "[plugin_adc128] channel0 : $res_ch0"
|
||||
$fmt_print "log" "Info" "[plugin_adc128] channel1 : $res_ch1"
|
||||
$fmt_print "log" "Info" "[plugin_adc128] channel2 : $res_ch2"
|
||||
$fmt_print "log" "Info" "[plugin_adc128] channel3 : $res_ch3"
|
||||
$fmt_print "log" "Info" "[plugin_adc128] channel4 : $res_ch4"
|
||||
$fmt_print "log" "Info" "[plugin_adc128] channel5 : $res_ch5"
|
||||
$fmt_print "log" "Info" "[plugin_adc128] channel6 : $res_ch6"
|
||||
$fmt_print "log" "Info" "[plugin_adc128] channel7 : $res_ch7"
|
||||
|
||||
# start parse raw data
|
||||
$fmt_print "console" "Info" "The ADC128 value is :"
|
||||
convert_adc128_data $res_ch0 "$ADC128_Channel0_name" $votage_division_factor_0
|
||||
convert_adc128_data $res_ch1 "$ADC128_Channel1_name" $votage_division_factor_1
|
||||
convert_adc128_data $res_ch2 "$ADC128_Channel2_name" $votage_division_factor_2
|
||||
convert_adc128_data $res_ch3 "$ADC128_Channel3_name" $votage_division_factor_3
|
||||
convert_adc128_data $res_ch4 "$ADC128_Channel4_name" $votage_division_factor_4
|
||||
convert_adc128_data $res_ch5 "$ADC128_Channel5_name" $votage_division_factor_5
|
||||
convert_adc128_data $res_ch6 "$ADC128_Channel6_name" $votage_division_factor_6
|
||||
convert_adc128_data $res_ch7 "$ADC128_Channel7_name" $votage_division_factor_7
|
||||
}
|
||||
|
||||
test_adc128_value(){
|
||||
convert_adc128_data $test_data1 $test_data2 "Volt" $test_factor
|
||||
}
|
||||
|
||||
case "${mode}" in
|
||||
"read")
|
||||
read_adc128_data
|
||||
;;
|
||||
"test")
|
||||
test_adc128_value
|
||||
;;
|
||||
"help")
|
||||
print_help
|
||||
;;
|
||||
*)
|
||||
$fmt_print "console" "Error" "[plugin_adc128]Unexpected Input Param : $mode"
|
||||
print_help
|
||||
;;
|
||||
esac
|
||||
@ -1,121 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
mode=$1
|
||||
i2c_bus=$2
|
||||
chip_slave=$3
|
||||
server_platform=$4
|
||||
|
||||
test_data1=$2
|
||||
test_data2=$3
|
||||
|
||||
path=`pwd`
|
||||
fmt_print="${path}/format_print.sh"
|
||||
i2c_script="${path}/i2c_${server_platform}.sh"
|
||||
|
||||
# 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 "---------------------------------------------------------"
|
||||
}
|
||||
|
||||
# @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"
|
||||
|
||||
}
|
||||
|
||||
read_emc1413_data(){
|
||||
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`
|
||||
|
||||
$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"
|
||||
}
|
||||
|
||||
case "${mode}" in
|
||||
"read")
|
||||
read_emc1413_data
|
||||
;;
|
||||
"test")
|
||||
test_emc1413_data
|
||||
;;
|
||||
"help")
|
||||
print_help
|
||||
;;
|
||||
*)
|
||||
$fmt_print "console" "Error" "[plugin_emc1413]Unexpected Input Param : $mode"
|
||||
print_help
|
||||
;;
|
||||
esac
|
||||
@ -1,183 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
mode=$1
|
||||
i2c_bus=$2
|
||||
chip_slave=$3
|
||||
server_platform=$4
|
||||
|
||||
test_data1=$2
|
||||
test_data2=$3
|
||||
test_resistor=$4
|
||||
|
||||
path=`pwd`
|
||||
fmt_print="${path}/format_print.sh"
|
||||
i2c_script="${path}/i2c_${server_platform}.sh"
|
||||
|
||||
# INA3221 shunt resistor(unit: mohm)
|
||||
shunt_resistor_0="2"
|
||||
shunt_resistor_1="2"
|
||||
shunt_resistor_2="5"
|
||||
|
||||
# INA3221 channel name
|
||||
INA3221_Channel0_name="Channel0"
|
||||
INA3221_Channel1_name="Channel1"
|
||||
INA3221_Channel2_name="Channel2"
|
||||
|
||||
ina3221_ch0_volt="0"
|
||||
ina3221_ch1_volt="0"
|
||||
ina3221_ch2_volt="0"
|
||||
ina3221_ch0_current="0"
|
||||
ina3221_ch1_current="0"
|
||||
ina3221_ch2_current="0"
|
||||
|
||||
REG_ina3221_ch1="0x01"
|
||||
REG_ina3221_ch2="0x03"
|
||||
REG_ina3221_ch3="0x05"
|
||||
REG_ina3221_bus1="0x02"
|
||||
REG_ina3221_bus2="0x04"
|
||||
REG_ina3221_bus3="0x06"
|
||||
|
||||
INA3221_SHUNT_VOLT=0
|
||||
INA3221_BUS_VOLT=1
|
||||
INA3221_POWER=2
|
||||
|
||||
print_help(){
|
||||
echo "---------------------------------------------------------"
|
||||
echo "<option> read"
|
||||
echo " Format : ./plugin_ina3221.sh read [i2c-bus] [slave] [platform]"
|
||||
echo " Example: ./plugin_ina3221.sh read 13 0x1f m7"
|
||||
echo "---------------------------------------------------------"
|
||||
echo "<option> test"
|
||||
echo " Format : ./plugin_ina3221.sh test [data1] [data2] [resistor]"
|
||||
echo " Example: ./plugin_ina3221.sh test 0xc7 0x00 5"
|
||||
echo "---------------------------------------------------------"
|
||||
echo "<option> help"
|
||||
echo " Format : ./plugin_ina3221.sh help"
|
||||
echo " Example: ./plugin_ina3221.sh help"
|
||||
echo "---------------------------------------------------------"
|
||||
}
|
||||
|
||||
# @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
|
||||
}
|
||||
|
||||
read_ina3221_data(){
|
||||
res_ch0=`$i2c_script $i2c_bus 1 $chip_slave $REG_ina3221_ch1 r2`
|
||||
res_ch1=`$i2c_script $i2c_bus 1 $chip_slave $REG_ina3221_ch2 r2`
|
||||
res_ch2=`$i2c_script $i2c_bus 1 $chip_slave $REG_ina3221_ch3 r2`
|
||||
res_bus0=`$i2c_script $i2c_bus 1 $chip_slave $REG_ina3221_bus1 r2`
|
||||
res_bus1=`$i2c_script $i2c_bus 1 $chip_slave $REG_ina3221_bus2 r2`
|
||||
res_bus2=`$i2c_script $i2c_bus 1 $chip_slave $REG_ina3221_bus3 r2`
|
||||
|
||||
$fmt_print "log" "Info" "[plugin_ina3221] channel 0 shunt volt: $res_ch0"
|
||||
$fmt_print "log" "Info" "[plugin_ina3221] channel 1 shunt volt: $res_ch1"
|
||||
$fmt_print "log" "Info" "[plugin_ina3221] channel 2 shunt volt: $res_ch2"
|
||||
$fmt_print "log" "Info" "[plugin_ina3221] channel 0 bus volt: $res_bus0"
|
||||
$fmt_print "log" "Info" "[plugin_ina3221] channel 0 bus volt: $res_bus1"
|
||||
$fmt_print "log" "Info" "[plugin_ina3221] channel 0 bus volt: $res_bus2"
|
||||
|
||||
$fmt_print "console" "Info" "The INA3221 shunt value is :"
|
||||
convert_ina3221_data $res_ch0 0 $INA3221_SHUNT_VOLT $shunt_resistor_0 "$INA3221_Channel0_name"
|
||||
convert_ina3221_data $res_ch1 1 $INA3221_SHUNT_VOLT $shunt_resistor_1 "$INA3221_Channel1_name"
|
||||
convert_ina3221_data $res_ch2 2 $INA3221_SHUNT_VOLT $shunt_resistor_2 "$INA3221_Channel2_name"
|
||||
|
||||
$fmt_print "console" "Info" "The INA3221 bus value is :"
|
||||
convert_ina3221_data $res_bus0 0 $INA3221_BUS_VOLT null "$INA3221_Channel0_name"
|
||||
convert_ina3221_data $res_bus1 1 $INA3221_BUS_VOLT null "$INA3221_Channel1_name"
|
||||
convert_ina3221_data $res_bus2 2 $INA3221_BUS_VOLT null "$INA3221_Channel2_name"
|
||||
|
||||
$fmt_print "console" "Info" "The INA3221 bus power is :"
|
||||
convert_ina3221_data 0 0 0 $INA3221_POWER
|
||||
}
|
||||
|
||||
test_ina3221_value(){
|
||||
convert_ina3221_data $test_data1 $test_data2 0 $INA3221_SHUNT_VOLT $test_resistor "INA3221"
|
||||
}
|
||||
|
||||
case "${mode}" in
|
||||
"read")
|
||||
read_ina3221_data
|
||||
;;
|
||||
"test")
|
||||
test_ina3221_value
|
||||
;;
|
||||
"help")
|
||||
print_help
|
||||
;;
|
||||
*)
|
||||
$fmt_print "console" "Error" "[plugin_ina3221]Unexpected Input Param : $mode"
|
||||
print_help
|
||||
;;
|
||||
esac
|
||||
@ -1,94 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
mode=$1
|
||||
i2c_bus=$2
|
||||
chip_slave=$3
|
||||
server_platform=$4
|
||||
|
||||
test_data1=$2
|
||||
test_data2=$3
|
||||
|
||||
path=`pwd`
|
||||
fmt_print="${path}/format_print.sh"
|
||||
i2c_script="${path}/i2c_${server_platform}.sh"
|
||||
|
||||
sensor_name="TMP112"
|
||||
|
||||
print_help(){
|
||||
echo "---------------------------------------------------------"
|
||||
echo "<option> read"
|
||||
echo " Format : ./plugin_tmp112.sh read [i2c-bus] [slave] [platform]"
|
||||
echo " Example: ./plugin_tmp112.sh read 13 0x48 m7"
|
||||
echo "---------------------------------------------------------"
|
||||
echo "<option> test"
|
||||
echo " Format : ./plugin_tmp112.sh test [data1] [data2]"
|
||||
echo " Example: ./plugin_tmp112.sh test 0x24 0x00"
|
||||
echo "---------------------------------------------------------"
|
||||
echo "<option> help"
|
||||
echo " Format : ./plugin_tmp112.sh help"
|
||||
echo " Example: ./plugin_tmp112.sh help"
|
||||
echo "---------------------------------------------------------"
|
||||
}
|
||||
|
||||
# @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"
|
||||
$fmt_print "log" "Info" "[plugin_tmp112] hex value : ${merge_value}"
|
||||
$fmt_print "log" "Info" "[plugin_tmp112] binary_number : ${binary_number}"
|
||||
$fmt_print "log" "Info" "[plugin_tmp112] bin_length : ${bin_length}"
|
||||
$fmt_print "log" "Info" "[plugin_tmp112] last_digit : ${last_digit}"
|
||||
}
|
||||
|
||||
read_tmp112_data(){
|
||||
res=`$i2c_script $i2c_bus "1" "$chip_slave" "0x00" "2"`
|
||||
convert_tmp112_data $res "$sensor_name"
|
||||
}
|
||||
|
||||
test_tmp112_data(){
|
||||
convert_tmp112_data $test_data1 $test_data2 "Temp"
|
||||
}
|
||||
|
||||
case "${mode}" in
|
||||
"read")
|
||||
read_tmp112_data
|
||||
;;
|
||||
"test")
|
||||
test_tmp112_data
|
||||
;;
|
||||
"help")
|
||||
print_help
|
||||
;;
|
||||
*)
|
||||
$fmt_print "console" "Error" "[plugin_tmp112] Unexpected Input Param : $mode"
|
||||
print_help
|
||||
;;
|
||||
esac
|
||||
@ -1,124 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
mode=$1
|
||||
i2c_bus=$2
|
||||
chip_slave=$3
|
||||
server_platform=$4
|
||||
|
||||
test_data1=$2
|
||||
test_data2=$3
|
||||
|
||||
path=`pwd`
|
||||
fmt_print="${path}/format_print.sh"
|
||||
i2c_script="${path}/i2c_${server_platform}.sh"
|
||||
|
||||
REG_tmp468="0x80"
|
||||
# TMP468 channel name
|
||||
TMP468_Channel0_name="Local"
|
||||
TMP468_Channel1_name="Remote1"
|
||||
TMP468_Channel2_name="Remote2"
|
||||
TMP468_Channel3_name="Remote3"
|
||||
TMP468_Channel4_name="Remote4"
|
||||
TMP468_Channel5_name="Remote5"
|
||||
TMP468_Channel6_name="Remote6"
|
||||
TMP468_Channel7_name="Remote7"
|
||||
TMP468_Channel8_name="Remote8"
|
||||
|
||||
print_help(){
|
||||
echo "---------------------------------------------------------"
|
||||
echo "<option> read"
|
||||
echo " Format : ./plugin_tmp468.sh read [i2c-bus] [slave] [platform]"
|
||||
echo " Example: ./plugin_tmp468.sh read 13 0x48 m7"
|
||||
echo "---------------------------------------------------------"
|
||||
echo "<option> test"
|
||||
echo " Format : ./plugin_tmp468.sh test [data1] [data2]"
|
||||
echo " Example: ./plugin_tmp468.sh test 0x24 0x00"
|
||||
echo "---------------------------------------------------------"
|
||||
echo "<option> help"
|
||||
echo " Format : ./plugin_tmp468.sh help"
|
||||
echo " Example: ./plugin_tmp468.sh help"
|
||||
echo "---------------------------------------------------------"
|
||||
}
|
||||
|
||||
|
||||
# @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 "
|
||||
}
|
||||
|
||||
read_tmp468_data(){
|
||||
res_tmp468=`$i2c_script $i2c_bus 1 $chip_slave $REG_tmp468 18`
|
||||
|
||||
$fmt_print "log" "Info" "[plugin_tmp468] Read Raw Data : $res_tmp468"
|
||||
|
||||
tmp468_res1_h=`echo $res_tmp468 | awk '{print $1}'`
|
||||
tmp468_res1_l=`echo $res_tmp468 | awk '{print $2}'`
|
||||
tmp468_res2_h=`echo $res_tmp468 | awk '{print $3}'`
|
||||
tmp468_res2_l=`echo $res_tmp468 | awk '{print $4}'`
|
||||
tmp468_res3_h=`echo $res_tmp468 | awk '{print $5}'`
|
||||
tmp468_res3_l=`echo $res_tmp468 | awk '{print $6}'`
|
||||
tmp468_res4_h=`echo $res_tmp468 | awk '{print $7}'`
|
||||
tmp468_res4_l=`echo $res_tmp468 | awk '{print $8}'`
|
||||
tmp468_res5_h=`echo $res_tmp468 | awk '{print $9}'`
|
||||
tmp468_res5_l=`echo $res_tmp468 | awk '{print $10}'`
|
||||
tmp468_res6_h=`echo $res_tmp468 | awk '{print $11}'`
|
||||
tmp468_res6_l=`echo $res_tmp468 | awk '{print $12}'`
|
||||
tmp468_res7_h=`echo $res_tmp468 | awk '{print $13}'`
|
||||
tmp468_res7_l=`echo $res_tmp468 | awk '{print $14}'`
|
||||
tmp468_res8_h=`echo $res_tmp468 | awk '{print $15}'`
|
||||
tmp468_res8_l=`echo $res_tmp468 | awk '{print $16}'`
|
||||
tmp468_res9_h=`echo $res_tmp468 | awk '{print $17}'`
|
||||
tmp468_res9_l=`echo $res_tmp468 | awk '{print $18}'`
|
||||
|
||||
$fmt_print "console" "Info" "Tmp468 read result:"
|
||||
convert_tmp468_data $tmp468_res1_h $tmp468_res1_l "$TMP468_Channel0_name"
|
||||
convert_tmp468_data $tmp468_res2_h $tmp468_res2_l "$TMP468_Channel1_name"
|
||||
convert_tmp468_data $tmp468_res3_h $tmp468_res3_l "$TMP468_Channel2_name"
|
||||
convert_tmp468_data $tmp468_res4_h $tmp468_res4_l "$TMP468_Channel3_name"
|
||||
convert_tmp468_data $tmp468_res5_h $tmp468_res5_l "$TMP468_Channel4_name"
|
||||
convert_tmp468_data $tmp468_res6_h $tmp468_res6_l "$TMP468_Channel5_name"
|
||||
convert_tmp468_data $tmp468_res7_h $tmp468_res7_l "$TMP468_Channel6_name"
|
||||
convert_tmp468_data $tmp468_res8_h $tmp468_res8_l "$TMP468_Channel7_name"
|
||||
convert_tmp468_data $tmp468_res9_h $tmp468_res9_l "$TMP468_Channel8_name"
|
||||
}
|
||||
|
||||
test_tmp468_data(){
|
||||
convert_tmp468_data $test_data1 $test_data2 "Temp"
|
||||
}
|
||||
|
||||
case "${mode}" in
|
||||
"read")
|
||||
read_tmp468_data
|
||||
;;
|
||||
"test")
|
||||
test_tmp468_data
|
||||
;;
|
||||
"help")
|
||||
print_help
|
||||
;;
|
||||
*)
|
||||
$fmt_print "console" "Error" "[plugin_tmp468] Unexpected Input Param : $mode"
|
||||
print_help
|
||||
;;
|
||||
esac
|
||||
34
tool/plugin/plugin_adc128.sh
Normal file
34
tool/plugin/plugin_adc128.sh
Normal file
@ -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
|
||||
45
tool/plugin/plugin_emc1413.sh
Normal file
45
tool/plugin/plugin_emc1413.sh
Normal file
@ -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
|
||||
79
tool/plugin/plugin_ina3221.sh
Normal file
79
tool/plugin/plugin_ina3221.sh
Normal file
@ -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
|
||||
38
tool/plugin/plugin_tmp112.sh
Normal file
38
tool/plugin/plugin_tmp112.sh
Normal file
@ -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
|
||||
29
tool/plugin/plugin_tmp468.sh
Normal file
29
tool/plugin/plugin_tmp468.sh
Normal file
@ -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
|
||||
Loading…
Reference in New Issue
Block a user