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