-
Notifications
You must be signed in to change notification settings - Fork 8
/
sat.sh
139 lines (105 loc) · 3.63 KB
/
sat.sh
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/bin/bash
path="/home/pi/sat.sh"
main () {
# check for arguments
if [ "$#" -eq 0 ]; then
# update sat orbit data
update_sat_data
# epmty pass.txt
> /var/www/html/sat/passes.txt
#Schedule Satellite Passes:
set_sat_cycle "NOAA 19" 137.1000
set_sat_cycle "NOAA 18" 137.9125
#set_sat_cycle "NOAA 15" 137.6200
else
# start recording if arg < 0 and pass data
# $1 = Satellite Name
# $2 = Frequency
# $3 = FileName base
# $4 = TLE File
# $5 = EPOC start time
# $6 = Time to capture
# $7 = File Path
rec_sat_data "$1" "$2" "$3" "$4" "$5" "$6" "$7"
fi
}
set_sat_cycle() {
# cutting upper part of prediction
PREDICTION_START=`/usr/bin/predict -t /etc/sat_data/data.txt -p "${1}" | head -1`
# cutting lower part of prediction
PREDICTION_END=`/usr/bin/predict -t /etc/sat_data/data.txt -p "${1}" | tail -1`
# extracting end date
var2=`echo $PREDICTION_END | cut -d " " -f 1`
# extracting elevation
MAXELEV=`/usr/bin/predict -t /etc/sat_data/data.txt -p "${1}" | awk -v max=0 '{if($5>max){max=$5}}END{print max}'`
# converting dates
while [ `date --date="TZ=\"UTC\" @${var2}" +%D` == `date +%D` ]; do
# extracting start time
START_TIME=`echo $PREDICTION_START | cut -d " " -f 3-4`
# extracting start time
var1=`echo $PREDICTION_START | cut -d " " -f 1`
# extracting end time
var3=`echo $START_TIME | cut -d " " -f 2 | cut -d ":" -f 3`
# calc pass tim
TIMER=`expr $var2 - $var1 + $var3`
# converting dates
OUTDATE=`date --date="TZ=\"UTC\" $START_TIME" +%Y%m%d-%H%M%S`
# check pass elevation
if [ $MAXELEV -gt 30 ]
then
# path for final file location
path_temp="/var/www/html/sat/${1//" "}${OUTDATE}"
echo ${1//" "}${OUTDATE} $MAXELEV
# create at job
echo "$path \"${1}\" $2 $path_temp/NOAA /etc/sat_data/data.txt $var1 $TIMER $path_temp" | at `date --date="TZ=\"UTC\" $START_TIME" +"%H:%M %D"`
time_cest=`date -d "$START_TIME UTC"`
# tee passes to pass file
echo "$1, $2, $time_cest" | tee -a /var/www/html/sat/passes.txt
fi
nextpredict=`expr $var2 + 60`
PREDICTION_START=`/usr/bin/predict -t /etc/sat_data/data.txt -p "${1}" $nextpredict | head -1`
PREDICTION_END=`/usr/bin/predict -t /etc/sat_data/data.txt -p "${1}" $nextpredict | tail -1`
MAXELEV=`/usr/bin/predict -t /etc/sat_data/data.txt -p "${1}" $nextpredict | awk -v max=0 '{if($5>max){max=$5}}END{print max}'`
var2=`echo $PREDICTION_END | cut -d " " -f 1`
done
}
rec_sat_data () {
# $1 = Satellite Name
# $2 = Frequency
# $3 = FileName base
# $4 = TLE File
# $5 = EPOC start time
# $6 = Time to capture
# $7 = File Path
# create folder for final files
mkdir $7
# create NOAA.txt and save pass data
touch $7/NOAA.txt
time_now=`date`;
# save pass data in NOAA.txt
echo "$1,$2,$time_now" > $7/NOAA.txt
# start recording
sudo timeout $6 rtl_fm -f ${2}M -s 60k -g 45 -p 55 -E wav -E deemp -F 9 - | sox -t wav - $3.wav rate 11025
# calc pass start time
PassStart=`expr $5 + 90`
if [ -e $3.wav ]; then
# creating map overlay
/usr/local/bin/wxmap -T "${1}" -H $4 -p 0 -l 0 -o $PassStart ${3}-map.png
# creating standard image
/usr/local/bin/wxtoimg -m ${3}-map.png -e HVC $3.wav $3.png
# creating colored image
/usr/local/bin/wxtoimg -m ${3}-map.png -e MSA $3.wav $3C.png
# creating thermal image
/usr/local/bin/wxtoimg -m ${3}-map.png -e therm $3.wav $3T.png
fi
}
update_sat_data () {
for i in `atq | awk '{print $1}'`; do atrm $i; done
if [ ! -d /etc/sat_data ] || [ ! -d /var/www/html/sat ] ; then
mkdir -p /etc/sat_data;
mkdir -p /var/www/html/sat;
fi
# downloading updated sat information
wget -qr https://www.celestrak.com/NORAD/elements/weather.txt -O /etc/sat_data/data.txt
}
main "$@"