2025-02-19 13:43:50 +08:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
2025-03-13 16:34:05 +08:00
|
|
|
script_version="v2.0"
|
|
|
|
|
server_type="5688m7"
|
2025-02-19 13:43:50 +08:00
|
|
|
server_platform="m7"
|
|
|
|
|
|
|
|
|
|
slot_name=$1
|
|
|
|
|
sensor_type=$2
|
|
|
|
|
chip_slave=$3
|
2025-02-21 09:33:20 +08:00
|
|
|
param_num=$#
|
2025-02-19 13:43:50 +08:00
|
|
|
|
|
|
|
|
nic_type=""
|
|
|
|
|
slot_id=""
|
|
|
|
|
|
2025-02-20 18:10:19 +08:00
|
|
|
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"
|
2025-02-19 13:43:50 +08:00
|
|
|
|
2025-02-21 09:33:20 +08:00
|
|
|
print_helper(){
|
2025-03-13 16:34:05 +08:00
|
|
|
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"
|
2025-02-21 09:33:20 +08:00
|
|
|
}
|
|
|
|
|
|
2025-02-26 16:28:01 +08:00
|
|
|
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"
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-19 13:43:50 +08:00
|
|
|
conf_pre_check(){
|
|
|
|
|
|
2025-02-21 09:33:20 +08:00
|
|
|
if [ $param_num -lt 1 ];then
|
|
|
|
|
print_helper
|
|
|
|
|
exit 0
|
|
|
|
|
fi
|
|
|
|
|
|
2025-02-19 13:43:50 +08:00
|
|
|
if [ ! -e $fmt_print ];then
|
|
|
|
|
echo "Missing file $fmt_print !!!"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ ! -e $server_script ];then
|
2025-02-21 09:33:20 +08:00
|
|
|
$fmt_print "console" "Error" "Server Script $server_script not exist! Maybe unsupport for now!"
|
2025-02-19 13:43:50 +08:00
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ ! -e $sensor_script ];then
|
2025-02-21 09:33:20 +08:00
|
|
|
$fmt_print "console" "Error" "Sensor Script $sensor_script not exist! Maybe unsupport for now!"
|
2025-02-19 13:43:50 +08:00
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ ! -e $i2c_script ];then
|
|
|
|
|
$fmt_print "console" "Error" "$i2c_script not exist!"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
2025-03-13 16:34:05 +08:00
|
|
|
|
|
|
|
|
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"
|
2025-02-19 13:43:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
parse_slot_name(){
|
|
|
|
|
# Get nic type and slot id from slot name
|
2025-02-20 18:10:19 +08:00
|
|
|
case "${slot_name}" in
|
2025-02-19 13:43:50 +08:00
|
|
|
ocp*)
|
|
|
|
|
nic_type="ocp"
|
|
|
|
|
slot_id=`echo $slot_name | cut -c 4`
|
2025-02-20 18:10:19 +08:00
|
|
|
;;
|
2025-02-19 13:43:50 +08:00
|
|
|
pcie*)
|
|
|
|
|
nic_type="pcie"
|
|
|
|
|
slot_id=`echo $slot_name | cut -c 5-`
|
2025-02-20 18:10:19 +08:00
|
|
|
;;
|
2025-02-19 13:43:50 +08:00
|
|
|
*)
|
|
|
|
|
$fmt_print "log" "Warning" "Undetermined nic type, default set to pcie"
|
|
|
|
|
nic_type="pcie"
|
|
|
|
|
slot_id=$slot_name
|
2025-02-20 18:10:19 +08:00
|
|
|
;;
|
2025-02-19 13:43:50 +08:00
|
|
|
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(){
|
2025-02-20 18:10:19 +08:00
|
|
|
$fmt_print "log" "Info" "start sensor reading"
|
2025-02-21 09:33:20 +08:00
|
|
|
|
|
|
|
|
$sensor_script "read" "${i2c_bus}" "${chip_slave}" "${server_platform}"
|
2025-02-19 13:43:50 +08:00
|
|
|
}
|
|
|
|
|
# ---------------------------------------------------------
|
|
|
|
|
# Start Execute Script
|
|
|
|
|
# ---------------------------------------------------------
|
2025-03-13 16:34:05 +08:00
|
|
|
# init debug log
|
|
|
|
|
if [ -e "/tmp/nicsensor_debug.log" ];then
|
|
|
|
|
rm /tmp/nicsensor_debug.log
|
|
|
|
|
fi
|
|
|
|
|
|
2025-02-26 16:28:01 +08:00
|
|
|
# check if is detect option
|
|
|
|
|
if [ "$1" = "detect" ];then
|
|
|
|
|
perform_detect
|
|
|
|
|
exit 0
|
|
|
|
|
fi
|
|
|
|
|
|
2025-02-19 13:43:50 +08:00
|
|
|
conf_pre_check
|
|
|
|
|
|
|
|
|
|
parse_slot_name
|
|
|
|
|
|
2025-02-21 09:33:20 +08:00
|
|
|
i2c_bus=`connect_i2c`
|
2025-03-27 09:43:19 +08:00
|
|
|
if [ $i2c_bus -lt 0 ];then
|
2025-03-13 16:34:05 +08:00
|
|
|
$fmt_print "console" "Error" "An Error occured when build i2c connection with ${nic_type} ${slot_id}"
|
2025-02-24 20:15:41 +08:00
|
|
|
exit 1
|
|
|
|
|
fi
|
2025-02-19 13:43:50 +08:00
|
|
|
|
2025-02-24 20:15:41 +08:00
|
|
|
start_sensor_reading
|