dvbd / src / dvbctuneparams.cpp @ de53ce58
History | View | Annotate | Download (3.78 KB)
1 |
/*
|
---|---|
2 |
Copyright 2004 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 |
DVBCTuneParams::DVBCTuneParams(const std::string &name, int apid, int vpid) |
31 |
: TuneParams(name, apid, vpid), |
32 |
freq(0),
|
33 |
inv(INVERSION_OFF), |
34 |
sr(0),
|
35 |
fec(HP_CODERATE_DEFAULT) |
36 |
{ |
37 |
} |
38 |
|
39 |
DVBCTuneParams::~DVBCTuneParams() |
40 |
{ |
41 |
} |
42 |
|
43 |
// transTable is an auxillary mapping from
|
44 |
// string keywords (eg FEC_1_2) to numbers
|
45 |
// FEC_1_2. Used in parsing. See translate() and
|
46 |
// DVBCTuneParams::createFromCZAP()
|
47 |
|
48 |
typedef std::map<std::string, int> StringIntMap; |
49 |
static StringIntMap transTable;
|
50 |
static bool transTableSetup = false; |
51 |
|
52 |
static int translate(const std::string &t) |
53 |
{ |
54 |
if (!transTableSetup) {
|
55 |
transTable["INVERSION_AUTO"] = INVERSION_AUTO;
|
56 |
transTable["INVERSION_OFF"] = INVERSION_OFF;
|
57 |
transTable["FEC_NONE"] = FEC_NONE;
|
58 |
transTable["FEC_1_2"] = FEC_1_2;
|
59 |
transTable["FEC_2_3"] = FEC_2_3;
|
60 |
transTable["FEC_3_4"] = FEC_3_4;
|
61 |
transTable["QAM_16"] = QAM_16;
|
62 |
transTable["QAM_32"] = QAM_32;
|
63 |
transTable["QAM_64"] = QAM_64;
|
64 |
transTable["GUARD_INTERVAL_1_32"] = GUARD_INTERVAL_1_32;
|
65 |
transTable["HIERARCHY_NONE"] = HIERARCHY_NONE;
|
66 |
transTable["BANDWIDTH_8_MHZ"] = BANDWIDTH_8_MHZ;
|
67 |
transTable["TRANSMISSION_MODE_2K"] = TRANSMISSION_MODE_2K;
|
68 |
} |
69 |
|
70 |
StringIntMap::const_iterator i = transTable.find(t); |
71 |
if (i == transTable.end()) {
|
72 |
std::cerr << "Fatal Error: no translation for \"" << t << "\" in " << __FILE__ << ":" << __LINE__ << "\n"; |
73 |
exit(1);
|
74 |
} |
75 |
return i->second;
|
76 |
} |
77 |
|
78 |
DVBCTuneParams *DVBCTuneParams::createFromCZAP(const std::string &line) |
79 |
{ |
80 |
// It is assumed that the line is a valid CZAP conf line
|
81 |
// (not a comment)
|
82 |
|
83 |
std::vector<std::string> v;
|
84 |
splitString(line, ':', v);
|
85 |
|
86 |
std::string &newName = v[0]; |
87 |
int vpid = toUnsignedLong(v[6]); |
88 |
int apid = toUnsignedLong(v[7]); |
89 |
|
90 |
DVBCTuneParams *p = new DVBCTuneParams(newName, vpid, apid);
|
91 |
p->freq = toUnsignedLong(v[1]);
|
92 |
p->inv = translate(v[2]);
|
93 |
p->sr = toUnsignedLong(v[3]);
|
94 |
p->fec = translate(v[4]);
|
95 |
p->qam = translate(v[5]);
|
96 |
return p;
|
97 |
} |
98 |
|
99 |
bool DVBCTuneParams::tune(int frontendFD) const |
100 |
{ |
101 |
// Possible todo:
|
102 |
// Change tune_it to observe lower code rate (fec2)
|
103 |
|
104 |
// Give it three goes at least!
|
105 |
for (int i = 0; i < 3; i++) { |
106 |
int rc = tune_it(frontendFD,
|
107 |
0, // old fd_sec |
108 |
freq, |
109 |
sr, // Symbol Rate for DVB-C or DVB-S
|
110 |
0, // Polarity |
111 |
-1, // Tone |
112 |
fe_spectral_inversion_t(inv), |
113 |
0, // diseqc |
114 |
fe_modulation_t(qam), |
115 |
fe_code_rate_t(fec), |
116 |
TRANSMISSION_MODE_DEFAULT, |
117 |
GUARD_INTERVAL_DEFAULT, |
118 |
BANDWIDTH_DEFAULT); |
119 |
|
120 |
if (rc >= 0) |
121 |
return true; |
122 |
} |
123 |
|
124 |
std::cerr << "Fatal error: failed to tune channel " << name << "\n"; |
125 |
return false; |
126 |
} |
127 |
|
128 |
bool DVBCTuneParams::sameAsExceptPIDs(const TuneParams &other) const |
129 |
{ |
130 |
const DVBCTuneParams &x = dynamic_cast<const DVBCTuneParams&>(other); |
131 |
|
132 |
if (&x == NULL) |
133 |
return false; |
134 |
|
135 |
return (freq == x.freq &&
|
136 |
inv == x.inv && |
137 |
sr == x.sr && |
138 |
fec == x.fec && |
139 |
qam == x.qam); |
140 |
} |