[root@qz.com: /]$ cat get_powerlevel
#!/bin/sh
# less than 3.8V will execute reboot
WARNPWR=700 # ad value
pString=
pVal=
preVal=0
avgVal=0
sumVal=0
Cnt=0
difVal=0
lowPwr=0 #low power flag
checkdata()
{
let sumVal=$sumVal+$pVal
let avgVal=$avgVal/5;
sumVal=0
echo "avgVal: $avgVal"
}
pNo=
kill_helloapp()
{
pNo=`ps | grep hello_app | sed '1p' | awk '{print $1}'`
echo "pNo: $pNo"
echo "killing hello_app..."
kill -9 $pNo
}
while :
do
# get power value
pVal=`/lib/modules/test/adc_noloop | awk '{print $3}'`
echo "pVal: $pVal"
# compare with provious value
let difVal=$preVal-$pVal
# abs difVal
difVal=${difVal#-}
if [ "$difVal" -ge 12 ]
then
preVal=$pVal
echo "diff is to biger: $difVal"
continue
fi
# get average for 5 times
let Cnt=$Cnt+1
let sumVal=$sumVal+$pVal
if [ "$Cnt" -ge 5 ]
then
Cnt=0
let avgVal=$sumVal/5;
sumVal=0
echo "avgVal: $avgVal"
else
continue
fi
preVal=$pVal
if [ $avgVal -lt $WARNPWR ]; then
lowPwr=1
echo "THE POWER IS TOO LOW."
kill_helloapp
else
lowPwr=0
fi
done
阅读(1257) | 评论(0) | 转发(0) |