PEP8: Fix whitespace
[openblackhole/openblackhole-enigma2.git] / lib / python / Tools / Transponder.py
1 from enigma import eDVBFrontendParametersSatellite, eDVBFrontendParametersCable, eDVBFrontendParametersTerrestrial
2 from Components.NimManager import nimmanager
3
4 def orbpos(pos):
5         return pos > 3600 and "N/A" or "%d.%d\xc2\xb0%s" % (pos > 1800 and ((3600 - pos) / 10, (3600 - pos) % 10, "W") or (pos / 10, pos % 10, "E"))
6
7 def getTunerDescription(nim):
8         try:
9                 return nimmanager.getTerrestrialDescription(nim)
10         except:
11                 print "[ChannelNumber] nimmanager.getTerrestrialDescription(nim) failed, nim:", nim
12         return ""
13
14 def getMHz(frequency):
15         return (frequency+50000)/100000/10.
16
17 def getChannelNumber(frequency, nim):
18         if nim == "DVB-T":
19                 for n in nimmanager.nim_slots:
20                         if n.isCompatible("DVB-T"):
21                                 nim = n.slot
22                                 break
23         f = getMHz(frequency)
24         descr = getTunerDescription(nim)
25         if "DVB-T" in descr:
26                 if "Europe" in descr:
27                         if 174 < f < 230:       # III
28                                 d = (f + 1) % 7
29                                 return str(int(f - 174)/7 + 5) + (d < 3 and "-" or d > 4 and "+" or "")
30                         elif 470 <= f < 863:    # IV,V
31                                 d = (f + 2) % 8
32                                 return str(int(f - 470) / 8 + 21) + (d < 3.5 and "-" or d > 4.5 and "+" or "")
33                 elif "Australia" in descr:
34                         d = (f + 1) % 7
35                         ds = (d < 3 and "-" or d > 4 and "+" or "")
36                         if 174 < f < 202:       # CH6-CH9
37                                 return str(int(f - 174)/7 + 6) + ds
38                         elif 202 <= f < 209:    # CH9A
39                                 return "9A" + ds
40                         elif 209 <= f < 230:    # CH10-CH12
41                                 return str(int(f - 209)/7 + 10) + ds
42                         elif 526 < f < 820:     # CH28-CH69
43                                 d = (f - 1) % 7
44                                 return str(int(f - 526)/7 + 28) + (d < 3 and "-" or d > 4 and "+" or "")
45         return ""
46
47 def supportedChannels(nim):
48         descr = getTunerDescription(nim)
49         return "Europe" in descr and "DVB-T" in descr
50
51 def channel2frequency(channel, nim):
52         descr = getTunerDescription(nim)
53         if "Europe" in descr and "DVB-T" in descr:
54                 if 5 <= channel <= 12:
55                         return (177500 + 7000*(channel- 5))*1000
56                 elif 21 <= channel <= 69:
57                         return (474000 + 8000*(channel-21))*1000
58         return 474000000
59
60 def ConvertToHumanReadable(tp, type = None):
61         ret = { }
62         if type is None:
63                 type = tp.get("tuner_type", "None")
64         if type == "DVB-S":
65                 ret["tuner_type"] = _("Satellite")
66                 ret["inversion"] = {
67                         eDVBFrontendParametersSatellite.Inversion_Unknown : _("Auto"),
68                         eDVBFrontendParametersSatellite.Inversion_On : _("On"),
69                         eDVBFrontendParametersSatellite.Inversion_Off : _("Off")}.get(tp.get("inversion"))
70                 ret["fec_inner"] = {
71                         eDVBFrontendParametersSatellite.FEC_None : _("None"),
72                         eDVBFrontendParametersSatellite.FEC_Auto : _("Auto"),
73                         eDVBFrontendParametersSatellite.FEC_1_2 : "1/2",
74                         eDVBFrontendParametersSatellite.FEC_2_3 : "2/3",
75                         eDVBFrontendParametersSatellite.FEC_3_4 : "3/4",
76                         eDVBFrontendParametersSatellite.FEC_5_6 : "5/6",
77                         eDVBFrontendParametersSatellite.FEC_6_7 : "6/7",
78                         eDVBFrontendParametersSatellite.FEC_7_8 : "7/8",
79                         eDVBFrontendParametersSatellite.FEC_3_5 : "3/5",
80                         eDVBFrontendParametersSatellite.FEC_4_5 : "4/5",
81                         eDVBFrontendParametersSatellite.FEC_8_9 : "8/9",
82                         eDVBFrontendParametersSatellite.FEC_9_10 : "9/10"}.get(tp.get("fec_inner"))
83                 ret["modulation"] = {
84                         eDVBFrontendParametersSatellite.Modulation_Auto : _("Auto"),
85                         eDVBFrontendParametersSatellite.Modulation_QPSK : "QPSK",
86                         eDVBFrontendParametersSatellite.Modulation_QAM16 : "QAM16",
87                         eDVBFrontendParametersSatellite.Modulation_8PSK : "8PSK"}.get(tp.get("modulation"))
88                 ret["orbital_position"] = nimmanager.getSatName(int(tp.get("orbital_position")))
89                 ret["orb_pos"] = orbpos(int(tp.get("orbital_position")))
90                 ret["polarization"] = {
91                         eDVBFrontendParametersSatellite.Polarisation_Horizontal : _("Horizontal"),
92                         eDVBFrontendParametersSatellite.Polarisation_Vertical : _("Vertical"),
93                         eDVBFrontendParametersSatellite.Polarisation_CircularLeft : _("Circular left"),
94                         eDVBFrontendParametersSatellite.Polarisation_CircularRight : _("Circular right")}.get(tp.get("polarization"))
95                 ret["polarization_abbreviation"] = {
96                         eDVBFrontendParametersSatellite.Polarisation_Horizontal : "H",
97                         eDVBFrontendParametersSatellite.Polarisation_Vertical : "V",
98                         eDVBFrontendParametersSatellite.Polarisation_CircularLeft : "L",
99                         eDVBFrontendParametersSatellite.Polarisation_CircularRight : "R"}.get(tp.get("polarization"))
100                 ret["system"] = {
101                         eDVBFrontendParametersSatellite.System_DVB_S : "DVB-S",
102                         eDVBFrontendParametersSatellite.System_DVB_S2 : "DVB-S2"}.get(tp.get("system"))
103                 if ret["system"] == "DVB-S2":
104                         ret["rolloff"] = {
105                                 eDVBFrontendParametersSatellite.RollOff_alpha_0_35 : "0.35",
106                                 eDVBFrontendParametersSatellite.RollOff_alpha_0_25 : "0.25",
107                                 eDVBFrontendParametersSatellite.RollOff_alpha_0_20 : "0.20",
108                                 eDVBFrontendParametersSatellite.RollOff_auto : _("Auto")}.get(tp.get("rolloff"))
109                         ret["pilot"] = {
110                                 eDVBFrontendParametersSatellite.Pilot_Unknown : _("Auto"),
111                                 eDVBFrontendParametersSatellite.Pilot_On : _("On"),
112                                 eDVBFrontendParametersSatellite.Pilot_Off : _("Off")}.get(tp.get("pilot"))
113         elif type == "DVB-C":
114                 ret["tuner_type"] = _("Cable")
115                 ret["modulation"] = {
116                         eDVBFrontendParametersCable.Modulation_Auto: _("Auto"),
117                         eDVBFrontendParametersCable.Modulation_QAM16 : "QAM16",
118                         eDVBFrontendParametersCable.Modulation_QAM32 : "QAM32",
119                         eDVBFrontendParametersCable.Modulation_QAM64 : "QAM64",
120                         eDVBFrontendParametersCable.Modulation_QAM128 : "QAM128",
121                         eDVBFrontendParametersCable.Modulation_QAM256 : "QAM256"}.get(tp.get("modulation"))
122                 ret["inversion"] = {
123                         eDVBFrontendParametersCable.Inversion_Unknown : _("Auto"),
124                         eDVBFrontendParametersCable.Inversion_On : _("On"),
125                         eDVBFrontendParametersCable.Inversion_Off : _("Off")}.get(tp.get("inversion"))
126                 ret["fec_inner"] = {
127                         eDVBFrontendParametersCable.FEC_None : _("None"),
128                         eDVBFrontendParametersCable.FEC_Auto : _("Auto"),
129                         eDVBFrontendParametersCable.FEC_1_2 : "1/2",
130                         eDVBFrontendParametersCable.FEC_2_3 : "2/3",
131                         eDVBFrontendParametersCable.FEC_3_4 : "3/4",
132                         eDVBFrontendParametersCable.FEC_5_6 : "5/6",
133                         eDVBFrontendParametersCable.FEC_7_8 : "7/8",
134                         eDVBFrontendParametersCable.FEC_8_9 : "8/9",
135                         eDVBFrontendParametersCable.FEC_3_5 : "3/5",
136                         eDVBFrontendParametersCable.FEC_4_5 : "4/5",
137                         eDVBFrontendParametersCable.FEC_9_10 : "9/10"}.get(tp.get("fec_inner"))
138                 ret["system"] = {
139                         eDVBFrontendParametersCable.System_DVB_C_ANNEX_A : "DVB-C",
140                         eDVBFrontendParametersCable.System_DVB_C_ANNEX_C : "DVB-C ANNEX C"}.get(tp.get("system"))
141         elif type == "DVB-T":
142                 ret["tuner_type"] = _("Terrestrial")
143                 ret["bandwidth"] = {
144                         0 : _("Auto"),
145                         10000000 : "10 MHz",
146                         8000000 : "8 MHz",
147                         7000000 : "7 MHz",
148                         6000000 : "6 MHz",
149                         5000000 : "5 MHz",
150                         1712000 : "1.712 MHz"}.get(tp.get("bandwidth"))
151                 ret["code_rate_lp"] = {
152                         eDVBFrontendParametersTerrestrial.FEC_Auto : _("Auto"),
153                         eDVBFrontendParametersTerrestrial.FEC_1_2 : "1/2",
154                         eDVBFrontendParametersTerrestrial.FEC_2_3 : "2/3",
155                         eDVBFrontendParametersTerrestrial.FEC_3_4 : "3/4",
156                         eDVBFrontendParametersTerrestrial.FEC_5_6 : "5/6",
157                         eDVBFrontendParametersTerrestrial.FEC_6_7 : "6/7",
158                         eDVBFrontendParametersTerrestrial.FEC_7_8 : "7/8",
159                         eDVBFrontendParametersTerrestrial.FEC_8_9 : "8/9"}.get(tp.get("code_rate_lp"))
160                 ret["code_rate_hp"] = {
161                         eDVBFrontendParametersTerrestrial.FEC_Auto : _("Auto"),
162                         eDVBFrontendParametersTerrestrial.FEC_1_2 : "1/2",
163                         eDVBFrontendParametersTerrestrial.FEC_2_3 : "2/3",
164                         eDVBFrontendParametersTerrestrial.FEC_3_4 : "3/4",
165                         eDVBFrontendParametersTerrestrial.FEC_5_6 : "5/6",
166                         eDVBFrontendParametersTerrestrial.FEC_6_7 : "6/7",
167                         eDVBFrontendParametersTerrestrial.FEC_7_8 : "7/8",
168                         eDVBFrontendParametersTerrestrial.FEC_8_9 : "8/9"}.get(tp.get("code_rate_hp"))
169                 ret["constellation"] = {
170                         eDVBFrontendParametersTerrestrial.Modulation_Auto : _("Auto"),
171                         eDVBFrontendParametersTerrestrial.Modulation_QPSK : "QPSK",
172                         eDVBFrontendParametersTerrestrial.Modulation_QAM16 : "QAM16",
173                         eDVBFrontendParametersTerrestrial.Modulation_QAM64 : "QAM64",
174                         eDVBFrontendParametersTerrestrial.Modulation_QAM256 : "QAM256"}.get(tp.get("constellation"))
175                 ret["transmission_mode"] = {
176                         eDVBFrontendParametersTerrestrial.TransmissionMode_Auto : _("Auto"),
177                         eDVBFrontendParametersTerrestrial.TransmissionMode_1k : "1k",
178                         eDVBFrontendParametersTerrestrial.TransmissionMode_2k : "2k",
179                         eDVBFrontendParametersTerrestrial.TransmissionMode_4k : "4k",
180                         eDVBFrontendParametersTerrestrial.TransmissionMode_8k : "8k",
181                         eDVBFrontendParametersTerrestrial.TransmissionMode_16k : "16k",
182                         eDVBFrontendParametersTerrestrial.TransmissionMode_32k : "32k"}.get(tp.get("transmission_mode"))
183                 ret["guard_interval"] = {
184                         eDVBFrontendParametersTerrestrial.GuardInterval_Auto : _("Auto"),
185                         eDVBFrontendParametersTerrestrial.GuardInterval_19_256 : "19/256",
186                         eDVBFrontendParametersTerrestrial.GuardInterval_19_128 : "19/128",
187                         eDVBFrontendParametersTerrestrial.GuardInterval_1_128 : "1/128",
188                         eDVBFrontendParametersTerrestrial.GuardInterval_1_32 : "1/32",
189                         eDVBFrontendParametersTerrestrial.GuardInterval_1_16 : "1/16",
190                         eDVBFrontendParametersTerrestrial.GuardInterval_1_8 : "1/8",
191                         eDVBFrontendParametersTerrestrial.GuardInterval_1_4 : "1/4"}.get(tp.get("guard_interval"))
192                 ret["hierarchy_information"] = {
193                         eDVBFrontendParametersTerrestrial.Hierarchy_Auto : _("Auto"),
194                         eDVBFrontendParametersTerrestrial.Hierarchy_None : _("None"),
195                         eDVBFrontendParametersTerrestrial.Hierarchy_1 : "1",
196                         eDVBFrontendParametersTerrestrial.Hierarchy_2 : "2",
197                         eDVBFrontendParametersTerrestrial.Hierarchy_4 : "4"}.get(tp.get("hierarchy_information"))
198                 ret["inversion"] = {
199                         eDVBFrontendParametersTerrestrial.Inversion_Unknown : _("Auto"),
200                         eDVBFrontendParametersTerrestrial.Inversion_On : _("On"),
201                         eDVBFrontendParametersTerrestrial.Inversion_Off : _("Off")}.get(tp.get("inversion"))
202                 ret["system"] = {
203                         eDVBFrontendParametersTerrestrial.System_DVB_T_T2 : "DVB-T/T2",
204                         eDVBFrontendParametersTerrestrial.System_DVB_T : "DVB-T",
205                         eDVBFrontendParametersTerrestrial.System_DVB_T2 : "DVB-T2"}.get(tp.get("system"))
206                 ret["channel"] = _("CH%s") % getChannelNumber(tp.get("frequency"), "DVB-T")
207         elif type == "ATSC":
208                 ret["tuner_type"] = "ATSC"
209                 ret["modulation"] = {
210                         eDVBFrontendParametersATSC.Modulation_Auto: _("Auto"),
211                         eDVBFrontendParametersATSC.Modulation_QAM16 : "QAM16",
212                         eDVBFrontendParametersATSC.Modulation_QAM32 : "QAM32",
213                         eDVBFrontendParametersATSC.Modulation_QAM64 : "QAM64",
214                         eDVBFrontendParametersATSC.Modulation_QAM128 : "QAM128",
215                         eDVBFrontendParametersATSC.Modulation_QAM256 : "QAM256",
216                         eDVBFrontendParametersATSC.Modulation_VSB_8 : "VSB_8",
217                         eDVBFrontendParametersATSC.Modulation_VSB_16 : "VSB_16"}.get(tp.get("modulation"))
218                 ret["inversion"] = {
219                         eDVBFrontendParametersATSC.Inversion_Unknown : _("Auto"),
220                         eDVBFrontendParametersATSC.Inversion_On : _("On"),
221                         eDVBFrontendParametersATSC.Inversion_Off : _("Off")}.get(tp.get("inversion"))
222                 ret["system"] = {
223                         eDVBFrontendParametersATSC.System_ATSC : "ATSC",
224                         eDVBFrontendParametersATSC.System_DVB_C_ANNEX_B : "DVB-C ANNEX B"}.get(tp.get("system"))
225         elif type != "None":
226                 print "ConvertToHumanReadable: no or unknown type in tpdata dict for type:", type
227         for k,v in tp.items():
228                 if k not in ret:
229                         ret[k] = v
230         return ret