Statistics
| Branch: | Tag: | Revision:

dvbd / src / dvbttuneparams.cpp @ 904d298f

History | View | Annotate | Download (4.38 KB)

1 bfdb7446 jak
/*
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 3f54700c jak
    freq(0),
33 bfdb7446 jak
    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 7d8cb14c jak
    transTable["INVERSION_AUTO"] = INVERSION_AUTO;
61 bfdb7446 jak
    transTable["INVERSION_OFF"] = INVERSION_OFF;
62 7d8cb14c jak
    transTable["INVERSION_ON"] = INVERSION_ON;
63 bfdb7446 jak
    transTable["FEC_1_2"] = FEC_1_2;
64
    transTable["FEC_2_3"] = FEC_2_3;
65
    transTable["FEC_3_4"] = FEC_3_4;
66
    transTable["QAM_16"] = QAM_16;
67
    transTable["QAM_64"] = QAM_64;
68 7d8cb14c jak
    transTable["GUARD_INTERVAL_1_8"] = GUARD_INTERVAL_1_8;
69
    transTable["GUARD_INTERVAL_1_16"] = GUARD_INTERVAL_1_16;
70 bfdb7446 jak
    transTable["GUARD_INTERVAL_1_32"] = GUARD_INTERVAL_1_32;
71
    transTable["HIERARCHY_NONE"] = HIERARCHY_NONE;
72 dc5f4342 jak
    transTable["BANDWIDTH_7_MHZ"] = BANDWIDTH_7_MHZ;
73 bfdb7446 jak
    transTable["BANDWIDTH_8_MHZ"] = BANDWIDTH_8_MHZ;
74
    transTable["TRANSMISSION_MODE_2K"] = TRANSMISSION_MODE_2K;
75 7d8cb14c jak
    transTable["TRANSMISSION_MODE_8K"] = TRANSMISSION_MODE_8K;
76 bfdb7446 jak
  }
77
78
  StringIntMap::const_iterator i = transTable.find(t);
79
  if (i == transTable.end()) {
80
    std::cerr << "Fatal Error: no translation for \"" << t << "\" in " << __FILE__ << ":" << __LINE__ << "\n";
81
    exit(1);
82
  }
83
  return i->second;
84
}
85
86
DVBTTuneParams *DVBTTuneParams::createFromTZAP(const std::string &line)
87
{
88
  // It is assumed that the line is a valid TZAP conf line
89
  // (not a comment) 
90
91
  std::vector<std::string> v;
92
  splitString(line, ':', v);
93
94
  std::string &newName = v[0];
95
  int vpid = toUnsignedLong(v[10]);
96
  int apid = toUnsignedLong(v[11]);
97
98
  DVBTTuneParams *p = new DVBTTuneParams(newName, vpid, apid);
99
  p->freq = toUnsignedLong(v[1]);
100
  p->inv = translate(v[2]);
101
  p->bandw = translate(v[3]);
102
  p->fec1 = translate(v[4]);
103
  p->fec2 = translate(v[5]);
104
  p->qam = translate(v[6]);
105
  p->mode = translate(v[7]);
106
  p->guard = translate(v[8]);
107
  p->hier = translate(v[9]);
108
  return p;
109
}
110
111
bool DVBTTuneParams::tune(int frontendFD) const
112
{
113
  // Possible todo:
114
  // Change tune_it to observe lower code rate (fec2)
115
116
  // Give it three goes at least!
117
  for (int i = 0; i < 3; i++) {
118
    int rc = tune_it(frontendFD, 
119
                     0,                // old fd_sec 
120
                     freq / 1000, 
121
                     0,                // Symbol Rate for DVB-C or DVB-S 
122
                     0,                // Polarity 
123
                     -1,        // Tone  
124
                     fe_spectral_inversion_t(inv), 
125
                     0,                // diseqc 
126
                     fe_modulation_t(qam),
127
                     fe_code_rate_t(fec1), 
128
                     fe_transmit_mode_t(mode),
129
                     fe_guard_interval_t(guard), 
130
                     fe_bandwidth_t(bandw));
131
    if (rc >= 0)
132
      return true;
133
  }
134
135
  std::cerr << "Fatal error: failed to tune channel " << name << "\n";
136
  return false;
137
}
138
139
bool DVBTTuneParams::sameAsExceptPIDs(const TuneParams &other) const
140
{
141
  const DVBTTuneParams &x = dynamic_cast<const DVBTTuneParams&>(other);
142
143
  if (&x == NULL)
144
    return false;
145
 
146
  return (freq == x.freq &&
147
          inv == x.inv &&
148
          bandw == x.bandw &&
149
          fec1 == x.fec1 &&
150
          fec2 == x.fec2 &&
151
          qam == x.qam &&
152
          mode == x.mode &&
153
          guard == x.guard &&
154
          hier == x.hier);
155
}