- new automatic scan - scans everything the NIM can handle
[enigma2.git] / lib / python / Screens / ScanSetup.py
1 from Screen import Screen
2 from ServiceScan import *
3 from Components.config import *
4 from Components.ActionMap import NumberActionMap
5 from Components.ConfigList import ConfigList
6 from Components.config import config
7 from Components.config import getConfigListEntry
8 from Components.NimManager import nimmanager
9 from Components.Label import Label
10 from enigma import eDVBFrontendParametersSatellite, eComponentScan
11
12 def getInitialTransponderList(tlist, pos):
13         list = nimmanager.getTransponders(pos)
14
15         for x in list:
16                 if x[0] == 0:           #SAT
17                         parm = eDVBFrontendParametersSatellite()
18                         parm.frequency = x[1]
19                         parm.symbol_rate = x[2]
20                         parm.polarisation = x[3]#lookup_sat_polarisation[x[3]] # eDVBFrontendParametersSatellite.Polarisation.Vertical
21                         parm.fec = x[4]                 # eDVBFrontendParametersSatellite.FEC.f3_4;
22                         #parm.fec = 6                                   # AUTO
23                         #parm.inversion = 1     #eDVBFrontendParametersSatellite.Inversion.Off;
24                         parm.inversion = 2              #AUTO
25                         parm.orbital_position = pos
26                         tlist.append(parm)
27
28 def getInitialCableTransponderList(tlist, cable):
29         list = nimmanager.getTranspondersCable(cable)
30
31         for x in list:
32                 if x[0] == 1:           #CABLE
33                         parm = eDVBFrontendParametersCable()
34                         parm.frequency = x[1]
35                         parm.symbol_rate = x[2]
36                         parm.modulation = x[3] # AUTO
37                         parm.fec_inner = x[4] # AUTO
38                         parm.inversion = 2 # AUTO
39                         tlist.append(parm)
40
41 class ScanSetup(Screen):
42         def __init__(self, session):
43                 Screen.__init__(self, session)
44
45                 self.updateSatList()
46                 self.createConfig()
47
48
49                 self["actions"] = NumberActionMap(["SetupActions"],
50                 {
51                         "ok": self.keyGo,
52                         "cancel": self.keyCancel,
53                         "left": self.keyLeft,
54                         "right": self.keyRight,
55                         "1": self.keyNumberGlobal,
56                         "2": self.keyNumberGlobal,
57                         "3": self.keyNumberGlobal,
58                         "4": self.keyNumberGlobal,
59                         "5": self.keyNumberGlobal,
60                         "6": self.keyNumberGlobal,
61                         "7": self.keyNumberGlobal,
62                         "8": self.keyNumberGlobal,
63                         "9": self.keyNumberGlobal,
64                         "0": self.keyNumberGlobal
65                 }, -1)
66
67                 self.list = []
68                 self["config"] = ConfigList(self.list)
69                 self.createSetup()
70
71                 self["introduction"] = Label(_("Press OK to start the scan"))
72
73         def run(self):
74                 self.keyGo()
75
76         def updateSatList(self):
77                 self.satList = []
78                 for slot in nimmanager.nimslots:
79                         if (nimmanager.getNimType(slot.slotid) == nimmanager.nimType["DVB-S"]):
80                                 self.satList.append(nimmanager.getSatListForNim(slot.slotid))
81                         else:
82                                 self.satList.append(None)
83                                 
84         def createSetup(self):
85                 self.list = []
86                 self.multiscanlist = []
87                 print "ID: " + str(config.scan.nims.value)
88
89                 self.tunerEntry = getConfigListEntry(_("Tuner"), config.scan.nims)
90                 self.list.append(self.tunerEntry)
91                 
92                 self.typeOfScanEntry = None
93                 if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-S"]):
94                         self.typeOfScanEntry = getConfigListEntry(_("Type of scan"), config.scan.type)
95                         self.list.append(self.typeOfScanEntry)
96                 elif (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-C"]):
97                         self.typeOfScanEntry = getConfigListEntry(_("Type of scan"), config.scan.typecable)
98                         self.list.append(self.typeOfScanEntry)
99                 elif (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-T"]):
100                         self.typeOfScanEntry = getConfigListEntry(_("Type of scan"), config.scan.typeterrestrial)
101                         self.list.append(self.typeOfScanEntry)
102
103
104                 if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-S"]):
105
106                         if currentConfigSelectionElement(config.scan.type) == "single_transponder":
107                                 self.list.append(getConfigListEntry(_('Satellite'), config.scan.satselection[config.scan.nims.value]))
108                                 self.list.append(getConfigListEntry(_('Frequency'), config.scan.sat.frequency))
109                                 self.list.append(getConfigListEntry(_('Inversion'), config.scan.sat.inversion))
110                                 self.list.append(getConfigListEntry(_('Symbol Rate'), config.scan.sat.symbolrate))
111                                 self.list.append(getConfigListEntry(_("Polarity"), config.scan.sat.polarization))
112                                 self.list.append(getConfigListEntry(_("FEC"), config.scan.sat.fec))
113                         elif currentConfigSelectionElement(config.scan.type) == "single_satellite":
114                                 self.updateSatList()
115                                 print config.scan.satselection[config.scan.nims.value]
116                                 self.list.append(getConfigListEntry(_("Satellite"), config.scan.satselection[config.scan.nims.value]))
117                         elif currentConfigSelectionElement(config.scan.type) == "multisat":
118                                 # if (norotor)
119                                 tlist = []
120                                 SatList = nimmanager.getSatListForNim(config.scan.nims.value)
121         
122                                 for x in SatList:
123                                         if self.Satexists(tlist, x[1]) == 0:
124                                                 tlist.append(x[1])
125                                                 sat = configElement_nonSave(x[1], configSelection, 0, (("enable", _("Enable")), ("disable", _("Disable"))))
126                                                 configEntry = getConfigListEntry(nimmanager.getSatDescription(x[1]), sat)
127                                                 self.list.append(configEntry)
128                                                 self.multiscanlist.append(configEntry)
129                                 # if (rotor):
130                            # for sat in nimmanager.satList:
131                                 #       self.list.append(getConfigListEntry(sat[0], config.scan.scansat[sat[1]]))
132
133
134                 if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-C"]):
135                         if currentConfigSelectionElement(config.scan.typecable) == "single_transponder":
136                                 self.list.append(getConfigListEntry(_("Frequency"), config.scan.cab.frequency))
137                                 self.list.append(getConfigListEntry(_("Inversion"), config.scan.cab.inversion))
138                                 self.list.append(getConfigListEntry(_("Symbol Rate"), config.scan.cab.symbolrate))
139                                 self.list.append(getConfigListEntry(_("Modulation"), config.scan.cab.modulation))
140                                 self.list.append(getConfigListEntry(_("FEC"), config.scan.cab.fec))
141                                 self.list.append(getConfigListEntry(_("Network scan"), config.scan.cab.networkScan))
142                         elif currentConfigSelectionElement(config.scan.typecable) == "complete":
143                                 pass
144                                 
145                 if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-T"]):
146                         if currentConfigSelectionElement(config.scan.typeterrestrial) == "single_transponder":
147                                 self.list.append(getConfigListEntry(_("Frequency"), config.scan.ter.frequency))
148                                 self.list.append(getConfigListEntry(_("Inversion"), config.scan.ter.inversion))
149                                 self.list.append(getConfigListEntry(_("Bandwidth"), config.scan.ter.bandwidth))
150                                 self.list.append(getConfigListEntry(_("Code rate high"), config.scan.ter.fechigh))
151                                 self.list.append(getConfigListEntry(_("Code rate low"), config.scan.ter.feclow))
152                                 self.list.append(getConfigListEntry(_("Modulation"), config.scan.ter.modulation))
153                                 self.list.append(getConfigListEntry(_("Transmission mode"), config.scan.ter.transmission))
154                                 self.list.append(getConfigListEntry(_("Guard interval mode"), config.scan.ter.guard))
155                                 self.list.append(getConfigListEntry(_("Hierarchy mode"), config.scan.ter.hierarchy))
156                         elif currentConfigSelectionElement(config.scan.typeterrestrial) == "complete":
157                                 pass
158
159                 self["config"].list = self.list
160                 self["config"].l.setList(self.list)
161
162         def Satexists(self, tlist, pos):
163                 for x in tlist:
164                         if x == pos:
165                                 return 1
166                 return 0
167
168         def newConfig(self):
169                 print self["config"].getCurrent()
170                 if self["config"].getCurrent() == self.typeOfScanEntry:
171                         self.createSetup()
172                 if self["config"].getCurrent() == self.tunerEntry:
173                         self.createSetup()
174
175         def createConfig(self):
176                         config.scan = ConfigSubsection()
177                         config.scan.sat = ConfigSubsection()
178                         config.scan.cab = ConfigSubsection()
179                         config.scan.ter = ConfigSubsection()
180
181                         config.scan.type = configElement_nonSave("config.scan.type", configSelection, 0, (("single_transponder", _("Single transponder")), ("single_satellite", _("Single satellite")), ("multisat", _("Multisat"))))
182                         config.scan.typecable = configElement_nonSave("config.scan.typecable", configSelection, 0, (("single_transponder", _("Single transponder")), ("complete", _("Complete"))))
183                         config.scan.typeterrestrial = configElement_nonSave("config.scan.typeterrestrial", configSelection, 0, (("single_transponder", _("Single transponder")), ("complete", _("Complete"))))
184
185                         nimList = [ ]
186                         for nim in nimmanager.nimList():
187                                 nimList.append(nim[0])
188                         #nimList.append("all")
189                         config.scan.nims = configElement_nonSave("config.scan.nims", configSelection, 0, nimList)
190
191                         # sat
192                         config.scan.sat.frequency = configElement_nonSave("config.scan.sat.frequency", configSequence, [11836], configsequencearg.get("INTEGER", (1, 99999)))
193                         config.scan.sat.inversion = configElement_nonSave("config.scan.sat.inversion", configSelection, 2, (("off", _("off")), ("on", _("on")), _("Auto")))
194                         config.scan.sat.symbolrate = configElement_nonSave("config.scan.sat.symbolrate", configSequence, [27500], configsequencearg.get("INTEGER", (1, 99999)))
195                         config.scan.sat.polarization = configElement_nonSave("config.scan.sat.polarization", configSelection, 0, (("horizontal", _("horizontal")), ("vertical", _("vertical")),  ("circular_left", _("circular left")), ("circular_right", _("circular right"))))
196                         config.scan.sat.fec = configElement_nonSave("config.scan.sat.fec", configSelection, 7, (("auto", _("Auto")), ("1_2", "1/2"), ("2_3", "2/3"), ("3_4", "3/4"), ("5_6", "5/6"), ("7_8", "7/8"), ("none", _("None"))))
197
198                         # cable
199                         config.scan.cab.frequency = configElement_nonSave("config.scan.cab.frequency", configSequence, [466], configsequencearg.get("INTEGER", (50, 999)))
200                         config.scan.cab.inversion = configElement_nonSave("config.scan.cab.inversion", configSelection, 2, (("off", _("off")), ("on", _("on")), ("auto", _("Auto"))))
201                         config.scan.cab.modulation = configElement_nonSave("config.scan.cab.modulation", configSelection, 0, (("auto", _("Auto")), ("16qam", "16-QAM"), ("32qam", "32-QAM"), ("64qam", "64-QAM"), ("128qam", "128-QAM"), ("256qam", "256-QAM")))
202                         config.scan.cab.fec = configElement_nonSave("config.scan.cab.fec", configSelection, 0, (("auto", _("Auto")), ("1_2", "1/2"), ("2_3", "2/3"), ("3_4", "3/4"), ("5_6", "5/6"), ("7_8", "7/8"), ("8_9", "8/9"), ("none", _("None"))))
203                         config.scan.cab.symbolrate = configElement_nonSave("config.scan.cab.symbolrate", configSequence, [6900], configsequencearg.get("INTEGER", (1, 9999)))
204                         config.scan.cab.networkScan = configElement_nonSave("config.scan.cab.networkScan", configSelection, 0, (("no", _("no")), ("yes", _("yes"))))
205
206                         # terrestial
207                         config.scan.ter.frequency = configElement_nonSave("config.scan.ter.frequency", configSequence, [466], configsequencearg.get("INTEGER", (100, 900)))
208                         config.scan.ter.inversion = configElement_nonSave("config.scan.ter.inversion", configSelection, 2, (("off", _("off")), ("on", _("on")), ("auto", _("Auto"))))
209                         config.scan.ter.bandwidth = configElement_nonSave("config.scan.ter.bandwidth", configSelection, 3, (("8MHz", "8MHz"), ("7MHz", "7MHz"), ("6MHz", "6MHz"), ("auto", _("Auto"))))
210                         config.scan.ter.fechigh = configElement_nonSave("config.scan.ter.fechigh", configSelection, 6, (("none", _("None")), "1/2", "2/3", "3/4", "5/6", "7/8", _("Auto")))
211                         config.scan.ter.feclow = configElement_nonSave("config.scan.ter.feclow", configSelection, 6, (_("None"), ("1_2", "1/2"), ("2_3", "2/3"), ("3_4", "3/4"), ("5_6", "5/6"), ("7_8", "7/8"), ("auto", _("Auto"))))
212                         config.scan.ter.modulation = configElement_nonSave("config.scan.ter.modulation", configSelection, 2, (("qpsk", "QPSK"), ("qam16", "QAM16"), ("auto", _("Auto"))))
213                         config.scan.ter.transmission = configElement_nonSave("config.scan.ter.transmission", configSelection, 2, (("2k", "2K"), ("8k", "8K"), ("auto", _("Auto"))))
214                         config.scan.ter.guard = configElement_nonSave("config.scan.ter.guard", configSelection, 4, (("1_32", "1/32"), ("1_16", "1/16"), ("1_8", "1/8"), ("1_4", "1/4"), ("auto", _("Auto"))))
215                         config.scan.ter.hierarchy = configElement_nonSave("config.scan.ter.hierarchy", configSelection, 4, (("none", _("None")), ("1", "1"), ("2", "2"), ("4", "4"), ("auto", _("Auto"))))
216
217                         config.scan.scansat = {}
218                         for sat in nimmanager.satList:
219                                 #print sat[1]
220                                 config.scan.scansat[sat[1]] = configElement_nonSave("config.scan.scansat[" + str(sat[1]) + "]", configSelection, 0, (("yes", _("yes")), ("no", _("no"))))
221
222                         config.scan.satselection = []
223                         slotid = 0
224                         for slot in nimmanager.nimslots:
225                                 if (nimmanager.getNimType(slot.slotid) == nimmanager.nimType["DVB-S"]):
226                                         print str(slot.slotid) + " : " + str(self.satList)
227                                         config.scan.satselection.append(configElement_nonSave("config.scan.satselection[" + str(slot.slotid) + "]", configSatlist, 0, self.satList[slot.slotid]))
228                                 else:
229                                         config.scan.satselection.append(None)
230         def keyLeft(self):
231                 self["config"].handleKey(config.key["prevElement"])
232                 self.newConfig()
233
234         def keyRight(self):
235                 self["config"].handleKey(config.key["nextElement"])
236                 self.newConfig()
237
238         def keyNumberGlobal(self, number):
239                 print "You pressed number " + str(number)
240                 if (self["config"].getCurrent()[1].parent.enabled == True):
241                         self["config"].handleKey(config.key[str(number)])
242
243         def addSatTransponder(self, tlist, frequency, symbol_rate, polarisation, fec, inversion, orbital_position):
244                 print "Add Sat: frequ: " + str(frequency) + " symbol: " + str(symbol_rate) + " pol: " + str(polarisation) + " fec: " + str(fec) + " inversion: " + str(inversion)
245                 print "orbpos: " + str(orbital_position)
246                 parm = eDVBFrontendParametersSatellite()
247                 parm.frequency = frequency * 1000
248                 parm.symbol_rate = symbol_rate * 1000
249                 parm.polarisation = polarisation # eDVBFrontendParametersSatellite.Polarisation.Verti   
250                 parm.fec = fec                  # eDVBFrontendParametersSatellite.FEC.f3_4;
251                 #parm.fec = 6                                   # AUTO
252                 parm.inversion = inversion      #eDVBFrontendParametersSatellite.Inversion.Off;
253                 #parm.inversion = 2             #AUTO
254                 parm.orbital_position = int(orbital_position)
255                 tlist.append(parm)
256
257         # FIXME use correct parameters
258         def addCabTransponder(self, tlist, frequency, symbol_rate, modulation, fec, inversion):
259                 print "Add Cab: frequ: " + str(frequency) + " symbol: " + str(symbol_rate) + " pol: " + str(modulation) + " fec: " + str(fec) + " inversion: " + str(inversion)
260                 parm = eDVBFrontendParametersCable()
261                 parm.frequency = frequency * 1000
262                 parm.symbol_rate = symbol_rate * 1000
263                 parm.modulation = modulation # modulation # eDVBFrontendParametersSatellite.Polarisation.Verti  
264                 parm.fec = fec                  # eDVBFrontendParametersSatellite.FEC.f3_4;
265                 #parm.fec = 6                                   # AUTO
266                 parm.inversion = inversion      #eDVBFrontendParametersSatellite.Inversion.Off;
267                 #parm.inversion = 2             #AUTO
268                 tlist.append(parm)
269
270         # FIXME use correct parameters
271         def addTerTransponder(self, tlist, frequency):
272                 parm = eDVBFrontendParametersTerrestrial()
273                 
274                 parm.frequency = frequency * 1000000
275                 parm.inversion = 2  # eDVBFrontendParametersTerrestrial.Inversion.Unknown;
276                 parm.bandwidth = 0  #eDVBFrontendParametersTerrestrial.Bandwidth.Bw8MHz;
277                 parm.code_rate_HP = parm.code_rate_LP = 6 #eDVBFrontendParametersTerrestrial.FEC.fAuto;
278                 parm.modulation = 1 #eDVBFrontendParametersTerrestrial.Modulation.QAM16;
279                 parm.transmission_mode = 1 # eDVBFrontendParametersTerrestrial.TransmissionMode.TM8k;
280                 parm.guard_interval = 0 # eDVBFrontendParametersTerrestrial.GuardInterval.GI_1_32;
281                 parm.hierarchy = 0 #eDVBFrontendParametersTerrestrial.Hierarchy.HNone;
282                 tlist.append(parm)
283
284         def keyGo(self):
285                 tlist = []
286                 flags = 0
287                 if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-S"]):
288                         if currentConfigSelectionElement(config.scan.type) == "single_transponder":
289
290                                 self.addSatTransponder(tlist, config.scan.sat.frequency.value[0],
291                                                                                           config.scan.sat.symbolrate.value[0],
292                                                                                           config.scan.sat.polarization.value,
293                                                                                           config.scan.sat.fec.value,
294                                                                                           config.scan.sat.inversion.value,
295                                                                                           self.satList[config.scan.nims.value][config.scan.satselection[config.scan.nims.value].value][1])
296                         elif currentConfigSelectionElement(config.scan.type) == "single_satellite":
297                                 getInitialTransponderList(tlist, int(self.satList[config.scan.nims.value][config.scan.satselection[config.scan.nims.value].value][1]))
298                                 flags |= eComponentScan.scanNetworkSearch
299         
300                         elif currentConfigSelectionElement(config.scan.type) == "multisat":
301                                 SatList = nimmanager.getSatListForNim(config.scan.nims.value)
302         
303                                 for x in self.multiscanlist:
304                                         if x[1].parent.value == 0:
305                                                 print "   " + str(x[1].parent.configPath)
306                                                 getInitialTransponderList(tlist, x[1].parent.configPath)
307                                 flags |= eComponentScan.scanNetworkSearch
308
309                 elif (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-C"]):
310                         if currentConfigSelectionElement(config.scan.typecable) == "single_transponder":
311                                 self.addCabTransponder(tlist, config.scan.cab.frequency.value[0],
312                                                                                           config.scan.cab.symbolrate.value[0],
313                                                                                           config.scan.cab.modulation.value,
314                                                                                           config.scan.cab.fec.value,
315                                                                                           config.scan.cab.inversion.value)
316                                 if  currentConfigSelectionElement(config.scan.cab.networkScan) == "yes":
317                                         flags |= eComponentScan.scanNetworkSearch
318                         elif currentConfigSelectionElement(config.scan.typecable) == "complete":
319                                 getInitialCableTransponderList(tlist, nimmanager.getCableDescription(config.scan.nims.value))
320                                 flags |= eComponentScan.scanNetworkSearch
321
322                 elif (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-T"]):
323                         if currentConfigSelectionElement(config.scan.typeterrestrial) == "single_transponder":
324                                 self.addTerTransponder(tlist, 
325                                                                                   config.scan.ter.frequency.value[0])
326                         if currentConfigSelectionElement(config.scan.typeterrestrial) == "complete":
327                                 pass
328
329
330
331                 for x in self["config"].list:
332                         x[1].save()
333
334                 feid = config.scan.nims.value
335                 # flags |= eComponentScan.scanSearchBAT
336                 self.session.openWithCallback(self.doNothing, ServiceScan, [{"transponders": tlist, "feid": feid, "flags": flags}])
337
338                 #self.close()
339         def doNothing(self):
340                 pass
341
342         def keyCancel(self):
343                 for x in self["config"].list:
344                         x[1].cancel()
345                 self.close()
346
347 class ScanSimple(Screen):
348         def run(self):
349                 self.keyGo()
350
351         def keyGo(self):
352                 scanList = []
353                 for x in self.list:
354                         slotid = x[1].parent.configPath
355                         print "configpath:", x[1].parent.configPath, "-", currentConfigSelectionElement(x[1].parent)
356                         if currentConfigSelectionElement(x[1].parent) == "yes":
357                                 tlist = [ ]
358                                 if nimmanager.getNimType(x[1].parent.configPath) == nimmanager.nimType["DVB-S"]:
359                                         SatList = nimmanager.getSatListForNim(slotid)
360                                         for sat in SatList:
361                                                 getInitialTransponderList(tlist, sat[1])
362                                 elif nimmanager.getNimType(x[1].parent.configPath) == nimmanager.nimType["DVB-C"]:
363                                         getInitialCableTransponderList(tlist, nimmanager.getCableDescription(slotid))
364                                 scanList.append({"transponders": tlist, "feid": slotid, "flags": eComponentScan.scanNetworkSearch})
365                 self.session.openWithCallback(self.doNothing, ServiceScan, scanList = scanList)
366
367         def doNothing(self):
368                 pass
369         
370         def keyCancel(self):
371                 self.close()
372
373         def keyLeft(self):
374                 self["config"].handleKey(config.key["prevElement"])
375
376         def keyRight(self):
377                 self["config"].handleKey(config.key["nextElement"])
378
379         def Satexists(self, tlist, pos):
380                 for x in tlist:
381                         if x == pos:
382                                 return 1
383                 return 0
384
385         def __init__(self, session):
386                 Screen.__init__(self, session)
387
388                 self["actions"] = ActionMap(["SetupActions"],
389                 {
390                         "ok": self.keyGo,
391                         "cancel": self.keyCancel,
392                         "left": self.keyLeft,
393                         "right": self.keyRight,
394                 }, -1)
395
396                 self.list = []
397                 tlist = []
398
399                 for slotid in range(nimmanager.getNimSocketCount()):
400                         nim = configElement_nonSave(slotid, configSelection, 0, (("yes", _("yes")), ("no", _("no"))))
401                         self.list.append(getConfigListEntry(_("Scan NIM") + " " + str(slotid) + " (" + nimmanager.getNimTypeName(slotid) + ")", nim))
402
403                 self["config"] = ConfigList(self.list)
404                 self["header"] = Label(_("Automatic Scan"))
405                 self["footer"] = Label(_("Press OK to scan"))