-
Notifications
You must be signed in to change notification settings - Fork 34
/
verify_ad9361_temp
executable file
·74 lines (69 loc) · 2.11 KB
/
verify_ad9361_temp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/sh
for i in $(find -L /sys/bus/iio/devices -maxdepth 2 -name name)
do
dev_name=$(cat $i)
if [ "$dev_name" = "ad9361-phy" ] ; then
ad9361=$(echo $i | sed 's:/name$::')
break
fi
done
if [ "x$ad9361" = "x" ] ; then
echo can not find ad9361 in /sys
exit
fi
cd $ad9361
bbpll=$(cat rx_path_rates | sed -e 's|^BBPLL:||' -e 's| .*$||')
device=$(echo $ad9361 | awk -F '/' '{print $NF}')
# determine the time for new temperatures to be added - can't get something faster than I should
if [ -d /sys/kernel/debug/iio/$device ] ; then
echo 0x00D > /sys/kernel/debug/iio/$device/direct_reg_access
len=$(printf "%d" `cat /sys/kernel/debug/iio/$device/direct_reg_access`)
else
len=127
fi
# (2^29 + 10%) = 5905580032
len=$(expr '(' $len '/' 2 ')' '*' 5905580032 '/' $bbpll)
len=$(printf "%d.%d\n" `expr $len '/' 10` `expr $len - '(' $len '/' 10 '*' 10 ')'`)
avg=$(cat in_temp0_input)
# tolerance of the temp sensor is +/- 3C
tolerance=3000
max=`expr $avg + $tolerance`
min=`expr $avg - $tolerance`
echo "found $ad9361, starting temp ${avg}, reading every $len seconds"
start=`date +%s`
last_err=-1
while [ 1 ]
do
sleep $len
temp=$(cat in_temp0_input)
# echo checking $temp against $max and $min, avg $avg
if [ $temp -gt $max ] ; then
if [ $last_err -ne $temp ] ; then
last_err=$temp
echo -n "read $temp, exceeds max of $max, avg = $avg "
err=`date +%s`
sec=`expr $err - $start`
hrs=`expr $sec / 3600`
min=`expr '(' $sec - '(' $hrs '*' 60 ')' ')' / 60`
sec=`expr $sec % 60`
printf "%d:%d:%02d elapsed\n" $hrs $min $sec
fi
else
if [ $temp -lt $min ] ; then
if [ $last_err -ne $temp ] ; then
last_err=$temp
echo -n "read $temp, under min of $min, avg = $avg "
err=`date +%s`
sec=`expr $err - $start`
hrs=`expr $sec / 3600`
min=`expr '(' $sec - '(' $hrs '*' 60 ')' ')' / 60`
sec=`expr $sec % 60`
printf "%d:%d:%02d elapsed\n" $hrs $min $sec
fi
else
avg=`expr '(' $avg + $temp ')' / 2`
max=`expr $avg + $tolerance`
min=`expr $avg - $tolerance`
fi
fi
done