[RecordTimer] fix repeat timer issue.
[vuplus_dvbapp] / lib / python / Screens / ScanSetup.py
1 from Screen import Screen
2 from Screens.DefaultWizard import DefaultWizard
3 from ServiceScan import ServiceScan
4 from Components.config import config, ConfigSubsection, ConfigSelection, \
5         ConfigYesNo, ConfigInteger, getConfigListEntry, ConfigSlider, ConfigEnableDisable
6 from Components.ActionMap import NumberActionMap, ActionMap
7 from Components.ConfigList import ConfigListScreen
8 from Components.NimManager import nimmanager, getConfigSatlist
9 from Components.Label import Label
10 from Components.SystemInfo import SystemInfo
11 from Tools.Directories import resolveFilename, SCOPE_DEFAULTPARTITIONMOUNTDIR, SCOPE_DEFAULTDIR, SCOPE_DEFAULTPARTITION
12 from Tools.HardwareInfo import HardwareInfo
13 from Screens.MessageBox import MessageBox
14 from enigma import eTimer, eDVBFrontendParametersSatellite, eComponentScan, \
15         eDVBSatelliteEquipmentControl, eDVBFrontendParametersTerrestrial, \
16         eDVBFrontendParametersCable, eConsoleAppContainer, eDVBResourceManager
17
18 def buildTerTransponder(frequency, 
19                 inversion=2, bandwidth = 3, fechigh = 6, feclow = 6,
20                 modulation = 2, transmission = 2, guard = 4,
21                 hierarchy = 4, system = 0, plpid = 0):
22 #       print "freq", frequency, "inv", inversion, "bw", bandwidth, "fech", fechigh, "fecl", feclow, "mod", modulation, "tm", transmission, "guard", guard, "hierarchy", hierarchy
23         parm = eDVBFrontendParametersTerrestrial()
24         parm.frequency = frequency
25         parm.inversion = inversion
26         parm.bandwidth = bandwidth
27         parm.code_rate_HP = fechigh
28         parm.code_rate_LP = feclow
29         parm.modulation = modulation
30         parm.transmission_mode = transmission
31         parm.guard_interval = guard
32         parm.hierarchy = hierarchy
33         parm.system = system
34         parm.plpid = plpid
35         return parm
36
37 def getInitialTransponderList(tlist, pos):
38         list = nimmanager.getTransponders(pos)
39         for x in list:
40                 if x[0] == 0:           #SAT
41                         parm = eDVBFrontendParametersSatellite()
42                         parm.frequency = x[1]
43                         parm.symbol_rate = x[2]
44                         parm.polarisation = x[3]
45                         parm.fec = x[4]
46                         parm.inversion = x[7]
47                         parm.orbital_position = pos
48                         parm.system = x[5]
49                         parm.modulation = x[6]
50                         parm.rolloff = x[8]
51                         parm.pilot = x[9]
52                         parm.is_id = x[10]
53                         parm.pls_mode = x[11]
54                         parm.pls_code = x[12]
55                         tlist.append(parm)
56
57 def getInitialCableTransponderList(tlist, nim):
58         list = nimmanager.getTranspondersCable(nim)
59         for x in list:
60                 if x[0] == 1: #CABLE
61                         parm = eDVBFrontendParametersCable()
62                         parm.frequency = x[1]
63                         parm.symbol_rate = x[2]
64                         parm.modulation = x[3]
65                         parm.fec_inner = x[4]
66                         parm.inversion = parm.Inversion_Unknown
67                         #print "frequency:", x[1]
68                         #print "symbol_rate:", x[2]
69                         #print "modulation:", x[3]
70                         #print "fec_inner:", x[4]
71                         #print "inversion:", 2
72                         tlist.append(parm)
73
74 def getInitialTerrestrialTransponderList(tlist, region, skip_t2 = False):
75         list = nimmanager.getTranspondersTerrestrial(region)
76
77         #self.transponders[self.parsedTer].append((2,freq,bw,const,crh,crl,guard,transm,hierarchy,inv,system,plpid))
78
79         #def buildTerTransponder(frequency, inversion = 2, bandwidth = 3, fechigh = 6, feclow = 6,
80                                 #modulation = 2, transmission = 2, guard = 4, hierarchy = 4, system = 0, plpid = 0):):
81
82         for x in list:
83                 if x[0] == 2: #TERRESTRIAL
84                         if skip_t2 and x[10] == eDVBFrontendParametersTerrestrial.System_DVB_T2:
85                                 # Should be searching on TerrestrialTransponderSearchSupport.
86                                 continue
87                         parm = buildTerTransponder(x[1], x[9], x[2], x[4], x[5], x[3], x[7], x[6], x[8], x[10], x[11])
88                         tlist.append(parm)
89
90 cable_bands = {
91         "DVBC_BAND_EU_VHF_I" : 1 << 0,
92         "DVBC_BAND_EU_MID" : 1 << 1,
93         "DVBC_BAND_EU_VHF_III" : 1 << 2,
94         "DVBC_BAND_EU_SUPER" : 1 << 3,
95         "DVBC_BAND_EU_HYPER" : 1 << 4,
96         "DVBC_BAND_EU_UHF_IV" : 1 << 5,
97         "DVBC_BAND_EU_UHF_V" : 1 << 6,
98         "DVBC_BAND_US_LO" : 1 << 7,
99         "DVBC_BAND_US_MID" : 1 << 8,
100         "DVBC_BAND_US_HI" : 1 << 9,
101         "DVBC_BAND_US_SUPER" : 1 << 10,
102         "DVBC_BAND_US_HYPER" : 1 << 11,
103 }
104
105 cable_autoscan_nimtype = {
106 'SSH108' : 'ssh108',
107 'TT3L10' : 'tt3l10',
108 'TURBO' : 'vuplus_turbo_c',
109 'TT2L08' : 'tt2l08',
110 'BCM3148' : 'bcm3148',
111 'BCM3158' : 'bcm3148',
112 }
113
114 terrestrial_autoscan_nimtype = {
115 'SSH108' : 'ssh108_t2_scan',
116 'TT3L10' : 'tt3l10_t2_scan',
117 'TURBO' : 'vuplus_turbo_t',
118 'TT2L08' : 'tt2l08_t2_scan',
119 'BCM3466' : 'bcm3466'
120 }
121
122 dual_tuner_list = ('TT3L10', 'BCM3466')
123
124 def GetDeviceId(filter, nim_idx):
125         tuners={}
126         device_id = 0
127         socket_id = 0
128         for nim in nimmanager.nim_slots:
129                 name_token = nim.description.split(' ')
130                 name = name_token[-1][4:-1]
131                 if name == filter:
132                         if socket_id == nim_idx:
133                                 break
134
135                         if device_id:   device_id = 0
136                         else:                   device_id = 1
137                 socket_id += 1
138         return device_id
139
140 def GetTerrestrial5VEnable(nim_idx):
141         nim = nimmanager.nim_slots[nim_idx]
142         return int(nim.config.terrestrial_5V.value)
143
144 class CableTransponderSearchSupport:
145 #       def setCableTransponderSearchResult(self, tlist):
146 #               pass
147
148 #       def cableTransponderSearchFinished(self):
149 #               pass
150
151         def tryGetRawFrontend(self, feid):
152                 res_mgr = eDVBResourceManager.getInstance()
153                 if res_mgr:
154                         raw_channel = res_mgr.allocateRawChannel(self.feid)
155                         if raw_channel:
156                                 frontend = raw_channel.getFrontend()
157                                 if frontend:
158                                         frontend.closeFrontend() # immediate close... 
159                                         del frontend
160                                         del raw_channel
161                                         return True
162                 return False
163
164         def cableTransponderSearchSessionClosed(self, *val):
165                 print "cableTransponderSearchSessionClosed, val", val
166                 self.cable_search_container.appClosed.remove(self.cableTransponderSearchClosed)
167                 self.cable_search_container.dataAvail.remove(self.getCableTransponderData)
168                 if val and len(val):
169                         if val[0]:
170                                 self.setCableTransponderSearchResult(self.__tlist)
171                         else:
172                                 self.cable_search_container.sendCtrlC()
173                                 self.setCableTransponderSearchResult(None)
174                 self.cable_search_container = None
175                 self.cable_search_session = None
176                 self.__tlist = None
177                 self.cableTransponderSearchFinished()
178
179         def cableTransponderSearchClosed(self, retval):
180                 print "cableTransponderSearch finished", retval
181                 self.cable_search_session.close(True)
182
183         def getCableTransponderData(self, str):
184                 data = str.split()
185                 if len(data):
186                         if data[0] == 'OK':
187                                 print str
188                                 parm = eDVBFrontendParametersCable()
189                                 qam = { "QAM16" : parm.Modulation_QAM16,
190                                         "QAM32" : parm.Modulation_QAM32,
191                                         "QAM64" : parm.Modulation_QAM64,
192                                         "QAM128" : parm.Modulation_QAM128,
193                                         "QAM256" : parm.Modulation_QAM256 }
194                                 inv = { "INVERSION_OFF" : parm.Inversion_Off,
195                                         "INVERSION_ON" : parm.Inversion_On,
196                                         "INVERSION_AUTO" : parm.Inversion_Unknown }
197                                 fec = { "FEC_AUTO" : parm.FEC_Auto,
198                                         "FEC_1_2" : parm.FEC_1_2,
199                                         "FEC_2_3" : parm.FEC_2_3,
200                                         "FEC_3_4" : parm.FEC_3_4,
201                                         "FEC_5_6": parm.FEC_5_6,
202                                         "FEC_7_8" : parm.FEC_7_8,
203                                         "FEC_8_9" : parm.FEC_8_9,
204                                         "FEC_NONE" : parm.FEC_None }
205                                 parm.frequency = int(data[1])
206                                 parm.symbol_rate = int(data[2])
207                                 parm.fec_inner = fec[data[3]]
208                                 parm.modulation = qam[data[4]]
209                                 parm.inversion = inv[data[5]]
210                                 self.__tlist.append(parm)
211                         tmpstr = _("Try to find used Transponders in cable network.. please wait...")
212                         tmpstr += "\n\n"
213                         tmpstr += data[1]
214                         tmpstr += " kHz "
215                         tmpstr += data[0]
216                         self.cable_search_session["text"].setText(tmpstr)
217
218         def startCableTransponderSearch(self, nim_idx):
219                 def GetCommand(nim_idx):
220                         global cable_autoscan_nimtype
221                         try:
222                                 nim_name = nimmanager.getNimName(nim_idx)
223                                 if nim_name is not None and nim_name != "":
224                                         device_id = ""
225                                         nim_name = nim_name.strip(':VTUNER').split(' ')[-1][4:-1]
226                                         if nim_name == 'TT3L10':
227                                                 try:
228                                                         device_id = GetDeviceId('TT3L10', nim_idx)
229                                                         device_id = "--device=%s" % (device_id)
230                                                 except Exception, err:
231                                                         print "GetCommand ->", err
232                                                         device_id = "--device=0"
233 #                                               print nim_idx, nim_name, cable_autoscan_nimtype[nim_name], device_id
234                                         command = "%s %s" % (cable_autoscan_nimtype[nim_name], device_id)
235                                         return command
236                         except Exception, err:
237                                 print "GetCommand ->", err
238                         return "tda1002x"
239
240                 if not self.tryGetRawFrontend(nim_idx):
241                         self.session.nav.stopService()
242                         if not self.tryGetRawFrontend(nim_idx):
243                                 if self.session.pipshown: # try to disable pip
244                                         self.session.pipshown = False
245                                         del self.session.pip
246                                 if not self.tryGetRawFrontend(nim_idx):
247                                         self.cableTransponderSearchFinished()
248                                         return
249                 self.__tlist = [ ]
250                 self.cable_search_container = eConsoleAppContainer()
251                 self.cable_search_container.appClosed.append(self.cableTransponderSearchClosed)
252                 self.cable_search_container.dataAvail.append(self.getCableTransponderData)
253                 cableConfig = config.Nims[nim_idx].cable
254                 tunername = nimmanager.getNimName(nim_idx)
255                 bus = nimmanager.getI2CDevice(nim_idx)
256                 if bus is None:
257                         print "ERROR: could not get I2C device for nim", nim_idx, "for cable transponder search"
258                         bus = 2
259
260                 if tunername == "CXD1981":
261                         cmd = "cxd1978 --init --scan --verbose --wakeup --inv 2 --bus %d" % bus
262                 else:
263                         bin_name = GetCommand(nim_idx)
264                         cmd = "%(BIN_NAME)s --init --scan --verbose --wakeup --inv 2 --bus %(BUS)d" % {'BIN_NAME':bin_name , 'BUS':bus}
265
266                 if cableConfig.scan_type.value == "bands":
267                         cmd += " --scan-bands "
268                         bands = 0
269                         if cableConfig.scan_band_EU_VHF_I.value:
270                                 bands |= cable_bands["DVBC_BAND_EU_VHF_I"]
271                         if cableConfig.scan_band_EU_MID.value:
272                                 bands |= cable_bands["DVBC_BAND_EU_MID"]
273                         if cableConfig.scan_band_EU_VHF_III.value:
274                                 bands |= cable_bands["DVBC_BAND_EU_VHF_III"]
275                         if cableConfig.scan_band_EU_UHF_IV.value:
276                                 bands |= cable_bands["DVBC_BAND_EU_UHF_IV"]
277                         if cableConfig.scan_band_EU_UHF_V.value:
278                                 bands |= cable_bands["DVBC_BAND_EU_UHF_V"]
279                         if cableConfig.scan_band_EU_SUPER.value:
280                                 bands |= cable_bands["DVBC_BAND_EU_SUPER"]
281                         if cableConfig.scan_band_EU_HYPER.value:
282                                 bands |= cable_bands["DVBC_BAND_EU_HYPER"]
283                         if cableConfig.scan_band_US_LOW.value:
284                                 bands |= cable_bands["DVBC_BAND_US_LO"]
285                         if cableConfig.scan_band_US_MID.value:
286                                 bands |= cable_bands["DVBC_BAND_US_MID"]
287                         if cableConfig.scan_band_US_HIGH.value:
288                                 bands |= cable_bands["DVBC_BAND_US_HI"]
289                         if cableConfig.scan_band_US_SUPER.value:
290                                 bands |= cable_bands["DVBC_BAND_US_SUPER"]
291                         if cableConfig.scan_band_US_HYPER.value:
292                                 bands |= cable_bands["DVBC_BAND_US_HYPER"]
293                         cmd += str(bands)
294                 else:
295                         cmd += " --scan-stepsize "
296                         cmd += str(cableConfig.scan_frequency_steps.value)
297                 if cableConfig.scan_mod_qam16.value:
298                         cmd += " --mod 16"
299                 if cableConfig.scan_mod_qam32.value:
300                         cmd += " --mod 32"
301                 if cableConfig.scan_mod_qam64.value:
302                         cmd += " --mod 64"
303                 if cableConfig.scan_mod_qam128.value:
304                         cmd += " --mod 128"
305                 if cableConfig.scan_mod_qam256.value:
306                         cmd += " --mod 256"
307                 if cableConfig.scan_sr_6900.value:
308                         cmd += " --sr 6900000"
309                 if cableConfig.scan_sr_6875.value:
310                         cmd += " --sr 6875000"
311                 if cableConfig.scan_sr_ext1.value > 450:
312                         cmd += " --sr "
313                         cmd += str(cableConfig.scan_sr_ext1.value)
314                         cmd += "000"
315                 if cableConfig.scan_sr_ext2.value > 450:
316                         cmd += " --sr "
317                         cmd += str(cableConfig.scan_sr_ext2.value)
318                         cmd += "000"
319                 print bin_name, " CMD is", cmd
320
321                 self.cable_search_container.execute(cmd)
322                 tmpstr = _("Try to find used transponders in cable network.. please wait...")
323                 tmpstr += "\n\n..."
324                 self.cable_search_session = self.session.openWithCallback(self.cableTransponderSearchSessionClosed, MessageBox, tmpstr, MessageBox.TYPE_INFO)
325
326 class TerrestrialTransponderSearchSupport:
327 #       def setTerrestrialTransponderSearchResult(self, tlist):
328 #               pass
329
330 #       def terrestrialTransponderSearchFinished(self):
331 #               pass
332
333         def terrestrialTransponderSearchSessionClosed(self, *val):
334                 print "TerrestrialTransponderSearchSessionClosed, val", val
335                 self.terrestrial_search_container.appClosed.remove(self.terrestrialTransponderSearchClosed)
336                 self.terrestrial_search_container.dataAvail.remove(self.getTerrestrialTransponderData)
337                 if val and len(val):
338                         if val[0]:
339                                 self.setTerrestrialTransponderSearchResult(self.__tlist)
340                         else:
341                                 self.terrestrial_search_container.sendCtrlC()
342                                 self.setTerrestrialTransponderSearchResult(None)
343                 self.terrestrial_search_container = None
344                 self.terrestrial_search_session = None
345                 self.__tlist = None
346                 self.terrestrialTransponderSearchFinished()
347
348         def terrestrialTransponderSearchClosed(self, retval):
349                 self.setTerrestrialTransponderData()
350                 opt = self.terrestrialTransponderGetOpt()
351                 if opt is None:
352                         print "terrestrialTransponderSearch finished", retval
353                         self.terrestrial_search_session.close(True)
354                 else:
355                         (freq, bandWidth) = opt
356                         self.terrestrialTransponderSearch(freq, bandWidth)
357
358         def getTerrestrialTransponderData(self, str):
359                 self.terrestrial_search_data += str
360
361         def setTerrestrialTransponderData(self):
362                 print self.terrestrial_search_data
363                 data = self.terrestrial_search_data.split()
364                 if len(data):
365 #                       print "[setTerrestrialTransponderData] data : ", data
366                         if data[0] == 'OK':
367                                 # DVB-T : OK frequency bandwidth delivery system -1
368                                 # DVB-T2 : OK frequency bandwidth delivery system number_of_plp plp_id0:plp_type0
369                                 if data[3] == 1: # DVB-T
370                                         parm = eDVBFrontendParametersTerrestrial()
371                                         parm.frequency = int(data[1])
372                                         parm.bandwidth = int(data[2])
373                                         parm.inversion = parm.Inversion_Unknown
374                                         parm.code_rate_HP = parm.FEC_Auto
375                                         parm.code_rate_LP = parm.FEC_Auto
376                                         parm.modulation = parm.Modulation_Auto
377                                         parm.transmission_mode = parm.TransmissionMode_Auto
378                                         parm.guard_interval = parm.GuardInterval_Auto
379                                         parm.hierarchy = parm.Hierarchy_Auto
380                                         parm.system = parm.System_DVB_T
381                                         parm.plpid = 0
382                                         self.__tlist.append(parm)
383                                 else:
384                                         plp_list = data[5:]
385                                         plp_num = int(data[4])
386                                         if len(plp_list) > plp_num:
387                                                 plp_list = plp_list[:plp_num]
388                                         for plp in plp_list:
389                                                 (plp_id, plp_type) = plp.split(':')
390                                                 if plp_type == '0': # common PLP:
391                                                         continue
392                                                 parm = eDVBFrontendParametersTerrestrial()
393                                                 parm.frequency = int(data[1])
394                                                 parm.bandwidth = self.terrestrialTransponderconvBandwidth_P(int(data[2]))
395                                                 parm.inversion = parm.Inversion_Unknown
396                                                 parm.code_rate_HP = parm.FEC_Auto
397                                                 parm.code_rate_LP = parm.FEC_Auto
398                                                 parm.modulation = parm.Modulation_Auto
399                                                 parm.transmission_mode = parm.TransmissionMode_Auto
400                                                 parm.guard_interval = parm.GuardInterval_Auto
401                                                 parm.hierarchy = parm.Hierarchy_Auto
402                                                 parm.system = parm.System_DVB_T2
403                                                 parm.plpid = int(plp_id)
404                                                 self.__tlist.append(parm)
405
406                         tmpstr = _("Try to find used Transponders in terrestrial network.. please wait...")
407                         tmpstr += "\n\n"
408                         tmpstr += data[1][:-3]
409                         tmpstr += " kHz "
410                         tmpstr += data[0]
411                         self.terrestrial_search_session["text"].setText(tmpstr)
412
413         def terrestrialTransponderInitSearchList(self, searchList, region):
414                 tpList = nimmanager.getTranspondersTerrestrial(region)
415                 for x in tpList:
416                         if x[0] == 2: #TERRESTRIAL
417                                 freq = x[1] # frequency
418                                 bandWidth = self.terrestrialTransponderConvBandwidth_I(x[2]) # bandWidth
419                                 parm = (freq, bandWidth)
420                                 searchList.append(parm)
421
422         def terrestrialTransponderConvBandwidth_I(self, _bandWidth):
423                 bandWidth = {
424                         eDVBFrontendParametersTerrestrial.Bandwidth_8MHz : 8000000,
425                         eDVBFrontendParametersTerrestrial.Bandwidth_7MHz : 7000000,
426                         eDVBFrontendParametersTerrestrial.Bandwidth_6MHz : 6000000,
427                         eDVBFrontendParametersTerrestrial.Bandwidth_5MHz : 5000000,
428                         eDVBFrontendParametersTerrestrial.Bandwidth_1_712MHz : 1712000,
429                         eDVBFrontendParametersTerrestrial.Bandwidth_10MHz : 10000000,
430                 }.get(_bandWidth, 8000000)
431                 return bandWidth
432
433         def terrestrialTransponderconvBandwidth_P(self, _bandWidth):
434                 bandWidth = {
435                         8000000 : eDVBFrontendParametersTerrestrial.Bandwidth_8MHz,
436                         7000000 : eDVBFrontendParametersTerrestrial.Bandwidth_7MHz,
437                         6000000 : eDVBFrontendParametersTerrestrial.Bandwidth_6MHz,
438                         5000000 : eDVBFrontendParametersTerrestrial.Bandwidth_5MHz,
439                         1712000 : eDVBFrontendParametersTerrestrial.Bandwidth_1_712MHz,
440                         10000000 : eDVBFrontendParametersTerrestrial.Bandwidth_10MHz,
441                 }.get(_bandWidth, eDVBFrontendParametersTerrestrial.Bandwidth_8MHz)
442                 return bandWidth
443
444         def terrestrialTransponderGetOpt(self):
445                 if len(self.terrestrial_search_list) > 0:
446                         return self.terrestrial_search_list.pop(0)
447                 else:
448                         return None
449
450         def terrestrialTransponderGetCmd(self, nim_idx):
451                 global terrestrial_autoscan_nimtype
452                 try:
453                         nim_name = nimmanager.getNimName(nim_idx)
454                         if nim_name is not None and nim_name != "":
455                                 device_id = ""
456                                 nim_name = nim_name.strip(':VTUNER').split(' ')[-1][4:-1]
457                                 if nim_name in dual_tuner_list:
458                                         try:
459                                                 device_id = GetDeviceId(nim_name, nim_idx)
460                                                 device_id = "--device %s" % (device_id)
461                                         except Exception, err:
462                                                 print "terrestrialTransponderGetCmd ->", err
463                                                 device_id = "--device 0"
464 #                                       print nim_idx, nim_name, terrestrial_autoscan_nimtype[nim_name], device_id
465                                 command = "%s %s" % (terrestrial_autoscan_nimtype[nim_name], device_id)
466                                 return command
467                 except Exception, err:
468                         print "terrestrialTransponderGetCmd ->", err
469                 return ""
470
471         def startTerrestrialTransponderSearch(self, nim_idx, region):
472                 if not self.tryGetRawFrontend(nim_idx):
473                         self.session.nav.stopService()
474                         if not self.tryGetRawFrontend(nim_idx):
475                                 if self.session.pipshown: # try to disable pip
476                                         self.session.pipshown = False
477                                         del self.session.pip
478                                 if not self.tryGetRawFrontend(nim_idx):
479                                         self.terrestrialTransponderSearchFinished()
480                                         return
481                 self.__tlist = [ ]
482                 self.terrestrial_search_container = eConsoleAppContainer()
483                 self.terrestrial_search_container.appClosed.append(self.terrestrialTransponderSearchClosed)
484                 self.terrestrial_search_container.dataAvail.append(self.getTerrestrialTransponderData)
485
486                 self.terrestrial_search_binName = self.terrestrialTransponderGetCmd(nim_idx)
487
488                 self.terrestrial_search_bus = nimmanager.getI2CDevice(nim_idx)
489                 if self.terrestrial_search_bus is None:
490 #                       print "ERROR: could not get I2C device for nim", nim_idx, "for terrestrial transponder search"
491                         self.terrestrial_search_bus = 2
492
493                 self.terrestrial_search_feid = nim_idx
494                 self.terrestrial_search_enable_5v = GetTerrestrial5VEnable(nim_idx)
495
496                 self.terrestrial_search_list = []
497                 self.terrestrialTransponderInitSearchList(self.terrestrial_search_list ,region)
498                 (freq, bandWidth) = self.terrestrialTransponderGetOpt()
499                 self.terrestrialTransponderSearch(freq, bandWidth)
500
501                 tmpstr = _("Try to find used transponders in terrestrial network.. please wait...")
502                 tmpstr += "\n\n..."
503                 self.terrestrial_search_session = self.session.openWithCallback(self.terrestrialTransponderSearchSessionClosed, MessageBox, tmpstr, MessageBox.TYPE_INFO)
504
505         def terrestrialTransponderSearch(self, freq, bandWidth):
506                 self.terrestrial_search_data = ""
507                 cmd = "%s --freq %d --bw %d --bus %d --ds 2" % (self.terrestrial_search_binName, freq, bandWidth, self.terrestrial_search_bus)
508                 if self.terrestrial_search_enable_5v:
509                         cmd += " --feid %d --5v %d" % (self.terrestrial_search_feid, self.terrestrial_search_enable_5v)
510                 print "SCAN CMD : ",cmd
511                 self.terrestrial_search_container.execute(cmd)
512
513 class DefaultSatLists(DefaultWizard):
514         def __init__(self, session, silent = True, showSteps = False):
515                 self.xmlfile = "defaultsatlists.xml"
516                 DefaultWizard.__init__(self, session, silent, showSteps, neededTag = "services")
517                 print "configuredSats:", nimmanager.getConfiguredSats()
518
519         def setDirectory(self):
520                 self.directory = []
521                 self.directory.append(resolveFilename(SCOPE_DEFAULTDIR))
522                 import os
523                 os.system("mount %s %s" % (resolveFilename(SCOPE_DEFAULTPARTITION), resolveFilename(SCOPE_DEFAULTPARTITIONMOUNTDIR)))
524                 self.directory.append(resolveFilename(SCOPE_DEFAULTPARTITIONMOUNTDIR))
525                                 
526         def statusCallback(self, status, progress):
527                 print "statusCallback:", status, progress
528                 from Components.DreamInfoHandler import DreamInfoHandler
529                 if status == DreamInfoHandler.STATUS_DONE:
530                         self["text"].setText(_("The installation of the default services lists is finished.") + "\n\n" + _("Please press OK to continue."))
531                         self.markDone()
532                         self.disableKeys = False        
533
534 class ScanSetup(ConfigListScreen, Screen, CableTransponderSearchSupport, TerrestrialTransponderSearchSupport):
535         def __init__(self, session):
536                 Screen.__init__(self, session)
537
538                 self.finished_cb = None
539                 self.updateSatList()
540                 self.service = session.nav.getCurrentService()
541                 self.feinfo = None
542                 frontendData = None
543                 if self.service is not None:
544                         self.feinfo = self.service.frontendInfo()
545                         frontendData = self.feinfo and self.feinfo.getAll(True)
546                 
547                 self.createConfig(frontendData)
548
549                 del self.feinfo
550                 del self.service
551
552                 self["actions"] = NumberActionMap(["SetupActions"],
553                 {
554                         "ok": self.keyGo,
555                         "cancel": self.keyCancel,
556                 }, -2)
557
558                 self.statusTimer = eTimer()
559                 self.statusTimer.callback.append(self.updateStatus)
560                 #self.statusTimer.start(5000, True)
561
562                 self.list = []
563                 ConfigListScreen.__init__(self, self.list)
564                 if not self.scan_nims.value == "":
565                         self.createSetup()
566                         self["introduction"] = Label(_("Press OK to start the scan"))
567                 else:
568                         self["introduction"] = Label(_("Nothing to scan!\nPlease setup your tuner settings before you start a service scan."))
569
570         def runAsync(self, finished_cb):
571                 self.finished_cb = finished_cb
572                 self.keyGo()
573
574         def updateSatList(self):
575                 self.satList = []
576                 for slot in nimmanager.nim_slots:
577                         if slot.isCompatible("DVB-S"):
578                                 self.satList.append(nimmanager.getSatListForNim(slot.slot))
579                         else:
580                                 self.satList.append(None)
581
582         def createSetup(self):
583                 self.list = []
584                 self.multiscanlist = []
585                 index_to_scan = int(self.scan_nims.value)
586                 print "ID: ", index_to_scan
587
588                 self.tunerEntry = getConfigListEntry(_("Tuner"), self.scan_nims)
589                 self.list.append(self.tunerEntry)
590                 
591                 if self.scan_nims == [ ]:
592                         return
593                 
594                 self.typeOfScanEntry = None
595                 self.systemEntry = None
596                 self.modulationEntry = None
597                 self.is_id_boolEntry = None
598                 self.plsModeEntry = None
599                 nim = nimmanager.nim_slots[index_to_scan]
600                 if nim.isCompatible("DVB-S"):
601                         self.typeOfScanEntry = getConfigListEntry(_("Type of scan"), self.scan_type)
602                         self.list.append(self.typeOfScanEntry)
603                 elif nim.isCompatible("DVB-C"):
604                         self.typeOfScanEntry = getConfigListEntry(_("Type of scan"), self.scan_typecable)
605                         self.list.append(self.typeOfScanEntry)
606                 elif nim.isCompatible("DVB-T"):
607                         self.typeOfScanEntry = getConfigListEntry(_("Type of scan"), self.scan_typeterrestrial)
608                         self.list.append(self.typeOfScanEntry)
609
610                 self.scan_networkScan.value = False
611                 if nim.isCompatible("DVB-S"):
612                         if self.scan_type.value == "single_transponder":
613                                 self.updateSatList()
614
615                                 scan_sat_system_value = self.scan_sat.system.value
616                                 if nim.isCompatible("DVB-S2X"):
617                                         scan_sat_system_value = self.scan_sat.system_dvbs2x.value
618                                         self.systemEntry = getConfigListEntry(_('System'), self.scan_sat.system_dvbs2x)
619                                         self.list.append(self.systemEntry)
620                                 elif nim.isCompatible("DVB-S2"):
621                                         self.systemEntry = getConfigListEntry(_('System'), self.scan_sat.system)
622                                         self.list.append(self.systemEntry)
623                                 else:
624                                         # downgrade to dvb-s, in case a -s2 config was active
625                                         self.scan_sat.system.value = eDVBFrontendParametersSatellite.System_DVB_S
626                                 self.list.append(getConfigListEntry(_('Satellite'), self.scan_satselection[index_to_scan]))
627                                 self.list.append(getConfigListEntry(_('Frequency'), self.scan_sat.frequency))
628                                 self.list.append(getConfigListEntry(_('Inversion'), self.scan_sat.inversion))
629                                 self.list.append(getConfigListEntry(_('Symbol rate'), self.scan_sat.symbolrate))
630                                 self.list.append(getConfigListEntry(_('Polarization'), self.scan_sat.polarization))
631
632                                 if scan_sat_system_value == eDVBFrontendParametersSatellite.System_DVB_S2:
633                                         self.modulationEntry = getConfigListEntry(_('Modulation'), self.scan_sat.modulation)
634                                         self.list.append(self.modulationEntry)
635                                         self.list.append(getConfigListEntry(_('Roll-off'), self.scan_sat.rolloff))
636                                         self.list.append(getConfigListEntry(_('Pilot'), self.scan_sat.pilot))
637                                 elif scan_sat_system_value == eDVBFrontendParametersSatellite.System_DVB_S2X:
638                                         self.modulationEntry = getConfigListEntry(_('Modulation'), self.scan_sat.modulation_dvbs2x)
639                                         self.list.append(self.modulationEntry)
640                                         self.list.append(getConfigListEntry(_('Roll-off'), self.scan_sat.rolloff))
641                                         self.list.append(getConfigListEntry(_('Pilot'), self.scan_sat.pilot))
642
643                                 if scan_sat_system_value == eDVBFrontendParametersSatellite.System_DVB_S:
644                                         self.list.append(getConfigListEntry(_("FEC"), self.scan_sat.fec))
645                                 elif scan_sat_system_value == eDVBFrontendParametersSatellite.System_DVB_S2:
646                                         self.list.append(getConfigListEntry(_("FEC"), self.scan_sat.fec_s2))
647                                 elif scan_sat_system_value == eDVBFrontendParametersSatellite.System_DVB_S2X:
648                                         if self.scan_sat.modulation_dvbs2x.value == eDVBFrontendParametersSatellite.Modulation_QPSK:
649                                                 self.list.append(getConfigListEntry(_("FEC"), self.scan_sat.fec_s2x_qpsk))
650                                         elif self.scan_sat.modulation_dvbs2x.value == eDVBFrontendParametersSatellite.Modulation_8PSK:
651                                                 self.list.append(getConfigListEntry(_("FEC"), self.scan_sat.fec_s2x_8psk))
652                                         elif self.scan_sat.modulation_dvbs2x.value == eDVBFrontendParametersSatellite.Modulation_8APSK:
653                                                 self.list.append(getConfigListEntry(_("FEC"), self.scan_sat.fec_s2x_8apsk))
654                                         elif self.scan_sat.modulation_dvbs2x.value == eDVBFrontendParametersSatellite.Modulation_16APSK:
655                                                 self.list.append(getConfigListEntry(_("FEC"), self.scan_sat.fec_s2x_16apsk))
656                                         elif self.scan_sat.modulation_dvbs2x.value == eDVBFrontendParametersSatellite.Modulation_32APSK:
657                                                 self.list.append(getConfigListEntry(_("FEC"), self.scan_sat.fec_s2x_32apsk))
658
659                                 if scan_sat_system_value in (eDVBFrontendParametersSatellite.System_DVB_S2, eDVBFrontendParametersSatellite.System_DVB_S2X):
660                                         if nim.isMultistream():
661                                                 self.is_id_boolEntry = getConfigListEntry(_('Transport Stream Type'), self.scan_sat.is_id_bool)
662                                                 self.list.append(self.is_id_boolEntry)
663                                                 if self.scan_sat.is_id_bool.value:
664                                                         self.list.append(getConfigListEntry(_('Input Stream ID'), self.scan_sat.is_id))
665                                                         self.plsModeEntry = getConfigListEntry(_('PLS Mode'), self.scan_sat.pls_mode)
666                                                         self.list.append(self.plsModeEntry)
667                                                         if self.scan_sat.pls_mode.value != eDVBFrontendParametersSatellite.PLS_Unknown:
668                                                                 self.list.append(getConfigListEntry(_('PLS Code'), self.scan_sat.pls_code))
669
670                         elif self.scan_type.value == "single_satellite":
671                                 self.updateSatList()
672                                 print self.scan_satselection[index_to_scan]
673                                 self.list.append(getConfigListEntry(_("Satellite"), self.scan_satselection[index_to_scan]))
674                                 self.scan_networkScan.value = True
675                         elif self.scan_type.value.find("multisat") != -1:
676                                 tlist = []
677                                 SatList = nimmanager.getSatListForNim(index_to_scan)
678                                 for x in SatList:
679                                         if self.Satexists(tlist, x[0]) == 0:
680                                                 tlist.append(x[0])
681                                                 sat = ConfigEnableDisable(default = self.scan_type.value.find("_yes") != -1 and True or False)
682                                                 configEntry = getConfigListEntry(nimmanager.getSatDescription(x[0]), sat)
683                                                 self.list.append(configEntry)
684                                                 self.multiscanlist.append((x[0], sat))
685                                 self.scan_networkScan.value = True
686                 elif nim.isCompatible("DVB-C"):
687                         if self.scan_typecable.value == "single_transponder":
688                                 self.list.append(getConfigListEntry(_("Frequency"), self.scan_cab.frequency))
689                                 self.list.append(getConfigListEntry(_("Inversion"), self.scan_cab.inversion))
690                                 self.list.append(getConfigListEntry(_("Symbol rate"), self.scan_cab.symbolrate))
691                                 self.list.append(getConfigListEntry(_("Modulation"), self.scan_cab.modulation))
692                                 self.list.append(getConfigListEntry(_("FEC"), self.scan_cab.fec))
693                 elif nim.isCompatible("DVB-T"):
694                         if self.scan_typeterrestrial.value == "single_transponder":
695                                 if nim.isCompatible("DVB-T2"):
696                                         self.systemEntry = getConfigListEntry(_('System'), self.scan_ter.system)
697                                         self.list.append(self.systemEntry)
698                                 else:
699                                         self.scan_ter.system.value = eDVBFrontendParametersTerrestrial.System_DVB_T
700                                 if self.scan_ter.system.value == eDVBFrontendParametersTerrestrial.System_DVB_T:
701                                         self.list.append(getConfigListEntry(_("Frequency"), self.scan_ter.frequency))
702                                         self.list.append(getConfigListEntry(_("Inversion"), self.scan_ter.inversion))
703                                         self.list.append(getConfigListEntry(_("Bandwidth"), self.scan_ter.bandwidth))
704                                         self.list.append(getConfigListEntry(_("Code rate HP"), self.scan_ter.fechigh))
705                                         self.list.append(getConfigListEntry(_("Code rate LP"), self.scan_ter.feclow))
706                                         self.list.append(getConfigListEntry(_("Modulation"), self.scan_ter.modulation))
707                                         self.list.append(getConfigListEntry(_("Transmission mode"), self.scan_ter.transmission))
708                                         self.list.append(getConfigListEntry(_("Guard interval"), self.scan_ter.guard))
709                                         self.list.append(getConfigListEntry(_("Hierarchy info"), self.scan_ter.hierarchy))
710                                 else: # DVB-T2
711                                         self.list.append(getConfigListEntry(_("Frequency"), self.scan_ter.frequency))
712                                         self.list.append(getConfigListEntry(_("Inversion"), self.scan_ter.inversion))
713                                         self.list.append(getConfigListEntry(_("Bandwidth"), self.scan_ter.bandwidth_t2))
714                                         self.list.append(getConfigListEntry(_("Code rate HP"), self.scan_ter.fechigh_t2))
715                                         self.list.append(getConfigListEntry(_("Code rate LP"), self.scan_ter.feclow_t2))
716                                         self.list.append(getConfigListEntry(_("Modulation"), self.scan_ter.modulation_t2))
717                                         self.list.append(getConfigListEntry(_("Transmission mode"), self.scan_ter.transmission_t2))
718                                         self.list.append(getConfigListEntry(_("Guard interval"), self.scan_ter.guard_t2))
719                                         self.list.append(getConfigListEntry(_("Hierarchy info"), self.scan_ter.hierarchy))
720                                         self.list.append(getConfigListEntry(_('PLP ID'), self.scan_ter.plp_id))
721                 self.list.append(getConfigListEntry(_("Network scan"), self.scan_networkScan))
722                 self.list.append(getConfigListEntry(_("Clear before scan"), self.scan_clearallservices))
723                 self.list.append(getConfigListEntry(_("Only Free scan"), self.scan_onlyfree))
724                 self["config"].list = self.list
725                 self["config"].l.setList(self.list)
726
727         def Satexists(self, tlist, pos):
728                 for x in tlist:
729                         if x == pos:
730                                 return 1
731                 return 0
732
733         def newConfig(self):
734                 cur = self["config"].getCurrent()
735                 print "cur is", cur
736                 if cur is None:
737                         return
738
739                 if cur == self.typeOfScanEntry or \
740                         cur == self.tunerEntry or \
741                         cur == self.systemEntry or \
742                         (self.modulationEntry and \
743                         (self.systemEntry[1].value in (eDVBFrontendParametersSatellite.System_DVB_S2, eDVBFrontendParametersSatellite.System_DVB_S2X)) and \
744                         cur == self.modulationEntry) or \
745                         cur == self.is_id_boolEntry or \
746                         cur == self.plsModeEntry:
747                         self.createSetup()
748
749         def createConfig(self, frontendData):
750                         defaultSat = {
751                                 "orbpos": 192,
752                                 "system": eDVBFrontendParametersSatellite.System_DVB_S,
753                                 "frequency": 11836,
754                                 "inversion": eDVBFrontendParametersSatellite.Inversion_Unknown,
755                                 "symbolrate": 27500,
756                                 "polarization": eDVBFrontendParametersSatellite.Polarisation_Horizontal,
757                                 "fec": eDVBFrontendParametersSatellite.FEC_Auto,
758                                 "fec_s2": eDVBFrontendParametersSatellite.FEC_9_10,
759                                 "fec_s2x_qpsk": eDVBFrontendParametersSatellite.FEC_13_45,
760                                 "fec_s2x_8psk": eDVBFrontendParametersSatellite.FEC_23_36,
761                                 "fec_s2x_8apsk": eDVBFrontendParametersSatellite.FEC_5_9_L,
762                                 "fec_s2x_16apsk": eDVBFrontendParametersSatellite.FEC_1_2_L,
763                                 "fec_s2x_32apsk": eDVBFrontendParametersSatellite.FEC_2_3_L,
764                                 "modulation": eDVBFrontendParametersSatellite.Modulation_QPSK,
765                                 "modulation_s2x": eDVBFrontendParametersSatellite.Modulation_QPSK,
766                                 "is_id": -1,
767                                 "pls_mode": eDVBFrontendParametersSatellite.PLS_Unknown,
768                                 "pls_code": 0 }
769                         defaultCab = {
770                                 "frequency": 466,
771                                 "inversion": eDVBFrontendParametersCable.Inversion_Unknown,
772                                 "modulation": eDVBFrontendParametersCable.Modulation_QAM64,
773                                 "fec": eDVBFrontendParametersCable.FEC_Auto,
774                                 "symbolrate": 6900 }
775                         defaultTer = {
776                                 "frequency" : 466000,
777                                 "inversion" : eDVBFrontendParametersTerrestrial.Inversion_Unknown,
778                                 "bandwidth" : eDVBFrontendParametersTerrestrial.Bandwidth_7MHz,
779                                 "fechigh" : eDVBFrontendParametersTerrestrial.FEC_Auto,
780                                 "feclow" : eDVBFrontendParametersTerrestrial.FEC_Auto,
781                                 "modulation" : eDVBFrontendParametersTerrestrial.Modulation_Auto,
782                                 "transmission_mode" : eDVBFrontendParametersTerrestrial.TransmissionMode_Auto,
783                                 "guard_interval" : eDVBFrontendParametersTerrestrial.GuardInterval_Auto,
784                                 "hierarchy": eDVBFrontendParametersTerrestrial.Hierarchy_Auto,
785                                 "system": eDVBFrontendParametersTerrestrial.System_DVB_T,
786                                 "plp_id": 0 }
787
788                         if frontendData is not None:
789                                 ttype = frontendData.get("tuner_type", "UNKNOWN")
790                                 if ttype == "DVB-S":
791                                         defaultSat["system"] = frontendData.get("system", eDVBFrontendParametersSatellite.System_DVB_S)
792                                         defaultSat["frequency"] = frontendData.get("frequency", 0) / 1000
793                                         defaultSat["inversion"] = frontendData.get("inversion", eDVBFrontendParametersSatellite.Inversion_Unknown)
794                                         defaultSat["symbolrate"] = frontendData.get("symbol_rate", 0) / 1000
795                                         defaultSat["polarization"] = frontendData.get("polarization", eDVBFrontendParametersSatellite.Polarisation_Horizontal)
796                                         defaultSat["orbpos"] = frontendData.get("orbital_position", 0)
797
798                                         defaultSat["modulation"] = frontendData.get("modulation", eDVBFrontendParametersSatellite.Modulation_QPSK)
799                                         defaultSat["modulation_s2x"] = frontendData.get("modulation", eDVBFrontendParametersSatellite.Modulation_QPSK)
800
801                                         if defaultSat["modulation"] > eDVBFrontendParametersSatellite.Modulation_8PSK:
802                                                 defaultSat["modulation"] = eDVBFrontendParametersSatellite.Modulation_8PSK
803
804                                         if defaultSat["system"] == eDVBFrontendParametersSatellite.System_DVB_S2:
805                                                 defaultSat["fec_s2"] = frontendData.get("fec_inner", eDVBFrontendParametersSatellite.FEC_Auto)
806                                         elif defaultSat["system"] == eDVBFrontendParametersSatellite.System_DVB_S2X:
807                                                 if defaultSat["modulation_s2x"] == eDVBFrontendParametersSatellite.Modulation_QPSK:
808                                                         defaultSat["fec_s2x_qpsk"] = frontendData.get("fec_inner", eDVBFrontendParametersSatellite.FEC_13_45)
809                                                 elif defaultSat["modulation_s2x"] == eDVBFrontendParametersSatellite.Modulation_8PSK:
810                                                         defaultSat["fec_s2x_8psk"] = frontendData.get("fec_inner", eDVBFrontendParametersSatellite.FEC_23_36)
811                                                 elif defaultSat["modulation_s2x"] == eDVBFrontendParametersSatellite.Modulation_8APSK:
812                                                         defaultSat["fec_s2x_8apsk"] = frontendData.get("fec_inner", eDVBFrontendParametersSatellite.FEC_5_9_L)
813                                                 elif defaultSat["modulation_s2x"] == eDVBFrontendParametersSatellite.Modulation_16APSK:
814                                                         defaultSat["fec_s2x_16apsk"] = frontendData.get("fec_inner", eDVBFrontendParametersSatellite.FEC_1_2_L)
815                                                 elif defaultSat["modulation_s2x"] == eDVBFrontendParametersSatellite.Modulation_32APSK:
816                                                         defaultSat["fec_s2x_32apsk"] = frontendData.get("fec_inner", eDVBFrontendParametersSatellite.FEC_2_3_L)
817                                         else:
818                                                 defaultSat["fec"] = frontendData.get("fec_inner", eDVBFrontendParametersSatellite.FEC_Auto)
819
820                                         if defaultSat["system"] in (eDVBFrontendParametersSatellite.System_DVB_S2, eDVBFrontendParametersSatellite.System_DVB_S2X):
821                                                 defaultSat["rolloff"] = frontendData.get("rolloff", eDVBFrontendParametersSatellite.RollOff_alpha_0_35)
822                                                 defaultSat["pilot"] = frontendData.get("pilot", eDVBFrontendParametersSatellite.Pilot_Unknown)
823                                                 defaultSat["is_id"] = frontendData.get("is_id", defaultSat["is_id"])
824                                                 defaultSat["pls_mode"] = frontendData.get("pls_mode", defaultSat["pls_mode"])
825                                                 defaultSat["pls_code"] = frontendData.get("pls_code", defaultSat["pls_code"])
826
827                                 elif ttype == "DVB-C":
828                                         defaultCab["frequency"] = frontendData.get("frequency", 0) / 1000
829                                         defaultCab["symbolrate"] = frontendData.get("symbol_rate", 0) / 1000
830                                         defaultCab["inversion"] = frontendData.get("inversion", eDVBFrontendParametersCable.Inversion_Unknown)
831                                         defaultCab["fec"] = frontendData.get("fec_inner", eDVBFrontendParametersCable.FEC_Auto)
832                                         defaultCab["modulation"] = frontendData.get("modulation", eDVBFrontendParametersCable.Modulation_QAM16)
833                                 elif ttype == "DVB-T":
834                                         defaultTer["frequency"] = frontendData.get("frequency", 0) / 1000
835                                         defaultTer["inversion"] = frontendData.get("inversion", eDVBFrontendParametersTerrestrial.Inversion_Unknown)
836                                         defaultTer["bandwidth"] = frontendData.get("bandwidth", eDVBFrontendParametersTerrestrial.Bandwidth_7MHz)
837                                         defaultTer["fechigh"] = frontendData.get("code_rate_hp", eDVBFrontendParametersTerrestrial.FEC_Auto)
838                                         defaultTer["feclow"] = frontendData.get("code_rate_lp", eDVBFrontendParametersTerrestrial.FEC_Auto)
839                                         defaultTer["modulation"] = frontendData.get("constellation", eDVBFrontendParametersTerrestrial.Modulation_Auto)
840                                         defaultTer["transmission_mode"] = frontendData.get("transmission_mode", eDVBFrontendParametersTerrestrial.TransmissionMode_Auto)
841                                         defaultTer["guard_interval"] = frontendData.get("guard_interval", eDVBFrontendParametersTerrestrial.GuardInterval_Auto)
842                                         defaultTer["hierarchy"] = frontendData.get("hierarchy_information", eDVBFrontendParametersTerrestrial.Hierarchy_Auto)
843                                         defaultTer["system"] = frontendData.get("system", eDVBFrontendParametersTerrestrial.System_DVB_T)
844                                         defaultTer["plp_id"] = frontendData.get("plp_id", 0)
845
846                         self.scan_sat = ConfigSubsection()
847                         self.scan_cab = ConfigSubsection()
848                         self.scan_ter = ConfigSubsection()
849
850                         self.scan_type = ConfigSelection(default = "single_transponder", choices = [("single_transponder", _("Single transponder")), ("single_satellite", _("Single satellite")), ("multisat", _("Multisat")), ("multisat_yes", _("Multisat"))])
851                         self.scan_typecable = ConfigSelection(default = "single_transponder", choices = [("single_transponder", _("Single transponder")), ("complete", _("Complete"))])
852                         self.scan_typeterrestrial = ConfigSelection(default = "single_transponder", choices = [("single_transponder", _("Single transponder")), ("complete", _("Complete"))])
853                         self.scan_clearallservices = ConfigSelection(default = "no", choices = [("no", _("no")), ("yes", _("yes")), ("yes_hold_feeds", _("yes (keep feeds)"))])
854                         self.scan_onlyfree = ConfigYesNo(default = False)
855                         self.scan_networkScan = ConfigYesNo(default = False)
856
857                         nim_list = []
858                         # collect all nims which are *not* set to "nothing"
859                         for n in nimmanager.nim_slots:
860                                 if n.config_mode == "nothing":
861                                         continue
862                                 if n.config_mode == "advanced" and len(nimmanager.getSatListForNim(n.slot)) < 1:
863                                         continue
864                                 if n.config_mode in ("loopthrough", "satposdepends"):
865                                         root_id = nimmanager.sec.getRoot(n.slot_id, int(n.config.connectedTo.value))
866                                         if n.type == nimmanager.nim_slots[root_id].type: # check if connected from a DVB-S to DVB-S2 Nim or vice versa
867                                                 continue
868                                 nim_list.append((str(n.slot), n.friendly_full_description))
869
870                         self.scan_nims = ConfigSelection(choices = nim_list)
871
872                         # status
873                         self.scan_snr = ConfigSlider()
874                         self.scan_snr.enabled = False
875                         self.scan_agc = ConfigSlider()
876                         self.scan_agc.enabled = False
877                         self.scan_ber = ConfigSlider()
878                         self.scan_ber.enabled = False
879
880                         # sat
881                         sat_choices = [
882                                 (eDVBFrontendParametersSatellite.System_DVB_S, _("DVB-S")),
883                                 (eDVBFrontendParametersSatellite.System_DVB_S2, _("DVB-S2"))]
884
885                         sat_choices_dvbs2x = [
886                                 (eDVBFrontendParametersSatellite.System_DVB_S, _("DVB-S")),
887                                 (eDVBFrontendParametersSatellite.System_DVB_S2, _("DVB-S2")),
888                                 (eDVBFrontendParametersSatellite.System_DVB_S2X, _("DVB-S2X"))]
889
890                         default_sat_system = defaultSat["system"]
891                         if default_sat_system not in sat_choices:
892                                 default_sat_system = eDVBFrontendParametersSatellite.System_DVB_S
893
894                         self.scan_sat.system = ConfigSelection(default = default_sat_system, choices = sat_choices)
895                         self.scan_sat.system_dvbs2x = ConfigSelection(default = defaultSat["system"], choices = sat_choices_dvbs2x)
896                         self.scan_sat.frequency = ConfigInteger(default = defaultSat["frequency"], limits = (1, 99999))
897                         self.scan_sat.inversion = ConfigSelection(default = defaultSat["inversion"], choices = [
898                                 (eDVBFrontendParametersSatellite.Inversion_Off, _("Off")),
899                                 (eDVBFrontendParametersSatellite.Inversion_On, _("On")),
900                                 (eDVBFrontendParametersSatellite.Inversion_Unknown, _("Auto"))])
901                         self.scan_sat.symbolrate = ConfigInteger(default = defaultSat["symbolrate"], limits = (1, 99999))
902                         self.scan_sat.polarization = ConfigSelection(default = defaultSat["polarization"], choices = [
903                                 (eDVBFrontendParametersSatellite.Polarisation_Horizontal, _("horizontal")),
904                                 (eDVBFrontendParametersSatellite.Polarisation_Vertical, _("vertical")),
905                                 (eDVBFrontendParametersSatellite.Polarisation_CircularLeft, _("circular left")),
906                                 (eDVBFrontendParametersSatellite.Polarisation_CircularRight, _("circular right"))])
907                         self.scan_sat.fec = ConfigSelection(default = defaultSat["fec"], choices = [
908                                 (eDVBFrontendParametersSatellite.FEC_Auto, _("Auto")),
909                                 (eDVBFrontendParametersSatellite.FEC_1_2, "1/2"),
910                                 (eDVBFrontendParametersSatellite.FEC_2_3, "2/3"),
911                                 (eDVBFrontendParametersSatellite.FEC_3_4, "3/4"),
912                                 (eDVBFrontendParametersSatellite.FEC_5_6, "5/6"),
913                                 (eDVBFrontendParametersSatellite.FEC_7_8, "7/8"),
914                                 (eDVBFrontendParametersSatellite.FEC_None, _("None"))])
915                         self.scan_sat.fec_s2 = ConfigSelection(default = defaultSat["fec_s2"], choices = [
916                                 (eDVBFrontendParametersSatellite.FEC_1_2, "1/2"),
917                                 (eDVBFrontendParametersSatellite.FEC_2_3, "2/3"),
918                                 (eDVBFrontendParametersSatellite.FEC_3_4, "3/4"),
919                                 (eDVBFrontendParametersSatellite.FEC_3_5, "3/5"),
920                                 (eDVBFrontendParametersSatellite.FEC_4_5, "4/5"),
921                                 (eDVBFrontendParametersSatellite.FEC_5_6, "5/6"),
922                                 (eDVBFrontendParametersSatellite.FEC_7_8, "7/8"),
923                                 (eDVBFrontendParametersSatellite.FEC_8_9, "8/9"),
924                                 (eDVBFrontendParametersSatellite.FEC_9_10, "9/10")])
925
926                         self.scan_sat.fec_s2x_qpsk = ConfigSelection(default = defaultSat["fec_s2x_qpsk"], choices = [
927                                 (eDVBFrontendParametersSatellite.FEC_13_45, "13/45"),
928                                 (eDVBFrontendParametersSatellite.FEC_9_20, "9/20"),
929                                 (eDVBFrontendParametersSatellite.FEC_11_20, "11/20")])
930
931                         self.scan_sat.fec_s2x_8psk = ConfigSelection(default = defaultSat["fec_s2x_8psk"], choices = [
932                                 (eDVBFrontendParametersSatellite.FEC_23_36, "23/36"),
933                                 (eDVBFrontendParametersSatellite.FEC_25_36, "25/36"),
934                                 (eDVBFrontendParametersSatellite.FEC_13_18, "13/28")])
935
936                         self.scan_sat.fec_s2x_8apsk = ConfigSelection(default = defaultSat["fec_s2x_8apsk"], choices = [
937                                 (eDVBFrontendParametersSatellite.FEC_5_9_L, "5/9-L"),
938                                 (eDVBFrontendParametersSatellite.FEC_26_45_L, "26/45-L")])
939
940                         self.scan_sat.fec_s2x_16apsk = ConfigSelection(default = defaultSat["fec_s2x_16apsk"], choices = [
941                                 (eDVBFrontendParametersSatellite.FEC_1_2_L, "1/2-L"),
942                                 (eDVBFrontendParametersSatellite.FEC_8_15_L, "8/15-L"),
943                                 (eDVBFrontendParametersSatellite.FEC_5_9_L, "5/9-L"),
944                                 (eDVBFrontendParametersSatellite.FEC_26_45, "26/45"),
945                                 (eDVBFrontendParametersSatellite.FEC_3_5, "3/5"),
946                                 (eDVBFrontendParametersSatellite.FEC_3_5_L, "3/5-L"),
947                                 (eDVBFrontendParametersSatellite.FEC_28_45, "28/45"),
948                                 (eDVBFrontendParametersSatellite.FEC_23_36, "23/36"),
949                                 (eDVBFrontendParametersSatellite.FEC_2_3_L, "2/3-L"),
950                                 (eDVBFrontendParametersSatellite.FEC_25_36, "25/36"),
951                                 (eDVBFrontendParametersSatellite.FEC_13_18, "13/18"),
952                                 (eDVBFrontendParametersSatellite.FEC_7_9, "7/9"),
953                                 (eDVBFrontendParametersSatellite.FEC_77_90, "77/90")])
954
955                         self.scan_sat.fec_s2x_32apsk = ConfigSelection(default = defaultSat["fec_s2x_32apsk"], choices = [
956                                 (eDVBFrontendParametersSatellite.FEC_2_3_L, "2/3-L"),
957                                 (eDVBFrontendParametersSatellite.FEC_32_45, "32/45"),
958                                 (eDVBFrontendParametersSatellite.FEC_11_15, "11/15"),
959                                 (eDVBFrontendParametersSatellite.FEC_7_9, "7/9")])
960
961                         self.scan_sat.modulation = ConfigSelection(default = defaultSat["modulation"], choices = [
962                                 (eDVBFrontendParametersSatellite.Modulation_QPSK, "QPSK"),
963                                 (eDVBFrontendParametersSatellite.Modulation_8PSK, "8PSK")])
964                         self.scan_sat.modulation_dvbs2x = ConfigSelection(default = defaultSat["modulation_s2x"], choices = [
965                                 (eDVBFrontendParametersSatellite.Modulation_QPSK, "QPSK"),
966                                 (eDVBFrontendParametersSatellite.Modulation_8PSK, "8PSK"),
967                                 (eDVBFrontendParametersSatellite.Modulation_8APSK, "8APSK"),
968                                 (eDVBFrontendParametersSatellite.Modulation_16APSK, "16APSK"),
969                                 (eDVBFrontendParametersSatellite.Modulation_32APSK, "32APSK")])
970                         self.scan_sat.rolloff = ConfigSelection(default = defaultSat.get("rolloff", eDVBFrontendParametersSatellite.RollOff_alpha_0_35), choices = [
971                                 (eDVBFrontendParametersSatellite.RollOff_alpha_0_35, "0.35"),
972                                 (eDVBFrontendParametersSatellite.RollOff_alpha_0_25, "0.25"),
973                                 (eDVBFrontendParametersSatellite.RollOff_alpha_0_20, "0.20")])
974                         self.scan_sat.pilot = ConfigSelection(default = defaultSat.get("pilot", eDVBFrontendParametersSatellite.Pilot_Unknown), choices = [
975                                 (eDVBFrontendParametersSatellite.Pilot_Off, _("Off")),
976                                 (eDVBFrontendParametersSatellite.Pilot_On, _("On")),
977                                 (eDVBFrontendParametersSatellite.Pilot_Unknown, _("Auto"))])
978                         self.scan_sat.is_id = ConfigInteger(default = defaultSat["is_id"] if defaultSat["is_id"] != -1 else 0, limits = (0, 255))
979                         self.scan_sat.is_id_bool = ConfigSelection(default = defaultSat["is_id"] != -1, choices = [(True, _("Multistream")),(False, _("Ordinary"))])
980                         self.scan_sat.pls_mode = ConfigSelection(default = defaultSat["pls_mode"], choices = [
981                                 (eDVBFrontendParametersSatellite.PLS_Root, _("Root")),
982                                 (eDVBFrontendParametersSatellite.PLS_Gold, _("Gold")),
983                                 (eDVBFrontendParametersSatellite.PLS_Combo, _("Combo")),
984                                 (eDVBFrontendParametersSatellite.PLS_Unknown, _("Auto"))])
985                         self.scan_sat.pls_code = ConfigInteger(default = defaultSat["pls_code"], limits = (0, 262143))
986
987                         # cable
988                         self.scan_cab.frequency = ConfigInteger(default = defaultCab["frequency"], limits = (50, 999))
989                         self.scan_cab.inversion = ConfigSelection(default = defaultCab["inversion"], choices = [
990                                 (eDVBFrontendParametersCable.Inversion_Off, _("Off")),
991                                 (eDVBFrontendParametersCable.Inversion_On, _("On")),
992                                 (eDVBFrontendParametersCable.Inversion_Unknown, _("Auto"))])
993                         self.scan_cab.modulation = ConfigSelection(default = defaultCab["modulation"], choices = [
994                                 (eDVBFrontendParametersCable.Modulation_QAM16, "16-QAM"),
995                                 (eDVBFrontendParametersCable.Modulation_QAM32, "32-QAM"),
996                                 (eDVBFrontendParametersCable.Modulation_QAM64, "64-QAM"),
997                                 (eDVBFrontendParametersCable.Modulation_QAM128, "128-QAM"),
998                                 (eDVBFrontendParametersCable.Modulation_QAM256, "256-QAM")])
999                         self.scan_cab.fec = ConfigSelection(default = defaultCab["fec"], choices = [
1000                                 (eDVBFrontendParametersCable.FEC_Auto, _("Auto")),
1001                                 (eDVBFrontendParametersCable.FEC_1_2, "1/2"),
1002                                 (eDVBFrontendParametersCable.FEC_2_3, "2/3"),
1003                                 (eDVBFrontendParametersCable.FEC_3_4, "3/4"),
1004                                 (eDVBFrontendParametersCable.FEC_5_6, "5/6"),
1005                                 (eDVBFrontendParametersCable.FEC_7_8, "7/8"),
1006                                 (eDVBFrontendParametersCable.FEC_8_9, "8/9"),
1007                                 (eDVBFrontendParametersCable.FEC_None, _("None"))])
1008                         self.scan_cab.symbolrate = ConfigInteger(default = defaultCab["symbolrate"], limits = (1, 99999))
1009
1010                         # terrestial
1011                         self.scan_ter.frequency = ConfigInteger(default = defaultTer["frequency"], limits = (50000, 999000))
1012                         self.scan_ter.inversion = ConfigSelection(default = defaultTer["inversion"], choices = [
1013                                 (eDVBFrontendParametersTerrestrial.Inversion_Off, _("Off")),
1014                                 (eDVBFrontendParametersTerrestrial.Inversion_On, _("On")),
1015                                 (eDVBFrontendParametersTerrestrial.Inversion_Unknown, _("Auto"))])
1016                         # WORKAROUND: we can't use BW-auto
1017                         self.scan_ter.bandwidth = ConfigSelection(default = defaultTer["bandwidth"], choices = [
1018                                 (eDVBFrontendParametersTerrestrial.Bandwidth_8MHz, "8MHz"),
1019                                 (eDVBFrontendParametersTerrestrial.Bandwidth_7MHz, "7MHz"),
1020                                 (eDVBFrontendParametersTerrestrial.Bandwidth_6MHz, "6MHz")])
1021                         self.scan_ter.bandwidth_t2 = ConfigSelection(default = defaultTer["bandwidth"], choices = [
1022                                 (eDVBFrontendParametersTerrestrial.Bandwidth_10MHz, "10MHz"),
1023                                 (eDVBFrontendParametersTerrestrial.Bandwidth_8MHz, "8MHz"),
1024                                 (eDVBFrontendParametersTerrestrial.Bandwidth_7MHz, "7MHz"),
1025                                 (eDVBFrontendParametersTerrestrial.Bandwidth_6MHz, "6MHz"),
1026                                 (eDVBFrontendParametersTerrestrial.Bandwidth_5MHz, "5MHz"),
1027                                 (eDVBFrontendParametersTerrestrial.Bandwidth_1_712MHz, "1.712MHz")])
1028                         #, (eDVBFrontendParametersTerrestrial.Bandwidth_Auto, _("Auto"))))
1029                         self.scan_ter.fechigh = ConfigSelection(default = defaultTer["fechigh"], choices = [
1030                                 (eDVBFrontendParametersTerrestrial.FEC_1_2, "1/2"),
1031                                 (eDVBFrontendParametersTerrestrial.FEC_2_3, "2/3"),
1032                                 (eDVBFrontendParametersTerrestrial.FEC_3_4, "3/4"),
1033                                 (eDVBFrontendParametersTerrestrial.FEC_5_6, "5/6"),
1034                                 (eDVBFrontendParametersTerrestrial.FEC_7_8, "7/8"),
1035                                 (eDVBFrontendParametersTerrestrial.FEC_Auto, _("Auto"))])
1036                         self.scan_ter.fechigh_t2 = ConfigSelection(default = defaultTer["fechigh"], choices = [
1037                                 (eDVBFrontendParametersTerrestrial.FEC_1_2, "1/2"),
1038                                 (eDVBFrontendParametersTerrestrial.FEC_2_3, "2/3"),
1039                                 (eDVBFrontendParametersTerrestrial.FEC_3_4, "3/4"),
1040                                 (eDVBFrontendParametersTerrestrial.FEC_5_6, "5/6"),
1041                                 (eDVBFrontendParametersTerrestrial.FEC_6_7, "6/7"),
1042                                 (eDVBFrontendParametersTerrestrial.FEC_7_8, "7/8"),
1043                                 (eDVBFrontendParametersTerrestrial.FEC_8_9, "8/9"),
1044                                 (eDVBFrontendParametersTerrestrial.FEC_Auto, _("Auto"))])
1045                         self.scan_ter.feclow = ConfigSelection(default = defaultTer["feclow"], choices = [
1046                                 (eDVBFrontendParametersTerrestrial.FEC_1_2, "1/2"),
1047                                 (eDVBFrontendParametersTerrestrial.FEC_2_3, "2/3"),
1048                                 (eDVBFrontendParametersTerrestrial.FEC_3_4, "3/4"),
1049                                 (eDVBFrontendParametersTerrestrial.FEC_5_6, "5/6"),
1050                                 (eDVBFrontendParametersTerrestrial.FEC_7_8, "7/8"),
1051                                 (eDVBFrontendParametersTerrestrial.FEC_Auto, _("Auto"))])
1052                         self.scan_ter.feclow_t2 = ConfigSelection(default = defaultTer["feclow"], choices = [
1053                                 (eDVBFrontendParametersTerrestrial.FEC_1_2, "1/2"),
1054                                 (eDVBFrontendParametersTerrestrial.FEC_2_3, "2/3"),
1055                                 (eDVBFrontendParametersTerrestrial.FEC_3_4, "3/4"),
1056                                 (eDVBFrontendParametersTerrestrial.FEC_5_6, "5/6"),
1057                                 (eDVBFrontendParametersTerrestrial.FEC_6_7, "6/7"),
1058                                 (eDVBFrontendParametersTerrestrial.FEC_7_8, "7/8"),
1059                                 (eDVBFrontendParametersTerrestrial.FEC_8_9, "8/9"),
1060                                 (eDVBFrontendParametersTerrestrial.FEC_Auto, _("Auto"))])
1061                         self.scan_ter.modulation = ConfigSelection(default = defaultTer["modulation"], choices = [
1062                                 (eDVBFrontendParametersTerrestrial.Modulation_QPSK, "QPSK"),
1063                                 (eDVBFrontendParametersTerrestrial.Modulation_QAM16, "QAM16"),
1064                                 (eDVBFrontendParametersTerrestrial.Modulation_QAM64, "QAM64"),
1065                                 (eDVBFrontendParametersTerrestrial.Modulation_Auto, _("Auto"))])
1066                         self.scan_ter.modulation_t2 = ConfigSelection(default = defaultTer["modulation"], choices = [
1067                                 (eDVBFrontendParametersTerrestrial.Modulation_QPSK, "QPSK"),
1068                                 (eDVBFrontendParametersTerrestrial.Modulation_QAM16, "QAM16"),
1069                                 (eDVBFrontendParametersTerrestrial.Modulation_QAM64, "QAM64"),
1070                                 (eDVBFrontendParametersTerrestrial.Modulation_QAM256, "QAM256"),
1071                                 (eDVBFrontendParametersTerrestrial.Modulation_Auto, _("Auto"))])
1072                         self.scan_ter.transmission = ConfigSelection(default = defaultTer["transmission_mode"], choices = [
1073                                 (eDVBFrontendParametersTerrestrial.TransmissionMode_2k, "2K"),
1074                                 (eDVBFrontendParametersTerrestrial.TransmissionMode_8k, "8K"),
1075                                 (eDVBFrontendParametersTerrestrial.TransmissionMode_Auto, _("Auto"))])
1076                         self.scan_ter.transmission_t2 = ConfigSelection(default = defaultTer["transmission_mode"], choices = [
1077                                 (eDVBFrontendParametersTerrestrial.TransmissionMode_1k, "1K"),
1078                                 (eDVBFrontendParametersTerrestrial.TransmissionMode_2k, "2K"),
1079                                 (eDVBFrontendParametersTerrestrial.TransmissionMode_4k, "4K"),
1080                                 (eDVBFrontendParametersTerrestrial.TransmissionMode_8k, "8K"),
1081                                 (eDVBFrontendParametersTerrestrial.TransmissionMode_16k, "16K"),
1082                                 (eDVBFrontendParametersTerrestrial.TransmissionMode_32k, "32K"),
1083                                 (eDVBFrontendParametersTerrestrial.TransmissionMode_Auto, _("Auto"))])
1084                         self.scan_ter.guard = ConfigSelection(default = defaultTer["guard_interval"], choices = [
1085                                 (eDVBFrontendParametersTerrestrial.GuardInterval_1_32, "1/32"),
1086                                 (eDVBFrontendParametersTerrestrial.GuardInterval_1_16, "1/16"),
1087                                 (eDVBFrontendParametersTerrestrial.GuardInterval_1_8, "1/8"),
1088                                 (eDVBFrontendParametersTerrestrial.GuardInterval_1_4, "1/4"),
1089                                 (eDVBFrontendParametersTerrestrial.GuardInterval_Auto, _("Auto"))])
1090                         self.scan_ter.guard_t2 = ConfigSelection(default = defaultTer["guard_interval"], choices = [
1091                                 (eDVBFrontendParametersTerrestrial.GuardInterval_19_256, "19/256"),
1092                                 (eDVBFrontendParametersTerrestrial.GuardInterval_19_128, "19/128"),
1093                                 (eDVBFrontendParametersTerrestrial.GuardInterval_1_128, "1/128"),
1094                                 (eDVBFrontendParametersTerrestrial.GuardInterval_1_32, "1/32"),
1095                                 (eDVBFrontendParametersTerrestrial.GuardInterval_1_16, "1/16"),
1096                                 (eDVBFrontendParametersTerrestrial.GuardInterval_1_8, "1/8"),
1097                                 (eDVBFrontendParametersTerrestrial.GuardInterval_1_4, "1/4"),
1098                                 (eDVBFrontendParametersTerrestrial.GuardInterval_Auto, _("Auto"))])
1099                         self.scan_ter.hierarchy = ConfigSelection(default = defaultTer["hierarchy"], choices = [
1100                                 (eDVBFrontendParametersTerrestrial.Hierarchy_None, _("None")),
1101                                 (eDVBFrontendParametersTerrestrial.Hierarchy_1, "1"),
1102                                 (eDVBFrontendParametersTerrestrial.Hierarchy_2, "2"),
1103                                 (eDVBFrontendParametersTerrestrial.Hierarchy_4, "4"),
1104                                 (eDVBFrontendParametersTerrestrial.Hierarchy_Auto, _("Auto"))])
1105                         self.scan_ter.system = ConfigSelection(default = defaultTer["system"], choices = [
1106                                 (eDVBFrontendParametersTerrestrial.System_DVB_T, _("DVB-T")),
1107                                 (eDVBFrontendParametersTerrestrial.System_DVB_T2, _("DVB-T2"))])
1108                         self.scan_ter.plp_id = ConfigInteger(default = defaultTer["plp_id"], limits = (0, 255))
1109
1110                         self.scan_scansat = {}
1111                         for sat in nimmanager.satList:
1112                                 #print sat[1]
1113                                 self.scan_scansat[sat[0]] = ConfigYesNo(default = False)
1114
1115                         self.scan_satselection = []
1116                         for slot in nimmanager.nim_slots:
1117                                 if slot.isCompatible("DVB-S"):
1118                                         self.scan_satselection.append(getConfigSatlist(defaultSat["orbpos"], self.satList[slot.slot]))
1119                                 else:
1120                                         self.scan_satselection.append(None)
1121
1122                         return True
1123
1124         def keyLeft(self):
1125                 ConfigListScreen.keyLeft(self)
1126                 self.newConfig()
1127
1128         def keyRight(self):
1129                 ConfigListScreen.keyRight(self)
1130                 self.newConfig()
1131
1132         def updateStatus(self):
1133                 print "updatestatus"
1134
1135         def addSatTransponder(self, tlist, frequency, symbol_rate, polarisation, fec, inversion, orbital_position, system, modulation, rolloff, pilot, is_id, pls_mode, pls_code):
1136                 print "Add Sat: frequ: " + str(frequency) + " symbol: " + str(symbol_rate) + " pol: " + str(polarisation) + " fec: " + str(fec) + " inversion: " + str(inversion) + " modulation: " + str(modulation) + " system: " + str(system) + " rolloff" + str(rolloff) + " pilot" + str(pilot) + " is_id" + str(is_id) + " pls_mode" + str(pls_mode) + " pls_code" + str(pls_code)
1137                 print "orbpos: " + str(orbital_position)
1138                 parm = eDVBFrontendParametersSatellite()
1139                 parm.modulation = modulation
1140                 parm.system = system
1141                 parm.frequency = frequency * 1000
1142                 parm.symbol_rate = symbol_rate * 1000
1143                 parm.polarisation = polarisation
1144                 parm.fec = fec
1145                 parm.inversion = inversion
1146                 parm.orbital_position = orbital_position
1147                 parm.rolloff = rolloff
1148                 parm.pilot = pilot
1149                 parm.is_id = is_id
1150                 parm.pls_mode = pls_mode
1151                 parm.pls_code = pls_code
1152                 tlist.append(parm)
1153
1154         def addCabTransponder(self, tlist, frequency, symbol_rate, modulation, fec, inversion):
1155                 print "Add Cab: frequ: " + str(frequency) + " symbol: " + str(symbol_rate) + " pol: " + str(modulation) + " fec: " + str(fec) + " inversion: " + str(inversion)
1156                 parm = eDVBFrontendParametersCable()
1157                 parm.frequency = frequency * 1000
1158                 parm.symbol_rate = symbol_rate * 1000
1159                 parm.modulation = modulation
1160                 parm.fec = fec
1161                 parm.inversion = inversion
1162                 tlist.append(parm)
1163
1164         def addTerTransponder(self, tlist, *args, **kwargs):
1165                 tlist.append(buildTerTransponder(*args, **kwargs))
1166
1167         def keyGo(self):
1168                 START_SCAN =0
1169                 SEARCH_CABLE_TRANSPONDERS = 1
1170                 SEARCH_TERRESTRIAL2_TRANSPONDERS = 2
1171
1172                 if self.scan_nims.value == "":
1173                         return
1174                 tlist = []
1175                 flags = None
1176                 action = START_SCAN
1177                 removeAll = True
1178                 index_to_scan = int(self.scan_nims.value)
1179                 
1180                 if self.scan_nims == [ ]:
1181                         self.session.open(MessageBox, _("No tuner is enabled!\nPlease setup your tuner settings before you start a service scan."), MessageBox.TYPE_ERROR)
1182                         return
1183
1184                 nim = nimmanager.nim_slots[index_to_scan]
1185                 print "nim", nim.slot
1186                 if nim.isCompatible("DVB-S"):
1187                         print "is compatible with DVB-S"
1188                         if self.scan_type.value == "single_transponder":
1189                                 # these lists are generated for each tuner, so this has work.
1190                                 assert len(self.satList) > index_to_scan
1191                                 assert len(self.scan_satselection) > index_to_scan
1192                                 
1193                                 nimsats = self.satList[index_to_scan]
1194                                 selsatidx = self.scan_satselection[index_to_scan].index
1195
1196                                 modulation = self.scan_sat.modulation.value
1197                                 # however, the satList itself could be empty. in that case, "index" is 0 (for "None").
1198                                 if len(nimsats):
1199                                         orbpos = nimsats[selsatidx][0]
1200
1201                                         system = self.scan_sat.system.value
1202                                         if nim.isCompatible("DVB-S2X"):
1203                                                 system = self.scan_sat.system_dvbs2x.value
1204
1205                                         if system == eDVBFrontendParametersSatellite.System_DVB_S:
1206                                                 fec = self.scan_sat.fec.value
1207                                         elif system == eDVBFrontendParametersSatellite.System_DVB_S2:
1208                                                 fec = self.scan_sat.fec_s2.value
1209                                         elif system == eDVBFrontendParametersSatellite.System_DVB_S2X:
1210                                                 modulation = self.scan_sat.modulation_dvbs2x.value
1211                                                 if modulation == eDVBFrontendParametersSatellite.Modulation_QPSK:
1212                                                         fec = self.scan_sat.fec_s2x_qpsk.value
1213                                                 elif modulation == eDVBFrontendParametersSatellite.Modulation_8PSK:
1214                                                         fec = self.scan_sat.fec_s2x_8psk.value
1215                                                 elif modulation == eDVBFrontendParametersSatellite.Modulation_8APSK:
1216                                                         fec = self.scan_sat.fec_s2x_8apsk.value
1217                                                 elif modulation == eDVBFrontendParametersSatellite.Modulation_16APSK:
1218                                                         fec = self.scan_sat.fec_s2x_16apsk.value
1219                                                 elif modulation == eDVBFrontendParametersSatellite.Modulation_32APSK:
1220                                                         fec = self.scan_sat.fec_s2x_32apsk.value
1221                                         else:
1222                                                 fec = self.scan_sat.fec_s2.value
1223
1224                                         is_id = -1
1225                                         pls_mode = eDVBFrontendParametersSatellite.PLS_Unknown
1226                                         pls_code = 0
1227                                         if self.scan_sat.is_id_bool.value:
1228                                                 is_id = self.scan_sat.is_id.value
1229                                                 pls_mode = self.scan_sat.pls_mode.value
1230                                                 if pls_mode == eDVBFrontendParametersSatellite.PLS_Unknown:
1231                                                         pls_code = 0
1232                                                 else:
1233                                                         pls_code = self.scan_sat.pls_code.value
1234
1235                                         print "add sat transponder"
1236                                         self.addSatTransponder(tlist, self.scan_sat.frequency.value,
1237                                                                 self.scan_sat.symbolrate.value,
1238                                                                 self.scan_sat.polarization.value,
1239                                                                 fec,
1240                                                                 self.scan_sat.inversion.value,
1241                                                                 orbpos,
1242                                                                 system,
1243                                                                 modulation,
1244                                                                 self.scan_sat.rolloff.value,
1245                                                                 self.scan_sat.pilot.value,
1246                                                                 is_id,
1247                                                                 pls_mode,
1248                                                                 pls_code)
1249                                 removeAll = False
1250                         elif self.scan_type.value == "single_satellite":
1251                                 sat = self.satList[index_to_scan][self.scan_satselection[index_to_scan].index]
1252                                 getInitialTransponderList(tlist, sat[0])
1253                         elif self.scan_type.value.find("multisat") != -1:
1254                                 SatList = nimmanager.getSatListForNim(index_to_scan)
1255                                 for x in self.multiscanlist:
1256                                         if x[1].value:
1257                                                 print "   " + str(x[0])
1258                                                 getInitialTransponderList(tlist, x[0])
1259
1260                 elif nim.isCompatible("DVB-C"):
1261                         if self.scan_typecable.value == "single_transponder":
1262                                 self.addCabTransponder(tlist, self.scan_cab.frequency.value,
1263                                                                                           self.scan_cab.symbolrate.value,
1264                                                                                           self.scan_cab.modulation.value,
1265                                                                                           self.scan_cab.fec.value,
1266                                                                                           self.scan_cab.inversion.value)
1267                                 removeAll = False
1268                         elif self.scan_typecable.value == "complete":
1269                                 if config.Nims[index_to_scan].cable.scan_type.value == "provider":
1270                                         getInitialCableTransponderList(tlist, index_to_scan)
1271                                 else:
1272                                         action = SEARCH_CABLE_TRANSPONDERS
1273
1274                 elif nim.isCompatible("DVB-T"):
1275                         if self.scan_typeterrestrial.value == "single_transponder":
1276                                 if self.scan_ter.system.value == eDVBFrontendParametersTerrestrial.System_DVB_T:
1277                                         self.addTerTransponder(tlist,
1278                                                         self.scan_ter.frequency.value * 1000,
1279                                                         inversion = self.scan_ter.inversion.value,
1280                                                         bandwidth = self.scan_ter.bandwidth.value,
1281                                                         fechigh = self.scan_ter.fechigh.value,
1282                                                         feclow = self.scan_ter.feclow.value,
1283                                                         modulation = self.scan_ter.modulation.value,
1284                                                         transmission = self.scan_ter.transmission.value,
1285                                                         guard = self.scan_ter.guard.value,
1286                                                         hierarchy = self.scan_ter.hierarchy.value,
1287                                                         system = self.scan_ter.system.value,
1288                                                         plpid = self.scan_ter.plp_id.value)
1289                                 else:
1290                                         self.addTerTransponder(tlist,
1291                                                         self.scan_ter.frequency.value * 1000,
1292                                                         inversion = self.scan_ter.inversion.value,
1293                                                         bandwidth = self.scan_ter.bandwidth_t2.value,
1294                                                         fechigh = self.scan_ter.fechigh_t2.value,
1295                                                         feclow = self.scan_ter.feclow_t2.value,
1296                                                         modulation = self.scan_ter.modulation_t2.value,
1297                                                         transmission = self.scan_ter.transmission_t2.value,
1298                                                         guard = self.scan_ter.guard_t2.value,
1299                                                         hierarchy = self.scan_ter.hierarchy.value,
1300                                                         system = self.scan_ter.system.value,
1301                                                         plpid = self.scan_ter.plp_id.value)
1302                                 removeAll = False
1303                         elif self.scan_typeterrestrial.value == "complete":
1304                                 skip_t2 = True
1305                                 if nim.isCompatible("DVB-T2"):
1306                                         scan_util = len(self.terrestrialTransponderGetCmd(nim.slot)) and True or False
1307                                         if scan_util:
1308                                                 action = SEARCH_TERRESTRIAL2_TRANSPONDERS
1309                                         else:
1310                                                 skip_t2 = False
1311
1312                                 getInitialTerrestrialTransponderList(tlist, nimmanager.getTerrestrialDescription(index_to_scan), skip_t2)
1313
1314                 flags = self.scan_networkScan.value and eComponentScan.scanNetworkSearch or 0
1315
1316                 tmp = self.scan_clearallservices.value
1317                 if tmp == "yes":
1318                         flags |= eComponentScan.scanRemoveServices
1319                 elif tmp == "yes_hold_feeds":
1320                         flags |= eComponentScan.scanRemoveServices
1321                         flags |= eComponentScan.scanDontRemoveFeeds
1322
1323                 if tmp != "no" and not removeAll:
1324                         flags |= eComponentScan.scanDontRemoveUnscanned
1325
1326                 if self.scan_onlyfree.value:
1327                         flags |= eComponentScan.scanOnlyFree
1328
1329                 for x in self["config"].list:
1330                         x[1].save()
1331
1332                 if action == START_SCAN:
1333                         self.startScan(tlist, flags, index_to_scan)
1334                 elif action == SEARCH_CABLE_TRANSPONDERS:
1335                         self.flags = flags
1336                         self.feid = index_to_scan
1337                         self.tlist = []
1338                         self.startCableTransponderSearch(self.feid)
1339                 elif action == SEARCH_TERRESTRIAL2_TRANSPONDERS:
1340                         self.flags = flags
1341                         self.feid = index_to_scan
1342                         self.tlist = tlist
1343                         self.startTerrestrialTransponderSearch(self.feid, nimmanager.getTerrestrialDescription(self.feid))
1344
1345         def setCableTransponderSearchResult(self, tlist):
1346                 self.tlist = tlist
1347
1348         def cableTransponderSearchFinished(self):
1349                 if self.tlist is None:
1350                         self.tlist = []
1351                 else:
1352                         self.startScan(self.tlist, self.flags, self.feid)
1353
1354         def setTerrestrialTransponderSearchResult(self, tlist):
1355                 if tlist is not None:
1356                         self.tlist.extend(tlist)
1357
1358         def terrestrialTransponderSearchFinished(self):
1359                 if self.tlist is None:
1360                         self.tlist = []
1361                 else:
1362                         self.startScan(self.tlist, self.flags, self.feid)
1363
1364         def startScan(self, tlist, flags, feid):
1365                 if len(tlist):
1366                         # flags |= eComponentScan.scanSearchBAT
1367                         if self.finished_cb:
1368                                 self.session.openWithCallback(self.finished_cb, ServiceScan, [{"transponders": tlist, "feid": feid, "flags": flags}])
1369                         else:
1370                                 self.session.open(ServiceScan, [{"transponders": tlist, "feid": feid, "flags": flags}])
1371                 else:
1372                         if self.finished_cb:
1373                                 self.session.openWithCallback(self.finished_cb, MessageBox, _("Nothing to scan!\nPlease setup your tuner settings before you start a service scan."), MessageBox.TYPE_ERROR)
1374                         else:
1375                                 self.session.open(MessageBox, _("Nothing to scan!\nPlease setup your tuner settings before you start a service scan."), MessageBox.TYPE_ERROR)
1376
1377         def keyCancel(self):
1378                 for x in self["config"].list:
1379                         x[1].cancel()
1380                 self.close()
1381
1382 class ScanSimple(ConfigListScreen, Screen, CableTransponderSearchSupport, TerrestrialTransponderSearchSupport):
1383         def getNetworksForNim(self, nim):
1384                 if nim.isCompatible("DVB-S"):
1385                         networks = nimmanager.getSatListForNim(nim.slot)
1386                 elif not nim.empty:
1387                         networks = [ nim.getType() ] # "DVB-C" or "DVB-T". TODO: seperate networks for different C/T tuners, if we want to support that.
1388                 else:
1389                         # empty tuners provide no networks.
1390                         networks = [ ]
1391                 return networks
1392
1393         def __init__(self, session):
1394                 Screen.__init__(self, session)
1395
1396                 self["actions"] = ActionMap(["SetupActions"],
1397                 {
1398                         "ok": self.keyGo,
1399                         "cancel": self.keyCancel,
1400                 }, -2)
1401
1402                 self.list = []
1403                 tlist = []
1404
1405                 known_networks = [ ]
1406                 nims_to_scan = [ ]
1407                 self.finished_cb = None
1408
1409                 for nim in nimmanager.nim_slots:
1410                         # don't offer to scan nims if nothing is connected
1411                         if not nimmanager.somethingConnected(nim.slot):
1412                                 continue
1413
1414                         # collect networks provided by this tuner
1415                         need_scan = False
1416                         networks = self.getNetworksForNim(nim)
1417                         
1418                         print "nim %d provides" % nim.slot, networks
1419                         print "known:", known_networks
1420
1421                         # we only need to scan on the first tuner which provides a network.
1422                         # this gives the first tuner for each network priority for scanning.
1423                         for x in networks:
1424                                 if x not in known_networks:
1425                                         need_scan = True
1426                                         print x, "not in ", known_networks
1427                                         known_networks.append(x)
1428
1429                         if need_scan:
1430                                 nims_to_scan.append(nim)
1431
1432
1433                 if "DVB-T2" in known_networks: # we need to remove "DVB-T" when networks have "DVB-T2"
1434                         nims_dvb_t = []
1435                         for nim in nims_to_scan:
1436                                 if nim.getType() == "DVB-T":
1437                                         nims_dvb_t.append(nim)
1438
1439                         for nim in nims_dvb_t:
1440                                 nims_to_scan.remove(nim)
1441
1442                 # we save the config elements to use them on keyGo
1443                 self.nim_enable = [ ]
1444
1445                 if len(nims_to_scan):
1446                         self.scan_clearallservices = ConfigSelection(default = "yes", choices = [("no", _("no")), ("yes", _("yes")), ("yes_hold_feeds", _("yes (keep feeds)"))])
1447                         self.list.append(getConfigListEntry(_("Clear before scan"), self.scan_clearallservices))
1448
1449                         for nim in nims_to_scan:
1450                                 nimconfig = ConfigYesNo(default = True)
1451                                 nimconfig.nim_index = nim.slot
1452                                 self.nim_enable.append(nimconfig)
1453                                 self.list.append(getConfigListEntry(_("Scan ") + nim.slot_name + " (" + nim.friendly_type + ")", nimconfig))
1454
1455                 ConfigListScreen.__init__(self, self.list)
1456                 self["header"] = Label(_("Automatic Scan"))
1457                 self["footer"] = Label(_("Press OK to scan"))
1458
1459         def runAsync(self, finished_cb):
1460                 self.finished_cb = finished_cb
1461                 self.keyGo()
1462
1463         def keyGo(self):
1464                 self.scanList = []
1465                 self.known_networks = set()
1466                 self.nim_iter=0
1467                 self.buildTransponderList()
1468
1469         def buildTransponderList(self): # this method is called multiple times because of asynchronous stuff
1470                 APPEND_NOW = 0
1471                 SEARCH_CABLE_TRANSPONDERS = 1
1472                 SEARCH_TERRESTRIAL2_TRANSPONDERS = 2
1473                 action = APPEND_NOW
1474
1475                 n = self.nim_iter < len(self.nim_enable) and self.nim_enable[self.nim_iter] or None
1476                 self.nim_iter += 1
1477                 if n:
1478                         if n.value: # check if nim is enabled
1479                                 flags = 0
1480                                 nim = nimmanager.nim_slots[n.nim_index]
1481                                 networks = set(self.getNetworksForNim(nim))
1482
1483                                 # don't scan anything twice
1484                                 networks.discard(self.known_networks)
1485
1486                                 tlist = [ ]
1487                                 if nim.isCompatible("DVB-S"):
1488                                         # get initial transponders for each satellite to be scanned
1489                                         for sat in networks:
1490                                                 getInitialTransponderList(tlist, sat[0])
1491                                 elif nim.isCompatible("DVB-C"):
1492                                         if config.Nims[nim.slot].cable.scan_type.value == "provider":
1493                                                 getInitialCableTransponderList(tlist, nim.slot)
1494                                         else:
1495                                                 action = SEARCH_CABLE_TRANSPONDERS
1496                                 elif nim.isCompatible("DVB-T"):
1497                                         skip_t2 = True
1498                                         if nim.isCompatible("DVB-T2"):
1499                                                 scan_util = len(self.terrestrialTransponderGetCmd(nim.slot)) and True or False
1500                                                 if scan_util:
1501                                                         action = SEARCH_TERRESTRIAL2_TRANSPONDERS
1502                                                 else:
1503                                                         skip_t2 = False
1504                                         getInitialTerrestrialTransponderList(tlist, nimmanager.getTerrestrialDescription(nim.slot), skip_t2)
1505                                 else:
1506                                         assert False
1507
1508                                 flags |= eComponentScan.scanNetworkSearch #FIXMEEE.. use flags from cables / satellites / terrestrial.xml
1509                                 tmp = self.scan_clearallservices.value
1510                                 if tmp == "yes":
1511                                         flags |= eComponentScan.scanRemoveServices
1512                                 elif tmp == "yes_hold_feeds":
1513                                         flags |= eComponentScan.scanRemoveServices
1514                                         flags |= eComponentScan.scanDontRemoveFeeds
1515
1516                                 if action == APPEND_NOW:
1517                                         self.scanList.append({"transponders": tlist, "feid": nim.slot, "flags": flags})
1518                                 elif action == SEARCH_CABLE_TRANSPONDERS:
1519                                         self.flags = flags
1520                                         self.feid = nim.slot
1521                                         self.startCableTransponderSearch(nim.slot)
1522                                         return
1523                                 elif action == SEARCH_TERRESTRIAL2_TRANSPONDERS:
1524                                         self.tlist = tlist
1525                                         self.flags = flags
1526                                         self.feid = nim.slot
1527                                         self.startTerrestrialTransponderSearch(nim.slot, nimmanager.getTerrestrialDescription(nim.slot))
1528                                         return
1529                                 else:
1530                                         assert False
1531
1532                         self.buildTransponderList() # recursive call of this function !!!
1533                         return
1534                 # when we are here, then the recursion is finished and all enabled nims are checked
1535                 # so we now start the real transponder scan
1536                 self.startScan(self.scanList)
1537
1538         def startScan(self, scanList):
1539                 if len(scanList):
1540                         if self.finished_cb:
1541                                 self.session.openWithCallback(self.finished_cb, ServiceScan, scanList = scanList)
1542                         else:
1543                                 self.session.open(ServiceScan, scanList = scanList)
1544                 else:
1545                         if self.finished_cb:
1546                                 self.session.openWithCallback(self.finished_cb, MessageBox, _("Nothing to scan!\nPlease setup your tuner settings before you start a service scan."), MessageBox.TYPE_ERROR)
1547                         else:
1548                                 self.session.open(MessageBox, _("Nothing to scan!\nPlease setup your tuner settings before you start a service scan."), MessageBox.TYPE_ERROR)
1549
1550         def setCableTransponderSearchResult(self, tlist):
1551                 if tlist is not None:
1552                         self.scanList.append({"transponders": tlist, "feid": self.feid, "flags": self.flags})
1553
1554         def cableTransponderSearchFinished(self):
1555                 self.buildTransponderList()
1556
1557         def setTerrestrialTransponderSearchResult(self, tlist):
1558                 if tlist is not None:
1559                         self.tlist.extend(tlist)
1560                 if self.tlist is not None:
1561                         self.scanList.append({"transponders": self.tlist, "feid": self.feid, "flags": self.flags})
1562
1563         def terrestrialTransponderSearchFinished(self):
1564                 self.buildTransponderList()
1565
1566         def keyCancel(self):
1567                 self.close()
1568
1569         def Satexists(self, tlist, pos):
1570                 for x in tlist:
1571                         if x == pos:
1572                                 return 1
1573                 return 0
1574