use dvb-t parameters
[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 enigma import eDVBFrontendParametersSatellite, eComponentScan, eDVBSatelliteEquipmentControl
9
10 def getInitialTransponderList(tlist, pos):
11         list = nimmanager.getTransponders(pos)
12
13         for x in list:
14                 if x[0] == 0:           #SAT
15                         parm = eDVBFrontendParametersSatellite()
16                         parm.frequency = x[1]
17                         parm.symbol_rate = x[2]
18                         parm.polarisation = x[3]#lookup_sat_polarisation[x[3]] # eDVBFrontendParametersSatellite.Polarisation.Vertical
19                         parm.fec = x[4]                 # eDVBFrontendParametersSatellite.FEC.f3_4;
20                         #parm.fec = 6                                   # AUTO
21                         #parm.inversion = 1     #eDVBFrontendParametersSatellite.Inversion.Off;
22                         parm.inversion = 2              #AUTO
23                         parm.orbital_position = pos
24                         tlist.append(parm)
25
26 def getInitialCableTransponderList(tlist, cable):
27         list = nimmanager.getTranspondersCable(cable)
28
29         for x in list:
30                 if x[0] == 1:           #CABLE
31                         parm = eDVBFrontendParametersCable()
32                         parm.frequency = x[1]
33                         parm.symbol_rate = x[2]
34                         parm.modulation = x[3] # AUTO
35                         parm.fec_inner = x[4] # AUTO
36                         parm.inversion = 2 # AUTO
37                         tlist.append(parm)
38
39 class ScanSetup(Screen):
40         def __init__(self, session):
41                 Screen.__init__(self, session)
42
43                 self.updateSatList()
44                 self.createConfig()
45
46
47                 self["actions"] = NumberActionMap(["SetupActions"],
48                 {
49                         "ok": self.keyGo,
50                         "cancel": self.keyCancel,
51                         "left": self.keyLeft,
52                         "right": self.keyRight,
53                         "1": self.keyNumberGlobal,
54                         "2": self.keyNumberGlobal,
55                         "3": self.keyNumberGlobal,
56                         "4": self.keyNumberGlobal,
57                         "5": self.keyNumberGlobal,
58                         "6": self.keyNumberGlobal,
59                         "7": self.keyNumberGlobal,
60                         "8": self.keyNumberGlobal,
61                         "9": self.keyNumberGlobal,
62                         "0": self.keyNumberGlobal
63                 }, -1)
64                 
65                 self.statusTimer = eTimer()
66                 self.statusTimer.timeout.get().append(self.updateStatus)
67                 #self.statusTimer.start(5000, True)
68
69                 self.list = []
70                 self["config"] = ConfigList(self.list)
71                 self.createSetup()
72
73                 self["introduction"] = Label(_("Press OK to start the scan"))
74
75         def run(self):
76                 self.keyGo()
77
78         def updateSatList(self):
79                 self.satList = []
80                 for slot in nimmanager.nimslots:
81                         if (nimmanager.getNimType(slot.slotid) == nimmanager.nimType["DVB-S"]):
82                                 self.satList.append(nimmanager.getSatListForNim(slot.slotid))
83                         else:
84                                 self.satList.append(None)
85                                 
86         def createSetup(self):
87                 self.list = []
88                 self.multiscanlist = []
89                 print "ID: " + str(config.scan.nims.value)
90
91                 self.tunerEntry = getConfigListEntry(_("Tuner"), config.scan.nims)
92                 self.list.append(self.tunerEntry)
93                 
94                 self.typeOfScanEntry = None
95                 if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-S"]):
96                         self.typeOfScanEntry = getConfigListEntry(_("Type of scan"), config.scan.type)
97                         self.list.append(self.typeOfScanEntry)
98                 elif (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-C"]):
99                         self.typeOfScanEntry = getConfigListEntry(_("Type of scan"), config.scan.typecable)
100                         self.list.append(self.typeOfScanEntry)
101                 elif (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-T"]):
102                         self.typeOfScanEntry = getConfigListEntry(_("Type of scan"), config.scan.typeterrestrial)
103                         self.list.append(self.typeOfScanEntry)
104
105
106                 if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-S"]):
107
108                         if currentConfigSelectionElement(config.scan.type) == "single_transponder":
109                                 self.list.append(getConfigListEntry(_('Satellite'), config.scan.satselection[config.scan.nims.value]))
110                                 self.list.append(getConfigListEntry(_('Frequency'), config.scan.sat.frequency))
111                                 self.list.append(getConfigListEntry(_('Inversion'), config.scan.sat.inversion))
112                                 self.list.append(getConfigListEntry(_('Symbol Rate'), config.scan.sat.symbolrate))
113                                 self.list.append(getConfigListEntry(_("Polarity"), config.scan.sat.polarization))
114                                 self.list.append(getConfigListEntry(_("FEC"), config.scan.sat.fec))
115                         elif currentConfigSelectionElement(config.scan.type) == "single_satellite":
116                                 self.updateSatList()
117                                 print config.scan.satselection[config.scan.nims.value]
118                                 self.list.append(getConfigListEntry(_("Satellite"), config.scan.satselection[config.scan.nims.value]))
119                         elif currentConfigSelectionElement(config.scan.type) == "multisat":
120                                 # if (norotor)
121                                 tlist = []
122                                 SatList = nimmanager.getSatListForNim(config.scan.nims.value)
123         
124                                 for x in SatList:
125                                         if self.Satexists(tlist, x[1]) == 0:
126                                                 tlist.append(x[1])
127                                                 sat = configElement_nonSave(x[1], configSelection, 0, (("enable", _("Enable")), ("disable", _("Disable"))))
128                                                 configEntry = getConfigListEntry(nimmanager.getSatDescription(x[1]), sat)
129                                                 self.list.append(configEntry)
130                                                 self.multiscanlist.append(configEntry)
131                                 # if (rotor):
132                            # for sat in nimmanager.satList:
133                                 #       self.list.append(getConfigListEntry(sat[0], config.scan.scansat[sat[1]]))
134
135
136                 if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-C"]):
137                         if currentConfigSelectionElement(config.scan.typecable) == "single_transponder":
138                                 self.list.append(getConfigListEntry(_("Frequency"), config.scan.cab.frequency))
139                                 self.list.append(getConfigListEntry(_("Inversion"), config.scan.cab.inversion))
140                                 self.list.append(getConfigListEntry(_("Symbol Rate"), config.scan.cab.symbolrate))
141                                 self.list.append(getConfigListEntry(_("Modulation"), config.scan.cab.modulation))
142                                 self.list.append(getConfigListEntry(_("FEC"), config.scan.cab.fec))
143                                 self.list.append(getConfigListEntry(_("Network scan"), config.scan.cab.networkScan))
144                         elif currentConfigSelectionElement(config.scan.typecable) == "complete":
145                                 pass
146                                 
147                 if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-T"]):
148                         if currentConfigSelectionElement(config.scan.typeterrestrial) == "single_transponder":
149                                 self.list.append(getConfigListEntry(_("Frequency"), config.scan.ter.frequency))
150                                 self.list.append(getConfigListEntry(_("Network scan"), config.scan.cab.networkScan))
151                                 self.list.append(getConfigListEntry(_("Inversion"), config.scan.ter.inversion))
152                                 self.list.append(getConfigListEntry(_("Bandwidth"), config.scan.ter.bandwidth))
153                                 self.list.append(getConfigListEntry(_("Code rate high"), config.scan.ter.fechigh))
154                                 self.list.append(getConfigListEntry(_("Code rate low"), config.scan.ter.feclow))
155                                 self.list.append(getConfigListEntry(_("Modulation"), config.scan.ter.modulation))
156                                 self.list.append(getConfigListEntry(_("Transmission mode"), config.scan.ter.transmission))
157                                 self.list.append(getConfigListEntry(_("Guard interval mode"), config.scan.ter.guard))
158                                 self.list.append(getConfigListEntry(_("Hierarchy mode"), config.scan.ter.hierarchy))
159                         elif currentConfigSelectionElement(config.scan.typeterrestrial) == "complete":
160                                 pass
161
162                 if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-S"] and currentConfigSelectionElement(config.scan.type) == "single_transponder") or \
163                         (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-C"] and currentConfigSelectionElement(config.scan.typecable) == "single_transponder") or \
164                         (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-T"] and currentConfigSelectionElement(config.scan.typeterrestrial) == "single_transponder"):
165                                 self.configElementSNR = getConfigListEntry(_("SNR"), config.scan.snr)
166                                 self.list.append(self.configElementSNR)
167                                 self.configElementACG = getConfigListEntry(_("AGC"), config.scan.agc)
168                                 self.list.append(self.configElementACG)
169                                 self.configElementBER = getConfigListEntry(_("BER"), config.scan.ber)
170                                 self.list.append(self.configElementBER)
171                                 self.statusTimer.start(500, False)
172                 else:
173                         self.statusTimer.stop()
174
175                 self["config"].list = self.list
176                 self["config"].l.setList(self.list)
177
178         def Satexists(self, tlist, pos):
179                 for x in tlist:
180                         if x == pos:
181                                 return 1
182                 return 0
183
184         def newConfig(self):
185                 print self["config"].getCurrent()
186                 if self["config"].getCurrent() == self.typeOfScanEntry:
187                         self.createSetup()
188                 if self["config"].getCurrent() == self.tunerEntry:
189                         self.createSetup()
190
191         def createConfig(self):
192                         config.scan = ConfigSubsection()
193                         config.scan.sat = ConfigSubsection()
194                         config.scan.cab = ConfigSubsection()
195                         config.scan.ter = ConfigSubsection()
196
197                         config.scan.type = configElement_nonSave("config.scan.type", configSelection, 0, (("single_transponder", _("Single transponder")), ("single_satellite", _("Single satellite")), ("multisat", _("Multisat"))))
198                         config.scan.typecable = configElement_nonSave("config.scan.typecable", configSelection, 0, (("single_transponder", _("Single transponder")), ("complete", _("Complete"))))
199                         config.scan.typeterrestrial = configElement_nonSave("config.scan.typeterrestrial", configSelection, 0, (("single_transponder", _("Single transponder")), ("complete", _("Complete"))))
200
201                         nimList = [ ]
202                         for nim in nimmanager.nimList():
203                                 nimList.append(nim[0])
204                         #nimList.append("all")
205                         config.scan.nims = configElement_nonSave("config.scan.nims", configSelection, 0, nimList)
206                         
207                         # status
208                         config.scan.snr = configElement_nonSave("config.scan.snr", configSlider, 0, (1, 100))
209                         config.scan.snr.enabled = False
210                         config.scan.agc = configElement_nonSave("config.scan.agc", configSlider, 0, (1, 100))
211                         config.scan.agc.enabled = False
212                         config.scan.ber = configElement_nonSave("config.scan.ber", configSlider, 0, (1, 100))
213                         config.scan.ber.enabled = False
214
215                         # sat
216                         config.scan.sat.frequency = configElement_nonSave("config.scan.sat.frequency", configSequence, [11836], configsequencearg.get("INTEGER", (1, 99999)))
217                         config.scan.sat.inversion = configElement_nonSave("config.scan.sat.inversion", configSelection, 2, (("off", _("off")), ("on", _("on")), _("Auto")))
218                         config.scan.sat.symbolrate = configElement_nonSave("config.scan.sat.symbolrate", configSequence, [27500], configsequencearg.get("INTEGER", (1, 99999)))
219                         config.scan.sat.polarization = configElement_nonSave("config.scan.sat.polarization", configSelection, 0, (("horizontal", _("horizontal")), ("vertical", _("vertical")),  ("circular_left", _("circular left")), ("circular_right", _("circular right"))))
220                         config.scan.sat.fec = configElement_nonSave("config.scan.sat.fec", configSelection, 7, (("auto", _("Auto")), ("1_2", "1/2"), ("2_3", "2/3"), ("3_4", "3/4"), ("5_6", "5/6"), ("7_8", "7/8"), ("none", _("None"))))
221
222                         # cable
223                         config.scan.cab.frequency = configElement_nonSave("config.scan.cab.frequency", configSequence, [466], configsequencearg.get("INTEGER", (50, 999)))
224                         config.scan.cab.inversion = configElement_nonSave("config.scan.cab.inversion", configSelection, 2, (("off", _("off")), ("on", _("on")), ("auto", _("Auto"))))
225                         config.scan.cab.modulation = configElement_nonSave("config.scan.cab.modulation", configSelection, 0, (("auto", _("Auto")), ("16qam", "16-QAM"), ("32qam", "32-QAM"), ("64qam", "64-QAM"), ("128qam", "128-QAM"), ("256qam", "256-QAM")))
226                         config.scan.cab.fec = configElement_nonSave("config.scan.cab.fec", configSelection, 0, (("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"))))
227                         config.scan.cab.symbolrate = configElement_nonSave("config.scan.cab.symbolrate", configSequence, [6900], configsequencearg.get("INTEGER", (1, 9999)))
228                         config.scan.cab.networkScan = configElement_nonSave("config.scan.cab.networkScan", configSelection, 0, (("no", _("no")), ("yes", _("yes"))))
229
230                         # terrestial
231                         config.scan.ter.frequency = configElement_nonSave("config.scan.ter.frequency", configSequence, [466], configsequencearg.get("INTEGER", (100, 900)))
232                         config.scan.ter.inversion = configElement_nonSave("config.scan.ter.inversion", configSelection, 2, (("off", _("off")), ("on", _("on")), ("auto", _("Auto"))))
233                         config.scan.ter.bandwidth = configElement_nonSave("config.scan.ter.bandwidth", configSelection, 3, (("8MHz", "8MHz"), ("7MHz", "7MHz"), ("6MHz", "6MHz"), ("auto", _("Auto"))))
234                         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")))
235                         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"))))
236                         config.scan.ter.modulation = configElement_nonSave("config.scan.ter.modulation", configSelection, 2, (("qpsk", "QPSK"), ("qam16", "QAM16"), ("auto", _("Auto"))))
237                         config.scan.ter.transmission = configElement_nonSave("config.scan.ter.transmission", configSelection, 2, (("2k", "2K"), ("8k", "8K"), ("auto", _("Auto"))))
238                         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"))))
239                         config.scan.ter.hierarchy = configElement_nonSave("config.scan.ter.hierarchy", configSelection, 4, (("none", _("None")), ("1", "1"), ("2", "2"), ("4", "4"), ("auto", _("Auto"))))
240                         config.scan.ter.networkScan = configElement_nonSave("config.scan.cab.networkScan", configSelection, 0, (("no", _("no")), ("yes", _("yes"))))
241
242                         config.scan.scansat = {}
243                         for sat in nimmanager.satList:
244                                 #print sat[1]
245                                 config.scan.scansat[sat[1]] = configElement_nonSave("config.scan.scansat[" + str(sat[1]) + "]", configSelection, 0, (("yes", _("yes")), ("no", _("no"))))
246
247                         config.scan.satselection = []
248                         slotid = 0
249                         for slot in nimmanager.nimslots:
250                                 if (nimmanager.getNimType(slot.slotid) == nimmanager.nimType["DVB-S"]):
251                                         print str(slot.slotid) + " : " + str(self.satList)
252                                         config.scan.satselection.append(configElement_nonSave("config.scan.satselection[" + str(slot.slotid) + "]", configSatlist, 0, self.satList[slot.slotid]))
253                                 else:
254                                         config.scan.satselection.append(None)
255         def keyLeft(self):
256                 self["config"].handleKey(config.key["prevElement"])
257                 self.newConfig()
258
259         def keyRight(self):
260                 self["config"].handleKey(config.key["nextElement"])
261                 self.newConfig()
262
263         def updateStatus(self):
264                 print "updatestatus"
265
266         def keyNumberGlobal(self, number):
267                 print "You pressed number " + str(number)
268                 if (self["config"].getCurrent()[1].parent.enabled == True):
269                         self["config"].handleKey(config.key[str(number)])
270
271         def addSatTransponder(self, tlist, frequency, symbol_rate, polarisation, fec, inversion, orbital_position):
272                 print "Add Sat: frequ: " + str(frequency) + " symbol: " + str(symbol_rate) + " pol: " + str(polarisation) + " fec: " + str(fec) + " inversion: " + str(inversion)
273                 print "orbpos: " + str(orbital_position)
274                 parm = eDVBFrontendParametersSatellite()
275                 parm.frequency = frequency * 1000
276                 parm.symbol_rate = symbol_rate * 1000
277                 parm.polarisation = polarisation # eDVBFrontendParametersSatellite.Polarisation.Verti   
278                 parm.fec = fec                  # eDVBFrontendParametersSatellite.FEC.f3_4;
279                 #parm.fec = 6                                   # AUTO
280                 parm.inversion = inversion      #eDVBFrontendParametersSatellite.Inversion.Off;
281                 #parm.inversion = 2             #AUTO
282                 parm.orbital_position = int(orbital_position)
283                 tlist.append(parm)
284
285         # FIXME use correct parameters
286         def addCabTransponder(self, tlist, frequency, symbol_rate, modulation, fec, inversion):
287                 print "Add Cab: frequ: " + str(frequency) + " symbol: " + str(symbol_rate) + " pol: " + str(modulation) + " fec: " + str(fec) + " inversion: " + str(inversion)
288                 parm = eDVBFrontendParametersCable()
289                 parm.frequency = frequency * 1000
290                 parm.symbol_rate = symbol_rate * 1000
291                 parm.modulation = modulation # modulation # eDVBFrontendParametersSatellite.Polarisation.Verti  
292                 parm.fec = fec                  # eDVBFrontendParametersSatellite.FEC.f3_4;
293                 #parm.fec = 6                                   # AUTO
294                 parm.inversion = inversion      #eDVBFrontendParametersSatellite.Inversion.Off;
295                 #parm.inversion = 2             #AUTO
296                 tlist.append(parm)
297
298         def addTerTransponder(self, tlist, frequency, 
299                         inversion=2, bandwidth = 3, fechigh = 6, feclow = 6,
300                         modulation = 2, transmission = 2, guard = 4,
301                         hierarchy = 4):
302                 # WARNING: normally, enums are working directly.
303                 # Don't copy this (very bad)!! Instead either fix swig (good) or
304                 # move this into a central place.
305                 Bw8MHz = 0
306                 Bw7MHz = 1
307                 Bw6MHz = 2
308                 Bw5MHz = 3
309                 BwAuto = 4
310                 
311                 f1_2 = 0
312                 f2_3 = 1
313                 f3_4 = 2
314                 f5_6 = 3
315                 f7_8 = 4
316                 fAuto = 5
317                 
318                 TM2k = 0
319                 TM8k = 1
320                 TM4k = 2
321                 TMAuto = 3
322                 
323                 GI_1_32 = 0
324                 GI_1_16 = 1
325                 GI_1_8 = 2
326                 GI_1_4 = 3
327                 GI_Auto = 4
328                 
329                 HNone = 0
330                 H1 = 1
331                 H2 = 2
332                 H4 = 3
333                 HAuto = 4
334
335                 QPSK = 0
336                 QAM16 = 1
337                 QAM64 = 2
338                 Auto = 3
339                 
340                 Off = 0
341                 On = 1
342                 Unknown = 2
343
344                 parm = eDVBFrontendParametersTerrestrial()
345                 
346                 parm.frequency = frequency * 1000000
347
348                 parm.inversion = [Off, On, Unknown][inversion]
349                 parm.bandwidth = [Bw8MHz, Bw7MHz, Bw6MHz, BwAuto][bandwidth] # Bw5MHz unsupported
350                 parm.code_rate_HP = [fAuto, f1_2, f2_3, f3_4, f5_6, f7_8, fAuto][fechigh]
351                 parm.code_rate_LP = [fAuto, f1_2, f2_3, f3_4, f5_6, f7_8, fAuto][feclow]
352                 parm.modulation = [QPSK, QAM16, Auto][modulation] # QAM64 unsupported
353                 parm.transmission_mode = [TM2k, TM8k, TMAuto][transmission] # TM4k unsupported
354                 parm.guard_interval = [GI_1_32, GI_1_16, GI_1_8, GI_1_4, GI_Auto][guard]
355                 parm.hierarchy = [HNone, H1, H2, H4, HAuto][hierarchy]
356                 tlist.append(parm)
357
358         def keyGo(self):
359                 tlist = []
360                 flags = 0
361                 if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-S"]):
362                         if currentConfigSelectionElement(config.scan.type) == "single_transponder":
363
364                                 self.addSatTransponder(tlist, config.scan.sat.frequency.value[0],
365                                                                                           config.scan.sat.symbolrate.value[0],
366                                                                                           config.scan.sat.polarization.value,
367                                                                                           config.scan.sat.fec.value,
368                                                                                           config.scan.sat.inversion.value,
369                                                                                           self.satList[config.scan.nims.value][config.scan.satselection[config.scan.nims.value].value][1])
370                         elif currentConfigSelectionElement(config.scan.type) == "single_satellite":
371                                 getInitialTransponderList(tlist, int(self.satList[config.scan.nims.value][config.scan.satselection[config.scan.nims.value].value][1]))
372                                 flags |= eComponentScan.scanNetworkSearch
373         
374                         elif currentConfigSelectionElement(config.scan.type) == "multisat":
375                                 SatList = nimmanager.getSatListForNim(config.scan.nims.value)
376         
377                                 for x in self.multiscanlist:
378                                         if x[1].parent.value == 0:
379                                                 print "   " + str(x[1].parent.configPath)
380                                                 getInitialTransponderList(tlist, x[1].parent.configPath)
381                                 flags |= eComponentScan.scanNetworkSearch
382
383                 elif (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-C"]):
384                         if currentConfigSelectionElement(config.scan.typecable) == "single_transponder":
385                                 self.addCabTransponder(tlist, config.scan.cab.frequency.value[0],
386                                                                                           config.scan.cab.symbolrate.value[0],
387                                                                                           config.scan.cab.modulation.value,
388                                                                                           config.scan.cab.fec.value,
389                                                                                           config.scan.cab.inversion.value)
390                                 if  currentConfigSelectionElement(config.scan.cab.networkScan) == "yes":
391                                         flags |= eComponentScan.scanNetworkSearch
392                         elif currentConfigSelectionElement(config.scan.typecable) == "complete":
393                                 getInitialCableTransponderList(tlist, nimmanager.getCableDescription(config.scan.nims.value))
394                                 flags |= eComponentScan.scanNetworkSearch
395
396                 elif (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-T"]):
397                         if currentConfigSelectionElement(config.scan.typeterrestrial) == "single_transponder":
398                                 self.addTerTransponder(tlist, 
399                                                 config.scan.ter.frequency.value[0],
400                                                 inversion = config.scan.ter.inversion.value,
401                                                 bandwidth = config.scan.ter.bandwidth.value,
402                                                 fechigh = config.scan.ter.fechigh.value,
403                                                 feclow = config.scan.ter.feclow.value,
404                                                 modulation = config.scan.ter.modulation.value,
405                                                 transmission = config.scan.ter.transmission.value,
406                                                 guard = config.scan.ter.guard.value,
407                                                 hierarchy = config.scan.ter.hierarchy.value)
408                                 if currentConfigSelectionElement(config.scan.ter.networkScan) == "yes":
409                                         flags |= eComponentScan.scanNetworkSearch
410                         if currentConfigSelectionElement(config.scan.typeterrestrial) == "complete":
411                                 pass
412
413                 for x in self["config"].list:
414                         x[1].save()
415
416                 feid = config.scan.nims.value
417                 # flags |= eComponentScan.scanSearchBAT
418                 self.session.openWithCallback(self.doNothing, ServiceScan, [{"transponders": tlist, "feid": feid, "flags": flags}])
419
420                 #self.close()
421         def doNothing(self):
422                 pass
423
424         def keyCancel(self):
425                 for x in self["config"].list:
426                         x[1].cancel()
427                 self.close()
428
429 class ScanSimple(Screen):
430         def run(self):
431                 self.keyGo()
432
433         def keyGo(self):
434                 scanList = []
435                 if nimmanager.getNimType(0) == nimmanager.nimType["DVB-S"] and nimmanager.getNimType(0) == nimmanager.getNimType(1):
436                         sec = eDVBSatelliteEquipmentControl.getInstance()
437                         if sec is not None:
438                                 exclusive_satellites = sec.get_exclusive_satellites(0,1)
439                         else:
440                                 exclusive_satellites = [0,0]
441                 else:
442                         exclusive_satellites = [0,0]
443                 print "exclusive satellites", exclusive_satellites
444                 for x in self.list:
445                         slotid = x[1].parent.configPath
446                         print "Scan Tuner", slotid, "-", currentConfigSelectionElement(x[1].parent)
447                         if currentConfigSelectionElement(x[1].parent) == "yes":
448                                 tlist = [ ]
449                                 if nimmanager.getNimType(x[1].parent.configPath) == nimmanager.nimType["DVB-S"]:
450                                         if slotid > 0:
451                                                 idx = exclusive_satellites[0]+1
452                                         else:
453                                                 idx = 0
454                                         exclusive_nim_sats = exclusive_satellites[idx+1:idx+1+exclusive_satellites[idx]]
455                                         print "exclusive_nim_sats", exclusive_nim_sats
456                                         SatList = nimmanager.getSatListForNim(slotid)
457                                         for sat in SatList:
458                                                 if sat[1] in exclusive_nim_sats or slotid == 0:
459                                                         print sat
460                                                         getInitialTransponderList(tlist, sat[1])
461                                 elif nimmanager.getNimType(x[1].parent.configPath) == nimmanager.nimType["DVB-C"]:
462                                         getInitialCableTransponderList(tlist, nimmanager.getCableDescription(slotid))
463                                 scanList.append({"transponders": tlist, "feid": slotid, "flags": eComponentScan.scanNetworkSearch})
464                 self.session.openWithCallback(self.doNothing, ServiceScan, scanList = scanList)
465
466         def doNothing(self):
467                 pass
468         
469         def keyCancel(self):
470                 self.close()
471
472         def keyLeft(self):
473                 self["config"].handleKey(config.key["prevElement"])
474
475         def keyRight(self):
476                 self["config"].handleKey(config.key["nextElement"])
477
478         def Satexists(self, tlist, pos):
479                 for x in tlist:
480                         if x == pos:
481                                 return 1
482                 return 0
483
484         def ScanNimTwoNeeded(self):
485                 if nimmanager.getNimType(0) != nimmanager.getNimType(1):
486                         return True
487                 if nimmanager.getNimType(0) == nimmanager.nimType["DVB-S"]: #two dvb-s nims
488                         if nimmanager.getNimConfigMode(1) in ["loopthrough", "satposdepends", "equal", "nothing"]:
489                                 return False
490                         sec = eDVBSatelliteEquipmentControl.getInstance()
491                         if sec is not None:
492                                 exclusive_satellites = sec.get_exclusive_satellites(0,1)
493                                 if len(exclusive_satellites) == 0:
494                                         return False
495                         return True
496
497         def __init__(self, session):
498                 Screen.__init__(self, session)
499
500                 self["actions"] = ActionMap(["SetupActions"],
501                 {
502                         "ok": self.keyGo,
503                         "cancel": self.keyCancel,
504                         "left": self.keyLeft,
505                         "right": self.keyRight,
506                 }, -1)
507
508                 self.list = []
509                 tlist = []
510
511                 nimcount = nimmanager.getNimSocketCount()
512                 if nimcount > 0:
513                         nim = configElement_nonSave(0, configSelection, 0,(("yes", _("yes")),("no", _("no"))))
514                         self.list.append(getConfigListEntry(_("Scan NIM") + " 0 (" + nimmanager.getNimTypeName(0) + ")", nim))
515                 if nimcount > 1 and self.ScanNimTwoNeeded():
516                         nim = configElement_nonSave(1, configSelection, 0, (("yes", _("yes")), ("no", _("no"))))
517                         self.list.append(getConfigListEntry(_("Scan NIM") + " 1 (" + nimmanager.getNimTypeName(1) + ")", nim))
518
519                 self["config"] = ConfigList(self.list)
520                 self["header"] = Label(_("Automatic Scan"))
521                 self["footer"] = Label(_("Press OK to scan"))