1 /*
2  * Simple MPEG/DVB parser to achieve network/service information without initial tuning data
3  *
4  * Copyright (C) 2006, 2007, 2008, 2009 Winfried Koehler
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  */
21 
22 /* this file is shared between w_scan2 and the VDR plugin wirbelscan.
23  * For details on the latter see http://wirbel.htpc-forum.de
24  */
25 #define B(ID) static const struct __sat_transponder ID[] = {
26 #define E(ID) };
27 
28 #include <stdio.h>
29 #include <string.h>
30 #include <unistd.h>
31 #include <stdlib.h>
32 #include "scan.h"
33 #include "satellites.h"
34 #include "extended_frontend.h"
35 #include "satellites.dat"
36 
37 /******************************************************************************
38  * convert position constant
39  * to index number
40  *
41  *****************************************************************************/
42 
txt_to_satellite(const char * id)43 int txt_to_satellite(const char *id)
44 {
45 	unsigned int i;
46 	for (i = 0; i < SAT_COUNT(sat_list); i++)
47 		if (!strcasecmp(id, sat_list[i].short_name))
48 			return sat_list[i].id;
49 	return -1;
50 }
51 
52 /******************************************************************************
53  * return numbers of satellites defined.
54  *
55  *
56  *****************************************************************************/
57 
sat_count()58 int sat_count()
59 {
60 	return SAT_COUNT(sat_list);
61 }
62 
63 /******************************************************************************
64  * convert index number
65  * to position constant
66  *
67  *****************************************************************************/
68 
satellite_to_short_name(int idx)69 const char *satellite_to_short_name(int idx)
70 {
71 	unsigned int i;
72 	for (i = 0; i < SAT_COUNT(sat_list); i++)
73 		if (idx == sat_list[i].id)
74 			return sat_list[i].short_name;
75 	return "??";
76 }
77 
78 /******************************************************************************
79  * convert index number
80  * to satellite name
81  *
82  *****************************************************************************/
83 
satellite_to_full_name(int idx)84 const char *satellite_to_full_name(int idx)
85 {
86 	unsigned int i;
87 	for (i = 0; i < SAT_COUNT(sat_list); i++)
88 		if (idx == sat_list[i].id)
89 			return sat_list[i].full_name;
90 	warning
91 	    ("SATELLITE CODE NOT DEFINED. PLEASE RE-CHECK WETHER YOU TYPED CORRECTLY.\n");
92 	usleep(5000000);
93 	return "??";
94 }
95 
96 /******************************************************************************
97  * return index number
98  * from rotor position
99  *
100  *****************************************************************************/
rotor_position_to_sat_list_index(int rotor_position)101 int rotor_position_to_sat_list_index(int rotor_position)
102 {
103 	unsigned int i;
104 	for (i = 0; i < SAT_COUNT(sat_list); i++)
105 		if (rotor_position == sat_list[i].rotor_position)
106 			return i;
107 	return 0;
108 }
109 
110 /******************************************************************************
111  * print list of
112  * all satellites
113  *
114  *****************************************************************************/
115 
print_satellites(void)116 void print_satellites(void)
117 {
118 	unsigned int i;
119 	for (i = 0; i < SAT_COUNT(sat_list); i++)
120 		info("\t%s\t\t%s\n", sat_list[i].short_name,
121 		     sat_list[i].full_name);
122 }
123 
124 /******************************************************************************
125  * get transponder data
126  *
127  *****************************************************************************/
128 //int get_frontend_param(uint16_t satellite, uint16_t table_index, struct tuning_parameters * param) {
129 //unsigned int i;
130 //
131 //for (i = 0; i < SAT_COUNT(sat_list); i++)
132 //    if (satellite == sat_list[i].id) {
133 //        if (table_index >= sat_list[i].item_count)
134 //            return 0; //error
135 //        memset(param, 0, sizeof(struct tuning_parameters));
136 //        param->frequency = sat_list[i].items[table_index].intermediate_frequency;
137 //        param->inversion = INVERSION_AUTO;
138 //        param->sat.modulation_system = sat_list[i].items[table_index].modulation_system;
139 //        param->sat.polarization      = sat_list[i].items[table_index].polarization;
140 //        param->sat.symbol_rate       = sat_list[i].items[table_index].symbol_rate;
141 //        param->sat.fec_inner         = sat_list[i].items[table_index].fec_inner;
142 //        param->sat.rolloff           = sat_list[i].items[table_index].rolloff;
143 //        param->sat.modulation_type   = sat_list[i].items[table_index].modulation_type;
144 //        return 1;
145 //        }
146 //return 0; // error
147 //}
148 
choose_satellite(const char * satellite,int * channellist)149 int choose_satellite(const char *satellite, int *channellist)
150 {
151 	int retval = 0;
152 	*channellist = txt_to_satellite(satellite);
153 	if (*channellist < 0) {
154 		*channellist = S19E2;
155 		warning
156 		    ("\n\nSATELLITE CODE IS NOT DEFINED. FALLING BACK TO \"S19E2\"\n\n");
157 		sleep(10);
158 		retval = -1;
159 	}
160 	info("using settings for %s\n", satellite_to_full_name(*channellist));
161 	return retval;
162 }
163