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