-
Notifications
You must be signed in to change notification settings - Fork 18
/
dvbtconfig.py
173 lines (152 loc) · 5.67 KB
/
dvbtconfig.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#! /usr/bin/env python3
#
# Copyright (C) 2016 Christian Pointner <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import dvbt
import configparser
class DVBTConfig:
config = configparser.RawConfigParser()
# DVB-T Parameters
dflt_channel_mhz = 6
dflt_mode = dvbt.T2k
dflt_code_rate = dvbt.C1_2
dflt_constellation = dvbt.QPSK
dflt_guard_interval = dvbt.G1_32
# Channel Parameters
dflt_center_freq = 498000000
# Hack-RF Parameters
dflt_hackrf_rf_gain = 14
dflt_hackrf_if_gain = 20
dflt_hackrf_bb_gain = 20
# tsrfsend Parameters
dflt_tsrfsend_gain = 0
dflt_tsrfsend_cell_id = 0
def __init__(self, configfile):
self.config.readfp(open(configfile))
def get_channel_mhz(self):
try:
c = self.config.getint('dvb-t', 'bandwith')
if c < 5 or c > 8:
raise ValueError("illegal value for bandwith: %d" % c)
return c
except configparser.NoSectionError:
return self.dflt_channel_mhz
except configparser.NoOptionError:
return self.dflt_channel_mhz
def get_mode(self):
try:
m = self.config.get('dvb-t', 'mode')
if m.upper() == "2K":
return dvbt.T2k
if m.upper() == "8K":
return dvbt.T8k
raise ValueError("illegal value for mode: %s" % m)
except configparser.NoSectionError:
return self.dflt_mode
except configparser.NoOptionError:
return self.dflt_mode
def get_code_rate(self):
try:
c = self.config.get('dvb-t', 'code-rate')
if c == "1/2":
return dvbt.C1_2
if c == "2/3":
return dvbt.C2_3
if c == "3/4":
return dvbt.C3_4
if c == "5/6":
return dvbt.C5_6
if c == "7/8":
return dvbt.C7_8
raise ValueError("illegal value for code_rate: %s" % c)
except configparser.NoSectionError:
return self.dflt_code_rate
except configparser.NoOptionError:
return self.dflt_code_rate
def get_constellation(self):
try:
c = self.config.get('dvb-t', 'constellation')
if c.upper() == "QPSK":
return dvbt.QPSK
if c.upper() == "QAM16":
return dvbt.QAM16
if c.upper() == "QAM64":
return dvbt.QAM64
raise ValueError("illegal value for constellation: %s" % c)
except configparser.NoSectionError:
return self.dflt_constellation
except configparser.NoOptionError:
return self.dflt_constellation
def get_guard_interval(self):
try:
g = self.config.get('dvb-t', 'guard-interval')
if g == "1/32":
return dvbt.G1_32
if g == "1/16":
return dvbt.G1_16
if g == "1/8":
return dvbt.G1_8
if g == "1/4":
return dvbt.G1_4
raise ValueError("illegal value for guard_interval: %s" % g)
except configparser.NoSectionError:
return self.dflt_guard_interval
except configparser.NoOptionError:
return self.dflt_guard_interval
def get_center_freq(self):
try:
f = self.config.getint('channel', 'frequency')
if f < 474000000 or f > 858000000:
raise ValueError("center frequency is out of allowed range: %d" % f)
return f
except configparser.NoSectionError:
return self.dflt_center_freq
except configparser.NoOptionError:
return self.dflt_center_freq
def get_hackrf_rf_gain(self):
try:
return self.config.getint('hackrf', 'rf-gain')
except configparser.NoSectionError:
return self.dflt_hackrf_rf_gain
except configparser.NoOptionError:
return self.dflt_hackrf_rf_gain
def get_hackrf_if_gain(self):
try:
return self.config.getint('hackrf', 'if-gain')
except configparser.NoSectionError:
return self.dflt_hackrf_if_gain
except configparser.NoOptionError:
return self.dflt_hackrf_if_gain
def get_hackrf_bb_gain(self):
try:
return self.config.getint('hackrf', 'bb-gain')
except configparser.NoSectionError:
return self.dflt_hackrf_bb_gain
except configparser.NoOptionError:
return self.dflt_hackrf_bb_gain
def get_tsrfsend_cell_id(self):
try:
return self.config.getint('tsrfsend', 'cell-id')
except configparser.NoSectionError:
return self.dflt_tsrfsend_cell_id
except configparser.NoOptionError:
return self.dflt_tsrfsend_cell_id
def get_tsrfsend_gain(self):
try:
return self.config.getint('tsrfsend', 'gain')
except configparser.NoSectionError:
return self.dflt_tsrfsend_gain
except configparser.NoOptionError:
return self.dflt_tsrfsend_gain