-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAutoLRPT_Meteor_M2-3
135 lines (97 loc) · 4.51 KB
/
AutoLRPT_Meteor_M2-3
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
#!/bin/bash
# Including AutoLRPT's config file
. Meteor_M2-3.cfg
# Name of the satellite
satname="METEOR-M2 3"
# Get the timestamp of the upcoming/current pass and the current timestamp
pass_ts=`predict -p "$satname" | awk '{print $1}' | head -n1`
cur_ts=`date +%s`
# If the pass's timestamp is less than the current timestamp, wait for 20 minutes before progressing.
# This ensures that if AutoLRPT is being started during a pass, it will get the time of the upcoming pass
# otherways it will wait until the next day.
[[ $pass_ts -le $cur_ts ]] && sleep 20m
# Infinite loop that will always schedule the next pass after the recent one is over
while true; do
# Automatic update of APID channels
if [[ $upd_channels -eq 1 ]]; then
# Updating the APID channel in mlrpt's config file ~/mlrpt/default.cfg
if [[ $(curl --connect-timeout 10 https://usradioguy.com/meteor-satellite/ 2>/dev/null | grep -E -o '((>ON<)|(>OFF<))' | sed 's/<//g' | sed 's/>//g' | sed '4q;d') == "ON" ]]; then
sed -i '123s/.*/67/' ~/mlrpt/default.cfg
else
sed -i '123s/.*/66/' ~/mlrpt/default.cfg
fi
# Return to ~/AutoLRPT
cd ..
fi
# Get the timestamp of the upcoming/current pass and the current timestamp
pass_ts=`predict -p "$satname" | awk '{print $1}' | head -n1`
cur_ts=`date +%s`
# Writing the date and time of the upcomming path into the file next_pass
echo $(date -d @$pass_ts --utc "+%Y-%m-%d %H:%M:%S") > ~/AutoLRPT/next_pass
# Get the UTC time of the upcoming pass from predict
passtime=`date -d @$pass_ts --utc "+%H:%M:%S"`
# Calculate the difference between the system time and the pass time
difr=$(( $pass_ts - $cur_ts ))
# Getting the elevations of the upcoming pass from predict and parsing them into an array.
elevs=`predict '-p' "$satname" | awk '{print $5}'`
readarray -t elev_array <<< $elevs
# Getting the maximum elevation of the upcoming pass.
IFS=$'\n'
max_elev=`echo "${elev_array[*]}" | sort -nr | head -n1`
# Getting the azimuths of the upcoming pass from predict and extracting the medium azimuth.
readarray -t azimuth <<< $(predict -p "$satname" | awk '{print $6}')
azimuth=${azimuth[ $(( ${#azimuth[@]} / 2 )) ]}
# Wait until the pass begins
sleep "$difr"s
# Variable for the recording success/failure
# IMAGE RECORDED -> If an image was received and saved (successful execution of mlrpt)
# NO_IMAGE_RECORDED -> If no image was received (successful execution of mlrpt)
# NO_RECORDING -> If the user disabled the recording (min_elev, evening_rec) under certain circumstances (no execution of mlrpt)
# NO_SDR_CONNECTED -> If mlrpt stops because no SDR was connected (unsuccessful execution of mlrpt)
# ERROR -> Any other errors
rec_status=""
# Variable to save the error code after executing mlrpt
# 0 -> successful, >0 -> not successful
success=1
# Minimum elevation check
if [[ $max_elev -ge $min_elev ]]; then
# Check if evening_rec is enabled/disabled and if it's evening.
if [[ $evening_rec -eq 1 ]] || [[ 10#$(date +"%H") -le 15 ]]; then
# Check if Autoflip is enabled and if it's evening
if [[ 10#$(date +"%H") -gt 15 ]] && [[ $autoflip -eq 1 ]]; then
mlrpt -c M2-3.cfg -i > ~/AutoLRPT/mlrpt.log 2>&1
success=$?
else
mlrpt -c M2-3.cfg > ~/AutoLRPT/mlrpt.log 2>&1
success=$?
fi
else
rec_status="NO_RECORDING"
fi
else
rec_status="NO_RECORDING"
fi
# Generating the status
if [[ $success -eq 0 ]] && [[ $rec_status != "NO_RECORDING" ]]; then
if [[ -z $(grep "Saving Image" ~/AutoLRPT/mlrpt.log) ]]; then
rec_status="NO_IMAGE_RECORDED"
else
rec_status="IMAGE_RECORDED"
fi
fi
if [[ $success -ne 0 ]] && [[ $rec_status != "NO_RECORDING" ]]; then
if [[ -z $(grep "Failed to open RTL-SDR device" ~/AutoLRPT/mlrpt.log) ]]; then
rec_status="ERROR"
else
rec_status="NO_SDR_CONNECTED"
fi
fi
# Writing the date, time, maximum elevation, medium azimuth and success/error into the log file AutoLRPT.log
[ $logging -eq 1 ] && printf "%s %s %s %2d %3d %s\n" $(date --utc +%Y-%m-%d) $passtime \"$satname\" $max_elev $azimuth $rec_status >> ~/AutoLRPT/AutoLRPT.log
# Moving the images to the webserver's image folder (Extension AutoLRPT-Slideshow)
# The webserver's image folder (in the case below /var/www/html/images) must have writing permissions for that!
#[[ $(ls ~/mlrpt/images) != "" ]] && mv ~/mlrpt/images/* /var/www/html/AutoLRPT-Slideshow/images
# Wait for 20 minutes until the next pass is being scheduled
# (This will ensure that the next pass will be scheduled although no SDR has been connected)
sleep 20m
done