1 /*
2  * Simple MPEG/DVB parser to achieve network/service information without initial tuning data
3  *
4  * Copyright (C) 2006-2014 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 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <time.h>
26 #include "extended_frontend.h"
27 #include "si_types.h"
28 #include "scan.h"
29 #include "dump-dvbscan.h"
30 #include "dvbscan.h"
31 #include "countries.h"
32 #include "satellites.h"
33 
34 /******************************************************************************
35  * print initial tuning data for dvbscan. Nevertheless it should be also
36  * reusable for 'w_scan2 -I <file>', therefore a part of the data might be
37  * used later in w_scan2.
38  *****************************************************************************/
39 
dvbscan_dump_tuningdata(FILE * f,struct transponder * t,uint16_t index,struct w_scan_flags * flags)40 void dvbscan_dump_tuningdata(FILE * f,
41 			     struct transponder *t,
42 			     uint16_t index, struct w_scan_flags *flags)
43 {
44 	const char *network_name = t->network_name;
45 	if (index == 0) {
46 		struct tm *ti;
47 		time_t rawtime;
48 		time(&rawtime);
49 		ti = localtime(&rawtime);
50 		fprintf(f,
51 			"#------------------------------------------------------------------------------\n");
52 		fprintf(f, "# file automatically generated by %s\n",
53 			PACKAGE_NAME);
54 		fprintf(f, "# (https://github.com/stefantalpalaru/w_scan2)\n");
55 		fprintf(f, "#! <w_scan> %s %u %u %s %s </w_scan>\n",
56 			flags->version,
57 			flags->tuning_timeout,
58 			flags->filter_timeout,
59 			scantype_to_txt(flags->scantype),
60 			flags->scantype == SCAN_SATELLITE ?
61 			satellite_to_short_name(flags->list_id) :
62 			country_to_short_name(flags->list_id));
63 		fprintf(f,
64 			"#------------------------------------------------------------------------------\n");
65 
66 		if (flags->scantype == SCAN_SATELLITE)
67 			fprintf(f, "# satellite            : %s\n",
68 				satellite_to_short_name(flags->list_id));
69 		else
70 			fprintf(f,
71 				"# location and provider: <add description here>\n");
72 		fprintf(f, "# date (yyyy-mm-dd)    : %.04d-%.02d-%.02d\n",
73 			ti->tm_year + 1900, ti->tm_mon + 1, ti->tm_mday);
74 		fprintf(f,
75 			"# provided by (opt)    : <your name or email here>\n");
76 		fprintf(f, "#\n");
77 
78 		switch (flags->scantype) {
79 		case SCAN_TERRCABLE_ATSC:
80 			fprintf(f, "# A[2] <freq> <mod> [# comment]\n");
81 			break;
82 		case SCAN_CABLE:
83 			fprintf(f,
84 				"# C[2] <freq> <sr> <fec> <mod> [plp_id] [data_slice_id] [system_id] [# comment]\n");
85 			break;
86 		case SCAN_TERRESTRIAL:
87 			fprintf(f,
88 				"# T[2] <freq> <bw> <fec_hi> <fec_lo> <mod>");
89 			fprintf(f, " <tm> <guard> <hi> [plp_id] [# comment]\n");	//  [system_id]
90 			break;
91 		case SCAN_SATELLITE:
92 			fprintf(f,
93 				"# S[2] <freq> <pol> <sr> <fec> [ro] [mod] [isi] [pls_code] [pls_mode] [# comment]\n");
94 			break;
95 		default:
96 			fatal("%s (%d): UNKNOWN SCAN TYPE %d\n", __FUNCTION__,
97 			      __LINE__, flags->scantype);
98 		};
99 		fprintf(f,
100 			"#------------------------------------------------------------------------------\n");
101 	}			/* end if index == 0 */
102 	switch (flags->scantype) {
103 	case SCAN_TERRCABLE_ATSC:
104 		fprintf(f, "A ");
105 		fprintf(f, "%9i ", t->frequency);
106 		fprintf(f, "%8s", atsc_mod_to_txt(t->modulation));
107 		break;
108 	case SCAN_CABLE:
109 		fprintf(f, "C ");
110 		if (t->delsys == SYS_DVBC2)
111 			fprintf(f, "2 %u %u %u", t->plp_id, t->data_slice_id,
112 				t->system_id);
113 		fprintf(f, "%9i ", t->frequency);
114 		fprintf(f, "%7i ", t->symbolrate);
115 		fprintf(f, "%4s ", cable_fec_to_txt(t->coderate));
116 		fprintf(f, "%8s", cable_mod_to_txt(t->modulation));
117 		break;
118 	case SCAN_TERRESTRIAL:
119 		fprintf(f, "%s", t->delsys == SYS_DVBT2 ? "T2" : "T");
120 		fprintf(f, " %9i ", t->frequency);
121 		fprintf(f, "%4s ", terr_bw_to_txt(t->bandwidth));
122 		fprintf(f, "%4s ", terr_fec_to_txt(t->coderate));
123 		fprintf(f, "%4s ", terr_fec_to_txt(t->coderate_LP));
124 		fprintf(f, "%8s ", terr_mod_to_txt(t->modulation));
125 		fprintf(f, "%4s ", terr_transmission_to_txt(t->transmission));
126 		fprintf(f, "%4s ", terr_guard_to_txt(t->guard));
127 		fprintf(f, "%4s", terr_hierarchy_to_txt(t->hierarchy));
128 		if (t->plp_id)
129 			fprintf(f, " %u", t->plp_id);
130 		break;
131 	case SCAN_SATELLITE:
132 		fprintf(f, "%-2s ", sat_delivery_system_to_txt(t->delsys));
133 		fprintf(f, "%8i ", t->frequency);
134 		fprintf(f, "%1s ", sat_pol_to_txt(t->polarization));
135 		fprintf(f, "%8i ", t->symbolrate);
136 		fprintf(f, "%4s", sat_fec_to_txt(t->coderate));
137 		if (t->delsys != SYS_DVBS) {
138 			fprintf(f, " %2s ", sat_rolloff_to_txt(t->rolloff));
139 			fprintf(f, "%6s", sat_mod_to_txt(t->modulation));
140 		}
141 		break;
142 	default:
143 		;
144 	};
145 	if (network_name != NULL)
146 		fprintf(f, "\t# %s", network_name);
147 	fprintf(f, "\n");
148 }
149