cd9a8f94028113f33144ad0a71e579b85c1e1c5f
[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", 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 def getInitialCableTransponderList(tlist, cable):
30         print "cable", cable
31         list = nimmanager.getTranspondersCable(cable)
32
33         for x in list:
34                 if x[0] == 1:           #CABLE
35                         print "[ScanSetup] cable-transponder to add:", x
36                         parm = eDVBFrontendParametersCable()
37                         parm.frequency = x[1]
38                         parm.symbol_rate = x[2]
39                         parm.modulation = 2 # x[3] # eDVBFrontendParametersSatellite.Polarisation.Verti 
40                         parm.fec = 6# x[4]                      # eDVBFrontendParametersSatellite.FEC.f3_4;
41                         #parm.fec = 6                                   # AUTO
42                         parm.inversion = 2 # AUTO
43                         #parm.inversion = 2             #AUTO
44                         tlist.append(parm)
45
46 class ScanSetup(Screen):
47         def __init__(self, session):
48                 Screen.__init__(self, session)
49
50                 self.updateSatList()
51                 self.createConfig()
52
53
54                 self["actions"] = NumberActionMap(["SetupActions"],
55                 {
56                         "ok": self.keyGo,
57                         "cancel": self.keyCancel,
58                         "left": self.keyLeft,
59                         "right": self.keyRight,
60                         "1": self.keyNumberGlobal,
61                         "2": self.keyNumberGlobal,
62                         "3": self.keyNumberGlobal,
63                         "4": self.keyNumberGlobal,
64                         "5": self.keyNumberGlobal,
65                         "6": self.keyNumberGlobal,
66                         "7": self.keyNumberGlobal,
67                         "8": self.keyNumberGlobal,
68                         "9": self.keyNumberGlobal,
69                         "0": self.keyNumberGlobal
70                 }, -1)
71
72                 self.list = []
73                 self["config"] = ConfigList(self.list)
74                 self.createSetup()
75
76                 self["introduction"] = Label(_("Press OK to start the scan"))
77
78         def updateSatList(self):
79                 self.satList = []
80                 for slot in nimmanager.nimslots:
81                         if (nimmanager.getNimType(slot.slotid) == nimmanager.nimType["DVB-S"]):
82                                 self.satList.append(nimmanager.getSatListForNim(slot.slotid))
83                         else:
84                                 self.satList.append(None)
85                                 
86         def createSetup(self):
87                 self.list = []
88                 self.multiscanlist = []
89                 print "ID: " + str(config.scan.nims.value)
90
91                 self.tunerEntry = getConfigListEntry(_("Tuner"), config.scan.nims)
92                 self.list.append(self.tunerEntry)
93                 
94                 self.typeOfScanEntry = None
95                 if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-S"]):
96                         self.typeOfScanEntry = getConfigListEntry(_("Type of scan"), config.scan.type)
97                         self.list.append(self.typeOfScanEntry)
98                 elif (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-C"]):
99                         self.typeOfScanEntry = getConfigListEntry(_("Type of scan"), config.scan.typecable)
100                         self.list.append(self.typeOfScanEntry)
101                 elif (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-T"]):
102                         self.typeOfScanEntry = getConfigListEntry(_("Type of scan"), config.scan.typeterrestrial)
103                         self.list.append(self.typeOfScanEntry)
104
105
106                 if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-S"]):
107
108                         if currentConfigSelectionElement(config.scan.type) == "single_transponder":
109                                 self.list.append(getConfigListEntry(_('Satellite'), config.scan.satselection[config.scan.nims.value]))
110                                 self.list.append(getConfigListEntry(_('Frequency'), config.scan.sat.frequency))
111                                 self.list.append(getConfigListEntry(_('Inversion'), config.scan.sat.inversion))
112                                 self.list.append(getConfigListEntry(_('Symbol Rate'), config.scan.sat.symbolrate))
113                                 self.list.append(getConfigListEntry(_("Polarity"), config.scan.sat.polarization))
114                                 self.list.append(getConfigListEntry(_("FEC"), config.scan.sat.fec))
115                         elif currentConfigSelectionElement(config.scan.type) == "single_satellite":
116                                 self.updateSatList()
117                                 print config.scan.satselection[config.scan.nims.value]
118                                 self.list.append(getConfigListEntry(_("Satellite"), config.scan.satselection[config.scan.nims.value]))
119                         elif currentConfigSelectionElement(config.scan.type) == "multisat":
120                                 # if (norotor)
121                                 tlist = []
122                                 SatList = nimmanager.getSatListForNim(config.scan.nims.value)
123         
124                                 for x in SatList:
125                                         if self.Satexists(tlist, x[1]) == 0:
126                                                 tlist.append(x[1])
127                                                 sat = configElement_nonSave(x[1], configSelection, 0, (("enable", _("Enable")), ("disable", _("Disable"))))
128                                                 configEntry = getConfigListEntry(nimmanager.getSatDescription(x[1]), sat)
129                                                 self.list.append(configEntry)
130                                                 self.multiscanlist.append(configEntry)
131                                 # if (rotor):
132                            # for sat in nimmanager.satList:
133                                 #       self.list.append(getConfigListEntry(sat[0], config.scan.scansat[sat[1]]))
134
135
136                 if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-C"]):
137                         if currentConfigSelectionElement(config.scan.typecable) == "single_transponder":
138                                 self.list.append(getConfigListEntry(_("Frequency"), config.scan.cab.frequency))
139                                 self.list.append(getConfigListEntry(_("Inversion"), config.scan.cab.inversion))
140                                 self.list.append(getConfigListEntry(_("Symbol Rate"), config.scan.cab.symbolrate))
141                                 self.list.append(getConfigListEntry(_("Modulation"), config.scan.cab.modulation))
142                                 self.list.append(getConfigListEntry(_("FEC"), config.scan.cab.fec))
143                         elif currentConfigSelectionElement(config.scan.typecable) == "complete":
144                                 pass
145                                 
146                 if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-T"]):
147                         if currentConfigSelectionElement(config.scan.typeterrestrial) == "single_transponder":
148                                 self.list.append(getConfigListEntry(_("Frequency"), config.scan.ter.frequency))
149                                 self.list.append(getConfigListEntry(_("Inversion"), config.scan.ter.inversion))
150                                 self.list.append(getConfigListEntry(_("Bandwidth"), config.scan.ter.bandwidth))
151                                 self.list.append(getConfigListEntry(_("Code rate high"), config.scan.ter.fechigh))
152                                 self.list.append(getConfigListEntry(_("Code rate low"), config.scan.ter.feclow))
153                                 self.list.append(getConfigListEntry(_("Modulation"), config.scan.ter.modulation))
154                                 self.list.append(getConfigListEntry(_("Transmission mode"), config.scan.ter.transmission))
155                                 self.list.append(getConfigListEntry(_("Guard interval mode"), config.scan.ter.guard))
156                                 self.list.append(getConfigListEntry(_("Hierarchy mode"), config.scan.ter.hierarchy))
157                         elif currentConfigSelectionElement(config.scan.typeterrestrial) == "complete":
158                                 pass
159
160                 self["config"].list = self.list
161                 self["config"].l.setList(self.list)
162
163         def Satexists(self, tlist, pos):
164                 for x in tlist:
165                         if x == pos:
166                                 return 1
167                 return 0
168
169         def newConfig(self):
170                 print self["config"].getCurrent()
171                 if self["config"].getCurrent() == self.typeOfScanEntry:
172                         self.createSetup()
173                 if self["config"].getCurrent() == self.tunerEntry:
174                         self.createSetup()
175
176         def createConfig(self):
177                         config.scan = ConfigSubsection()
178                         config.scan.sat = ConfigSubsection()
179                         config.scan.cab = ConfigSubsection()
180                         config.scan.ter = ConfigSubsection()
181
182                         config.scan.type = configElement_nonSave("config.scan.type", configSelection, 0, (("single_transponder", _("Single transponder")), ("single_satellite", _("Single satellite")), ("multisat", _("Multisat"))))
183                         config.scan.typecable = configElement_nonSave("config.scan.typecable", configSelection, 0, (("single_transponder", _("Single transponder")), ("complete", _("Complete"))))
184                         config.scan.typeterrestrial = configElement_nonSave("config.scan.typeterrestrial", configSelection, 0, (("single_transponder", _("Single transponder")), ("complete", _("Complete"))))
185
186                         nimList = [ ]
187                         for nim in nimmanager.nimList():
188                                 nimList.append(nim[0])
189                         #nimList.append("all")
190                         config.scan.nims = configElement_nonSave("config.scan.nims", configSelection, 0, nimList)
191
192                         # sat
193                         config.scan.sat.frequency = configElement_nonSave("config.scan.sat.frequency", configSequence, [11836], configsequencearg.get("INTEGER", (1, 99999)))
194                         config.scan.sat.inversion = configElement_nonSave("config.scan.sat.inversion", configSelection, 2, (("off", _("off")), ("on", _("on")), _("Auto")))
195                         config.scan.sat.symbolrate = configElement_nonSave("config.scan.sat.symbolrate", configSequence, [27500], configsequencearg.get("INTEGER", (1, 99999)))
196                         config.scan.sat.polarization = configElement_nonSave("config.scan.sat.polarization", configSelection, 0, (("horizontal", _("horizontal")), ("vertical", _("vertical")),  ("circular_left", _("circular left")), ("circular_right", _("circular right"))))
197                         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"))))
198
199                         # cable
200                         config.scan.cab.frequency = configElement_nonSave("config.scan.cab.frequency", configSequence, [466], configsequencearg.get("INTEGER", (50, 9999)))
201                         config.scan.cab.inversion = configElement_nonSave("config.scan.cab.inversion", configSelection, 2, (("off", _("off")), ("on", _("on")), ("auto", _("Auto"))))
202                         config.scan.cab.modulation = configElement_nonSave("config.scan.cab.modulation", configSelection, 2, (("16qam", "16-QAM"), ("32qam", "32-QAM"), ("64qam", "64-QAM"), ("128qam", "128-QAM"), ("256qam", "256-QAM"), ("auto", _("Auto"))))
203                         config.scan.cab.fec = configElement_nonSave("config.scan.cab.fec", configSelection, 9, (("none", _("None")), ("1_2", "1/2"), ("2_3", "2/3"), ("3_4", "3/4"), ("5_6", "5/6"), ("7_8", "7/8"), ("auto", _("Auto"))))
204                         config.scan.cab.symbolrate = configElement_nonSave("config.scan.cab.symbolrate", configSequence, [6900], configsequencearg.get("INTEGER", (1, 9999)))
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 Sat: 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 # 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                         elif currentConfigSelectionElement(config.scan.typecable) == "complete":
317                                 getInitialCableTransponderList(tlist, nimmanager.getCableDescription(config.scan.nims.value))
318                                 flags |= eComponentScan.scanNetworkSearch
319
320                 elif (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-T"]):
321                         if currentConfigSelectionElement(config.scan.typeterrestrial) == "single_transponder":
322                                 self.addTerTransponder(tlist, 
323                                                                                   config.scan.ter.frequency.value[0])
324                         if currentConfigSelectionElement(config.scan.typeterrestrial) == "complete":
325                                 pass
326
327
328
329                 for x in self["config"].list:
330                         x[1].save()
331
332                 feid = config.scan.nims.value
333                 # flags |= eComponentScan.scanSearchBAT
334                 self.session.openWithCallback(self.doNothing, ServiceScan, tlist, feid, flags)
335
336                 #self.close()
337         def doNothing(self):
338                 pass
339
340         def keyCancel(self):
341                 for x in self["config"].list:
342                         x[1].cancel()
343                 self.close()
344
345 class ScanSimple(Screen):
346
347         def run(self):
348                 print "start scan for sats:"
349                 tlist = [ ]
350                 for x in self.list:
351                         if x[1].parent.value == 0:
352                                 print "   " + str(x[1].parent.configPath)
353                                 getInitialTransponderList(tlist, x[1].parent.configPath)
354
355                 feid = 0 # FIXME
356                 self.session.openWithCallback(self.doNothing, ServiceScan, tlist, feid, eComponentScan.scanNetworkSearch)
357                 
358
359         def keyGo(self):
360                 print "start scan for sats:"
361                 tlist = [ ]
362                 for x in self.list:
363                         if x[1].parent.value == 0:
364                                 print "   " + str(x[1].parent.configPath)
365                                 getInitialTransponderList(tlist, x[1].parent.configPath)
366
367                 feid = 0 # FIXME
368                 self.session.openWithCallback(self.doNothing, ServiceScan, tlist, feid, eComponentScan.scanNetworkSearch)
369
370         def doNothing(self):
371                 pass
372         
373         def keyCancel(self):
374                 self.close()
375
376         def keyLeft(self):
377                 self["config"].handleKey(config.key["prevElement"])
378
379         def keyRight(self):
380                 self["config"].handleKey(config.key["nextElement"])
381
382         def Satexists(self, tlist, pos):
383                 for x in tlist:
384                         if x == pos:
385                                 return 1
386                 return 0
387
388         def __init__(self, session):
389                 Screen.__init__(self, session)
390
391                 self["actions"] = ActionMap(["SetupActions"],
392                 {
393                         "ok": self.keyGo,
394                         "cancel": self.keyCancel,
395                         "left": self.keyLeft,
396                         "right": self.keyRight,
397                 }, -1)
398
399                 self.list = []
400                 tlist = []
401
402
403                 for slotid in nimmanager.getNimListOfType(nimmanager.nimType["DVB-S"]):
404                         SatList = nimmanager.getSatListForNim(slotid)
405
406                         for x in SatList:
407                                 if self.Satexists(tlist, x[1]) == 0:
408                                         tlist.append(x[1])
409                                         sat = configElement_nonSave(x[1], configSelection, 0, (("enable", _("Enable")), ("disable", _("Disable"))))
410                                         self.list.append(getConfigListEntry(nimmanager.getSatDescription(x[1]), sat))
411
412                 self["config"] = ConfigList(self.list)
413                 self["header"] = Label(_("Automatic Scan"))
414                 self["footer"] = Label(_("Press OK to scan"))