dvbd / src / dvbttuneparams.cpp @ 0c89a4ee
History | View | Annotate | Download (4.41 KB)
1 |
/*
|
---|---|
2 |
Copyright 2003 John Knottenbelt
|
3 |
|
4 |
This program is free software; you can redistribute it and/or modify
|
5 |
it under the terms of the GNU General Public License as published by
|
6 |
the Free Software Foundation; either version 2 of the License, or
|
7 |
(at your option) any later version.
|
8 |
|
9 |
This program is distributed in the hope that it will be useful,
|
10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12 |
GNU General Public License for more details.
|
13 |
|
14 |
You should have received a copy of the GNU General Public License
|
15 |
along with this program; if not, write to the Free Software
|
16 |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
|
17 |
*/
|
18 |
|
19 |
#include "config.h" |
20 |
#include "tuneparams.h" |
21 |
#include "stringutil.h" |
22 |
|
23 |
#include <map> |
24 |
#include <iostream> |
25 |
#include <cstdlib> |
26 |
#include "tune.h" |
27 |
|
28 |
// DVB-T Tuning Parameters
|
29 |
|
30 |
DVBTTuneParams::DVBTTuneParams(const std::string &name, int apid, int vpid) |
31 |
: TuneParams(name, apid, vpid), |
32 |
freq(0),
|
33 |
qam(CONSTELLATION_DEFAULT), |
34 |
inv(INVERSION_OFF), |
35 |
fec1(HP_CODERATE_DEFAULT), |
36 |
fec2(HP_CODERATE_DEFAULT), |
37 |
hier(HIERARCHY_DEFAULT), |
38 |
bandw(BANDWIDTH_DEFAULT), |
39 |
mode(TRANSMISSION_MODE_DEFAULT), |
40 |
guard(GUARD_INTERVAL_DEFAULT) |
41 |
{ |
42 |
} |
43 |
|
44 |
DVBTTuneParams::~DVBTTuneParams() |
45 |
{ |
46 |
} |
47 |
|
48 |
// transTable is an auxillary mapping from
|
49 |
// string keywords (eg FEC_1_2) to numbers
|
50 |
// FEC_1_2. Used in parsing. See translate() and
|
51 |
// DVBTTuneParams::createFromTZAP()
|
52 |
|
53 |
typedef std::map<std::string, int> StringIntMap; |
54 |
static StringIntMap transTable;
|
55 |
static bool transTableSetup = false; |
56 |
|
57 |
static int translate(const std::string &t) |
58 |
{ |
59 |
if (!transTableSetup) {
|
60 |
transTable["INVERSION_AUTO"] = INVERSION_AUTO;
|
61 |
transTable["INVERSION_OFF"] = INVERSION_OFF;
|
62 |
transTable["INVERSION_ON"] = INVERSION_ON;
|
63 |
transTable["FEC_NONE"] = FEC_NONE;
|
64 |
transTable["FEC_1_2"] = FEC_1_2;
|
65 |
transTable["FEC_2_3"] = FEC_2_3;
|
66 |
transTable["FEC_3_4"] = FEC_3_4;
|
67 |
transTable["QAM_16"] = QAM_16;
|
68 |
transTable["QAM_64"] = QAM_64;
|
69 |
transTable["GUARD_INTERVAL_1_8"] = GUARD_INTERVAL_1_8;
|
70 |
transTable["GUARD_INTERVAL_1_16"] = GUARD_INTERVAL_1_16;
|
71 |
transTable["GUARD_INTERVAL_1_32"] = GUARD_INTERVAL_1_32;
|
72 |
transTable["HIERARCHY_NONE"] = HIERARCHY_NONE;
|
73 |
transTable["BANDWIDTH_7_MHZ"] = BANDWIDTH_7_MHZ;
|
74 |
transTable["BANDWIDTH_8_MHZ"] = BANDWIDTH_8_MHZ;
|
75 |
transTable["TRANSMISSION_MODE_2K"] = TRANSMISSION_MODE_2K;
|
76 |
transTable["TRANSMISSION_MODE_8K"] = TRANSMISSION_MODE_8K;
|
77 |
} |
78 |
|
79 |
StringIntMap::const_iterator i = transTable.find(t); |
80 |
if (i == transTable.end()) {
|
81 |
std::cerr << "Fatal Error: no translation for \"" << t << "\" in " << __FILE__ << ":" << __LINE__ << "\n"; |
82 |
exit(1);
|
83 |
} |
84 |
return i->second;
|
85 |
} |
86 |
|
87 |
DVBTTuneParams *DVBTTuneParams::createFromTZAP(const std::string &line) |
88 |
{ |
89 |
// It is assumed that the line is a valid TZAP conf line
|
90 |
// (not a comment)
|
91 |
|
92 |
std::vector<std::string> v;
|
93 |
splitString(line, ':', v);
|
94 |
|
95 |
std::string &newName = v[0]; |
96 |
int vpid = toUnsignedLong(v[10]); |
97 |
int apid = toUnsignedLong(v[11]); |
98 |
|
99 |
DVBTTuneParams *p = new DVBTTuneParams(newName, vpid, apid);
|
100 |
p->freq = toUnsignedLong(v[1]);
|
101 |
p->inv = translate(v[2]);
|
102 |
p->bandw = translate(v[3]);
|
103 |
p->fec1 = translate(v[4]);
|
104 |
p->fec2 = translate(v[5]);
|
105 |
p->qam = translate(v[6]);
|
106 |
p->mode = translate(v[7]);
|
107 |
p->guard = translate(v[8]);
|
108 |
p->hier = translate(v[9]);
|
109 |
return p;
|
110 |
} |
111 |
|
112 |
bool DVBTTuneParams::tune(int frontendFD) const |
113 |
{ |
114 |
// Possible todo:
|
115 |
// Change tune_it to observe lower code rate (fec2)
|
116 |
|
117 |
// Give it three goes at least!
|
118 |
for (int i = 0; i < 3; i++) { |
119 |
int rc = tune_it(frontendFD,
|
120 |
0, // old fd_sec |
121 |
freq / 1000,
|
122 |
0, // Symbol Rate for DVB-C or DVB-S |
123 |
0, // Polarity |
124 |
-1, // Tone |
125 |
fe_spectral_inversion_t(inv), |
126 |
0, // diseqc |
127 |
fe_modulation_t(qam), |
128 |
fe_code_rate_t(fec1), |
129 |
fe_transmit_mode_t(mode), |
130 |
fe_guard_interval_t(guard), |
131 |
fe_bandwidth_t(bandw)); |
132 |
if (rc >= 0) |
133 |
return true; |
134 |
} |
135 |
|
136 |
std::cerr << "Fatal error: failed to tune channel " << name << "\n"; |
137 |
return false; |
138 |
} |
139 |
|
140 |
bool DVBTTuneParams::sameAsExceptPIDs(const TuneParams &other) const |
141 |
{ |
142 |
const DVBTTuneParams &x = dynamic_cast<const DVBTTuneParams&>(other); |
143 |
|
144 |
if (&x == NULL) |
145 |
return false; |
146 |
|
147 |
return (freq == x.freq &&
|
148 |
inv == x.inv && |
149 |
bandw == x.bandw && |
150 |
fec1 == x.fec1 && |
151 |
fec2 == x.fec2 && |
152 |
qam == x.qam && |
153 |
mode == x.mode && |
154 |
guard == x.guard && |
155 |
hier == x.hier); |
156 |
} |