Statistics
| Branch: | Tag: | Revision:

dvbd / src / dvbttuneparams.cpp @ a24dbbce

History | View | Annotate | Download (3.13 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 "dvbtuneparamscommon.h"
22
#include "stringutil.h"
23

    
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(LP_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

    
49
DVBTTuneParams *DVBTTuneParams::createFromTZAP(const std::string &line)
50
{
51
  // It is assumed that the line is a valid TZAP conf line
52
  // (not a comment) 
53

    
54
  std::vector<std::string> v;
55
  splitString(line, ':', v);
56

    
57
  std::string &newName = v[0];
58
  int vpid = toUnsignedLong(v[10]);
59
  int apid = toUnsignedLong(v[11]);
60

    
61
  DVBTTuneParams *p = new DVBTTuneParams(newName, vpid, apid);
62
  p->freq = toUnsignedLong(v[1]);
63
  p->inv = translateTuneParam(v[2]);
64
  p->bandw = translateTuneParam(v[3]);
65
  p->fec1 = translateTuneParam(v[4]);
66
  p->fec2 = translateTuneParam(v[5]);
67
  p->qam = translateTuneParam(v[6]);
68
  p->mode = translateTuneParam(v[7]);
69
  p->guard = translateTuneParam(v[8]);
70
  p->hier = translateTuneParam(v[9]);
71
  return p;
72
}
73

    
74
bool DVBTTuneParams::tune(int frontendFD) const
75
{
76
  // Possible todo:
77
  // Change tune_it to observe lower code rate (fec2)
78

    
79
  // Give it three goes at least!
80
  for (int i = 0; i < 3; i++) {
81
    int rc = tune_it(frontendFD, 
82
                     freq / 1000, 
83
                     0,                // Symbol Rate for DVB-C or DVB-S 
84
                     0,                // Polarity 
85
                     -1,        // Tone  
86
                     fe_spectral_inversion_t(inv), 
87
                     0,                // diseqc 
88
                     fe_modulation_t(qam),
89
                     fe_code_rate_t(fec1), 
90
                     fe_transmit_mode_t(mode),
91
                     fe_guard_interval_t(guard), 
92
                     fe_bandwidth_t(bandw),
93
                     fe_code_rate_t(fec2),
94
                     fe_hierarchy_t(hier));
95
    if (rc >= 0)
96
      return true;
97
  }
98

    
99
  std::cerr << "Fatal error: failed to tune channel " << name << "\n";
100
  return false;
101
}
102

    
103
bool DVBTTuneParams::sameAsExceptPIDs(const TuneParams &other) const
104
{
105
  const DVBTTuneParams &x = dynamic_cast<const DVBTTuneParams&>(other);
106

    
107
  if (&x == NULL)
108
    return false;
109
 
110
  return (freq == x.freq &&
111
          inv == x.inv &&
112
          bandw == x.bandw &&
113
          fec1 == x.fec1 &&
114
          fec2 == x.fec2 &&
115
          qam == x.qam &&
116
          mode == x.mode &&
117
          guard == x.guard &&
118
          hier == x.hier);
119
}