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