scan: add allocateFrontendByIndex, so ServiceScan uses a fixed frontend ID - currentl...
[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         print pos
14         list = nimmanager.getTransponders(pos)
15
16         for x in list:
17                 if x[0] == 0:           #SAT
18                         parm = eDVBFrontendParametersSatellite()
19                         parm.frequency = x[1]
20                         parm.symbol_rate = x[2]
21                         parm.polarisation = x[3] # eDVBFrontendParametersSatellite.Polarisation.Vertical
22                         #parm.fec = x[4]                        # eDVBFrontendParametersSatellite.FEC.f3_4;
23                         parm.fec = 6                                    # AUTO
24                         #parm.inversion = 1     #eDVBFrontendParametersSatellite.Inversion.Off;
25                         parm.inversion = 2              #AUTO
26                         parm.orbital_position = pos
27                         tlist.append(parm)
28
29 class ScanSetup(Screen):
30         def __init__(self, session):
31                 Screen.__init__(self, session)
32
33                 self.updateSatList()
34                 self.createConfig()
35
36
37                 self["actions"] = NumberActionMap(["SetupActions"],
38                 {
39                         "ok": self.keyGo,
40                         "cancel": self.keyCancel,
41                         "left": self.keyLeft,
42                         "right": self.keyRight,
43                         "1": self.keyNumberGlobal,
44                         "2": self.keyNumberGlobal,
45                         "3": self.keyNumberGlobal,
46                         "4": self.keyNumberGlobal,
47                         "5": self.keyNumberGlobal,
48                         "6": self.keyNumberGlobal,
49                         "7": self.keyNumberGlobal,
50                         "8": self.keyNumberGlobal,
51                         "9": self.keyNumberGlobal,
52                         "0": self.keyNumberGlobal
53                 }, -1)
54
55                 self.list = []
56                 self["config"] = ConfigList(self.list)
57                 self.createSetup()
58
59                 self["introduction"] = Label("Press OK to start the scan")
60
61         def updateSatList(self):
62                 self.satList = []
63                 for slot in nimmanager.nimslots:
64                         self.satList.append(nimmanager.getSatListForNim(slot.slotid))
65
66         def createSetup(self):
67                 self.list = []
68
69                 self.list.append(getConfigListEntry("Type of scan", config.scan.type))
70                 self.list.append(getConfigListEntry("Tuner", config.scan.nims))
71
72                 # single transponder scan
73                 if (config.scan.type.value == 0):
74                         if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-S"]):
75                                 self.list.append(getConfigListEntry(_('Satellite'), config.scan.satselection[config.scan.nims.value]))
76                                 self.list.append(getConfigListEntry(_('Frequency'), config.scan.sat.frequency))
77                                 self.list.append(getConfigListEntry(_('Inversion'), config.scan.sat.inversion))
78                                 self.list.append(getConfigListEntry(_('Symbolrate'), config.scan.sat.symbolrate))
79                                 self.list.append(getConfigListEntry("Polarity", config.scan.sat.polarization))
80                                 self.list.append(getConfigListEntry("FEC", config.scan.sat.fec))
81                         if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-C"]):
82                                 self.list.append(getConfigListEntry("Frequency", config.scan.cab.frequency))
83                                 self.list.append(getConfigListEntry("Inversion", config.scan.cab.inversion))
84                                 self.list.append(getConfigListEntry("Symbolrate", config.scan.cab.symbolrate))
85                                 self.list.append(getConfigListEntry("Modulation", config.scan.cab.modulation))
86                                 self.list.append(getConfigListEntry("FEC", config.scan.cab.fec))
87                         if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-T"]):
88                                 self.list.append(getConfigListEntry("Frequency", config.scan.ter.frequency))
89                                 self.list.append(getConfigListEntry("Inversion", config.scan.ter.inversion))
90                                 self.list.append(getConfigListEntry("Bandwidth", config.scan.ter.bandwidth))
91                                 self.list.append(getConfigListEntry("Code rate high", config.scan.ter.fechigh))
92                                 self.list.append(getConfigListEntry("Code rate low", config.scan.ter.feclow))
93                                 self.list.append(getConfigListEntry("Modulation", config.scan.ter.modulation))
94                                 self.list.append(getConfigListEntry("Transmission mode", config.scan.ter.transmission))
95                                 self.list.append(getConfigListEntry("Guard interval mode", config.scan.ter.guard))
96                                 self.list.append(getConfigListEntry("Hierarchy mode", config.scan.ter.hierarchy))
97
98                 # single satellite scan
99                 print config.scan.satselection
100                 if (config.scan.type.value == 1):
101                         self.updateSatList()
102                         print config.scan.satselection[config.scan.nims.value]
103                         self.list.append(getConfigListEntry("Satellite", config.scan.satselection[config.scan.nims.value]))
104
105
106                 # multi sat scan
107                 if (config.scan.type.value == 2):
108                         # if (norotor)
109                         tlist = []
110                         SatList = nimmanager.getSatListForNim(config.scan.nims.value)
111
112                         for x in SatList:
113                                 if self.Satexists(tlist, x[1]) == 0:
114                                         tlist.append(x[1])
115                                         sat = configElement_nonSave(x[1], configSelection, 0, ("Enable", "Disable"))
116                                         self.list.append(getConfigListEntry(nimmanager.getSatDescription(x[1]), sat))
117
118                         # if (rotor):
119                    # for sat in nimmanager.satList:
120                         #       self.list.append(getConfigListEntry(sat[0], config.scan.scansat[sat[1]]))
121
122                 self["config"].list = self.list
123                 self["config"].l.setList(self.list)
124
125         def Satexists(self, tlist, pos):
126                 for x in tlist:
127                         if x == pos:
128                                 return 1
129                 return 0
130
131         def newConfig(self):
132                 print self["config"].getCurrent()
133                 if self["config"].getCurrent()[0] == "Type of scan":
134                         self.createSetup()
135                 if self["config"].getCurrent()[0] == "Tuner":
136                         self.createSetup()
137
138         def createConfig(self):
139                         config.scan = ConfigSubsection()
140                         config.scan.sat = ConfigSubsection()
141                         config.scan.cab = ConfigSubsection()
142                         config.scan.ter = ConfigSubsection()
143
144                         config.scan.type = configElement_nonSave("config.scan.type", configSelection, 0, ("Single transponder", "Single satellite", "Multisat"))
145                         nimList = [ ]
146                         for nim in nimmanager.nimList():
147                                 nimList.append(nim[0])
148                         nimList.append("all")
149                         config.scan.nims = configElement_nonSave("config.scan.nims", configSelection, 0, nimList)
150
151                         # sat
152                         config.scan.sat.frequency = configElement_nonSave("config.scan.sat.frequency", configSequence, [11836], configsequencearg.get("INTEGER", (10000, 14000)))
153                         config.scan.sat.inversion = configElement_nonSave("config.scan.sat.inversion", configSelection, 2, ("on", "off", "auto"))
154                         config.scan.sat.symbolrate = configElement_nonSave("config.scan.sat.symbolrate", configSequence, [27500], configsequencearg.get("INTEGER", (1, 30000)))
155                         config.scan.sat.polarization = configElement_nonSave("config.scan.sat.polarization", configSelection, 0, ("horizontal", "vertical",  "circular left", "circular right"))
156                         config.scan.sat.fec = configElement_nonSave("config.scan.sat.fec", configSelection, 7, ("None", "1/2", "2/3", "3/4", "5/6", "7/8", "auto"))
157
158
159                         # cable
160                         config.scan.cab.frequency = configElement_nonSave("config.scan.cab.frequency", configSequence, [466], configsequencearg.get("INTEGER", (10000, 14000)))
161                         config.scan.cab.inversion = configElement_nonSave("config.scan.cab.inversion", configSelection, 0, ("auto", "off", "on"))
162                         config.scan.cab.modulation = configElement_nonSave("config.scan.cab.modulation", configSelection, 0, ("Auto", "16-QAM", "32-QAM", "64-QAM", "128-QAM", "256-QAM"))
163                         config.scan.cab.fec = configElement_nonSave("config.scan.cab.fec", configSelection, 0, ("Auto", "1/2", "2/3", "3/4", "4/5", "5/6", "7/8", "8/9"))
164                         config.scan.cab.symbolrate = configElement_nonSave("config.scan.cab.symbolrate", configSequence, [6900], configsequencearg.get("INTEGER", (1, 30000)))
165
166                         # terrestial
167                         config.scan.ter.frequency = configElement_nonSave("config.scan.ter.frequency", configSequence, [466], configsequencearg.get("INTEGER", (10000, 14000)))
168                         config.scan.ter.inversion = configElement_nonSave("config.scan.ter.inversion", configSelection, 0, ("auto", "off", "on"))
169                         config.scan.ter.bandwidth = configElement_nonSave("config.scan.ter.bandwidth", configSelection, 0, ("Auto", "6 MHz", "7MHz", "8MHz"))
170                         config.scan.ter.fechigh = configElement_nonSave("config.scan.ter.fechigh", configSelection, 0, ("Auto", "1/2", "2/3", "3/4", "4/5", "5/6", "7/8", "8/9"))
171                         config.scan.ter.feclow = configElement_nonSave("config.scan.ter.feclow", configSelection, 0, ("Auto", "1/2", "2/3", "3/4", "4/5", "5/6", "7/8", "8/9"))
172                         config.scan.ter.modulation = configElement_nonSave("config.scan.ter.modulation", configSelection, 0, ("Auto", "16-QAM", "32-QAM", "64-QAM", "128-QAM", "256-QAM"))
173                         config.scan.ter.transmission = configElement_nonSave("config.scan.ter.transmission", configSelection, 0, ("Auto", "2K", "8K"))
174                         config.scan.ter.guard = configElement_nonSave("config.scan.ter.guard", configSelection, 0, ("Auto", "1/4", "1/8", "1/16", "1/32"))
175                         config.scan.ter.hierarchy = configElement_nonSave("config.scan.ter.hierarchy", configSelection, 0, ("Auto", "1", "2", "4"))
176
177                         config.scan.scansat = {}
178                         for sat in nimmanager.satList:
179                                 #print sat[1]
180                                 config.scan.scansat[sat[1]] = configElement_nonSave("config.scan.scansat[" + str(sat[1]) + "]", configSelection, 0, ("yes", "no"))
181
182                         config.scan.satselection = []
183                         slotid = 0
184                         for slot in nimmanager.nimslots:
185                                 config.scan.satselection.append(configElement_nonSave("config.scan.satselection[" + str(slot.slotid) + "]", configSatlist, 0, self.satList[slot.slotid]))
186
187         def keyLeft(self):
188                 self["config"].handleKey(config.key["prevElement"])
189                 self.newConfig()
190
191         def keyRight(self):
192                 self["config"].handleKey(config.key["nextElement"])
193                 self.newConfig()
194
195         def keyNumberGlobal(self, number):
196                 print "You pressed number " + str(number)
197                 if (self["config"].getCurrent()[1].parent.enabled == True):
198                         self["config"].handleKey(config.key[str(number)])
199
200         def addSatTransponder(self, tlist, frequency, symbol_rate, polarisation, fec, inversion, orbital_position):
201                 print "Add Sat: frequ: " + str(frequency) + " symbol: " + str(symbol_rate) + " pol: " + str(polarisation) + " fec: " + str(fec) + " inversion: " + str(inversion)
202                 print "orbpos: " + str(orbital_position)
203                 parm = eDVBFrontendParametersSatellite()
204                 parm.frequency = frequency * 1000
205                 parm.symbol_rate = symbol_rate * 1000
206                 parm.polarisation = polarisation # eDVBFrontendParametersSatellite.Polarisation.Verti   
207                 parm.fec = fec                  # eDVBFrontendParametersSatellite.FEC.f3_4;
208                 #parm.fec = 6                                   # AUTO
209                 parm.inversion = inversion      #eDVBFrontendParametersSatellite.Inversion.Off;
210                 #parm.inversion = 2             #AUTO
211                 parm.orbital_position = int(orbital_position)
212                 tlist.append(parm)
213
214         # FIXME use correct parameters
215         def addCabTransponder(self, tlist, frequency, symbol_rate, polarisation, fec, inversion, orbital_position):
216                 print "Add Sat: frequ: " + str(frequency) + " symbol: " + str(symbol_rate) + " pol: " + str(polarisation) + " fec: " + str(fec) + " inversion: " + str(inversion)
217                 print "orbpos: " + str(orbital_position)
218                 parm = eDVBFrontendParametersCable()
219                 parm.frequency = frequency * 1000
220                 parm.symbol_rate = symbol_rate * 1000
221                 parm.polarisation = polarisation # eDVBFrontendParametersSatellite.Polarisation.Verti   
222                 parm.fec = fec                  # eDVBFrontendParametersSatellite.FEC.f3_4;
223                 #parm.fec = 6                                   # AUTO
224                 parm.inversion = inversion      #eDVBFrontendParametersSatellite.Inversion.Off;
225                 #parm.inversion = 2             #AUTO
226                 parm.orbital_position = int(orbital_position)
227                 tlist.append(parm)
228
229         # FIXME use correct parameters
230         def addTerTransponder(self, tlist, frequency, symbol_rate, polarisation, fec, inversion, orbital_position):
231                 print "Add Sat: frequ: " + str(frequency) + " symbol: " + str(symbol_rate) + " pol: " + str(polarisation) + " fec: " + str(fec) + " inversion: " + str(inversion)
232                 print "orbpos: " + str(orbital_position)
233                 parm = eDVBFrontendParametersTerrestrial()
234                 parm.frequency = frequency * 1000
235                 parm.symbol_rate = symbol_rate * 1000
236                 parm.polarisation = polarisation # eDVBFrontendParametersSatellite.Polarisation.Verti   
237                 parm.fec = fec                  # eDVBFrontendParametersSatellite.FEC.f3_4;
238                 #parm.fec = 6                                   # AUTO
239                 parm.inversion = inversion      #eDVBFrontendParametersSatellite.Inversion.Off;
240                 #parm.inversion = 2             #AUTO
241                 parm.orbital_position = int(orbital_position)
242                 tlist.append(parm)
243
244         def keyGo(self):
245                 tlist = []
246                 flags = 0
247                 if (config.scan.type.value == 0): # single transponder scan
248                         if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-S"]):
249                                 self.addSatTransponder(tlist, config.scan.sat.frequency.value[0],
250                                                                                           config.scan.sat.symbolrate.value[0],
251                                                                                           config.scan.sat.polarization.value,
252                                                                                           config.scan.sat.fec.value,
253                                                                                           config.scan.sat.inversion.value,
254                                                                                           self.satList[config.scan.nims.value][config.scan.satselection[config.scan.nims.value].value][1])
255                         if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-C"]):
256                                 self.addCabTransponder(tlist, config.scan.cab.frequency.value[0],
257                                                                                           config.scan.cab.symbolrate.value[0],
258                                                                                           config.scan.cab.polarization.value,
259                                                                                           config.scan.cab.fec.value,
260                                                                                           config.scan.cab.inversion.value,
261                                                                                           self.satList[config.scan.nims.value][config.scan.satselection[config.scan.nims.value].value][1])
262                         if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-T"]):
263                                 self.addTerTransponder(tlist, config.scan.sat.frequency.value[0],
264                                                                                           config.scan.sat.symbolrate.value[0],
265                                                                                           config.scan.sat.polarization.value,
266                                                                                           config.scan.sat.fec.value,
267                                                                                           config.scan.sat.inversion.value,
268                                                                                           self.satList[config.scan.nims.value][config.scan.satselection[config.scan.nims.value].value][1])
269
270                 if (config.scan.type.value == 1): # single sat scan
271                         getInitialTransponderList(tlist, int(self.satList[config.scan.nims.value][config.scan.satselection[config.scan.nims.value].value][1]))
272                         flags |= eComponentScan.scanNetworkSearch
273
274                 if (config.scan.type.value == 2): # multi sat scan
275                         SatList = nimmanager.getSatListForNim(config.scan.nims.value)
276
277                         for x in self.list:
278                                 if x[1].parent.value == 0:
279                                         print "   " + str(x[1].parent.configPath)
280                                         getInitialTransponderList(tlist, x[1].parent.configPath)
281                         flags |= eComponentScan.scanNetworkSearch
282
283                 for x in self["config"].list:
284                         x[1].save()
285
286                 feid = 0 # insert correct frontend id here (should be user-selectable)
287                 # flags |= eComponentScan.scanSearchBAT
288                 self.session.openWithCallback(self.keyCancel, ServiceScan, tlist, feid, flags)
289
290                 #self.close()
291
292         def keyCancel(self):
293                 for x in self["config"].list:
294                         x[1].cancel()
295                 self.close()
296
297 class ScanSimple(Screen):
298
299         def keyOK(self):
300                 print "start scan for sats:"
301                 tlist = [ ]
302                 for x in self.list:
303                         if x[1].parent.value == 0:
304                                 print "   " + str(x[1].parent.configPath)
305                                 getInitialTransponderList(tlist, x[1].parent.configPath)
306
307                 feid = 0 # FIXME
308                 self.session.openWithCallback(self.keyCancel, ServiceScan, tlist, feid, eComponentScan.scanNetworkSearch)
309
310         def keyCancel(self):
311                 self.close()
312
313         def keyLeft(self):
314                 self["config"].handleKey(config.key["prevElement"])
315
316         def keyRight(self):
317                 self["config"].handleKey(config.key["nextElement"])
318
319         def Satexists(self, tlist, pos):
320                 for x in tlist:
321                         if x == pos:
322                                 return 1
323                 return 0
324
325         def __init__(self, session):
326                 Screen.__init__(self, session)
327
328                 self["actions"] = ActionMap(["SetupActions"],
329                 {
330                         "ok": self.keyOK,
331                         "cancel": self.keyCancel,
332                         "left": self.keyLeft,
333                         "right": self.keyRight,
334                 }, -1)
335
336                 self.list = []
337                 tlist = []
338
339                 SatList = nimmanager.getConfiguredSats()
340
341                 for x in SatList:
342                         if self.Satexists(tlist, x) == 0:
343                                 tlist.append(x)
344                                 sat = configElement_nonSave(x, configSelection, 0, ("Enable", "Disable"))
345                                 self.list.append(getConfigListEntry(nimmanager.getSatDescription(x), sat))
346
347                 self["config"] = ConfigList(self.list)
348                 self["header"] = Label("Automatic Scan")
349                 self["footer"] = Label("Press OK to scan")