Statistics
| Branch: | Tag: | Revision:

dvbd / dvbttuneparams.cpp @ bfdb7446

History | View | Annotate | Download (4.04 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
    qam(CONSTELLATION_DEFAULT),
33
    inv(INVERSION_OFF),
34
    fec1(HP_CODERATE_DEFAULT),
35
    fec2(HP_CODERATE_DEFAULT),
36
    hier(HIERARCHY_DEFAULT),
37
    bandw(BANDWIDTH_DEFAULT),
38
    mode(TRANSMISSION_MODE_DEFAULT),
39
    guard(GUARD_INTERVAL_DEFAULT)
40
{
41
}
42

    
43
DVBTTuneParams::~DVBTTuneParams()
44
{
45
}
46

    
47
// transTable is an auxillary mapping from
48
// string keywords (eg FEC_1_2) to numbers
49
// FEC_1_2. Used in parsing. See translate() and
50
// DVBTTuneParams::createFromTZAP() 
51

    
52
typedef std::map<std::string, int> StringIntMap;
53
static StringIntMap transTable;
54
static bool transTableSetup = false;
55

    
56
static int translate(const std::string &t) 
57
{
58
  if (!transTableSetup) {
59
    transTable["INVERSION_OFF"] = INVERSION_OFF;
60
    transTable["FEC_1_2"] = FEC_1_2;
61
    transTable["FEC_2_3"] = FEC_2_3;
62
    transTable["FEC_3_4"] = FEC_3_4;
63
    transTable["QAM_16"] = QAM_16;
64
    transTable["QAM_64"] = QAM_64;
65
    transTable["GUARD_INTERVAL_1_32"] = GUARD_INTERVAL_1_32;
66
    transTable["HIERARCHY_NONE"] = HIERARCHY_NONE;
67
    transTable["BANDWIDTH_8_MHZ"] = BANDWIDTH_8_MHZ;
68
    transTable["TRANSMISSION_MODE_2K"] = TRANSMISSION_MODE_2K;
69
  }
70

    
71
  StringIntMap::const_iterator i = transTable.find(t);
72
  if (i == transTable.end()) {
73
    std::cerr << "Fatal Error: no translation for \"" << t << "\" in " << __FILE__ << ":" << __LINE__ << "\n";
74
    exit(1);
75
  }
76
  return i->second;
77
}
78

    
79
DVBTTuneParams *DVBTTuneParams::createFromTZAP(const std::string &line)
80
{
81
  // It is assumed that the line is a valid TZAP conf line
82
  // (not a comment) 
83

    
84
  std::vector<std::string> v;
85
  splitString(line, ':', v);
86

    
87
  std::string &newName = v[0];
88
  int vpid = toUnsignedLong(v[10]);
89
  int apid = toUnsignedLong(v[11]);
90

    
91
  DVBTTuneParams *p = new DVBTTuneParams(newName, vpid, apid);
92
  p->freq = toUnsignedLong(v[1]);
93
  p->inv = translate(v[2]);
94
  p->bandw = translate(v[3]);
95
  p->fec1 = translate(v[4]);
96
  p->fec2 = translate(v[5]);
97
  p->qam = translate(v[6]);
98
  p->mode = translate(v[7]);
99
  p->guard = translate(v[8]);
100
  p->hier = translate(v[9]);
101
  return p;
102
}
103

    
104
bool DVBTTuneParams::tune(int frontendFD) const
105
{
106
  // Possible todo:
107
  // Change tune_it to observe lower code rate (fec2)
108

    
109
  // Give it three goes at least!
110
  for (int i = 0; i < 3; i++) {
111
    int rc = tune_it(frontendFD, 
112
                     0,                // old fd_sec 
113
                     freq / 1000, 
114
                     0,                // Symbol Rate for DVB-C or DVB-S 
115
                     0,                // Polarity 
116
                     -1,        // Tone  
117
                     fe_spectral_inversion_t(inv), 
118
                     0,                // diseqc 
119
                     fe_modulation_t(qam),
120
                     fe_code_rate_t(fec1), 
121
                     fe_transmit_mode_t(mode),
122
                     fe_guard_interval_t(guard), 
123
                     fe_bandwidth_t(bandw));
124
    if (rc >= 0)
125
      return true;
126
  }
127

    
128
  std::cerr << "Fatal error: failed to tune channel " << name << "\n";
129
  return false;
130
}
131

    
132
bool DVBTTuneParams::sameAsExceptPIDs(const TuneParams &other) const
133
{
134
  const DVBTTuneParams &x = dynamic_cast<const DVBTTuneParams&>(other);
135

    
136
  if (&x == NULL)
137
    return false;
138
 
139
  return (freq == x.freq &&
140
          inv == x.inv &&
141
          bandw == x.bandw &&
142
          fec1 == x.fec1 &&
143
          fec2 == x.fec2 &&
144
          qam == x.qam &&
145
          mode == x.mode &&
146
          guard == x.guard &&
147
          hier == x.hier);
148
}