move __init__ to top
[enigma2.git] / lib / python / Screens / ScanSetup.py
1 from Screen import Screen
2 from ServiceScan import *
3 from Components.config import *
4 from Components.ActionMap import NumberActionMap
5 from Components.ConfigList import ConfigList
6 from Components.NimManager import nimmanager
7 from Components.Label import Label
8 from Screens.MessageBox import MessageBox
9 from enigma import eDVBFrontendParametersSatellite, eComponentScan, eDVBSatelliteEquipmentControl, eDVBFrontendParametersTerrestrial
10
11 def buildTerTransponder(frequency, 
12                 inversion=2, bandwidth = 3, fechigh = 6, feclow = 6,
13                 modulation = 2, transmission = 2, guard = 4,
14                 hierarchy = 4):
15         # WARNING: normally, enums are working directly.
16         # Don't copy this (very bad)!! Instead either fix swig (good) or
17         # move this into a central place.
18         Bw8MHz = 0
19         Bw7MHz = 1
20         Bw6MHz = 2
21         Bw5MHz = 3
22         BwAuto = 4
23         
24         f1_2 = 0
25         f2_3 = 1
26         f3_4 = 2
27         f5_6 = 3
28         f7_8 = 4
29         fAuto = 5
30         
31         TM2k = 0
32         TM8k = 1
33         TM4k = 2
34         TMAuto = 3
35         
36         GI_1_32 = 0
37         GI_1_16 = 1
38         GI_1_8 = 2
39         GI_1_4 = 3
40         GI_Auto = 4
41         
42         HNone = 0
43         H1 = 1
44         H2 = 2
45         H4 = 3
46         HAuto = 4
47
48         QPSK = 0
49         QAM16 = 1
50         QAM64 = 2
51         Auto = 3
52         
53         Off = 0
54         On = 1
55         Unknown = 2
56
57         parm = eDVBFrontendParametersTerrestrial()
58
59         parm.frequency = frequency
60
61         parm.inversion = [Off, On, Unknown][inversion]
62         parm.bandwidth = [Bw8MHz, Bw7MHz, Bw6MHz, BwAuto][bandwidth] # Bw5MHz unsupported
63         parm.code_rate_HP = [fAuto, f1_2, f2_3, f3_4, f5_6, f7_8, fAuto][fechigh]
64         parm.code_rate_LP = [fAuto, f1_2, f2_3, f3_4, f5_6, f7_8, fAuto][feclow]
65         parm.modulation = [QPSK, QAM16, Auto][modulation] # QAM64 unsupported
66         parm.transmission_mode = [TM2k, TM8k, TMAuto][transmission] # TM4k unsupported
67         parm.guard_interval = [GI_1_32, GI_1_16, GI_1_8, GI_1_4, GI_Auto][guard]
68         parm.hierarchy = [HNone, H1, H2, H4, HAuto][hierarchy]
69         
70         return parm
71
72 def getInitialTransponderList(tlist, pos):
73         list = nimmanager.getTransponders(pos)
74
75         for x in list:
76                 if x[0] == 0:           #SAT
77                         parm = eDVBFrontendParametersSatellite()
78                         parm.frequency = x[1]
79                         parm.symbol_rate = x[2]
80                         parm.polarisation = x[3]#lookup_sat_polarisation[x[3]] # eDVBFrontendParametersSatellite.Polarisation.Vertical
81                         parm.fec = x[4]                 # eDVBFrontendParametersSatellite.FEC.f3_4;
82                         #parm.fec = 6                                   # AUTO
83                         #parm.inversion = 1     #eDVBFrontendParametersSatellite.Inversion.Off;
84                         parm.inversion = 2              #AUTO
85                         parm.orbital_position = pos
86                         parm.system = x[5]  #DVB-S or DVB-S2
87                         parm.modulation = x[6]
88                         tlist.append(parm)
89
90 def getInitialCableTransponderList(tlist, cable):
91         list = nimmanager.getTranspondersCable(cable)
92
93         for x in list:
94                 if x[0] == 1:           #CABLE
95                         parm = eDVBFrontendParametersCable()
96                         parm.frequency = x[1]
97                         parm.symbol_rate = x[2]
98                         parm.modulation = x[3] # AUTO
99                         parm.fec_inner = x[4] # AUTO
100                         parm.inversion = 2 # AUTO
101                         tlist.append(parm)
102
103 def getInitialTerrestrialTransponderList(tlist, region):
104         list = nimmanager.getTranspondersTerrestrial(region)
105         
106
107 #               inversion=2, bandwidth = 3, fechigh = 6, feclow = 6,
108 #               modulation = 2, transmission = 2, guard = 4,
109 #               hierarchy = 4):
110
111         for x in list:
112 #self.transponders[self.parsedTer].append((2, freq, bw, const, crh, crl, guard, transm, hierarchy, inv))
113                 if x[0] == 2:           #TERRESTRIAL
114                         # FIXME: we need to convert the other parameters...
115                         
116                                 # convert terrestrial.xml bandwidth to our enum
117                         #if x[2] in [0, 1]:
118                         #       bandwidth = [1, 0][x[2]]
119                         #else:
120                         #       bandwidth = 3 # auto
121                         #
122                         #parm = buildTerTransponder(x[1], bandwidth = [1, 0][x[2]])
123                         parm = buildTerTransponder(x[1], inversion = x[9], bandwidth = x[2])
124                         tlist.append(parm)
125
126
127 class ScanSetup(Screen):
128         def __init__(self, session):
129                 Screen.__init__(self, session)
130
131                 self.updateSatList()
132                 self.service = session.nav.getCurrentService()
133                 self.feinfo = None
134                 frontendData = None
135                 if self.service is not None:
136                         self.feinfo = self.service.frontendInfo()
137                         frontendData = self.feinfo and self.feinfo.getFrontendData(True)
138                 self.createConfig(frontendData)
139                 del self.feinfo
140                 del self.service
141
142
143                 self["actions"] = NumberActionMap(["SetupActions"],
144                 {
145                         "ok": self.keyGo,
146                         "cancel": self.keyCancel,
147                         "left": self.keyLeft,
148                         "right": self.keyRight,
149                         "1": self.keyNumberGlobal,
150                         "2": self.keyNumberGlobal,
151                         "3": self.keyNumberGlobal,
152                         "4": self.keyNumberGlobal,
153                         "5": self.keyNumberGlobal,
154                         "6": self.keyNumberGlobal,
155                         "7": self.keyNumberGlobal,
156                         "8": self.keyNumberGlobal,
157                         "9": self.keyNumberGlobal,
158                         "0": self.keyNumberGlobal
159                 }, -1)
160                 
161                 self.statusTimer = eTimer()
162                 self.statusTimer.timeout.get().append(self.updateStatus)
163                 #self.statusTimer.start(5000, True)
164
165                 self.list = []
166                 self["config"] = ConfigList(self.list)
167                 self.createSetup()
168
169                 self["introduction"] = Label(_("Press OK to start the scan"))
170
171         def run(self):
172                 self.keyGo()
173
174         def updateSatList(self):
175                 self.satList = []
176                 for slot in nimmanager.nimslots:
177                         if (nimmanager.getNimType(slot.slotid) == nimmanager.nimType["DVB-S"]):
178                                 self.satList.append(nimmanager.getSatListForNim(slot.slotid))
179                         else:
180                                 self.satList.append(None)
181                                 
182         def createSetup(self):
183                 self.list = []
184                 self.multiscanlist = []
185                 print "ID: " + str(config.scan.nims.value)
186
187                 self.tunerEntry = getConfigListEntry(_("Tuner"), config.scan.nims)
188                 self.list.append(self.tunerEntry)
189                 
190                 self.typeOfScanEntry = None
191                 self.systemEntry = None
192                 if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-S"]):
193                         self.typeOfScanEntry = getConfigListEntry(_("Type of scan"), config.scan.type)
194                         self.list.append(self.typeOfScanEntry)
195                 elif (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-C"]):
196                         self.typeOfScanEntry = getConfigListEntry(_("Type of scan"), config.scan.typecable)
197                         self.list.append(self.typeOfScanEntry)
198                 elif (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-T"]):
199                         self.typeOfScanEntry = getConfigListEntry(_("Type of scan"), config.scan.typeterrestrial)
200                         self.list.append(self.typeOfScanEntry)
201
202
203                 if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-S"]):
204
205                         if currentConfigSelectionElement(config.scan.type) == "single_transponder":
206                                 self.systemEntry = getConfigListEntry(_('Transpondertype'), config.scan.sat.system)
207                                 self.list.append(self.systemEntry)
208                                 self.list.append(getConfigListEntry(_('Satellite'), config.scan.satselection[config.scan.nims.value]))
209                                 self.list.append(getConfigListEntry(_('Frequency'), config.scan.sat.frequency))
210                                 self.list.append(getConfigListEntry(_('Inversion'), config.scan.sat.inversion))
211                                 self.list.append(getConfigListEntry(_('Symbol Rate'), config.scan.sat.symbolrate))
212                                 self.list.append(getConfigListEntry(_("Polarity"), config.scan.sat.polarization))
213                                 if currentConfigSelectionElement(config.scan.sat.system) == "dvb-s":
214                                         self.list.append(getConfigListEntry(_("FEC"), config.scan.sat.fec))
215                                 elif currentConfigSelectionElement(config.scan.sat.system) == "dvb-s2":
216                                         self.list.append(getConfigListEntry(_("FEC"), config.scan.sat.fec_s2))
217                                         self.list.append(getConfigListEntry(_('Modulation'), config.scan.sat.modulation))
218                         elif currentConfigSelectionElement(config.scan.type) == "single_satellite":
219                                 self.updateSatList()
220                                 print config.scan.satselection[config.scan.nims.value]
221                                 self.list.append(getConfigListEntry(_("Satellite"), config.scan.satselection[config.scan.nims.value]))
222                                 self.list.append(getConfigListEntry(_("Clear before scan"), config.scan.clearallservices))
223                         elif currentConfigSelectionElement(config.scan.type) == "multisat":
224                                 # if (norotor)
225                                 tlist = []
226                                 SatList = nimmanager.getSatListForNim(config.scan.nims.value)
227                                 self.list.append(getConfigListEntry(_("Clear before scan"), config.scan.clearallservices))
228                                 for x in SatList:
229                                         if self.Satexists(tlist, x[1]) == 0:
230                                                 tlist.append(x[1])
231                                                 sat = configElement_nonSave(x[1], configSelection, 0, (("enable", _("Enable")), ("disable", _("Disable"))))
232                                                 configEntry = getConfigListEntry(nimmanager.getSatDescription(x[1]), sat)
233                                                 self.list.append(configEntry)
234                                                 self.multiscanlist.append(configEntry)
235                                 # if (rotor):
236                            # for sat in nimmanager.satList:
237                                 #       self.list.append(getConfigListEntry(sat[0], config.scan.scansat[sat[1]]))
238
239
240                 if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-C"]):
241                         if currentConfigSelectionElement(config.scan.typecable) == "single_transponder":
242                                 self.list.append(getConfigListEntry(_("Frequency"), config.scan.cab.frequency))
243                                 self.list.append(getConfigListEntry(_("Inversion"), config.scan.cab.inversion))
244                                 self.list.append(getConfigListEntry(_("Symbol Rate"), config.scan.cab.symbolrate))
245                                 self.list.append(getConfigListEntry(_("Modulation"), config.scan.cab.modulation))
246                                 self.list.append(getConfigListEntry(_("FEC"), config.scan.cab.fec))
247                                 self.list.append(getConfigListEntry(_("Network scan"), config.scan.cab.networkScan))
248                         elif currentConfigSelectionElement(config.scan.typecable) == "complete":
249                                 self.list.append(getConfigListEntry(_("Clear before scan"), config.scan.clearallservices))
250                                 
251                 if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-T"]):
252                         if currentConfigSelectionElement(config.scan.typeterrestrial) == "single_transponder":
253                                 self.list.append(getConfigListEntry(_("Frequency"), config.scan.ter.frequency))
254                                 self.list.append(getConfigListEntry(_("Network scan"), config.scan.ter.networkScan))
255                                 self.list.append(getConfigListEntry(_("Inversion"), config.scan.ter.inversion))
256                                 self.list.append(getConfigListEntry(_("Bandwidth"), config.scan.ter.bandwidth))
257                                 self.list.append(getConfigListEntry(_("Code rate high"), config.scan.ter.fechigh))
258                                 self.list.append(getConfigListEntry(_("Code rate low"), config.scan.ter.feclow))
259                                 self.list.append(getConfigListEntry(_("Modulation"), config.scan.ter.modulation))
260                                 self.list.append(getConfigListEntry(_("Transmission mode"), config.scan.ter.transmission))
261                                 self.list.append(getConfigListEntry(_("Guard interval mode"), config.scan.ter.guard))
262                                 self.list.append(getConfigListEntry(_("Hierarchy mode"), config.scan.ter.hierarchy))
263                         elif currentConfigSelectionElement(config.scan.typeterrestrial) == "complete":
264                                 self.list.append(getConfigListEntry(_("Clear before scan"), config.scan.clearallservices))
265
266 #               if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-S"] and currentConfigSelectionElement(config.scan.type) == "single_transponder") or \
267 #                       (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-C"] and currentConfigSelectionElement(config.scan.typecable) == "single_transponder") or \
268 #                       (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-T"] and currentConfigSelectionElement(config.scan.typeterrestrial) == "single_transponder"):
269 #                               self.configElementSNR = getConfigListEntry(_("SNR"), config.scan.snr)
270 #                               self.list.append(self.configElementSNR)
271 #                               self.configElementACG = getConfigListEntry(_("AGC"), config.scan.agc)
272 #                               self.list.append(self.configElementACG)
273 #                               self.configElementBER = getConfigListEntry(_("BER"), config.scan.ber)
274 #                               self.list.append(self.configElementBER)
275 #                               self.statusTimer.start(500, False)
276 #               else:
277 #                       self.statusTimer.stop()
278
279                 self["config"].list = self.list
280                 self["config"].l.setList(self.list)
281
282         def Satexists(self, tlist, pos):
283                 for x in tlist:
284                         if x == pos:
285                                 return 1
286                 return 0
287
288         def newConfig(self):
289                 print self["config"].getCurrent()
290                 if self["config"].getCurrent() == self.typeOfScanEntry:
291                         self.createSetup()
292                 elif self["config"].getCurrent() == self.tunerEntry:
293                         self.createSetup()
294                 elif self["config"].getCurrent() == self.systemEntry:
295                         self.createSetup()
296
297         def createConfig(self, frontendData):
298                                                            #("Type", frontendData["system"], TYPE_TEXT),
299                                            #("Modulation", frontendData["modulation"], TYPE_TEXT),
300                                            #("Orbital position", frontendData["orbital_position"], TYPE_VALUE_DEC),
301                                            #("Frequency", frontendData["frequency"], TYPE_VALUE_DEC),
302                                            #("Symbolrate", frontendData["symbol_rate"], TYPE_VALUE_DEC),
303                                            #("Polarization", frontendData["polarization"], TYPE_TEXT),
304                                            #("Inversion", frontendData["inversion"], TYPE_TEXT),
305                                            #("FEC inner", frontendData["fec_inner"], TYPE_TEXT),
306                                                 #)
307                 #elif frontendData["tuner_type"] == "DVB-C":
308                         #return ( ("NIM", ['A', 'B', 'C', 'D'][frontendData["tuner_number"]], TYPE_TEXT),
309                                            #("Type", frontendData["tuner_type"], TYPE_TEXT),
310                                            #("Frequency", frontendData["frequency"], TYPE_VALUE_DEC),
311                                            #("Symbolrate", frontendData["symbol_rate"], TYPE_VALUE_DEC),
312                                            #("Modulation", frontendData["modulation"], TYPE_TEXT),
313                                            #("Inversion", frontendData["inversion"], TYPE_TEXT),
314                         #                  ("FEC inner", frontendData["fec_inner"], TYPE_TEXT),
315                                                 #)
316                 #elif frontendData["tuner_type"] == "DVB-T":
317                         #return ( ("NIM", ['A', 'B', 'C', 'D'][frontendData["tuner_number"]], TYPE_TEXT),
318                                            #("Type", frontendData["tuner_type"], TYPE_TEXT),
319                                            #("Frequency", frontendData["frequency"], TYPE_VALUE_DEC),
320                                            #("Inversion", frontendData["inversion"], TYPE_TEXT),
321                                            #("Bandwidth", frontendData["bandwidth"], TYPE_VALUE_DEC),
322                                            #("CodeRateLP", frontendData["code_rate_lp"], TYPE_TEXT),
323                                            #("CodeRateHP", frontendData["code_rate_hp"], TYPE_TEXT),
324                                            #("Constellation", frontendData["constellation"], TYPE_TEXT),
325                                            #("Transmission Mode", frontendData["transmission_mode"], TYPE_TEXT),
326                                            #("Guard Interval", frontendData["guard_interval"], TYPE_TEXT),
327                                            #("Hierarchy Inform.", frontendData["hierarchy_information"], TYPE_TEXT),
328                         defaultSat = { "orbpos": 192, "system": 0, "frequency": [11836], "inversion": 2, "symbolrate": [27500], "polarization": 0, "fec": 0, "fec_s2": 8, "modulation": 0 }
329                         defaultCab = {"frequency": [466], "inversion": 2, "modulation": 2, "fec": 0, "symbolrate": [6900]}
330                         if frontendData is not None:
331                                 if frontendData["tuner_type"] == "DVB-S":
332                                         defaultSat["system"] = {"DVB-S": 0, "DVB-S2": 1}[frontendData["system"]]
333                                         defaultSat["frequency"] = [int(frontendData["frequency"] / 1000)]
334                                         defaultSat["inversion"] = {"INVERSION_OFF": 0, "INVERSION_ON": 1, "INVERSION_AUTO": 2}[frontendData["inversion"]]
335                                         defaultSat["symbolrate"] = [int(frontendData["symbol_rate"] / 1000)]
336                                         defaultSat["polarization"] = {"HORIZONTAL": 0, "VERTICAL": 1, "CIRCULAR_LEFT": 2, "CIRCULAR_RIGHT": 3, "UNKNOWN": 0}[frontendData["polarization"]]
337                                         defaultSat["fec"] = {"DVB-S": {"FEC_AUTO": 0, "FEC_1_2": 1, "FEC_2_3": 2, "FEC_3_4": 3, "FEC_5_6": 4, "FEC_7_8": 5, "FEC_NONE": 6}, "DVB-S2": {"FEC_1_2": 0, "FEC_2_3": 1, "FEC_3_4": 2, "FEC_4_5": 3, "FEC_5_6": 4, "FEC_7_8": 5, "FEC_8_9": 6, "FEC_9_10": 7}}[frontendData["system"]][frontendData["fec_inner"]]
338                                         defaultSat["modulation"] = {"QPSK": 0, "8PSK": 1}[frontendData["modulation"]]
339                                         defaultSat["orbpos"] = frontendData["orbital_position"]
340                                 elif frontendData["tuner_type"] == "DVB-C":
341                                         defaultCab["frequency"] = [int(frontendData["frequency"] / 1000)]
342                                         defaultCab["symbolrate"] = [int(frontendData["symbol_rate"] / 1000)]
343                                         defaultSat["inversion"] = {"INVERSION_OFF": 0, "INVERSION_ON": 1, "INVERSION_AUTO": 2}[frontendData["inversion"]]
344                                         defaultSat["fec"] = {"FEC_AUTO": 0, "FEC_1_2": 1, "FEC_2_3": 2, "FEC_3_4": 3, "FEC_5_6": 4, "FEC_7_8": 5, "FEC_8_9": 6, "FEC_NONE": 7}[frontendData["fec_inner"]]
345                                         defaultSat["modulation"] = {"QAM_AUTO": 0, "QAM_16": 1, "QAM_16": 2, "QAM_32": 3, "QAM_64": 4, "QAM_128": 5, "QAM_256": 6}[frontendData["modulation"]]
346                                                                                 
347                         config.scan = ConfigSubsection()
348                         config.scan.sat = ConfigSubsection()
349                         config.scan.cab = ConfigSubsection()
350                         config.scan.ter = ConfigSubsection()
351
352                         config.scan.type = configElement_nonSave("config.scan.type", configSelection, 0, (("single_transponder", _("Single transponder")), ("single_satellite", _("Single satellite")), ("multisat", _("Multisat"))))
353                         config.scan.typecable = configElement_nonSave("config.scan.typecable", configSelection, 0, (("single_transponder", _("Single transponder")), ("complete", _("Complete"))))
354                         config.scan.typeterrestrial = configElement_nonSave("config.scan.typeterrestrial", configSelection, 0, (("single_transponder", _("Single transponder")), ("complete", _("Complete"))))
355                         config.scan.clearallservices = configElement_nonSave("config.scan.clearallservices", configSelection, 0, (("no", _("no")), ("yes", _("yes")), ("yes_hold_feeds", _("yes (keep feeds)"))))
356
357                         nimList = [ ]
358                         for nim in nimmanager.nimList():
359                                 nimList.append(nim[0])
360                         #nimList.append("all")
361                         config.scan.nims = configElement_nonSave("config.scan.nims", configSelection, 0, nimList)
362                         
363                         # status
364                         config.scan.snr = configElement_nonSave("config.scan.snr", configSlider, 0, (1, 100))
365                         config.scan.snr.enabled = False
366                         config.scan.agc = configElement_nonSave("config.scan.agc", configSlider, 0, (1, 100))
367                         config.scan.agc.enabled = False
368                         config.scan.ber = configElement_nonSave("config.scan.ber", configSlider, 0, (1, 100))
369                         config.scan.ber.enabled = False
370
371                         # sat
372                         config.scan.sat.system = configElement_nonSave("config.scan.sat.system", configSelection, defaultSat["system"], (("dvb-s", _("DVB-S")), ("dvb-s2", _("DVB-S2"))))
373                         config.scan.sat.frequency = configElement_nonSave("config.scan.sat.frequency", configSequence, defaultSat["frequency"], configsequencearg.get("INTEGER", (1, 99999)))
374                         config.scan.sat.inversion = configElement_nonSave("config.scan.sat.inversion", configSelection, defaultSat["inversion"], (("off", _("off")), ("on", _("on")), ("auto", _("Auto"))))
375                         config.scan.sat.symbolrate = configElement_nonSave("config.scan.sat.symbolrate", configSequence, defaultSat["symbolrate"], configsequencearg.get("INTEGER", (1, 99999)))
376                         config.scan.sat.polarization = configElement_nonSave("config.scan.sat.polarization", configSelection, defaultSat["polarization"], (("horizontal", _("horizontal")), ("vertical", _("vertical")),  ("circular_left", _("circular left")), ("circular_right", _("circular right"))))
377                         config.scan.sat.fec = configElement_nonSave("config.scan.sat.fec", configSelection, defaultSat["fec"], (("auto", _("Auto")), ("1_2", "1/2"), ("2_3", "2/3"), ("3_4", "3/4"), ("5_6", "5/6"), ("7_8", "7/8"), ("none", _("None"))))
378                         config.scan.sat.fec_s2 = configElement_nonSave("config.scan.sat.fec_s2", configSelection, defaultSat["fec_s2"], (("1_2", "1/2"), ("2_3", "2/3"), ("3_4", "3/4"), ("3_5", "3/5"), ("4_5", "4/5"), ("5_6", "5/6"), ("7_8", "7/8"), ("8_9", "8/9"), ("9_10", "9/10")))
379                         config.scan.sat.modulation = configElement_nonSave("config.scan.sat.modulation", configSelection, defaultSat["modulation"], (("qpsk", "QPSK"), ("8psk", "8PSK")))
380         
381                         # cable
382                         config.scan.cab.frequency = configElement_nonSave("config.scan.cab.frequency", configSequence, defaultCab["frequency"], configsequencearg.get("INTEGER", (50, 999)))
383                         config.scan.cab.inversion = configElement_nonSave("config.scan.cab.inversion", configSelection, defaultCab["inversion"], (("off", _("off")), ("on", _("on")), ("auto", _("Auto"))))
384                         config.scan.cab.modulation = configElement_nonSave("config.scan.cab.modulation", configSelection, defaultCab["modulation"], (("16qam", "16-QAM"), ("32qam", "32-QAM"), ("64qam", "64-QAM"), ("128qam", "128-QAM"), ("256qam", "256-QAM")))
385                         config.scan.cab.fec = configElement_nonSave("config.scan.cab.fec", configSelection, defaultCab["fec"], (("auto", _("Auto")), ("1_2", "1/2"), ("2_3", "2/3"), ("3_4", "3/4"), ("5_6", "5/6"), ("7_8", "7/8"), ("8_9", "8/9"), ("none", _("None"))))
386                         config.scan.cab.symbolrate = configElement_nonSave("config.scan.cab.symbolrate", configSequence, defaultCab["symbolrate"], configsequencearg.get("INTEGER", (1, 9999)))
387                         config.scan.cab.networkScan = configElement_nonSave("config.scan.cab.networkScan", configSelection, 0, (("no", _("no")), ("yes", _("yes"))))
388
389                         # terrestial
390                         config.scan.ter.frequency = configElement_nonSave("config.scan.ter.frequency", configSequence, [466], configsequencearg.get("INTEGER", (100, 900)))
391                         config.scan.ter.inversion = configElement_nonSave("config.scan.ter.inversion", configSelection, 2, (("off", _("off")), ("on", _("on")), ("auto", _("Auto"))))
392                         # WORKAROUND: we can't use BW-auto
393                         config.scan.ter.bandwidth = configElement_nonSave("config.scan.ter.bandwidth", configSelection, 0, (("8MHz", "8MHz"), ("7MHz", "7MHz"), ("6MHz", "6MHz")))
394                         #, ("auto", _("Auto"))))
395                         config.scan.ter.fechigh = configElement_nonSave("config.scan.ter.fechigh", configSelection, 6, (("none", _("None")), "1/2", "2/3", "3/4", "5/6", "7/8", _("Auto")))
396                         config.scan.ter.feclow = configElement_nonSave("config.scan.ter.feclow", configSelection, 6, (_("None"), ("1_2", "1/2"), ("2_3", "2/3"), ("3_4", "3/4"), ("5_6", "5/6"), ("7_8", "7/8"), ("auto", _("Auto"))))
397                         config.scan.ter.modulation = configElement_nonSave("config.scan.ter.modulation", configSelection, 2, (("qpsk", "QPSK"), ("qam16", "QAM16"), ("auto", _("Auto"))))
398                         config.scan.ter.transmission = configElement_nonSave("config.scan.ter.transmission", configSelection, 2, (("2k", "2K"), ("8k", "8K"), ("auto", _("Auto"))))
399                         config.scan.ter.guard = configElement_nonSave("config.scan.ter.guard", configSelection, 4, (("1_32", "1/32"), ("1_16", "1/16"), ("1_8", "1/8"), ("1_4", "1/4"), ("auto", _("Auto"))))
400                         config.scan.ter.hierarchy = configElement_nonSave("config.scan.ter.hierarchy", configSelection, 4, (("none", _("None")), ("1", "1"), ("2", "2"), ("4", "4"), ("auto", _("Auto"))))
401                         config.scan.ter.networkScan = configElement_nonSave("config.scan.cab.networkScan", configSelection, 0, (("no", _("no")), ("yes", _("yes"))))
402
403                         config.scan.scansat = {}
404                         for sat in nimmanager.satList:
405                                 #print sat[1]
406                                 config.scan.scansat[sat[1]] = configElement_nonSave("config.scan.scansat[" + str(sat[1]) + "]", configSelection, 0, (("yes", _("yes")), ("no", _("no"))))
407
408                         config.scan.satselection = []
409                         slotid = 0
410                         for slot in nimmanager.nimslots:
411                                 if (nimmanager.getNimType(slot.slotid) == nimmanager.nimType["DVB-S"]):
412                                         print str(slot.slotid) + " : " + str(self.satList)
413                                         config.scan.satselection.append(configElement_nonSave("config.scan.satselection[" + str(slot.slotid) + "]", configSatlist, defaultSat["orbpos"], self.satList[slot.slotid]))
414                                 else:
415                                         config.scan.satselection.append(None)
416         def keyLeft(self):
417                 self["config"].handleKey(config.key["prevElement"])
418                 self.newConfig()
419
420         def keyRight(self):
421                 self["config"].handleKey(config.key["nextElement"])
422                 self.newConfig()
423
424         def updateStatus(self):
425                 print "updatestatus"
426
427         def keyNumberGlobal(self, number):
428                 print "You pressed number " + str(number)
429                 if (self["config"].getCurrent()[1].parent.enabled == True):
430                         self["config"].handleKey(config.key[str(number)])
431
432         fecmap = { "auto": 0,
433                            "1_2": 1,
434                            "2_3": 2,
435                            "3_4": 3,
436                            "5_6": 4,
437                            "7_8": 5,
438                            "8_9": 6,
439                            "3_5": 7,
440                            "4_5": 8,
441                            "9_10": 9,
442                            "none": 15
443                            }
444
445         def addSatTransponder(self, tlist, frequency, symbol_rate, polarisation, fec, inversion, orbital_position, system, modulation):
446                 print "Add Sat: frequ: " + str(frequency) + " symbol: " + str(symbol_rate) + " pol: " + str(polarisation) + " fec: " + str(self.fecmap[fec]) + " inversion: " + str(inversion) + " modulation: " + str(modulation) + " system: " + str(system)
447                 print "orbpos: " + str(orbital_position)
448                 parm = eDVBFrontendParametersSatellite()
449                 if modulation == 1:
450                         parm.modulation = 2 # eDVBFrontendParametersSatellite.Modulation.8PSK
451                 else:
452                         parm.modulation = 1 # eDVBFrontendParametersSatellite.Modulation.QPSK
453                 parm.system = system
454                 parm.frequency = frequency * 1000
455                 parm.symbol_rate = symbol_rate * 1000
456                 parm.polarisation = polarisation # eDVBFrontendParametersSatellite.Polarisation.Verti
457                 parm.fec = self.fecmap[fec]                     # eDVBFrontendParametersSatellite.FEC.f3_4;
458                 #parm.fec = 6                                   # AUTO
459                 parm.inversion = inversion      #eDVBFrontendParametersSatellite.Inversion.Off;
460                 #parm.inversion = 2             #AUTO
461                 parm.orbital_position = int(orbital_position)
462                 tlist.append(parm)
463
464         # FIXME use correct parameters
465         def addCabTransponder(self, tlist, frequency, symbol_rate, modulation, fec, inversion):
466                 print "Add Cab: frequ: " + str(frequency) + " symbol: " + str(symbol_rate) + " pol: " + str(modulation) + " fec: " + str(fec) + " inversion: " + str(inversion)
467                 parm = eDVBFrontendParametersCable()
468                 parm.frequency = frequency * 1000
469                 parm.symbol_rate = symbol_rate * 1000
470                 parm.modulation = modulation # modulation # eDVBFrontendParametersSatellite.Polarisation.Verti
471                 parm.fec = fec                  # eDVBFrontendParametersSatellite.FEC.f3_4;
472                 #parm.fec = 6                                   # AUTO
473                 parm.inversion = inversion      #eDVBFrontendParametersSatellite.Inversion.Off;
474                 #parm.inversion = 2             #AUTO
475                 tlist.append(parm)
476
477         def addTerTransponder(self, tlist, *args, **kwargs):
478                 tlist.append(buildTerTransponder(*args, **kwargs))
479
480         def keyGo(self):
481                 tlist = []
482                 flags = 0
483                 if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-S"]):
484                         if currentConfigSelectionElement(config.scan.type) == "single_transponder":
485                                 l = len(self.satList)
486                                 if l and l > config.scan.nims.value:
487                                         nimsats=self.satList[config.scan.nims.value]
488                                         l = len(config.scan.satselection)
489                                         if l and l > config.scan.nims.value:
490                                                 selsatidx=config.scan.satselection[config.scan.nims.value].value
491                                                 l = len(nimsats)
492                                                 if l and l > selsatidx:
493                                                         orbpos=nimsats[selsatidx][1]
494                                                         if currentConfigSelectionElement(config.scan.sat.system) == "dvb-s":
495                                                                 fec = currentConfigSelectionElement(config.scan.sat.fec)
496                                                         else:
497                                                                 fec = currentConfigSelectionElement(config.scan.sat.fec_s2)
498                                                         self.addSatTransponder(tlist, config.scan.sat.frequency.value[0],
499                                                                                 config.scan.sat.symbolrate.value[0],
500                                                                                 config.scan.sat.polarization.value,
501                                                                                 fec,
502                                                                                 config.scan.sat.inversion.value,
503                                                                                 orbpos,
504                                                                                 config.scan.sat.system.value,
505                                                                                 config.scan.sat.modulation.value)
506                         elif currentConfigSelectionElement(config.scan.type) == "single_satellite":
507                                 sat = self.satList[config.scan.nims.value][config.scan.satselection[config.scan.nims.value].value]
508                                 getInitialTransponderList(tlist, int(sat[1]))
509                                 flags |= eComponentScan.scanNetworkSearch
510                                 tmp = currentConfigSelectionElement(config.scan.clearallservices)
511                                 if tmp == "yes":
512                                         flags |= eComponentScan.scanRemoveServices
513                                 elif tmp == "yes_hold_feeds":
514                                         flags |= eComponentScan.scanRemoveServices
515                                         flags |= eComponentScan.scanDontRemoveFeeds
516                         elif currentConfigSelectionElement(config.scan.type) == "multisat":
517                                 SatList = nimmanager.getSatListForNim(config.scan.nims.value)
518                                 for x in self.multiscanlist:
519                                         if x[1].parent.value == 0:
520                                                 print "   " + str(x[1].parent.configPath)
521                                                 getInitialTransponderList(tlist, x[1].parent.configPath)
522                                 flags |= eComponentScan.scanNetworkSearch
523                                 tmp = currentConfigSelectionElement(config.scan.clearallservices)
524                                 if tmp == "yes":
525                                         flags |= eComponentScan.scanRemoveServices
526                                 elif tmp == "yes_hold_feeds":
527                                         flags |= eComponentScan.scanRemoveServices
528                                         flags |= eComponentScan.scanDontRemoveFeeds
529
530                 elif (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-C"]):
531                         if currentConfigSelectionElement(config.scan.typecable) == "single_transponder":
532                                 self.addCabTransponder(tlist, config.scan.cab.frequency.value[0],
533                                                                                           config.scan.cab.symbolrate.value[0],
534                                                                                           config.scan.cab.modulation.value + 1,
535                                                                                           config.scan.cab.fec.value,
536                                                                                           config.scan.cab.inversion.value)
537                                 if currentConfigSelectionElement(config.scan.cab.networkScan) == "yes":
538                                         flags |= eComponentScan.scanNetworkSearch
539                         elif currentConfigSelectionElement(config.scan.typecable) == "complete":
540                                 getInitialCableTransponderList(tlist, nimmanager.getCableDescription(config.scan.nims.value))
541                                 flags |= eComponentScan.scanNetworkSearch
542                                 tmp = currentConfigSelectionElement(config.scan.clearallservices)
543                                 if tmp == "yes":
544                                         flags |= eComponentScan.scanRemoveServices
545                                 elif tmp == "yes_hold_feeds":
546                                         flags |= eComponentScan.scanRemoveServices
547                                         flags |= eComponentScan.scanDontRemoveFeeds
548
549                 elif (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-T"]):
550                         if currentConfigSelectionElement(config.scan.typeterrestrial) == "single_transponder":
551                                 self.addTerTransponder(tlist,
552                                                 config.scan.ter.frequency.value[0] * 1000000,
553                                                 inversion = config.scan.ter.inversion.value,
554                                                 bandwidth = config.scan.ter.bandwidth.value,
555                                                 fechigh = config.scan.ter.fechigh.value,
556                                                 feclow = config.scan.ter.feclow.value,
557                                                 modulation = config.scan.ter.modulation.value,
558                                                 transmission = config.scan.ter.transmission.value,
559                                                 guard = config.scan.ter.guard.value,
560                                                 hierarchy = config.scan.ter.hierarchy.value)
561                                 if currentConfigSelectionElement(config.scan.ter.networkScan) == "yes":
562                                         flags |= eComponentScan.scanNetworkSearch
563                         elif currentConfigSelectionElement(config.scan.typeterrestrial) == "complete":
564                                 getInitialTerrestrialTransponderList(tlist, nimmanager.getTerrestrialDescription(config.scan.nims.value))
565                                 flags |= eComponentScan.scanNetworkSearch
566                                 tmp = currentConfigSelectionElement(config.scan.clearallservices)
567                                 if tmp == "yes":
568                                         flags |= eComponentScan.scanRemoveServices
569                                 elif tmp == "yes_hold_feeds":
570                                         flags |= eComponentScan.scanRemoveServices
571                                         flags |= eComponentScan.scanDontRemoveFeeds
572
573                 for x in self["config"].list:
574                         x[1].save()
575
576                 if len(tlist):
577                         feid = config.scan.nims.value
578                         # flags |= eComponentScan.scanSearchBAT
579                         self.session.openWithCallback(self.doNothing, ServiceScan, [{"transponders": tlist, "feid": feid, "flags": flags}])
580                 else:
581                         self.session.open(MessageBox, _("Nothing to scan!\nPlease setup your tuner settings before you start a service scan."), MessageBox.TYPE_ERROR)
582
583         def doNothing(self):
584                 pass
585
586         def keyCancel(self):
587                 for x in self["config"].list:
588                         x[1].cancel()
589                 self.close()
590
591 class ScanSimple(Screen):
592         def run(self):
593                 self.keyGo()
594
595         def keyGo(self):
596                 scanList = []
597                 if nimmanager.getNimType(0) == nimmanager.nimType["DVB-S"] and nimmanager.getNimType(0) == nimmanager.getNimType(1):
598                         sec = eDVBSatelliteEquipmentControl.getInstance()
599                         if sec is not None:
600                                 exclusive_satellites = sec.get_exclusive_satellites(0,1)
601                         else:
602                                 exclusive_satellites = [0,0]
603                         print "exclusive satellites", exclusive_satellites
604                         two_sat_tuners = True
605                 else:
606                         two_sat_tuners = False
607
608                 for x in self.list:
609                         slotid = x[1].parent.configPath
610                         print "Scan Tuner", slotid, "-", currentConfigSelectionElement(x[1].parent)
611                         if currentConfigSelectionElement(x[1].parent) == "yes":
612                                 scanPossible = False
613                                 tlist = [ ]
614                                 if nimmanager.getNimType(x[1].parent.configPath) == nimmanager.nimType["DVB-S"]:
615                                         if two_sat_tuners:
616                                                 if slotid > 0:
617                                                         idx = exclusive_satellites[0]+1
618                                                 else:
619                                                         idx = 0
620                                                 exclusive_nim_sats = exclusive_satellites[idx+1:idx+1+exclusive_satellites[idx]]
621                                                 print "exclusive_nim_sats", exclusive_nim_sats
622                                         SatList = nimmanager.getSatListForNim(slotid)
623                                         for sat in SatList:
624                                                 if not two_sat_tuners or (sat[1] in exclusive_nim_sats or slotid == 0):
625                                                         scanPossible = True
626                                                         print sat
627                                                         getInitialTransponderList(tlist, sat[1])
628                                 elif nimmanager.getNimType(x[1].parent.configPath) == nimmanager.nimType["DVB-C"]:
629                                         scanPossible = True
630                                         getInitialCableTransponderList(tlist, nimmanager.getCableDescription(slotid))
631                                 elif nimmanager.getNimType(x[1].parent.configPath) == nimmanager.nimType["DVB-T"]:
632                                         scanPossible = True
633                                         getInitialTerrestrialTransponderList(tlist, nimmanager.getTerrestrialDescription(slotid))
634                                 if scanPossible:
635                                         flags=eComponentScan.scanNetworkSearch
636                                         tmp = currentConfigSelectionElement(config.scan.clearallservices)
637                                         if tmp == "yes":
638                                                 flags |= eComponentScan.scanRemoveServices
639                                         elif tmp == "yes_hold_feeds":
640                                                 flags |= eComponentScan.scanRemoveServices
641                                                 flags |= eComponentScan.scanDontRemoveFeeds
642                                         scanList.append({"transponders": tlist, "feid": slotid, "flags": flags})
643                 if len(scanList):
644                         self.session.openWithCallback(self.doNothing, ServiceScan, scanList = scanList)
645                 else:
646                         self.session.open(MessageBox, _("Nothing to scan!\nPlease setup your tuner settings before you start a service scan."), MessageBox.TYPE_ERROR)
647
648         def doNothing(self):
649                 pass
650
651         def keyCancel(self):
652                 self.close()
653
654         def keyLeft(self):
655                 self["config"].handleKey(config.key["prevElement"])
656
657         def keyRight(self):
658                 self["config"].handleKey(config.key["nextElement"])
659
660         def Satexists(self, tlist, pos):
661                 for x in tlist:
662                         if x == pos:
663                                 return 1
664                 return 0
665
666         def ScanNimTwoNeeded(self):
667                 if nimmanager.getNimType(0) != nimmanager.getNimType(1):
668                         return True
669                 if nimmanager.getNimType(0) == nimmanager.nimType["DVB-S"]: #two dvb-s nims
670                         if nimmanager.getNimConfigMode(1) in ["loopthrough", "satposdepends", "equal", "nothing"]:
671                                 return False
672                         sec = eDVBSatelliteEquipmentControl.getInstance()
673                         if sec is not None:
674                                 exclusive_satellites = sec.get_exclusive_satellites(0,1)
675                                 if len(exclusive_satellites) == 2:
676                                         return False
677                                 idx = exclusive_satellites[0]+1
678                                 exclusive_nim_sats = exclusive_satellites[idx+1:idx+1+exclusive_satellites[idx]]
679                                 if len(exclusive_nim_sats):
680                                         return True
681                 return False # two -C or two -T tuners
682
683         def __init__(self, session):
684                 Screen.__init__(self, session)
685
686                 self["actions"] = ActionMap(["SetupActions"],
687                 {
688                         "ok": self.keyGo,
689                         "cancel": self.keyCancel,
690                         "left": self.keyLeft,
691                         "right": self.keyRight,
692                 }, -1)
693
694                 self.list = []
695                 tlist = []
696
697                 nimcount = nimmanager.getNimSocketCount()
698                 if nimcount > 0:
699                         nimtype = nimmanager.getNimType(0)
700                         scan_possible=True
701                         config.scan = ConfigSubsection()
702                         config.scan.clearallservices = configElement_nonSave("config.scan.clearallservices", configSelection, 0, (("no", _("no")), ("yes", _("yes")), ("yes_hold_feeds", _("yes (keep feeds)"))))
703                         self.list.append(getConfigListEntry(_("Clear before scan"), config.scan.clearallservices))
704                         nim = configElement_nonSave(0, configSelection, 0, (("yes", _("yes")), ("no", _("no"))))
705                         if nimtype == nimmanager.nimType["DVB-S"] and not len(nimmanager.getSatListForNim(0)):
706                                 scan_possible=False
707                         if scan_possible:
708                                 self.list.append(getConfigListEntry(_("Scan NIM") + " 0 (" + nimmanager.getNimTypeName(0) + ")", nim))
709         
710                 if nimcount > 1 and self.ScanNimTwoNeeded():
711                         nim = configElement_nonSave(1, configSelection, 0, (("yes", _("yes")), ("no", _("no"))))
712                         self.list.append(getConfigListEntry(_("Scan NIM") + " 1 (" + nimmanager.getNimTypeName(1) + ")", nim))
713
714                 self["config"] = ConfigList(self.list)
715                 self["header"] = Label(_("Automatic Scan"))
716                 self["footer"] = Label(_("Press OK to scan"))