* extra/dvbiscovery: New shell script which allows to guess which network we are on.
[dvblast.git] / extra / dvbiscovery / dvbiscovery.sh
blob578a78aefb6dcfc6889a2e9d717d7fd33135b9d6
1 #!/bin/sh
2 ###############################################################################
3 # dvbiscovery.sh
4 ###############################################################################
5 # Copyright (C) 2010 VideoLAN
6 # $Id$
8 # Authors: Christophe Massiot <massiot@via.ecp.fr>
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write to the Free Software
22 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 ###############################################################################
25 CONF_BASE="/usr/local/share/dvblast/dvbiscovery-"
26 #CONF_BASE="./"
27 DVBLAST=dvblast
28 LOCK_TIMEOUT=2500
29 QUIT_TIMEOUT=15000
31 usage() {
32 echo "Usage: $0 [-a <adapter #>] [-S <diseqc sat num>] [-c <conf file>]" >&2
33 exit 1
36 conf_file_passed=""
37 adapter=""
38 diseqc=""
40 TEMP=`getopt -o a:S:c: -n "$0" -- "$@"`
42 if test $? -ne 0; then
43 usage
46 eval set -- "$TEMP"
48 while :; do
49 case "$1" in
50 -a)
51 adapter="-a $2"
52 shift 2
54 -c)
55 conf_file_passed=$2
56 shift 2
58 -S)
59 diseqc="-S $2"
60 shift 2
62 --)
63 shift
64 break
67 usage
69 esac
70 done
72 type=`$DVBLAST $diseqc $adapter -f 0 2>&1 | grep '^debug: Frontend' | sed 's/^debug: Frontend ".*" type "\(.*\)" supports:$/\1/'`
73 tune=""
74 conf_file=""
76 case "$type" in
77 "QPSK (DVB-S/S2)")
78 conf_file="${CONF_BASE}_dvb-s.conf"
79 tune=tune_sat
81 "QAM (DVB-C)")
82 conf_file="${CONF_BASE}_dvb-c.conf"
83 tune=tune_cable
85 "OFDM (DVB-T)")
86 conf_file="${CONF_BASE}_dvb-t.conf"
87 tune=tune_dtt
89 "ATSC")
90 conf_file="${CONF_BASE}_atsc.conf"
91 tune=tune_atsc
94 echo "unknown frontend type $type" >&2
95 exit 1
96 esac
98 if test -n "$conf_file_passed"; then
99 conf_file=$conf_file_passed
102 if ! test -r "$conf_file"; then
103 echo "unable to open $conf_file" >&2
104 exit 1
107 signal_catch() {
108 if test $childpid -ne 0; then
109 kill $childpid
111 exit 1
114 exec_dvblast() {
115 tmp_file=`mktemp`
117 $DVBLAST $diseqc $adapter -O $LOCK_TIMEOUT -Q $QUIT_TIMEOUT $opts 2>| $tmp_file &
118 childpid=$!
119 wait $childpid
120 if test $? -eq 0; then
121 cat $tmp_file
122 rm $tmp_file
123 exit 0
126 childpid=0
127 rm $tmp_file
130 strtofec() {
131 case "$1" in
132 "NONE") opts="$opts $2 0" ;;
133 "1/2") opts="$opts $2 12" ;;
134 "2/3") opts="$opts $2 23" ;;
135 "3/4") opts="$opts $2 34" ;;
136 "4/5") opts="$opts $2 45" ;;
137 "5/6") opts="$opts $2 56" ;;
138 "6/7") opts="$opts $2 67" ;;
139 "7/8") opts="$opts $2 78" ;;
140 "8/9") opts="$opts $2 89" ;;
141 "AUTO"|*) ;;
142 esac
145 strtomod() {
146 case "$1" in
147 "QPSK") opts="$opts -m qpsk" ;;
148 "QAM16") opts="$opts -m qam_16" ;;
149 "QAM32") opts="$opts -m qam_32" ;;
150 "QAM64") opts="$opts -m qam_64" ;;
151 "QAM128") opts="$opts -m qam_128" ;;
152 "8VSB") opts="$opts -m vsb_8" ;;
153 "16VSB") opts="$opts -m vsb_16" ;;
154 "AUTO"|*) ;;
155 esac
158 tune_sat() {
159 childpid=0
160 trap signal_catch 1 2 3 15
162 while read sys freq pol srate fec what mod; do
163 opts="-f $freq -s $srate"
165 case "$sys" in
166 "S") ;;
167 "S2")
168 case "$mod" in
169 "QPSK") opts="$opts -m qpsk" ;;
170 "8PSK") opts="$opts -m psk_8" ;;
172 echo "invalid modulation $mod" >&2
174 esac
177 echo "incompatible file" >&2
178 exit 1
180 esac
182 strtofec $fec "-F"
184 case "$pol" in
185 "V") opts="$opts -v 13" ;;
186 "H") opts="$opts -v 18" ;;
187 *) ;;
188 esac
190 exec_dvblast
191 done
194 tune_cable() {
195 childpid=0
196 trap signal_catch 1 2 3 15
198 while read sys freq srate fec mod; do
199 opts="-f $freq -s $srate"
201 case "$sys" in
202 "C") ;;
204 echo "incompatible file" >&2
205 exit 1
207 esac
209 strtofec $fec "-F"
210 strtomod $mod
212 exec_dvblast
213 done
216 tune_dtt() {
217 childpid=0
218 trap signal_catch 1 2 3 15
220 while read sys freq bw fec fec2 mod mode guard hier; do
221 opts="-f $freq"
223 case "$sys" in
224 "T"|"T2") ;;
226 echo "incompatible file" >&2
227 exit 1
229 esac
231 case "$bw" in
232 "8MHz") opts="$opts -b 8" ;;
233 "7MHz") opts="$opts -b 7" ;;
234 "6MHz") opts="$opts -b 6" ;;
235 "AUTO"|*) ;;
236 esac
238 strtofec $fec "-F"
239 strtofec $fec2 "-K"
240 strtomod $mod
242 case "$mode" in
243 "2k") opts="$opts -X 2" ;;
244 "8k") opts="$opts -X 8" ;;
245 "AUTO"|*) ;;
246 esac
248 case "$guard" in
249 "1/32") opts="$opts -G 32" ;;
250 "1/16") opts="$opts -G 16" ;;
251 "1/8") opts="$opts -G 8" ;;
252 "1/4") opts="$opts -G 4" ;;
253 "AUTO"|*) ;;
254 esac
256 case "$hier" in
257 "NONE") opts="$opts -H 0" ;;
258 "1") opts="$opts -H 1" ;;
259 "2") opts="$opts -H 2" ;;
260 "4") opts="$opts -H 4" ;;
261 "AUTO"|*) ;;
262 esac
264 exec_dvblast
265 done
268 tune_atsc() {
269 childpid=0
270 trap signal_catch 1 2 3 15
272 while read sys freq mod; do
273 opts="-f $freq"
275 case "$sys" in
276 "A") ;;
278 echo "incompatible file" >&2
279 exit 1
281 esac
283 strtomod $mod
285 exec_dvblast
286 done
289 childpid=0
290 trap signal_catch 1 2 3 15
292 grep -v "^#" < "$conf_file" 2>/dev/null | $tune &
293 childpid=$!
294 wait $childpid
296 exit 100